1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_bridges.hxx" 30*cdf0e10cSrcweir #include "jni_bridge.h" 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp" 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #include "jvmaccess/unovirtualmachine.hxx" 35*cdf0e10cSrcweir #include "rtl/string.hxx" 36*cdf0e10cSrcweir #include "rtl/strbuf.hxx" 37*cdf0e10cSrcweir #include "rtl/ustrbuf.hxx" 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include "uno/lbnames.h" 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir namespace css = ::com::sun::star; 43*cdf0e10cSrcweir using namespace ::std; 44*cdf0e10cSrcweir using namespace ::osl; 45*cdf0e10cSrcweir using namespace ::rtl; 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir namespace jni_uno 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir //______________________________________________________________________________ 51*cdf0e10cSrcweir JNI_type_info::JNI_type_info( 52*cdf0e10cSrcweir JNI_context const & jni, typelib_TypeDescription * td ) 53*cdf0e10cSrcweir : m_td( td ), 54*cdf0e10cSrcweir m_class( 0 ) 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir m_td.makeComplete(); 57*cdf0e10cSrcweir if (! m_td.get()->bComplete) 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir OUStringBuffer buf( 128 ); 60*cdf0e10cSrcweir buf.appendAscii( 61*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("cannot make type complete: ") ); 62*cdf0e10cSrcweir buf.append( OUString::unacquired( &m_td.get()->pTypeName ) ); 63*cdf0e10cSrcweir buf.append( jni.get_stack_trace() ); 64*cdf0e10cSrcweir throw BridgeRuntimeError( buf.makeStringAndClear() ); 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir //______________________________________________________________________________ 70*cdf0e10cSrcweir void JNI_interface_type_info::destroy( JNIEnv * jni_env ) 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir JNI_type_info::destruct( jni_env ); 73*cdf0e10cSrcweir jni_env->DeleteGlobalRef( m_proxy_ctor ); 74*cdf0e10cSrcweir jni_env->DeleteGlobalRef( m_type ); 75*cdf0e10cSrcweir delete [] m_methods; 76*cdf0e10cSrcweir delete this; 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir //______________________________________________________________________________ 80*cdf0e10cSrcweir JNI_interface_type_info::JNI_interface_type_info( 81*cdf0e10cSrcweir JNI_context const & jni, typelib_TypeDescription * td_ ) 82*cdf0e10cSrcweir : JNI_type_info( jni, td_ ) 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir OSL_ASSERT( typelib_TypeClass_INTERFACE == m_td.get()->eTypeClass ); 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir OUString const & uno_name = OUString::unacquired( &m_td.get()->pTypeName ); 87*cdf0e10cSrcweir JNI_info const * jni_info = jni.get_info(); 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir JLocalAutoRef jo_class( 90*cdf0e10cSrcweir jni, 91*cdf0e10cSrcweir find_class( 92*cdf0e10cSrcweir jni, 93*cdf0e10cSrcweir ( OUStringToOString( uno_name, RTL_TEXTENCODING_JAVA_UTF8 ). 94*cdf0e10cSrcweir getStr() ) ) ); 95*cdf0e10cSrcweir JLocalAutoRef jo_type( jni, create_type( jni, (jclass) jo_class.get() ) ); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir // get proxy ctor 98*cdf0e10cSrcweir jvalue arg; 99*cdf0e10cSrcweir arg.l = jo_class.get(); 100*cdf0e10cSrcweir JLocalAutoRef jo_proxy_ctor( 101*cdf0e10cSrcweir jni, jni->CallStaticObjectMethodA( 102*cdf0e10cSrcweir jni_info->m_class_JNI_proxy, 103*cdf0e10cSrcweir jni_info->m_method_JNI_proxy_get_proxy_ctor, &arg ) ); 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir if (is_XInterface( m_td.get()->pWeakRef )) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir m_methods = 0; // no methods 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir else 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir // retrieve method ids for all direct members 112*cdf0e10cSrcweir try 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir typelib_InterfaceTypeDescription * td = 115*cdf0e10cSrcweir reinterpret_cast< typelib_InterfaceTypeDescription * >( 116*cdf0e10cSrcweir m_td.get() ); 117*cdf0e10cSrcweir m_methods = new jmethodID[ td->nMapFunctionIndexToMemberIndex ]; 118*cdf0e10cSrcweir sal_Int32 nMethodIndex = 0; 119*cdf0e10cSrcweir typelib_TypeDescriptionReference ** ppMembers = td->ppMembers; 120*cdf0e10cSrcweir sal_Int32 nMembers = td->nMembers; 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir for ( sal_Int32 nPos = 0; nPos < nMembers; ++nPos ) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir TypeDescr member_td( ppMembers[ nPos ] ); 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir OStringBuffer sig_buf( 64 ); 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir if (typelib_TypeClass_INTERFACE_METHOD == 129*cdf0e10cSrcweir member_td.get()->eTypeClass) // method 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir typelib_InterfaceMethodTypeDescription * method_td = 132*cdf0e10cSrcweir reinterpret_cast< 133*cdf0e10cSrcweir typelib_InterfaceMethodTypeDescription * >( 134*cdf0e10cSrcweir member_td.get() ); 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir sig_buf.append( '(' ); 137*cdf0e10cSrcweir for ( sal_Int32 i = 0; i < method_td->nParams; ++i ) 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir typelib_MethodParameter const & param = 140*cdf0e10cSrcweir method_td->pParams[ i ]; 141*cdf0e10cSrcweir if (param.bOut) 142*cdf0e10cSrcweir sig_buf.append( '[' ); 143*cdf0e10cSrcweir JNI_info::append_sig( &sig_buf, param.pTypeRef ); 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir sig_buf.append( ')' ); 146*cdf0e10cSrcweir JNI_info::append_sig( &sig_buf, method_td->pReturnTypeRef ); 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir OString method_signature( sig_buf.makeStringAndClear() ); 149*cdf0e10cSrcweir OString method_name( 150*cdf0e10cSrcweir OUStringToOString( OUString::unacquired( 151*cdf0e10cSrcweir &method_td->aBase.pMemberName ), 152*cdf0e10cSrcweir RTL_TEXTENCODING_JAVA_UTF8 ) ); 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir m_methods[ nMethodIndex ] = jni->GetMethodID( 155*cdf0e10cSrcweir (jclass) jo_class.get(), method_name.getStr(), 156*cdf0e10cSrcweir method_signature.getStr() ); 157*cdf0e10cSrcweir jni.ensure_no_exception(); 158*cdf0e10cSrcweir OSL_ASSERT( 0 != m_methods[ nMethodIndex ] ); 159*cdf0e10cSrcweir ++nMethodIndex; 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir else // attribute 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir OSL_ASSERT( 164*cdf0e10cSrcweir typelib_TypeClass_INTERFACE_ATTRIBUTE == 165*cdf0e10cSrcweir member_td.get()->eTypeClass ); 166*cdf0e10cSrcweir typelib_InterfaceAttributeTypeDescription * attribute_td = 167*cdf0e10cSrcweir reinterpret_cast< 168*cdf0e10cSrcweir typelib_InterfaceAttributeTypeDescription * >( 169*cdf0e10cSrcweir member_td.get() ); 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir // type sig 172*cdf0e10cSrcweir JNI_info::append_sig( 173*cdf0e10cSrcweir &sig_buf, attribute_td->pAttributeTypeRef ); 174*cdf0e10cSrcweir OString type_sig( sig_buf.makeStringAndClear() ); 175*cdf0e10cSrcweir sig_buf.ensureCapacity( 64 ); 176*cdf0e10cSrcweir // member name 177*cdf0e10cSrcweir OUString const & member_name = 178*cdf0e10cSrcweir OUString::unacquired( 179*cdf0e10cSrcweir &attribute_td->aBase.pMemberName ); 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir // getter 182*cdf0e10cSrcweir sig_buf.append( RTL_CONSTASCII_STRINGPARAM("()") ); 183*cdf0e10cSrcweir sig_buf.append( type_sig ); 184*cdf0e10cSrcweir OString method_signature( sig_buf.makeStringAndClear() ); 185*cdf0e10cSrcweir OUStringBuffer name_buf( 3 + member_name.getLength() ); 186*cdf0e10cSrcweir name_buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("get") ); 187*cdf0e10cSrcweir name_buf.append( member_name ); 188*cdf0e10cSrcweir OString method_name( 189*cdf0e10cSrcweir OUStringToOString( 190*cdf0e10cSrcweir name_buf.makeStringAndClear(), 191*cdf0e10cSrcweir RTL_TEXTENCODING_JAVA_UTF8 ) ); 192*cdf0e10cSrcweir m_methods[ nMethodIndex ] = jni->GetMethodID( 193*cdf0e10cSrcweir (jclass) jo_class.get(), method_name.getStr(), 194*cdf0e10cSrcweir method_signature.getStr() ); 195*cdf0e10cSrcweir jni.ensure_no_exception(); 196*cdf0e10cSrcweir OSL_ASSERT( 0 != m_methods[ nMethodIndex ] ); 197*cdf0e10cSrcweir ++nMethodIndex; 198*cdf0e10cSrcweir if (! attribute_td->bReadOnly) 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir // setter 201*cdf0e10cSrcweir sig_buf.ensureCapacity( 64 ); 202*cdf0e10cSrcweir sig_buf.append( '(' ); 203*cdf0e10cSrcweir sig_buf.append( type_sig ); 204*cdf0e10cSrcweir sig_buf.append( RTL_CONSTASCII_STRINGPARAM(")V") ); 205*cdf0e10cSrcweir method_signature = sig_buf.makeStringAndClear(); 206*cdf0e10cSrcweir name_buf.ensureCapacity( 3 + member_name.getLength() ); 207*cdf0e10cSrcweir name_buf.appendAscii( 208*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("set") ); 209*cdf0e10cSrcweir name_buf.append( member_name ); 210*cdf0e10cSrcweir method_name = OUStringToOString( 211*cdf0e10cSrcweir name_buf.makeStringAndClear(), 212*cdf0e10cSrcweir RTL_TEXTENCODING_JAVA_UTF8 ); 213*cdf0e10cSrcweir m_methods[ nMethodIndex ] = jni->GetMethodID( 214*cdf0e10cSrcweir (jclass) jo_class.get(), method_name.getStr(), 215*cdf0e10cSrcweir method_signature.getStr() ); 216*cdf0e10cSrcweir jni.ensure_no_exception(); 217*cdf0e10cSrcweir OSL_ASSERT( 0 != m_methods[ nMethodIndex ] ); 218*cdf0e10cSrcweir ++nMethodIndex; 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir catch (...) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir delete [] m_methods; 226*cdf0e10cSrcweir throw; 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir m_class = (jclass) jni->NewGlobalRef( jo_class.get() ); 230*cdf0e10cSrcweir m_type = jni->NewGlobalRef( jo_type.get() ); 231*cdf0e10cSrcweir m_proxy_ctor = jni->NewGlobalRef( jo_proxy_ctor.get() ); 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir //______________________________________________________________________________ 236*cdf0e10cSrcweir void JNI_compound_type_info::destroy( JNIEnv * jni_env ) 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir JNI_type_info::destruct( jni_env ); 239*cdf0e10cSrcweir delete [] m_fields; 240*cdf0e10cSrcweir delete this; 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir //______________________________________________________________________________ 244*cdf0e10cSrcweir JNI_compound_type_info::JNI_compound_type_info( 245*cdf0e10cSrcweir JNI_context const & jni, typelib_TypeDescription * td_ ) 246*cdf0e10cSrcweir : JNI_type_info( jni, td_ ), 247*cdf0e10cSrcweir m_exc_ctor( 0 ), 248*cdf0e10cSrcweir m_fields( 0 ) 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir OSL_ASSERT( typelib_TypeClass_STRUCT == m_td.get()->eTypeClass || 251*cdf0e10cSrcweir typelib_TypeClass_EXCEPTION == m_td.get()->eTypeClass ); 252*cdf0e10cSrcweir typelib_CompoundTypeDescription * td = 253*cdf0e10cSrcweir reinterpret_cast< typelib_CompoundTypeDescription * >( m_td.get() ); 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir OUString const & uno_name = 256*cdf0e10cSrcweir OUString::unacquired( &((typelib_TypeDescription *)td)->pTypeName ); 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir // Erase type arguments of instantiated polymorphic struct types: 259*cdf0e10cSrcweir OUString nucleus; 260*cdf0e10cSrcweir sal_Int32 i = uno_name.indexOf( '<' ); 261*cdf0e10cSrcweir if ( i < 0 ) { 262*cdf0e10cSrcweir nucleus = uno_name; 263*cdf0e10cSrcweir } else { 264*cdf0e10cSrcweir nucleus = uno_name.copy( 0, i ); 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir JLocalAutoRef jo_class( 267*cdf0e10cSrcweir jni, 268*cdf0e10cSrcweir find_class( 269*cdf0e10cSrcweir jni, 270*cdf0e10cSrcweir OUStringToOString( 271*cdf0e10cSrcweir nucleus, RTL_TEXTENCODING_JAVA_UTF8 ).getStr() ) ); 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir JNI_info const * jni_info = jni.get_info(); 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir if (typelib_TypeClass_EXCEPTION == m_td.get()->eTypeClass) 276*cdf0e10cSrcweir { 277*cdf0e10cSrcweir // retrieve exc ctor( msg ) 278*cdf0e10cSrcweir m_exc_ctor = jni->GetMethodID( 279*cdf0e10cSrcweir (jclass) jo_class.get(), "<init>", "(Ljava/lang/String;)V" ); 280*cdf0e10cSrcweir jni.ensure_no_exception(); 281*cdf0e10cSrcweir OSL_ASSERT( 0 != m_exc_ctor ); 282*cdf0e10cSrcweir } 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir // retrieve info for base type 285*cdf0e10cSrcweir typelib_TypeDescription * base_td = 286*cdf0e10cSrcweir reinterpret_cast< typelib_TypeDescription * >( 287*cdf0e10cSrcweir td->pBaseTypeDescription ); 288*cdf0e10cSrcweir m_base = (0 == base_td ? 0 : jni_info->get_type_info( jni, base_td )); 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir try 291*cdf0e10cSrcweir { 292*cdf0e10cSrcweir if (type_equals( 293*cdf0e10cSrcweir ((typelib_TypeDescription *)td)->pWeakRef, 294*cdf0e10cSrcweir jni_info->m_Exception_type.getTypeLibType() ) || 295*cdf0e10cSrcweir type_equals( 296*cdf0e10cSrcweir ((typelib_TypeDescription *)td)->pWeakRef, 297*cdf0e10cSrcweir jni_info->m_RuntimeException_type.getTypeLibType() )) 298*cdf0e10cSrcweir { 299*cdf0e10cSrcweir m_fields = new jfieldID[ 2 ]; 300*cdf0e10cSrcweir m_fields[ 0 ] = 0; // special Throwable.getMessage() 301*cdf0e10cSrcweir // field Context 302*cdf0e10cSrcweir m_fields[ 1 ] = jni->GetFieldID( 303*cdf0e10cSrcweir (jclass) jo_class.get(), "Context", "Ljava/lang/Object;" ); 304*cdf0e10cSrcweir jni.ensure_no_exception(); 305*cdf0e10cSrcweir OSL_ASSERT( 0 != m_fields[ 1 ] ); 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir else 308*cdf0e10cSrcweir { 309*cdf0e10cSrcweir // retrieve field ids for all direct members 310*cdf0e10cSrcweir sal_Int32 nMembers = td->nMembers; 311*cdf0e10cSrcweir m_fields = new jfieldID[ nMembers ]; 312*cdf0e10cSrcweir 313*cdf0e10cSrcweir for ( sal_Int32 nPos = 0; nPos < nMembers; ++nPos ) 314*cdf0e10cSrcweir { 315*cdf0e10cSrcweir OString sig; 316*cdf0e10cSrcweir if (td->aBase.eTypeClass == typelib_TypeClass_STRUCT 317*cdf0e10cSrcweir && reinterpret_cast< typelib_StructTypeDescription * >( 318*cdf0e10cSrcweir td)->pParameterizedTypes != 0 319*cdf0e10cSrcweir && reinterpret_cast< typelib_StructTypeDescription * >( 320*cdf0e10cSrcweir td)->pParameterizedTypes[nPos]) 321*cdf0e10cSrcweir { 322*cdf0e10cSrcweir sig = OString( 323*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("Ljava/lang/Object;")); 324*cdf0e10cSrcweir } else { 325*cdf0e10cSrcweir OStringBuffer sig_buf( 32 ); 326*cdf0e10cSrcweir JNI_info::append_sig( &sig_buf, td->ppTypeRefs[ nPos ] ); 327*cdf0e10cSrcweir sig = sig_buf.makeStringAndClear(); 328*cdf0e10cSrcweir } 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir OString member_name( 331*cdf0e10cSrcweir OUStringToOString( 332*cdf0e10cSrcweir OUString::unacquired( &td->ppMemberNames[ nPos ] ), 333*cdf0e10cSrcweir RTL_TEXTENCODING_JAVA_UTF8 ) ); 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir m_fields[ nPos ] = jni->GetFieldID( 336*cdf0e10cSrcweir (jclass) jo_class.get(), member_name.getStr(), 337*cdf0e10cSrcweir sig.getStr() ); 338*cdf0e10cSrcweir jni.ensure_no_exception(); 339*cdf0e10cSrcweir OSL_ASSERT( 0 != m_fields[ nPos ] ); 340*cdf0e10cSrcweir } 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir } 343*cdf0e10cSrcweir catch (...) 344*cdf0e10cSrcweir { 345*cdf0e10cSrcweir delete [] m_fields; 346*cdf0e10cSrcweir throw; 347*cdf0e10cSrcweir } 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir m_class = (jclass) jni->NewGlobalRef( jo_class.get() ); 350*cdf0e10cSrcweir } 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir 353*cdf0e10cSrcweir //______________________________________________________________________________ 354*cdf0e10cSrcweir JNI_type_info const * JNI_info::create_type_info( 355*cdf0e10cSrcweir JNI_context const & jni, typelib_TypeDescription * td ) const 356*cdf0e10cSrcweir { 357*cdf0e10cSrcweir OUString const & uno_name = OUString::unacquired( &td->pTypeName ); 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir JNI_type_info * new_info; 360*cdf0e10cSrcweir switch (td->eTypeClass) 361*cdf0e10cSrcweir { 362*cdf0e10cSrcweir case typelib_TypeClass_STRUCT: 363*cdf0e10cSrcweir case typelib_TypeClass_EXCEPTION: 364*cdf0e10cSrcweir { 365*cdf0e10cSrcweir new_info = new JNI_compound_type_info( jni, td ); 366*cdf0e10cSrcweir break; 367*cdf0e10cSrcweir } 368*cdf0e10cSrcweir case typelib_TypeClass_INTERFACE: 369*cdf0e10cSrcweir { 370*cdf0e10cSrcweir new_info = new JNI_interface_type_info( jni, td ); 371*cdf0e10cSrcweir break; 372*cdf0e10cSrcweir } 373*cdf0e10cSrcweir default: 374*cdf0e10cSrcweir { 375*cdf0e10cSrcweir OUStringBuffer buf( 128 ); 376*cdf0e10cSrcweir buf.appendAscii( 377*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("type info not supported for ") ); 378*cdf0e10cSrcweir buf.append( uno_name ); 379*cdf0e10cSrcweir buf.append( jni.get_stack_trace() ); 380*cdf0e10cSrcweir throw BridgeRuntimeError( buf.makeStringAndClear() ); 381*cdf0e10cSrcweir } 382*cdf0e10cSrcweir } 383*cdf0e10cSrcweir 384*cdf0e10cSrcweir // look up 385*cdf0e10cSrcweir JNI_type_info * info; 386*cdf0e10cSrcweir ClearableMutexGuard guard( m_mutex ); 387*cdf0e10cSrcweir JNI_type_info_holder & holder = m_type_map[ uno_name ]; 388*cdf0e10cSrcweir if (0 == holder.m_info) // new insertion 389*cdf0e10cSrcweir { 390*cdf0e10cSrcweir holder.m_info = new_info; 391*cdf0e10cSrcweir guard.clear(); 392*cdf0e10cSrcweir info = new_info; 393*cdf0e10cSrcweir } 394*cdf0e10cSrcweir else // inserted in the meantime 395*cdf0e10cSrcweir { 396*cdf0e10cSrcweir info = holder.m_info; 397*cdf0e10cSrcweir guard.clear(); 398*cdf0e10cSrcweir new_info->destroy( jni.get_jni_env() ); 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir return info; 401*cdf0e10cSrcweir } 402*cdf0e10cSrcweir 403*cdf0e10cSrcweir //______________________________________________________________________________ 404*cdf0e10cSrcweir JNI_type_info const * JNI_info::get_type_info( 405*cdf0e10cSrcweir JNI_context const & jni, typelib_TypeDescription * td ) const 406*cdf0e10cSrcweir { 407*cdf0e10cSrcweir if (is_XInterface( td->pWeakRef )) 408*cdf0e10cSrcweir { 409*cdf0e10cSrcweir return m_XInterface_type_info; 410*cdf0e10cSrcweir } 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir OUString const & uno_name = OUString::unacquired( &td->pTypeName ); 413*cdf0e10cSrcweir JNI_type_info const * info; 414*cdf0e10cSrcweir ClearableMutexGuard guard( m_mutex ); 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir t_str2type::const_iterator iFind( m_type_map.find( uno_name ) ); 417*cdf0e10cSrcweir if (iFind == m_type_map.end()) 418*cdf0e10cSrcweir { 419*cdf0e10cSrcweir guard.clear(); 420*cdf0e10cSrcweir info = create_type_info( jni, td ); 421*cdf0e10cSrcweir } 422*cdf0e10cSrcweir else 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir info = iFind->second.m_info; 425*cdf0e10cSrcweir } 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir return info; 428*cdf0e10cSrcweir } 429*cdf0e10cSrcweir 430*cdf0e10cSrcweir //______________________________________________________________________________ 431*cdf0e10cSrcweir JNI_type_info const * JNI_info::get_type_info( 432*cdf0e10cSrcweir JNI_context const & jni, typelib_TypeDescriptionReference * type ) const 433*cdf0e10cSrcweir { 434*cdf0e10cSrcweir if (is_XInterface( type )) 435*cdf0e10cSrcweir { 436*cdf0e10cSrcweir return m_XInterface_type_info; 437*cdf0e10cSrcweir } 438*cdf0e10cSrcweir 439*cdf0e10cSrcweir OUString const & uno_name = OUString::unacquired( &type->pTypeName ); 440*cdf0e10cSrcweir JNI_type_info const * info; 441*cdf0e10cSrcweir ClearableMutexGuard guard( m_mutex ); 442*cdf0e10cSrcweir t_str2type::const_iterator iFind( m_type_map.find( uno_name ) ); 443*cdf0e10cSrcweir if (iFind == m_type_map.end()) 444*cdf0e10cSrcweir { 445*cdf0e10cSrcweir guard.clear(); 446*cdf0e10cSrcweir TypeDescr td( type ); 447*cdf0e10cSrcweir info = create_type_info( jni, td.get() ); 448*cdf0e10cSrcweir } 449*cdf0e10cSrcweir else 450*cdf0e10cSrcweir { 451*cdf0e10cSrcweir info = iFind->second.m_info; 452*cdf0e10cSrcweir } 453*cdf0e10cSrcweir 454*cdf0e10cSrcweir return info; 455*cdf0e10cSrcweir } 456*cdf0e10cSrcweir 457*cdf0e10cSrcweir //______________________________________________________________________________ 458*cdf0e10cSrcweir JNI_type_info const * JNI_info::get_type_info( 459*cdf0e10cSrcweir JNI_context const & jni, OUString const & uno_name ) const 460*cdf0e10cSrcweir { 461*cdf0e10cSrcweir if (uno_name.equalsAsciiL( 462*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("com.sun.star.uno.XInterface") )) 463*cdf0e10cSrcweir { 464*cdf0e10cSrcweir return m_XInterface_type_info; 465*cdf0e10cSrcweir } 466*cdf0e10cSrcweir 467*cdf0e10cSrcweir JNI_type_info const * info; 468*cdf0e10cSrcweir ClearableMutexGuard guard( m_mutex ); 469*cdf0e10cSrcweir t_str2type::const_iterator iFind( m_type_map.find( uno_name ) ); 470*cdf0e10cSrcweir if (iFind == m_type_map.end()) 471*cdf0e10cSrcweir { 472*cdf0e10cSrcweir guard.clear(); 473*cdf0e10cSrcweir css::uno::TypeDescription td( uno_name ); 474*cdf0e10cSrcweir if (! td.is()) 475*cdf0e10cSrcweir { 476*cdf0e10cSrcweir OUStringBuffer buf( 128 ); 477*cdf0e10cSrcweir buf.appendAscii( 478*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("UNO type not found: ") ); 479*cdf0e10cSrcweir buf.append( uno_name ); 480*cdf0e10cSrcweir buf.append( jni.get_stack_trace() ); 481*cdf0e10cSrcweir throw BridgeRuntimeError( buf.makeStringAndClear() ); 482*cdf0e10cSrcweir } 483*cdf0e10cSrcweir info = create_type_info( jni, td.get() ); 484*cdf0e10cSrcweir } 485*cdf0e10cSrcweir else 486*cdf0e10cSrcweir { 487*cdf0e10cSrcweir info = iFind->second.m_info; 488*cdf0e10cSrcweir } 489*cdf0e10cSrcweir 490*cdf0e10cSrcweir return info; 491*cdf0e10cSrcweir } 492*cdf0e10cSrcweir 493*cdf0e10cSrcweir //______________________________________________________________________________ 494*cdf0e10cSrcweir JNI_info::JNI_info( 495*cdf0e10cSrcweir JNIEnv * jni_env, jobject class_loader, jclass classClass, 496*cdf0e10cSrcweir jmethodID methodForName ) 497*cdf0e10cSrcweir : m_class_Class( classClass ), 498*cdf0e10cSrcweir m_method_Class_forName( methodForName ), 499*cdf0e10cSrcweir m_class_JNI_proxy( 0 ), 500*cdf0e10cSrcweir m_XInterface_queryInterface_td( 501*cdf0e10cSrcweir (reinterpret_cast< typelib_InterfaceTypeDescription * >( 502*cdf0e10cSrcweir css::uno::TypeDescription( 503*cdf0e10cSrcweir ::getCppuType( 504*cdf0e10cSrcweir (css::uno::Reference< css::uno::XInterface > const *)0 ) ) 505*cdf0e10cSrcweir .get())->ppMembers[ 0 ] ) ), 506*cdf0e10cSrcweir m_Exception_type( ::getCppuType( (css::uno::Exception const *)0 ) ), 507*cdf0e10cSrcweir m_RuntimeException_type( 508*cdf0e10cSrcweir ::getCppuType( (css::uno::RuntimeException const *)0 ) ), 509*cdf0e10cSrcweir m_void_type( ::getCppuVoidType() ), 510*cdf0e10cSrcweir m_XInterface_type_info( 0 ) 511*cdf0e10cSrcweir { 512*cdf0e10cSrcweir JNI_context jni( this, jni_env, class_loader ); // !no proper jni_info! 513*cdf0e10cSrcweir 514*cdf0e10cSrcweir // class lookup 515*cdf0e10cSrcweir JLocalAutoRef jo_Object( 516*cdf0e10cSrcweir jni, find_class( jni, "java.lang.Object" ) ); 517*cdf0e10cSrcweir JLocalAutoRef jo_Class( 518*cdf0e10cSrcweir jni, find_class( jni, "java.lang.Class" ) ); 519*cdf0e10cSrcweir JLocalAutoRef jo_Throwable( 520*cdf0e10cSrcweir jni, find_class( jni, "java.lang.Throwable" ) ); 521*cdf0e10cSrcweir JLocalAutoRef jo_Character( 522*cdf0e10cSrcweir jni, find_class( jni, "java.lang.Character" ) ); 523*cdf0e10cSrcweir JLocalAutoRef jo_Boolean( 524*cdf0e10cSrcweir jni, find_class( jni, "java.lang.Boolean" ) ); 525*cdf0e10cSrcweir JLocalAutoRef jo_Byte( 526*cdf0e10cSrcweir jni, find_class( jni, "java.lang.Byte" ) ); 527*cdf0e10cSrcweir JLocalAutoRef jo_Short( 528*cdf0e10cSrcweir jni, find_class( jni, "java.lang.Short" ) ); 529*cdf0e10cSrcweir JLocalAutoRef jo_Integer( 530*cdf0e10cSrcweir jni, find_class( jni, "java.lang.Integer" ) ); 531*cdf0e10cSrcweir JLocalAutoRef jo_Long( 532*cdf0e10cSrcweir jni, find_class( jni, "java.lang.Long" ) ); 533*cdf0e10cSrcweir JLocalAutoRef jo_Float( 534*cdf0e10cSrcweir jni, find_class( jni, "java.lang.Float" ) ); 535*cdf0e10cSrcweir JLocalAutoRef jo_Double( 536*cdf0e10cSrcweir jni, find_class( jni, "java.lang.Double" ) ); 537*cdf0e10cSrcweir JLocalAutoRef jo_String( 538*cdf0e10cSrcweir jni, find_class( jni, "java.lang.String" ) ); 539*cdf0e10cSrcweir JLocalAutoRef jo_RuntimeException( 540*cdf0e10cSrcweir jni, find_class( jni, "com.sun.star.uno.RuntimeException" ) ); 541*cdf0e10cSrcweir JLocalAutoRef jo_UnoRuntime( 542*cdf0e10cSrcweir jni, find_class( jni, "com.sun.star.uno.UnoRuntime" ) ); 543*cdf0e10cSrcweir JLocalAutoRef jo_Any( 544*cdf0e10cSrcweir jni, find_class( jni, "com.sun.star.uno.Any" ) ); 545*cdf0e10cSrcweir JLocalAutoRef jo_Enum( 546*cdf0e10cSrcweir jni, find_class( jni, "com.sun.star.uno.Enum" ) ); 547*cdf0e10cSrcweir JLocalAutoRef jo_Type( 548*cdf0e10cSrcweir jni, find_class( jni, "com.sun.star.uno.Type" ) ); 549*cdf0e10cSrcweir JLocalAutoRef jo_TypeClass( 550*cdf0e10cSrcweir jni, find_class( jni, "com.sun.star.uno.TypeClass" ) ); 551*cdf0e10cSrcweir JLocalAutoRef jo_IEnvironment( 552*cdf0e10cSrcweir jni, find_class( jni, "com.sun.star.uno.IEnvironment" ) ); 553*cdf0e10cSrcweir JLocalAutoRef jo_JNI_proxy( 554*cdf0e10cSrcweir jni, find_class( jni, "com.sun.star.bridges.jni_uno.JNI_proxy" ) ); 555*cdf0e10cSrcweir 556*cdf0e10cSrcweir // method Object.toString() 557*cdf0e10cSrcweir m_method_Object_toString = jni->GetMethodID( 558*cdf0e10cSrcweir (jclass) jo_Object.get(), "toString", "()Ljava/lang/String;" ); 559*cdf0e10cSrcweir jni.ensure_no_exception(); 560*cdf0e10cSrcweir OSL_ASSERT( 0 != m_method_Object_toString ); 561*cdf0e10cSrcweir // method Class.getName() 562*cdf0e10cSrcweir m_method_Class_getName = jni->GetMethodID( 563*cdf0e10cSrcweir (jclass) jo_Class.get(), "getName", "()Ljava/lang/String;" ); 564*cdf0e10cSrcweir jni.ensure_no_exception(); 565*cdf0e10cSrcweir OSL_ASSERT( 0 != m_method_Class_getName ); 566*cdf0e10cSrcweir 567*cdf0e10cSrcweir // method Throwable.getMessage() 568*cdf0e10cSrcweir m_method_Throwable_getMessage = jni->GetMethodID( 569*cdf0e10cSrcweir (jclass) jo_Throwable.get(), "getMessage", "()Ljava/lang/String;" ); 570*cdf0e10cSrcweir jni.ensure_no_exception(); 571*cdf0e10cSrcweir OSL_ASSERT( 0 != m_method_Throwable_getMessage ); 572*cdf0e10cSrcweir 573*cdf0e10cSrcweir // method Character.charValue() 574*cdf0e10cSrcweir m_method_Character_charValue = jni->GetMethodID( 575*cdf0e10cSrcweir (jclass) jo_Character.get(), "charValue", "()C" ); 576*cdf0e10cSrcweir jni.ensure_no_exception(); 577*cdf0e10cSrcweir OSL_ASSERT( 0 != m_method_Character_charValue ); 578*cdf0e10cSrcweir // method Boolean.booleanValue() 579*cdf0e10cSrcweir m_method_Boolean_booleanValue = jni->GetMethodID( 580*cdf0e10cSrcweir (jclass) jo_Boolean.get(), "booleanValue", "()Z" ); 581*cdf0e10cSrcweir jni.ensure_no_exception(); 582*cdf0e10cSrcweir OSL_ASSERT( 0 != m_method_Boolean_booleanValue ); 583*cdf0e10cSrcweir // method Byte.byteValue() 584*cdf0e10cSrcweir m_method_Byte_byteValue = jni->GetMethodID( 585*cdf0e10cSrcweir (jclass) jo_Byte.get(), "byteValue", "()B" ); 586*cdf0e10cSrcweir jni.ensure_no_exception(); 587*cdf0e10cSrcweir OSL_ASSERT( 0 != m_method_Byte_byteValue ); 588*cdf0e10cSrcweir // method Short.shortValue() 589*cdf0e10cSrcweir m_method_Short_shortValue = jni->GetMethodID( 590*cdf0e10cSrcweir (jclass) jo_Short.get(), "shortValue", "()S" ); 591*cdf0e10cSrcweir jni.ensure_no_exception(); 592*cdf0e10cSrcweir OSL_ASSERT( 0 != m_method_Short_shortValue ); 593*cdf0e10cSrcweir // method Integer.intValue() 594*cdf0e10cSrcweir m_method_Integer_intValue = jni->GetMethodID( 595*cdf0e10cSrcweir (jclass) jo_Integer.get(), "intValue", "()I" ); 596*cdf0e10cSrcweir jni.ensure_no_exception(); 597*cdf0e10cSrcweir OSL_ASSERT( 0 != m_method_Integer_intValue ); 598*cdf0e10cSrcweir // method Long.longValue() 599*cdf0e10cSrcweir m_method_Long_longValue = jni->GetMethodID( 600*cdf0e10cSrcweir (jclass) jo_Long.get(), "longValue", "()J" ); 601*cdf0e10cSrcweir jni.ensure_no_exception(); 602*cdf0e10cSrcweir OSL_ASSERT( 0 != m_method_Long_longValue ); 603*cdf0e10cSrcweir // method Float.floatValue() 604*cdf0e10cSrcweir m_method_Float_floatValue = jni->GetMethodID( 605*cdf0e10cSrcweir (jclass) jo_Float.get(), "floatValue", "()F" ); 606*cdf0e10cSrcweir jni.ensure_no_exception(); 607*cdf0e10cSrcweir OSL_ASSERT( 0 != m_method_Float_floatValue ); 608*cdf0e10cSrcweir // method Double.doubleValue() 609*cdf0e10cSrcweir m_method_Double_doubleValue = jni->GetMethodID( 610*cdf0e10cSrcweir (jclass) jo_Double.get(), "doubleValue", "()D" ); 611*cdf0e10cSrcweir jni.ensure_no_exception(); 612*cdf0e10cSrcweir OSL_ASSERT( 0 != m_method_Double_doubleValue ); 613*cdf0e10cSrcweir 614*cdf0e10cSrcweir // ctor Character( char ) 615*cdf0e10cSrcweir m_ctor_Character_with_char = jni->GetMethodID( 616*cdf0e10cSrcweir (jclass) jo_Character.get(), "<init>", "(C)V" ); 617*cdf0e10cSrcweir jni.ensure_no_exception(); 618*cdf0e10cSrcweir OSL_ASSERT( 0 != m_ctor_Character_with_char ); 619*cdf0e10cSrcweir // ctor Boolean( boolean ) 620*cdf0e10cSrcweir m_ctor_Boolean_with_boolean = jni->GetMethodID( 621*cdf0e10cSrcweir (jclass) jo_Boolean.get(), "<init>", "(Z)V" ); 622*cdf0e10cSrcweir jni.ensure_no_exception(); 623*cdf0e10cSrcweir OSL_ASSERT( 0 != m_ctor_Boolean_with_boolean ); 624*cdf0e10cSrcweir // ctor Byte( byte ) 625*cdf0e10cSrcweir m_ctor_Byte_with_byte = jni->GetMethodID( 626*cdf0e10cSrcweir (jclass) jo_Byte.get(), "<init>", "(B)V" ); 627*cdf0e10cSrcweir jni.ensure_no_exception(); 628*cdf0e10cSrcweir OSL_ASSERT( 0 != m_ctor_Byte_with_byte ); 629*cdf0e10cSrcweir // ctor Short( short ) 630*cdf0e10cSrcweir m_ctor_Short_with_short = jni->GetMethodID( 631*cdf0e10cSrcweir (jclass) jo_Short.get(), "<init>", "(S)V" ); 632*cdf0e10cSrcweir jni.ensure_no_exception(); 633*cdf0e10cSrcweir OSL_ASSERT( 0 != m_ctor_Short_with_short ); 634*cdf0e10cSrcweir // ctor Integer( int ) 635*cdf0e10cSrcweir m_ctor_Integer_with_int = jni->GetMethodID( 636*cdf0e10cSrcweir (jclass) jo_Integer.get(), "<init>", "(I)V" ); 637*cdf0e10cSrcweir jni.ensure_no_exception(); 638*cdf0e10cSrcweir OSL_ASSERT( 0 != m_ctor_Integer_with_int ); 639*cdf0e10cSrcweir // ctor Long( long ) 640*cdf0e10cSrcweir m_ctor_Long_with_long = jni->GetMethodID( 641*cdf0e10cSrcweir (jclass) jo_Long.get(), "<init>", "(J)V" ); 642*cdf0e10cSrcweir jni.ensure_no_exception(); 643*cdf0e10cSrcweir OSL_ASSERT( 0 != m_ctor_Long_with_long ); 644*cdf0e10cSrcweir // ctor Float( float ) 645*cdf0e10cSrcweir m_ctor_Float_with_float = jni->GetMethodID( 646*cdf0e10cSrcweir (jclass) jo_Float.get(), "<init>", "(F)V" ); 647*cdf0e10cSrcweir jni.ensure_no_exception(); 648*cdf0e10cSrcweir OSL_ASSERT( 0 != m_ctor_Float_with_float ); 649*cdf0e10cSrcweir // ctor Double( double ) 650*cdf0e10cSrcweir m_ctor_Double_with_double = jni->GetMethodID( 651*cdf0e10cSrcweir (jclass) jo_Double.get(), "<init>", "(D)V" ); 652*cdf0e10cSrcweir jni.ensure_no_exception(); 653*cdf0e10cSrcweir OSL_ASSERT( 0 != m_ctor_Double_with_double ); 654*cdf0e10cSrcweir 655*cdf0e10cSrcweir // static method UnoRuntime.generateOid() 656*cdf0e10cSrcweir m_method_UnoRuntime_generateOid = jni->GetStaticMethodID( 657*cdf0e10cSrcweir (jclass) jo_UnoRuntime.get(), 658*cdf0e10cSrcweir "generateOid", "(Ljava/lang/Object;)Ljava/lang/String;" ); 659*cdf0e10cSrcweir jni.ensure_no_exception(); 660*cdf0e10cSrcweir OSL_ASSERT( 0 != m_method_UnoRuntime_generateOid ); 661*cdf0e10cSrcweir // static method UnoRuntime.queryInterface() 662*cdf0e10cSrcweir m_method_UnoRuntime_queryInterface = jni->GetStaticMethodID( 663*cdf0e10cSrcweir (jclass) jo_UnoRuntime.get(), 664*cdf0e10cSrcweir "queryInterface", 665*cdf0e10cSrcweir "(Lcom/sun/star/uno/Type;Ljava/lang/Object;)Ljava/lang/Object;" ); 666*cdf0e10cSrcweir jni.ensure_no_exception(); 667*cdf0e10cSrcweir OSL_ASSERT( 0 != m_method_UnoRuntime_queryInterface ); 668*cdf0e10cSrcweir 669*cdf0e10cSrcweir // field Enum.m_value 670*cdf0e10cSrcweir m_field_Enum_m_value = jni->GetFieldID( 671*cdf0e10cSrcweir (jclass) jo_Enum.get(), "m_value", "I" ); 672*cdf0e10cSrcweir jni.ensure_no_exception(); 673*cdf0e10cSrcweir OSL_ASSERT( 0 != m_field_Enum_m_value ); 674*cdf0e10cSrcweir 675*cdf0e10cSrcweir // static method TypeClass.fromInt() 676*cdf0e10cSrcweir m_method_TypeClass_fromInt = jni->GetStaticMethodID( 677*cdf0e10cSrcweir (jclass) jo_TypeClass.get(), 678*cdf0e10cSrcweir "fromInt", "(I)Lcom/sun/star/uno/TypeClass;" ); 679*cdf0e10cSrcweir jni.ensure_no_exception(); 680*cdf0e10cSrcweir OSL_ASSERT( 0 != m_method_TypeClass_fromInt ); 681*cdf0e10cSrcweir 682*cdf0e10cSrcweir // ctor Type( Class ) 683*cdf0e10cSrcweir m_ctor_Type_with_Class = jni->GetMethodID( 684*cdf0e10cSrcweir (jclass) jo_Type.get(), "<init>", "(Ljava/lang/Class;)V" ); 685*cdf0e10cSrcweir jni.ensure_no_exception(); 686*cdf0e10cSrcweir OSL_ASSERT( 0 != m_ctor_Type_with_Class ); 687*cdf0e10cSrcweir // ctor Type( String, TypeClass ) 688*cdf0e10cSrcweir m_ctor_Type_with_Name_TypeClass = jni->GetMethodID( 689*cdf0e10cSrcweir (jclass) jo_Type.get(), 690*cdf0e10cSrcweir "<init>", "(Ljava/lang/String;Lcom/sun/star/uno/TypeClass;)V" ); 691*cdf0e10cSrcweir jni.ensure_no_exception(); 692*cdf0e10cSrcweir OSL_ASSERT( 0 != m_ctor_Type_with_Name_TypeClass ); 693*cdf0e10cSrcweir // field Type._typeName 694*cdf0e10cSrcweir m_field_Type__typeName = jni->GetFieldID( 695*cdf0e10cSrcweir (jclass) jo_Type.get(), "_typeName", "Ljava/lang/String;" ); 696*cdf0e10cSrcweir jni.ensure_no_exception(); 697*cdf0e10cSrcweir OSL_ASSERT( 0 != m_field_Type__typeName ); 698*cdf0e10cSrcweir 699*cdf0e10cSrcweir // ctor Any( Type, Object ) 700*cdf0e10cSrcweir m_ctor_Any_with_Type_Object = jni->GetMethodID( 701*cdf0e10cSrcweir (jclass) jo_Any.get(), 702*cdf0e10cSrcweir "<init>", "(Lcom/sun/star/uno/Type;Ljava/lang/Object;)V" ); 703*cdf0e10cSrcweir jni.ensure_no_exception(); 704*cdf0e10cSrcweir OSL_ASSERT( 0 != m_ctor_Any_with_Type_Object ); 705*cdf0e10cSrcweir 706*cdf0e10cSrcweir // field Any._type 707*cdf0e10cSrcweir m_field_Any__type = jni->GetFieldID( 708*cdf0e10cSrcweir (jclass) jo_Any.get(), "_type", "Lcom/sun/star/uno/Type;" ); 709*cdf0e10cSrcweir jni.ensure_no_exception(); 710*cdf0e10cSrcweir OSL_ASSERT( 0 != m_field_Any__type ); 711*cdf0e10cSrcweir // field Any._object 712*cdf0e10cSrcweir m_field_Any__object = jni->GetFieldID( 713*cdf0e10cSrcweir (jclass) jo_Any.get(), "_object", "Ljava/lang/Object;" ); 714*cdf0e10cSrcweir jni.ensure_no_exception(); 715*cdf0e10cSrcweir OSL_ASSERT( 0 != m_field_Any__object ); 716*cdf0e10cSrcweir 717*cdf0e10cSrcweir // method IEnvironment.getRegisteredInterface() 718*cdf0e10cSrcweir m_method_IEnvironment_getRegisteredInterface = jni->GetMethodID( 719*cdf0e10cSrcweir (jclass) jo_IEnvironment.get(), 720*cdf0e10cSrcweir "getRegisteredInterface", 721*cdf0e10cSrcweir "(Ljava/lang/String;Lcom/sun/star/uno/Type;)Ljava/lang/Object;" ); 722*cdf0e10cSrcweir jni.ensure_no_exception(); 723*cdf0e10cSrcweir OSL_ASSERT( 0 != m_method_IEnvironment_getRegisteredInterface ); 724*cdf0e10cSrcweir // method IEnvironment.registerInterface() 725*cdf0e10cSrcweir m_method_IEnvironment_registerInterface = jni->GetMethodID( 726*cdf0e10cSrcweir (jclass) jo_IEnvironment.get(), "registerInterface", 727*cdf0e10cSrcweir "(Ljava/lang/Object;[Ljava/lang/String;Lcom/sun/star/uno/Type;)" 728*cdf0e10cSrcweir "Ljava/lang/Object;" ); 729*cdf0e10cSrcweir jni.ensure_no_exception(); 730*cdf0e10cSrcweir OSL_ASSERT( 0 != m_method_IEnvironment_registerInterface ); 731*cdf0e10cSrcweir 732*cdf0e10cSrcweir // static method JNI_proxy.get_proxy_ctor() 733*cdf0e10cSrcweir m_method_JNI_proxy_get_proxy_ctor = jni->GetStaticMethodID( 734*cdf0e10cSrcweir (jclass) jo_JNI_proxy.get(), "get_proxy_ctor", 735*cdf0e10cSrcweir "(Ljava/lang/Class;)Ljava/lang/reflect/Constructor;" ); 736*cdf0e10cSrcweir jni.ensure_no_exception(); 737*cdf0e10cSrcweir OSL_ASSERT( 0 != m_method_JNI_proxy_get_proxy_ctor ); 738*cdf0e10cSrcweir // static method JNI_proxy.create() 739*cdf0e10cSrcweir m_method_JNI_proxy_create = jni->GetStaticMethodID( 740*cdf0e10cSrcweir (jclass) jo_JNI_proxy.get(), "create", 741*cdf0e10cSrcweir "(JLcom/sun/star/uno/IEnvironment;JJLcom/sun/star/uno/Type;Ljava/lang" 742*cdf0e10cSrcweir "/String;Ljava/lang/reflect/Constructor;)Ljava/lang/Object;" ); 743*cdf0e10cSrcweir jni.ensure_no_exception(); 744*cdf0e10cSrcweir OSL_ASSERT( 0 != m_method_JNI_proxy_create ); 745*cdf0e10cSrcweir // field JNI_proxy.m_receiver_handle 746*cdf0e10cSrcweir m_field_JNI_proxy_m_receiver_handle = jni->GetFieldID( 747*cdf0e10cSrcweir (jclass) jo_JNI_proxy.get(), "m_receiver_handle", "J" ); 748*cdf0e10cSrcweir jni.ensure_no_exception(); 749*cdf0e10cSrcweir OSL_ASSERT( 0 != m_field_JNI_proxy_m_receiver_handle ); 750*cdf0e10cSrcweir // field JNI_proxy.m_td_handle 751*cdf0e10cSrcweir m_field_JNI_proxy_m_td_handle = jni->GetFieldID( 752*cdf0e10cSrcweir (jclass) jo_JNI_proxy.get(), "m_td_handle", "J" ); 753*cdf0e10cSrcweir jni.ensure_no_exception(); 754*cdf0e10cSrcweir OSL_ASSERT( 0 != m_field_JNI_proxy_m_td_handle ); 755*cdf0e10cSrcweir // field JNI_proxy.m_type 756*cdf0e10cSrcweir m_field_JNI_proxy_m_type = jni->GetFieldID( 757*cdf0e10cSrcweir (jclass) jo_JNI_proxy.get(), "m_type", "Lcom/sun/star/uno/Type;" ); 758*cdf0e10cSrcweir jni.ensure_no_exception(); 759*cdf0e10cSrcweir OSL_ASSERT( 0 != m_field_JNI_proxy_m_type ); 760*cdf0e10cSrcweir // field JNI_proxy.m_oid 761*cdf0e10cSrcweir m_field_JNI_proxy_m_oid = jni->GetFieldID( 762*cdf0e10cSrcweir (jclass) jo_JNI_proxy.get(), "m_oid", "Ljava/lang/String;" ); 763*cdf0e10cSrcweir jni.ensure_no_exception(); 764*cdf0e10cSrcweir OSL_ASSERT( 0 != m_field_JNI_proxy_m_oid ); 765*cdf0e10cSrcweir 766*cdf0e10cSrcweir // get java env 767*cdf0e10cSrcweir OUString java_env_type_name( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_JAVA) ); 768*cdf0e10cSrcweir JLocalAutoRef jo_java( 769*cdf0e10cSrcweir jni, ustring_to_jstring( jni, java_env_type_name.pData ) ); 770*cdf0e10cSrcweir jvalue args[ 2 ]; 771*cdf0e10cSrcweir args[ 0 ].l = jo_java.get(); 772*cdf0e10cSrcweir args[ 1 ].l = 0; 773*cdf0e10cSrcweir jmethodID method_getEnvironment = jni->GetStaticMethodID( 774*cdf0e10cSrcweir (jclass) jo_UnoRuntime.get(), "getEnvironment", 775*cdf0e10cSrcweir "(Ljava/lang/String;Ljava/lang/Object;)" 776*cdf0e10cSrcweir "Lcom/sun/star/uno/IEnvironment;" ); 777*cdf0e10cSrcweir jni.ensure_no_exception(); 778*cdf0e10cSrcweir OSL_ASSERT( 0 != method_getEnvironment ); 779*cdf0e10cSrcweir JLocalAutoRef jo_java_env( 780*cdf0e10cSrcweir jni, jni->CallStaticObjectMethodA( 781*cdf0e10cSrcweir (jclass) jo_UnoRuntime.get(), method_getEnvironment, args ) ); 782*cdf0e10cSrcweir 783*cdf0e10cSrcweir // get com.sun.star.uno.Any.VOID 784*cdf0e10cSrcweir jfieldID field_Any_VOID = jni->GetStaticFieldID( 785*cdf0e10cSrcweir (jclass) jo_Any.get(), "VOID", "Lcom/sun/star/uno/Any;" ); 786*cdf0e10cSrcweir jni.ensure_no_exception(); 787*cdf0e10cSrcweir OSL_ASSERT( 0 != field_Any_VOID ); 788*cdf0e10cSrcweir JLocalAutoRef jo_Any_VOID( 789*cdf0e10cSrcweir jni, jni->GetStaticObjectField( 790*cdf0e10cSrcweir (jclass) jo_Any.get(), field_Any_VOID ) ); 791*cdf0e10cSrcweir // get com.sun.star.uno.Type.UNSIGNED_SHORT 792*cdf0e10cSrcweir jfieldID field_Type_UNSIGNED_SHORT = jni->GetStaticFieldID( 793*cdf0e10cSrcweir (jclass) jo_Type.get(), "UNSIGNED_SHORT", "Lcom/sun/star/uno/Type;" ); 794*cdf0e10cSrcweir jni.ensure_no_exception(); 795*cdf0e10cSrcweir OSL_ASSERT( 0 != field_Type_UNSIGNED_SHORT ); 796*cdf0e10cSrcweir JLocalAutoRef jo_Type_UNSIGNED_SHORT( 797*cdf0e10cSrcweir jni, jni->GetStaticObjectField( 798*cdf0e10cSrcweir (jclass) jo_Type.get(), field_Type_UNSIGNED_SHORT ) ); 799*cdf0e10cSrcweir // get com.sun.star.uno.Type.UNSIGNED_LONG 800*cdf0e10cSrcweir jfieldID field_Type_UNSIGNED_LONG = jni->GetStaticFieldID( 801*cdf0e10cSrcweir (jclass) jo_Type.get(), "UNSIGNED_LONG", "Lcom/sun/star/uno/Type;" ); 802*cdf0e10cSrcweir jni.ensure_no_exception(); 803*cdf0e10cSrcweir OSL_ASSERT( 0 != field_Type_UNSIGNED_LONG ); 804*cdf0e10cSrcweir JLocalAutoRef jo_Type_UNSIGNED_LONG( 805*cdf0e10cSrcweir jni, jni->GetStaticObjectField( 806*cdf0e10cSrcweir (jclass) jo_Type.get(), field_Type_UNSIGNED_LONG ) ); 807*cdf0e10cSrcweir // get com.sun.star.uno.Type.UNSIGNED_HYPER 808*cdf0e10cSrcweir jfieldID field_Type_UNSIGNED_HYPER = jni->GetStaticFieldID( 809*cdf0e10cSrcweir (jclass) jo_Type.get(), "UNSIGNED_HYPER", "Lcom/sun/star/uno/Type;" ); 810*cdf0e10cSrcweir jni.ensure_no_exception(); 811*cdf0e10cSrcweir OSL_ASSERT( 0 != field_Type_UNSIGNED_HYPER ); 812*cdf0e10cSrcweir JLocalAutoRef jo_Type_UNSIGNED_HYPER( 813*cdf0e10cSrcweir jni, jni->GetStaticObjectField( 814*cdf0e10cSrcweir (jclass) jo_Type.get(), field_Type_UNSIGNED_HYPER ) ); 815*cdf0e10cSrcweir 816*cdf0e10cSrcweir // make global refs 817*cdf0e10cSrcweir m_class_UnoRuntime = 818*cdf0e10cSrcweir (jclass) jni->NewGlobalRef( jo_UnoRuntime.get() ); 819*cdf0e10cSrcweir m_class_RuntimeException = 820*cdf0e10cSrcweir (jclass) jni->NewGlobalRef( jo_RuntimeException.get() ); 821*cdf0e10cSrcweir m_class_Any = 822*cdf0e10cSrcweir (jclass) jni->NewGlobalRef( jo_Any.get() ); 823*cdf0e10cSrcweir m_class_Type = 824*cdf0e10cSrcweir (jclass) jni->NewGlobalRef( jo_Type.get() ); 825*cdf0e10cSrcweir m_class_TypeClass = 826*cdf0e10cSrcweir (jclass) jni->NewGlobalRef( jo_TypeClass.get() ); 827*cdf0e10cSrcweir m_class_JNI_proxy = 828*cdf0e10cSrcweir (jclass) jni->NewGlobalRef( jo_JNI_proxy.get() ); 829*cdf0e10cSrcweir 830*cdf0e10cSrcweir m_class_Character = 831*cdf0e10cSrcweir (jclass) jni->NewGlobalRef( jo_Character.get() ); 832*cdf0e10cSrcweir m_class_Boolean = 833*cdf0e10cSrcweir (jclass) jni->NewGlobalRef( jo_Boolean.get() ); 834*cdf0e10cSrcweir m_class_Byte = 835*cdf0e10cSrcweir (jclass) jni->NewGlobalRef( jo_Byte.get() ); 836*cdf0e10cSrcweir m_class_Short = 837*cdf0e10cSrcweir (jclass) jni->NewGlobalRef( jo_Short.get() ); 838*cdf0e10cSrcweir m_class_Integer = 839*cdf0e10cSrcweir (jclass) jni->NewGlobalRef( jo_Integer.get() ); 840*cdf0e10cSrcweir m_class_Long = 841*cdf0e10cSrcweir (jclass) jni->NewGlobalRef( jo_Long.get() ); 842*cdf0e10cSrcweir m_class_Float = 843*cdf0e10cSrcweir (jclass) jni->NewGlobalRef( jo_Float.get() ); 844*cdf0e10cSrcweir m_class_Double = 845*cdf0e10cSrcweir (jclass) jni->NewGlobalRef( jo_Double.get() ); 846*cdf0e10cSrcweir m_class_String = 847*cdf0e10cSrcweir (jclass) jni->NewGlobalRef( jo_String.get() ); 848*cdf0e10cSrcweir m_class_Object = 849*cdf0e10cSrcweir (jclass) jni->NewGlobalRef( jo_Object.get() ); 850*cdf0e10cSrcweir m_class_Class = 851*cdf0e10cSrcweir (jclass) jni->NewGlobalRef( m_class_Class ); 852*cdf0e10cSrcweir 853*cdf0e10cSrcweir m_object_Any_VOID = 854*cdf0e10cSrcweir jni->NewGlobalRef( jo_Any_VOID.get() ); 855*cdf0e10cSrcweir m_object_Type_UNSIGNED_SHORT = 856*cdf0e10cSrcweir jni->NewGlobalRef( jo_Type_UNSIGNED_SHORT.get() ); 857*cdf0e10cSrcweir m_object_Type_UNSIGNED_LONG = 858*cdf0e10cSrcweir jni->NewGlobalRef( jo_Type_UNSIGNED_LONG.get() ); 859*cdf0e10cSrcweir m_object_Type_UNSIGNED_HYPER = 860*cdf0e10cSrcweir jni->NewGlobalRef( jo_Type_UNSIGNED_HYPER.get() ); 861*cdf0e10cSrcweir m_object_java_env = jni->NewGlobalRef( jo_java_env.get() ); 862*cdf0e10cSrcweir 863*cdf0e10cSrcweir try 864*cdf0e10cSrcweir { 865*cdf0e10cSrcweir css::uno::TypeDescription XInterface_td( 866*cdf0e10cSrcweir ::getCppuType( 867*cdf0e10cSrcweir (css::uno::Reference< css::uno::XInterface > const *)0 ) ); 868*cdf0e10cSrcweir m_XInterface_type_info = 869*cdf0e10cSrcweir new JNI_interface_type_info( jni, XInterface_td.get() ); 870*cdf0e10cSrcweir } 871*cdf0e10cSrcweir catch (...) 872*cdf0e10cSrcweir { 873*cdf0e10cSrcweir destruct( jni_env ); 874*cdf0e10cSrcweir throw; 875*cdf0e10cSrcweir } 876*cdf0e10cSrcweir } 877*cdf0e10cSrcweir 878*cdf0e10cSrcweir //______________________________________________________________________________ 879*cdf0e10cSrcweir void JNI_info::destruct( JNIEnv * jni_env ) 880*cdf0e10cSrcweir { 881*cdf0e10cSrcweir t_str2type::const_iterator iPos( m_type_map.begin() ); 882*cdf0e10cSrcweir t_str2type::const_iterator const iEnd( m_type_map.begin() ); 883*cdf0e10cSrcweir for ( ; iPos != iEnd; ++iPos ) 884*cdf0e10cSrcweir { 885*cdf0e10cSrcweir iPos->second.m_info->destroy( jni_env ); 886*cdf0e10cSrcweir } 887*cdf0e10cSrcweir if (0 != m_XInterface_type_info) 888*cdf0e10cSrcweir { 889*cdf0e10cSrcweir const_cast< JNI_interface_type_info * >( 890*cdf0e10cSrcweir m_XInterface_type_info )->destroy( jni_env ); 891*cdf0e10cSrcweir } 892*cdf0e10cSrcweir 893*cdf0e10cSrcweir // free global refs 894*cdf0e10cSrcweir jni_env->DeleteGlobalRef( m_object_java_env ); 895*cdf0e10cSrcweir jni_env->DeleteGlobalRef( m_object_Any_VOID ); 896*cdf0e10cSrcweir jni_env->DeleteGlobalRef( m_object_Type_UNSIGNED_SHORT ); 897*cdf0e10cSrcweir jni_env->DeleteGlobalRef( m_object_Type_UNSIGNED_LONG ); 898*cdf0e10cSrcweir jni_env->DeleteGlobalRef( m_object_Type_UNSIGNED_HYPER ); 899*cdf0e10cSrcweir 900*cdf0e10cSrcweir jni_env->DeleteGlobalRef( m_class_Class ); 901*cdf0e10cSrcweir jni_env->DeleteGlobalRef( m_class_Object ); 902*cdf0e10cSrcweir jni_env->DeleteGlobalRef( m_class_String ); 903*cdf0e10cSrcweir jni_env->DeleteGlobalRef( m_class_Double ); 904*cdf0e10cSrcweir jni_env->DeleteGlobalRef( m_class_Float ); 905*cdf0e10cSrcweir jni_env->DeleteGlobalRef( m_class_Long ); 906*cdf0e10cSrcweir jni_env->DeleteGlobalRef( m_class_Integer ); 907*cdf0e10cSrcweir jni_env->DeleteGlobalRef( m_class_Short ); 908*cdf0e10cSrcweir jni_env->DeleteGlobalRef( m_class_Byte ); 909*cdf0e10cSrcweir jni_env->DeleteGlobalRef( m_class_Boolean ); 910*cdf0e10cSrcweir jni_env->DeleteGlobalRef( m_class_Character ); 911*cdf0e10cSrcweir 912*cdf0e10cSrcweir jni_env->DeleteGlobalRef( m_class_JNI_proxy ); 913*cdf0e10cSrcweir jni_env->DeleteGlobalRef( m_class_RuntimeException ); 914*cdf0e10cSrcweir jni_env->DeleteGlobalRef( m_class_UnoRuntime ); 915*cdf0e10cSrcweir jni_env->DeleteGlobalRef( m_class_TypeClass ); 916*cdf0e10cSrcweir jni_env->DeleteGlobalRef( m_class_Type ); 917*cdf0e10cSrcweir jni_env->DeleteGlobalRef( m_class_Any ); 918*cdf0e10cSrcweir } 919*cdf0e10cSrcweir 920*cdf0e10cSrcweir //______________________________________________________________________________ 921*cdf0e10cSrcweir JNI_info const * JNI_info::get_jni_info( 922*cdf0e10cSrcweir rtl::Reference< jvmaccess::UnoVirtualMachine > const & uno_vm ) 923*cdf0e10cSrcweir { 924*cdf0e10cSrcweir // !!!no JNI_info available at JNI_context!!! 925*cdf0e10cSrcweir ::jvmaccess::VirtualMachine::AttachGuard guard( 926*cdf0e10cSrcweir uno_vm->getVirtualMachine() ); 927*cdf0e10cSrcweir JNIEnv * jni_env = guard.getEnvironment(); 928*cdf0e10cSrcweir JNI_context jni( 929*cdf0e10cSrcweir 0, jni_env, static_cast< jobject >(uno_vm->getClassLoader()) ); 930*cdf0e10cSrcweir 931*cdf0e10cSrcweir jclass jo_class; 932*cdf0e10cSrcweir jmethodID jo_forName; 933*cdf0e10cSrcweir jni.getClassForName( &jo_class, &jo_forName ); 934*cdf0e10cSrcweir jni.ensure_no_exception(); 935*cdf0e10cSrcweir JLocalAutoRef jo_JNI_info_holder( 936*cdf0e10cSrcweir jni, 937*cdf0e10cSrcweir jni.findClass( 938*cdf0e10cSrcweir "com.sun.star.bridges.jni_uno.JNI_info_holder", jo_class, 939*cdf0e10cSrcweir jo_forName, false ) ); 940*cdf0e10cSrcweir // field JNI_info_holder.m_jni_info_handle 941*cdf0e10cSrcweir jfieldID field_s_jni_info_handle = 942*cdf0e10cSrcweir jni->GetStaticFieldID( 943*cdf0e10cSrcweir (jclass) jo_JNI_info_holder.get(), "s_jni_info_handle", "J" ); 944*cdf0e10cSrcweir jni.ensure_no_exception(); 945*cdf0e10cSrcweir OSL_ASSERT( 0 != field_s_jni_info_handle ); 946*cdf0e10cSrcweir 947*cdf0e10cSrcweir JNI_info const * jni_info = 948*cdf0e10cSrcweir reinterpret_cast< JNI_info const * >( 949*cdf0e10cSrcweir jni->GetStaticLongField( 950*cdf0e10cSrcweir (jclass) jo_JNI_info_holder.get(), field_s_jni_info_handle ) ); 951*cdf0e10cSrcweir if (0 == jni_info) // un-initialized? 952*cdf0e10cSrcweir { 953*cdf0e10cSrcweir JNI_info * new_info = new JNI_info( 954*cdf0e10cSrcweir jni_env, static_cast< jobject >(uno_vm->getClassLoader()), jo_class, 955*cdf0e10cSrcweir jo_forName ); 956*cdf0e10cSrcweir 957*cdf0e10cSrcweir ClearableMutexGuard g( Mutex::getGlobalMutex() ); 958*cdf0e10cSrcweir jni_info = 959*cdf0e10cSrcweir reinterpret_cast< JNI_info const * >( 960*cdf0e10cSrcweir jni->GetStaticLongField( 961*cdf0e10cSrcweir (jclass) jo_JNI_info_holder.get(), 962*cdf0e10cSrcweir field_s_jni_info_handle ) ); 963*cdf0e10cSrcweir if (0 == jni_info) // still un-initialized? 964*cdf0e10cSrcweir { 965*cdf0e10cSrcweir jni->SetStaticLongField( 966*cdf0e10cSrcweir (jclass) jo_JNI_info_holder.get(), field_s_jni_info_handle, 967*cdf0e10cSrcweir reinterpret_cast< jlong >( new_info ) ); 968*cdf0e10cSrcweir jni_info = new_info; 969*cdf0e10cSrcweir } 970*cdf0e10cSrcweir else 971*cdf0e10cSrcweir { 972*cdf0e10cSrcweir g.clear(); 973*cdf0e10cSrcweir new_info->destroy( jni_env ); 974*cdf0e10cSrcweir } 975*cdf0e10cSrcweir } 976*cdf0e10cSrcweir 977*cdf0e10cSrcweir return jni_info; 978*cdf0e10cSrcweir } 979*cdf0e10cSrcweir 980*cdf0e10cSrcweir } 981*cdf0e10cSrcweir 982*cdf0e10cSrcweir extern "C" 983*cdf0e10cSrcweir { 984*cdf0e10cSrcweir 985*cdf0e10cSrcweir //------------------------------------------------------------------------------ 986*cdf0e10cSrcweir JNIEXPORT void 987*cdf0e10cSrcweir JNICALL Java_com_sun_star_bridges_jni_1uno_JNI_1info_1holder_finalize__J( 988*cdf0e10cSrcweir JNIEnv * jni_env, jobject, jlong jni_info_handle ) 989*cdf0e10cSrcweir SAL_THROW_EXTERN_C() 990*cdf0e10cSrcweir { 991*cdf0e10cSrcweir ::jni_uno::JNI_info * jni_info = 992*cdf0e10cSrcweir reinterpret_cast< ::jni_uno::JNI_info * >( jni_info_handle ); 993*cdf0e10cSrcweir jni_info->destroy( jni_env ); 994*cdf0e10cSrcweir } 995*cdf0e10cSrcweir 996*cdf0e10cSrcweir } 997