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