merge the formfield patch from ooo-build
[ooovba.git] / bridges / test / java_uno / any / transport.cxx
blob2c2ddca3b2e670e0c9e477421acdde095d4aa193
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: transport.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_bridges.hxx"
34 #include "jni.h"
36 #include "uno/mapping.hxx"
37 #include "uno/environment.hxx"
38 #include "jvmaccess/virtualmachine.hxx"
39 #include "jvmaccess/unovirtualmachine.hxx"
40 #include "cppuhelper/implbase1.hxx"
42 #include "test/java_uno/anytest/XTransport.hpp"
43 #include "test/java_uno/anytest/DerivedInterface.hpp"
46 using namespace ::com::sun::star::uno;
47 using ::test::java_uno::anytest::XTransport;
48 using ::rtl::OUString;
50 namespace
52 //==================================================================================================
53 class Transport : public ::cppu::WeakImplHelper1< XTransport >
55 public:
56 virtual Any SAL_CALL mapAny( Any const & any )
57 throw (RuntimeException);
59 //__________________________________________________________________________________________________
60 Any Transport::mapAny( Any const & any )
61 throw (RuntimeException)
63 return any;
67 //##################################################################################################
68 extern "C" JNIEXPORT jobject JNICALL Java_test_java_1uno_anytest_TestJni_create_1jni_1transport(
69 JNIEnv * jni_env, jclass, jobject loader )
70 SAL_THROW_EXTERN_C()
72 // publish some idl types
73 ::getCppuType( (Reference< XTransport > const *)0 );
74 ::getCppuType( (Reference< ::test::java_uno::anytest::DerivedInterface > const *)0 );
76 Reference< XTransport > xRet( new Transport() );
78 // get java vm
79 JavaVM * java_vm;
80 OSL_VERIFY( 0 == jni_env->GetJavaVM( &java_vm ) );
81 // create jvmaccess vm
82 ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > vm;
83 try {
84 vm = new ::jvmaccess::UnoVirtualMachine(
85 new ::jvmaccess::VirtualMachine(
86 java_vm, JNI_VERSION_1_2, false, jni_env ),
87 loader );
88 } catch ( ::jvmaccess::UnoVirtualMachine::CreationException & ) {
89 OSL_ASSERT( false );
90 throw;
92 // create uno envs
93 OUString java_name( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_JAVA) );
94 OUString cpp_name( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) );
95 Environment java_env, cpp_env;
96 uno_getEnvironment( (uno_Environment **)&java_env, java_name.pData, vm.get() );
97 OSL_ASSERT( java_env.is() );
98 uno_getEnvironment( (uno_Environment **)&cpp_env, cpp_name.pData, 0 );
99 OSL_ASSERT( cpp_env.is() );
101 // map interface
102 Mapping mapping( cpp_env.get(), java_env.get() );
103 OSL_ASSERT( mapping.is() );
104 jobject jo_global = (jobject)mapping.mapInterface( xRet.get(), ::getCppuType( &xRet ) );
105 OSL_ASSERT( 0 != jo_global );
107 // return
108 jobject jo_ret = jni_env->NewLocalRef( jo_global );
109 jni_env->DeleteGlobalRef( jo_global );
110 return jo_ret;