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 throw (RuntimeException); 51 }; 52 //__________________________________________________________________________________________________ 53 Any Transport::mapAny( Any const & any ) 54 throw (RuntimeException) 55 { 56 return any; 57 } 58 } 59 60 //################################################################################################## 61 extern "C" JNIEXPORT jobject JNICALL Java_test_java_1uno_anytest_TestJni_create_1jni_1transport( 62 JNIEnv * jni_env, jclass, jobject loader ) 63 SAL_THROW_EXTERN_C() 64 { 65 // publish some idl types 66 ::getCppuType( (Reference< XTransport > const *)0 ); 67 ::getCppuType( (Reference< ::test::java_uno::anytest::DerivedInterface > const *)0 ); 68 69 Reference< XTransport > xRet( new Transport() ); 70 71 // get java vm 72 JavaVM * java_vm; 73 OSL_VERIFY( 0 == jni_env->GetJavaVM( &java_vm ) ); 74 // create jvmaccess vm 75 ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > vm; 76 try { 77 vm = new ::jvmaccess::UnoVirtualMachine( 78 new ::jvmaccess::VirtualMachine( 79 java_vm, JNI_VERSION_1_2, false, jni_env ), 80 loader ); 81 } catch ( ::jvmaccess::UnoVirtualMachine::CreationException & ) { 82 OSL_ASSERT( false ); 83 throw; 84 } 85 // create uno envs 86 OUString java_name( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_JAVA) ); 87 OUString cpp_name( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ); 88 Environment java_env, cpp_env; 89 uno_getEnvironment( (uno_Environment **)&java_env, java_name.pData, vm.get() ); 90 OSL_ASSERT( java_env.is() ); 91 uno_getEnvironment( (uno_Environment **)&cpp_env, cpp_name.pData, 0 ); 92 OSL_ASSERT( cpp_env.is() ); 93 94 // map interface 95 Mapping mapping( cpp_env.get(), java_env.get() ); 96 OSL_ASSERT( mapping.is() ); 97 jobject jo_global = (jobject)mapping.mapInterface( xRet.get(), ::getCppuType( &xRet ) ); 98 OSL_ASSERT( 0 != jo_global ); 99 100 // return 101 jobject jo_ret = jni_env->NewLocalRef( jo_global ); 102 jni_env->DeleteGlobalRef( jo_global ); 103 return jo_ret; 104 } 105