1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_bridges.hxx"
26
27 #include "jni.h"
28
29 #include "uno/mapping.hxx"
30 #include "uno/environment.hxx"
31 #include "jvmaccess/virtualmachine.hxx"
32 #include "jvmaccess/unovirtualmachine.hxx"
33 #include "cppuhelper/implbase1.hxx"
34
35 #include "test/java_uno/anytest/XTransport.hpp"
36 #include "test/java_uno/anytest/DerivedInterface.hpp"
37
38
39 using namespace ::com::sun::star::uno;
40 using ::test::java_uno::anytest::XTransport;
41 using ::rtl::OUString;
42
43 namespace
44 {
45 //==================================================================================================
46 class Transport : public ::cppu::WeakImplHelper1< XTransport >
47 {
48 public:
49 virtual Any SAL_CALL mapAny( Any const & any );
50 };
51 //__________________________________________________________________________________________________
mapAny(Any const & any)52 Any Transport::mapAny( Any const & any )
53 {
54 return any;
55 }
56 }
57
58 //##################################################################################################
Java_test_java_1uno_anytest_TestJni_create_1jni_1transport(JNIEnv * jni_env,jclass,jobject loader)59 extern "C" JNIEXPORT jobject JNICALL Java_test_java_1uno_anytest_TestJni_create_1jni_1transport(
60 JNIEnv * jni_env, jclass, jobject loader )
61 SAL_THROW_EXTERN_C()
62 {
63 // publish some idl types
64 ::getCppuType( (Reference< XTransport > const *)0 );
65 ::getCppuType( (Reference< ::test::java_uno::anytest::DerivedInterface > const *)0 );
66
67 Reference< XTransport > xRet( new Transport() );
68
69 // get java vm
70 JavaVM * java_vm;
71 OSL_VERIFY( 0 == jni_env->GetJavaVM( &java_vm ) );
72 // create jvmaccess vm
73 ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > vm;
74 try {
75 vm = new ::jvmaccess::UnoVirtualMachine(
76 new ::jvmaccess::VirtualMachine(
77 java_vm, JNI_VERSION_1_2, false, jni_env ),
78 loader );
79 } catch ( ::jvmaccess::UnoVirtualMachine::CreationException & ) {
80 OSL_ASSERT( false );
81 throw;
82 }
83 // create uno envs
84 OUString java_name( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_JAVA) );
85 OUString cpp_name( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) );
86 Environment java_env, cpp_env;
87 uno_getEnvironment( (uno_Environment **)&java_env, java_name.pData, vm.get() );
88 OSL_ASSERT( java_env.is() );
89 uno_getEnvironment( (uno_Environment **)&cpp_env, cpp_name.pData, 0 );
90 OSL_ASSERT( cpp_env.is() );
91
92 // map interface
93 Mapping mapping( cpp_env.get(), java_env.get() );
94 OSL_ASSERT( mapping.is() );
95 jobject jo_global = (jobject)mapping.mapInterface( xRet.get(), ::getCppuType( &xRet ) );
96 OSL_ASSERT( 0 != jo_global );
97
98 // return
99 jobject jo_ret = jni_env->NewLocalRef( jo_global );
100 jni_env->DeleteGlobalRef( jo_global );
101 return jo_ret;
102 }
103