1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: jni_data.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_bridges.hxx"
34 #include "jni_bridge.h"
36 #include "rtl/strbuf.hxx"
37 #include "rtl/ustrbuf.hxx"
38 #include "uno/sequence2.h"
41 using namespace ::std
;
42 using namespace ::rtl
;
47 //------------------------------------------------------------------------------
48 inline rtl_mem
* seq_allocate( sal_Int32 nElements
, sal_Int32 nSize
)
50 auto_ptr
< rtl_mem
> seq(
51 rtl_mem::allocate( SAL_SEQUENCE_HEADER_SIZE
+ (nElements
* nSize
) ) );
52 uno_Sequence
* p
= (uno_Sequence
*)seq
.get();
54 p
->nElements
= nElements
;
58 //______________________________________________________________________________
61 void createDefaultUnoValue(
62 JNI_context
const & jni
, void * uno_data
,
63 typelib_TypeDescriptionReference
* type
,
64 JNI_type_info
const * info
/* maybe 0 */, bool assign
)
66 switch (type
->eTypeClass
) {
67 case typelib_TypeClass_BOOLEAN
:
68 *static_cast< sal_Bool
* >(uno_data
) = false;
71 case typelib_TypeClass_BYTE
:
72 *static_cast< sal_Int8
* >(uno_data
) = 0;
75 case typelib_TypeClass_SHORT
:
76 *static_cast< sal_Int16
* >(uno_data
) = 0;
79 case typelib_TypeClass_UNSIGNED_SHORT
:
80 *static_cast< sal_uInt16
* >(uno_data
) = 0;
83 case typelib_TypeClass_LONG
:
84 *static_cast< sal_Int32
* >(uno_data
) = 0;
87 case typelib_TypeClass_UNSIGNED_LONG
:
88 *static_cast< sal_uInt32
* >(uno_data
) = 0;
91 case typelib_TypeClass_HYPER
:
92 *static_cast< sal_Int64
* >(uno_data
) = 0;
95 case typelib_TypeClass_UNSIGNED_HYPER
:
96 *static_cast< sal_uInt64
* >(uno_data
) = 0;
99 case typelib_TypeClass_FLOAT
:
100 *static_cast< float * >(uno_data
) = 0;
103 case typelib_TypeClass_DOUBLE
:
104 *static_cast< double * >(uno_data
) = 0;
107 case typelib_TypeClass_CHAR
:
108 *static_cast< sal_Unicode
* >(uno_data
) = 0;
111 case typelib_TypeClass_STRING
:
113 *static_cast< rtl_uString
** >(uno_data
) = 0;
115 rtl_uString_new(static_cast< rtl_uString
** >(uno_data
));
118 case typelib_TypeClass_TYPE
:
120 typelib_typedescriptionreference_release(
121 *static_cast< typelib_TypeDescriptionReference
** >(uno_data
));
123 *static_cast< typelib_TypeDescriptionReference
** >(uno_data
)
124 = *typelib_static_type_getByTypeClass(typelib_TypeClass_VOID
);
126 *static_cast< typelib_TypeDescriptionReference
** >(uno_data
) != 0);
127 typelib_typedescriptionreference_acquire(
128 *static_cast< typelib_TypeDescriptionReference
** >(uno_data
));
131 case typelib_TypeClass_ANY
:
133 uno_any_destruct(static_cast< uno_Any
* >(uno_data
), 0);
136 static_cast< uno_Any
* >(uno_data
), 0,
137 jni
.get_info()->m_XInterface_type_info
->m_td
.get(), 0);
140 case typelib_TypeClass_SEQUENCE
:
142 auto_ptr
< rtl_mem
> seq(seq_allocate(0, 0));
144 uno_type_destructData(uno_data
, type
, 0);
146 *static_cast< uno_Sequence
** >(uno_data
)
147 = reinterpret_cast< uno_Sequence
* >(seq
.release());
151 case typelib_TypeClass_ENUM
:
153 typelib_TypeDescription
* td
= 0;
154 TYPELIB_DANGER_GET(&td
, type
);
155 *static_cast< sal_Int32
* >(uno_data
)
156 = (reinterpret_cast< typelib_EnumTypeDescription
* >(td
)->
158 TYPELIB_DANGER_RELEASE(td
);
162 case typelib_TypeClass_STRUCT
:
165 info
= jni
.get_info()->get_type_info(jni
, type
);
167 JNI_compound_type_info
const * comp_info
168 = static_cast< JNI_compound_type_info
const * >(info
);
169 typelib_CompoundTypeDescription
* comp_td
170 = reinterpret_cast< typelib_CompoundTypeDescription
* >(
171 comp_info
->m_td
.get());
173 sal_Int32 nMembers
= comp_td
->nMembers
;
175 if (comp_td
->pBaseTypeDescription
!= 0) {
176 createDefaultUnoValue(
178 comp_td
->pBaseTypeDescription
->aBase
.pWeakRef
,
179 comp_info
->m_base
, assign
);
181 for (; nPos
< nMembers
; ++nPos
) {
182 createDefaultUnoValue(
184 (static_cast< char * >(uno_data
)
185 + comp_td
->pMemberOffsets
[nPos
]),
186 comp_td
->ppTypeRefs
[nPos
], 0, assign
);
190 for (sal_Int32 i
= 0; i
< nPos
; ++i
) {
191 uno_type_destructData(
192 (static_cast< char * >(uno_data
)
193 + comp_td
->pMemberOffsets
[i
]),
194 comp_td
->ppTypeRefs
[i
], 0);
196 if (comp_td
->pBaseTypeDescription
!= 0) {
198 uno_data
, &comp_td
->pBaseTypeDescription
->aBase
, 0);
206 case typelib_TypeClass_INTERFACE
:
208 uno_Interface
* p
= *static_cast< uno_Interface
** >(uno_data
);
213 *static_cast< uno_Interface
** >(uno_data
) = 0;
224 void Bridge::map_to_uno(
225 JNI_context
const & jni
,
226 void * uno_data
, jvalue java_data
,
227 typelib_TypeDescriptionReference
* type
,
228 JNI_type_info
const * info
/* maybe 0 */,
229 bool assign
, bool out_param
,
230 bool special_wrapped_integral_types
) const
234 (1 == jni
->GetArrayLength( (jarray
) java_data
.l
)) );
236 switch (type
->eTypeClass
)
238 case typelib_TypeClass_CHAR
:
241 jni
->GetCharArrayRegion(
242 (jcharArray
) java_data
.l
, 0, 1, (jchar
*) uno_data
);
243 jni
.ensure_no_exception();
245 else if (special_wrapped_integral_types
)
247 *(jchar
*) uno_data
= jni
->CallCharMethodA(
248 java_data
.l
, m_jni_info
->m_method_Character_charValue
, 0 );
249 jni
.ensure_no_exception();
253 *(jchar
*) uno_data
= java_data
.c
;
256 case typelib_TypeClass_BOOLEAN
:
259 jni
->GetBooleanArrayRegion(
260 (jbooleanArray
) java_data
.l
, 0, 1, (jboolean
*) uno_data
);
261 jni
.ensure_no_exception();
263 else if (special_wrapped_integral_types
)
265 *(jboolean
*) uno_data
= jni
->CallBooleanMethodA(
266 java_data
.l
, m_jni_info
->m_method_Boolean_booleanValue
, 0 );
267 jni
.ensure_no_exception();
271 *(jboolean
*) uno_data
= java_data
.z
;
274 case typelib_TypeClass_BYTE
:
277 jni
->GetByteArrayRegion(
278 (jbyteArray
) java_data
.l
, 0, 1, (jbyte
*) uno_data
);
279 jni
.ensure_no_exception();
281 else if (special_wrapped_integral_types
)
283 *(jbyte
*) uno_data
= jni
->CallByteMethodA(
284 java_data
.l
, m_jni_info
->m_method_Byte_byteValue
, 0 );
285 jni
.ensure_no_exception();
289 *(jbyte
*) uno_data
= java_data
.b
;
292 case typelib_TypeClass_SHORT
:
293 case typelib_TypeClass_UNSIGNED_SHORT
:
296 jni
->GetShortArrayRegion(
297 (jshortArray
) java_data
.l
, 0, 1, (jshort
*) uno_data
);
298 jni
.ensure_no_exception();
300 else if (special_wrapped_integral_types
)
302 *(jshort
*) uno_data
= jni
->CallShortMethodA(
303 java_data
.l
, m_jni_info
->m_method_Short_shortValue
, 0 );
304 jni
.ensure_no_exception();
308 *(jshort
*) uno_data
= java_data
.s
;
311 case typelib_TypeClass_LONG
:
312 case typelib_TypeClass_UNSIGNED_LONG
:
315 jni
->GetIntArrayRegion(
316 (jintArray
) java_data
.l
, 0, 1, (jint
*) uno_data
);
317 jni
.ensure_no_exception();
319 else if (special_wrapped_integral_types
)
321 *(jint
*) uno_data
= jni
->CallIntMethodA(
322 java_data
.l
, m_jni_info
->m_method_Integer_intValue
, 0 );
323 jni
.ensure_no_exception();
327 *(jint
*) uno_data
= java_data
.i
;
330 case typelib_TypeClass_HYPER
:
331 case typelib_TypeClass_UNSIGNED_HYPER
:
334 jni
->GetLongArrayRegion(
335 (jlongArray
) java_data
.l
, 0, 1, (jlong
*) uno_data
);
336 jni
.ensure_no_exception();
338 else if (special_wrapped_integral_types
)
340 *(jlong
*) uno_data
= jni
->CallLongMethodA(
341 java_data
.l
, m_jni_info
->m_method_Long_longValue
, 0 );
342 jni
.ensure_no_exception();
346 *(jlong
*) uno_data
= java_data
.j
;
349 case typelib_TypeClass_FLOAT
:
352 jni
->GetFloatArrayRegion(
353 (jfloatArray
) java_data
.l
, 0, 1, (jfloat
*) uno_data
);
354 jni
.ensure_no_exception();
356 else if (special_wrapped_integral_types
)
358 *(jfloat
*) uno_data
= jni
->CallFloatMethodA(
359 java_data
.l
, m_jni_info
->m_method_Float_floatValue
, 0 );
360 jni
.ensure_no_exception();
364 *(jfloat
*) uno_data
= java_data
.f
;
367 case typelib_TypeClass_DOUBLE
:
370 jni
->GetDoubleArrayRegion(
371 (jdoubleArray
) java_data
.l
, 0, 1, (jdouble
*) uno_data
);
372 jni
.ensure_no_exception();
374 else if (special_wrapped_integral_types
)
376 *(jdouble
*) uno_data
= jni
->CallDoubleMethodA(
377 java_data
.l
, m_jni_info
->m_method_Double_doubleValue
, 0 );
378 jni
.ensure_no_exception();
382 *(jdouble
*) uno_data
= java_data
.d
;
385 case typelib_TypeClass_STRING
:
387 JLocalAutoRef
jo_out_holder( jni
);
391 jni
->GetObjectArrayElement( (jobjectArray
) java_data
.l
, 0 ) );
392 jni
.ensure_no_exception();
393 java_data
.l
= jo_out_holder
.get();
395 if (0 == java_data
.l
)
397 OUStringBuffer
buf( 128 );
398 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
399 buf
.append( OUString::unacquired( &type
->pTypeName
) );
400 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("] null-ref given!") );
401 buf
.append( jni
.get_stack_trace() );
402 throw BridgeRuntimeError( buf
.makeStringAndClear() );
405 *(rtl_uString
**)uno_data
= 0;
407 jni
, (rtl_uString
**)uno_data
, (jstring
) java_data
.l
);
410 case typelib_TypeClass_TYPE
:
412 JLocalAutoRef
jo_out_holder( jni
);
416 jni
->GetObjectArrayElement( (jobjectArray
) java_data
.l
, 0 ) );
417 jni
.ensure_no_exception();
418 java_data
.l
= jo_out_holder
.get();
420 if (0 == java_data
.l
)
422 OUStringBuffer
buf( 128 );
423 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
424 buf
.append( OUString::unacquired( &type
->pTypeName
) );
425 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("] null-ref given!") );
426 buf
.append( jni
.get_stack_trace() );
427 throw BridgeRuntimeError( buf
.makeStringAndClear() );
431 JLocalAutoRef
jo_type_name(
432 jni
, jni
->GetObjectField(
433 java_data
.l
, m_jni_info
->m_field_Type__typeName
) );
434 if (! jo_type_name
.is())
436 OUStringBuffer
buf( 128 );
437 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
438 buf
.append( OUString::unacquired( &type
->pTypeName
) );
440 RTL_CONSTASCII_STRINGPARAM("] incomplete type object: "
442 buf
.append( jni
.get_stack_trace() );
443 throw BridgeRuntimeError( buf
.makeStringAndClear() );
446 jstring_to_oustring( jni
, (jstring
) jo_type_name
.get() ) );
447 ::com::sun::star::uno::TypeDescription
td( type_name
);
450 OUStringBuffer
buf( 128 );
451 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
452 buf
.append( OUString::unacquired( &type
->pTypeName
) );
454 RTL_CONSTASCII_STRINGPARAM("] UNO type not found: ") );
455 buf
.append( type_name
);
456 buf
.append( jni
.get_stack_trace() );
457 throw BridgeRuntimeError( buf
.makeStringAndClear() );
459 typelib_typedescriptionreference_acquire( td
.get()->pWeakRef
);
462 typelib_typedescriptionreference_release(
463 *(typelib_TypeDescriptionReference
**)uno_data
);
465 *(typelib_TypeDescriptionReference
**)uno_data
= td
.get()->pWeakRef
;
468 case typelib_TypeClass_ANY
:
470 JLocalAutoRef
jo_out_holder( jni
);
474 jni
->GetObjectArrayElement( (jobjectArray
) java_data
.l
, 0 ) );
475 jni
.ensure_no_exception();
476 java_data
.l
= jo_out_holder
.get();
479 uno_Any
* pAny
= (uno_Any
*)uno_data
;
480 if (0 == java_data
.l
) // null-ref maps to XInterface null-ref
483 uno_any_destruct( pAny
, 0 );
485 pAny
, 0, m_jni_info
->m_XInterface_type_info
->m_td
.get(), 0 );
489 JLocalAutoRef
jo_type( jni
);
490 JLocalAutoRef
jo_wrapped_holder( jni
);
492 if (JNI_FALSE
!= jni
->IsInstanceOf(
493 java_data
.l
, m_jni_info
->m_class_Any
))
496 jo_type
.reset( jni
->GetObjectField(
497 java_data
.l
, m_jni_info
->m_field_Any__type
) );
500 OUStringBuffer
buf( 128 );
501 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
502 buf
.append( OUString::unacquired( &type
->pTypeName
) );
504 RTL_CONSTASCII_STRINGPARAM("] no type set at "
505 "com.sun.star.uno.Any!") );
506 buf
.append( jni
.get_stack_trace() );
507 throw BridgeRuntimeError( buf
.makeStringAndClear() );
510 jo_wrapped_holder
.reset(
512 java_data
.l
, m_jni_info
->m_field_Any__object
) );
513 java_data
.l
= jo_wrapped_holder
.get();
517 // create type out of class
518 JLocalAutoRef
jo_class( jni
, jni
->GetObjectClass( java_data
.l
) );
519 jo_type
.reset( create_type( jni
, (jclass
) jo_class
.get() ) );
520 #if OSL_DEBUG_LEVEL > 1
522 JLocalAutoRef
jo_toString(
523 jni
, jni
->CallObjectMethodA(
524 java_data
.l
, m_jni_info
->m_method_Object_toString
, 0 ) );
525 jni
.ensure_no_exception();
527 jstring_to_oustring( jni
, (jstring
) jo_toString
.get() ) );
533 JLocalAutoRef
jo_type_name(
534 jni
, jni
->GetObjectField(
535 jo_type
.get(), m_jni_info
->m_field_Type__typeName
) );
536 jni
.ensure_no_exception();
538 jstring_to_oustring( jni
, (jstring
) jo_type_name
.get() ) );
540 ::com::sun::star::uno::TypeDescription
value_td( type_name
);
543 OUStringBuffer
buf( 128 );
544 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
545 buf
.append( OUString::unacquired( &type
->pTypeName
) );
547 RTL_CONSTASCII_STRINGPARAM("] UNO type not found: ") );
548 buf
.append( type_name
);
549 buf
.append( jni
.get_stack_trace() );
550 throw BridgeRuntimeError( buf
.makeStringAndClear() );
552 typelib_TypeClass type_class
= value_td
.get()->eTypeClass
;
556 uno_any_destruct( pAny
, 0 );
562 case typelib_TypeClass_VOID
:
563 pAny
->pData
= &pAny
->pReserved
;
565 case typelib_TypeClass_CHAR
:
566 *(jchar
*) &pAny
->pReserved
= jni
->CallCharMethodA(
567 java_data
.l
, m_jni_info
->m_method_Character_charValue
, 0 );
568 jni
.ensure_no_exception();
569 pAny
->pData
= &pAny
->pReserved
;
571 case typelib_TypeClass_BOOLEAN
:
572 *(jboolean
*) &pAny
->pReserved
= jni
->CallBooleanMethodA(
573 java_data
.l
, m_jni_info
->m_method_Boolean_booleanValue
, 0 );
574 jni
.ensure_no_exception();
575 pAny
->pData
= &pAny
->pReserved
;
577 case typelib_TypeClass_BYTE
:
578 *(jbyte
*) &pAny
->pReserved
= jni
->CallByteMethodA(
579 java_data
.l
, m_jni_info
->m_method_Byte_byteValue
, 0 );
580 jni
.ensure_no_exception();
581 pAny
->pData
= &pAny
->pReserved
;
583 case typelib_TypeClass_SHORT
:
584 case typelib_TypeClass_UNSIGNED_SHORT
:
585 *(jshort
*) &pAny
->pReserved
= jni
->CallShortMethodA(
586 java_data
.l
, m_jni_info
->m_method_Short_shortValue
, 0 );
587 jni
.ensure_no_exception();
588 pAny
->pData
= &pAny
->pReserved
;
590 case typelib_TypeClass_LONG
:
591 case typelib_TypeClass_UNSIGNED_LONG
:
592 *(jint
*) &pAny
->pReserved
= jni
->CallIntMethodA(
593 java_data
.l
, m_jni_info
->m_method_Integer_intValue
, 0 );
594 jni
.ensure_no_exception();
595 pAny
->pData
= &pAny
->pReserved
;
597 case typelib_TypeClass_HYPER
:
598 case typelib_TypeClass_UNSIGNED_HYPER
:
599 if (sizeof (sal_Int64
) <= sizeof (void *))
601 *(jlong
*) &pAny
->pReserved
= jni
->CallLongMethodA(
602 java_data
.l
, m_jni_info
->m_method_Long_longValue
, 0 );
603 jni
.ensure_no_exception();
604 pAny
->pData
= &pAny
->pReserved
;
608 auto_ptr
< rtl_mem
> mem(
609 rtl_mem::allocate( sizeof (sal_Int64
) ) );
610 *(jlong
*) mem
.get() = jni
->CallLongMethodA(
611 java_data
.l
, m_jni_info
->m_method_Long_longValue
, 0 );
612 jni
.ensure_no_exception();
613 pAny
->pData
= mem
.release();
616 case typelib_TypeClass_FLOAT
:
617 if (sizeof (float) <= sizeof (void *))
619 *(jfloat
*) &pAny
->pReserved
= jni
->CallFloatMethodA(
620 java_data
.l
, m_jni_info
->m_method_Float_floatValue
, 0 );
621 jni
.ensure_no_exception();
622 pAny
->pData
= &pAny
->pReserved
;
626 auto_ptr
< rtl_mem
> mem(
627 rtl_mem::allocate( sizeof (float) ) );
628 *(jfloat
*) mem
.get() = jni
->CallFloatMethodA(
629 java_data
.l
, m_jni_info
->m_method_Float_floatValue
, 0 );
630 jni
.ensure_no_exception();
631 pAny
->pData
= mem
.release();
634 case typelib_TypeClass_DOUBLE
:
635 if (sizeof (double) <= sizeof (void *))
637 *(jdouble
*) &pAny
->pReserved
=
638 jni
->CallDoubleMethodA(
640 m_jni_info
->m_method_Double_doubleValue
, 0 );
641 jni
.ensure_no_exception();
642 pAny
->pData
= &pAny
->pReserved
;
646 auto_ptr
< rtl_mem
> mem(
647 rtl_mem::allocate( sizeof (double) ) );
648 *(jdouble
*) mem
.get() =
649 jni
->CallDoubleMethodA(
651 m_jni_info
->m_method_Double_doubleValue
, 0 );
652 jni
.ensure_no_exception();
653 pAny
->pData
= mem
.release();
656 case typelib_TypeClass_STRING
:
657 // opt: anies often contain strings; copy string directly
660 jni
, (rtl_uString
**)&pAny
->pReserved
,
661 (jstring
) java_data
.l
);
662 pAny
->pData
= &pAny
->pReserved
;
664 case typelib_TypeClass_TYPE
:
665 case typelib_TypeClass_ENUM
:
666 case typelib_TypeClass_SEQUENCE
:
667 case typelib_TypeClass_INTERFACE
:
669 jni
, &pAny
->pReserved
, java_data
,
670 value_td
.get()->pWeakRef
, 0,
671 false /* no assign */, false /* no out param */ );
672 pAny
->pData
= &pAny
->pReserved
;
674 case typelib_TypeClass_STRUCT
:
675 case typelib_TypeClass_EXCEPTION
:
677 auto_ptr
< rtl_mem
> mem(
678 rtl_mem::allocate( value_td
.get()->nSize
) );
680 jni
, mem
.get(), java_data
, value_td
.get()->pWeakRef
, 0,
681 false /* no assign */, false /* no out param */ );
682 pAny
->pData
= mem
.release();
687 OUStringBuffer
buf( 128 );
688 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
689 buf
.append( type_name
);
691 RTL_CONSTASCII_STRINGPARAM("] unsupported value type "
693 buf
.append( jni
.get_stack_trace() );
694 throw BridgeRuntimeError( buf
.makeStringAndClear() );
702 // restore to valid any
703 uno_any_construct( pAny
, 0, 0, 0 );
707 typelib_typedescriptionreference_acquire( value_td
.get()->pWeakRef
);
708 pAny
->pType
= value_td
.get()->pWeakRef
;
711 case typelib_TypeClass_ENUM
:
713 JLocalAutoRef
jo_out_holder( jni
);
717 jni
->GetObjectArrayElement( (jobjectArray
) java_data
.l
, 0 ) );
718 jni
.ensure_no_exception();
719 java_data
.l
= jo_out_holder
.get();
721 if (0 == java_data
.l
)
723 OUStringBuffer
buf( 128 );
724 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
725 buf
.append( OUString::unacquired( &type
->pTypeName
) );
726 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("] null-ref given!") );
727 buf
.append( jni
.get_stack_trace() );
728 throw BridgeRuntimeError( buf
.makeStringAndClear() );
731 *(jint
*) uno_data
= jni
->GetIntField(
732 java_data
.l
, m_jni_info
->m_field_Enum_m_value
);
735 case typelib_TypeClass_STRUCT
:
736 case typelib_TypeClass_EXCEPTION
:
738 JLocalAutoRef
jo_out_holder( jni
);
742 jni
->GetObjectArrayElement( (jobjectArray
) java_data
.l
, 0 ) );
743 jni
.ensure_no_exception();
744 java_data
.l
= jo_out_holder
.get();
746 if (0 == java_data
.l
)
748 OUStringBuffer
buf( 128 );
749 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
750 buf
.append( OUString::unacquired( &type
->pTypeName
) );
751 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("] null-ref given!") );
752 buf
.append( jni
.get_stack_trace() );
753 throw BridgeRuntimeError( buf
.makeStringAndClear() );
757 info
= m_jni_info
->get_type_info( jni
, type
);
758 JNI_compound_type_info
const * comp_info
=
759 static_cast< JNI_compound_type_info
const * >( info
);
761 typelib_CompoundTypeDescription
* comp_td
=
762 (typelib_CompoundTypeDescription
*)comp_info
->m_td
.get();
764 = comp_td
->aBase
.eTypeClass
== typelib_TypeClass_STRUCT
765 && reinterpret_cast< typelib_StructTypeDescription
* >(
766 comp_td
)->pParameterizedTypes
!= 0;
769 sal_Int32 nMembers
= comp_td
->nMembers
;
772 if (0 != comp_td
->pBaseTypeDescription
)
775 jni
, uno_data
, java_data
,
776 ((typelib_TypeDescription
*) comp_td
->pBaseTypeDescription
)
779 assign
, false /* no out param */ );
782 for ( ; nPos
< nMembers
; ++nPos
)
784 void * p
= (char *)uno_data
+ comp_td
->pMemberOffsets
[ nPos
];
785 typelib_TypeDescriptionReference
* member_type
=
786 comp_td
->ppTypeRefs
[ nPos
];
787 jfieldID field_id
= comp_info
->m_fields
[ nPos
];
788 bool parameterizedType
= polymorphic
789 && reinterpret_cast< typelib_StructTypeDescription
* >(
790 comp_td
)->pParameterizedTypes
[nPos
];
791 switch (member_type
->eTypeClass
)
793 case typelib_TypeClass_CHAR
:
794 if (parameterizedType
) {
796 jni
, jni
->GetObjectField( java_data
.l
, field_id
) );
797 if ( jo
.get() == 0 ) {
803 jni
, p
, val
, member_type
, 0, assign
, false,
807 *(jchar
*) p
= jni
->GetCharField(
808 java_data
.l
, field_id
);
811 case typelib_TypeClass_BOOLEAN
:
812 if (parameterizedType
) {
814 jni
, jni
->GetObjectField( java_data
.l
, field_id
) );
815 if ( jo
.get() == 0 ) {
816 *(jboolean
*) p
= false;
821 jni
, p
, val
, member_type
, 0, assign
, false,
825 *(jboolean
*) p
= jni
->GetBooleanField(
826 java_data
.l
, field_id
);
829 case typelib_TypeClass_BYTE
:
830 if (parameterizedType
) {
832 jni
, jni
->GetObjectField( java_data
.l
, field_id
) );
833 if ( jo
.get() == 0 ) {
839 jni
, p
, val
, member_type
, 0, assign
, false,
843 *(jbyte
*) p
= jni
->GetByteField(
844 java_data
.l
, field_id
);
847 case typelib_TypeClass_SHORT
:
848 case typelib_TypeClass_UNSIGNED_SHORT
:
849 if (parameterizedType
) {
851 jni
, jni
->GetObjectField( java_data
.l
, field_id
) );
852 if ( jo
.get() == 0 ) {
858 jni
, p
, val
, member_type
, 0, assign
, false,
862 *(jshort
*) p
= jni
->GetShortField(
863 java_data
.l
, field_id
);
866 case typelib_TypeClass_LONG
:
867 case typelib_TypeClass_UNSIGNED_LONG
:
868 if (parameterizedType
) {
870 jni
, jni
->GetObjectField( java_data
.l
, field_id
) );
871 if ( jo
.get() == 0 ) {
877 jni
, p
, val
, member_type
, 0, assign
, false,
881 *(jint
*) p
= jni
->GetIntField( java_data
.l
, field_id
);
884 case typelib_TypeClass_HYPER
:
885 case typelib_TypeClass_UNSIGNED_HYPER
:
886 if (parameterizedType
) {
888 jni
, jni
->GetObjectField( java_data
.l
, field_id
) );
889 if ( jo
.get() == 0 ) {
895 jni
, p
, val
, member_type
, 0, assign
, false,
899 *(jlong
*) p
= jni
->GetLongField(
900 java_data
.l
, field_id
);
903 case typelib_TypeClass_FLOAT
:
904 if (parameterizedType
) {
906 jni
, jni
->GetObjectField( java_data
.l
, field_id
) );
907 if ( jo
.get() == 0 ) {
913 jni
, p
, val
, member_type
, 0, assign
, false,
917 *(jfloat
*) p
= jni
->GetFloatField(
918 java_data
.l
, field_id
);
921 case typelib_TypeClass_DOUBLE
:
922 if (parameterizedType
) {
924 jni
, jni
->GetObjectField( java_data
.l
, field_id
) );
925 if ( jo
.get() == 0 ) {
931 jni
, p
, val
, member_type
, 0, assign
, false,
935 *(jdouble
*) p
= jni
->GetDoubleField(
936 java_data
.l
, field_id
);
941 JLocalAutoRef
jo_field( jni
);
945 // special for Message: call Throwable.getMessage()
949 m_jni_info
->m_Exception_type
.getTypeLibType() )
952 m_jni_info
->m_RuntimeException_type
.
953 getTypeLibType() ) );
954 OSL_ASSERT( 0 == nPos
); // first member
957 jni
->CallObjectMethodA(
959 m_jni_info
->m_method_Throwable_getMessage
, 0 )
961 jni
.ensure_no_exception();
967 jni
->GetObjectField( java_data
.l
, field_id
) );
968 checkNull
= parameterizedType
;
970 if (checkNull
&& !jo_field
.is()) {
971 createDefaultUnoValue(jni
, p
, member_type
, 0, assign
);
974 val
.l
= jo_field
.get();
976 jni
, p
, val
, member_type
, 0,
977 assign
, false /* no out param */ );
989 for ( sal_Int32 nCleanup
= 0; nCleanup
< nPos
; ++nCleanup
)
992 (char *)uno_data
+ comp_td
->pMemberOffsets
[ nCleanup
];
993 uno_type_destructData(
994 p
, comp_td
->ppTypeRefs
[ nCleanup
], 0 );
996 if (0 != comp_td
->pBaseTypeDescription
)
1000 (typelib_TypeDescription
*) comp_td
1001 ->pBaseTypeDescription
, 0 );
1008 case typelib_TypeClass_SEQUENCE
:
1010 JLocalAutoRef
jo_out_holder( jni
);
1013 jo_out_holder
.reset(
1014 jni
->GetObjectArrayElement( (jobjectArray
) java_data
.l
, 0 ) );
1015 jni
.ensure_no_exception();
1016 java_data
.l
= jo_out_holder
.get();
1018 if (0 == java_data
.l
)
1020 OUStringBuffer
buf( 128 );
1021 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
1022 buf
.append( OUString::unacquired( &type
->pTypeName
) );
1023 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("] null-ref given!") );
1024 buf
.append( jni
.get_stack_trace() );
1025 throw BridgeRuntimeError( buf
.makeStringAndClear() );
1028 TypeDescr
td( type
);
1029 typelib_TypeDescriptionReference
* element_type
=
1030 ((typelib_IndirectTypeDescription
*)td
.get())->pType
;
1032 auto_ptr
< rtl_mem
> seq
;
1033 sal_Int32 nElements
= jni
->GetArrayLength( (jarray
) java_data
.l
);
1035 switch (element_type
->eTypeClass
)
1037 case typelib_TypeClass_CHAR
:
1038 seq
.reset( seq_allocate( nElements
, sizeof (sal_Unicode
) ) );
1039 jni
->GetCharArrayRegion(
1040 (jcharArray
) java_data
.l
, 0, nElements
,
1041 (jchar
*) ((uno_Sequence
*) seq
.get())->elements
);
1042 jni
.ensure_no_exception();
1044 case typelib_TypeClass_BOOLEAN
:
1045 seq
.reset( seq_allocate( nElements
, sizeof (sal_Bool
) ) );
1046 jni
->GetBooleanArrayRegion(
1047 (jbooleanArray
) java_data
.l
, 0, nElements
,
1048 (jboolean
*) ((uno_Sequence
*) seq
.get())->elements
);
1049 jni
.ensure_no_exception();
1051 case typelib_TypeClass_BYTE
:
1052 seq
.reset( seq_allocate( nElements
, sizeof (sal_Int8
) ) );
1053 jni
->GetByteArrayRegion(
1054 (jbyteArray
) java_data
.l
, 0, nElements
,
1055 (jbyte
*) ((uno_Sequence
*) seq
.get())->elements
);
1056 jni
.ensure_no_exception();
1058 case typelib_TypeClass_SHORT
:
1059 case typelib_TypeClass_UNSIGNED_SHORT
:
1060 seq
.reset( seq_allocate( nElements
, sizeof (sal_Int16
) ) );
1061 jni
->GetShortArrayRegion(
1062 (jshortArray
) java_data
.l
, 0, nElements
,
1063 (jshort
*) ((uno_Sequence
*) seq
.get())->elements
);
1064 jni
.ensure_no_exception();
1066 case typelib_TypeClass_LONG
:
1067 case typelib_TypeClass_UNSIGNED_LONG
:
1068 seq
.reset( seq_allocate( nElements
, sizeof (sal_Int32
) ) );
1069 jni
->GetIntArrayRegion(
1070 (jintArray
) java_data
.l
, 0, nElements
,
1071 (jint
*) ((uno_Sequence
*) seq
.get())->elements
);
1072 jni
.ensure_no_exception();
1074 case typelib_TypeClass_HYPER
:
1075 case typelib_TypeClass_UNSIGNED_HYPER
:
1076 seq
.reset( seq_allocate( nElements
, sizeof (sal_Int64
) ) );
1077 jni
->GetLongArrayRegion(
1078 (jlongArray
) java_data
.l
, 0, nElements
,
1079 (jlong
*) ((uno_Sequence
*) seq
.get())->elements
);
1080 jni
.ensure_no_exception();
1082 case typelib_TypeClass_FLOAT
:
1083 seq
.reset( seq_allocate( nElements
, sizeof (float) ) );
1084 jni
->GetFloatArrayRegion(
1085 (jfloatArray
) java_data
.l
, 0, nElements
,
1086 (jfloat
*)((uno_Sequence
*)seq
.get())->elements
);
1087 jni
.ensure_no_exception();
1089 case typelib_TypeClass_DOUBLE
:
1090 seq
.reset( seq_allocate( nElements
, sizeof (double) ) );
1091 jni
->GetDoubleArrayRegion(
1092 (jdoubleArray
) java_data
.l
, 0, nElements
,
1093 (jdouble
*) ((uno_Sequence
*) seq
.get())->elements
);
1094 jni
.ensure_no_exception();
1096 case typelib_TypeClass_STRING
:
1097 case typelib_TypeClass_TYPE
:
1098 case typelib_TypeClass_ANY
:
1099 case typelib_TypeClass_ENUM
:
1100 case typelib_TypeClass_STRUCT
:
1101 case typelib_TypeClass_EXCEPTION
:
1102 case typelib_TypeClass_SEQUENCE
:
1103 case typelib_TypeClass_INTERFACE
:
1105 TypeDescr
element_td( element_type
);
1106 seq
.reset( seq_allocate( nElements
, element_td
.get()->nSize
) );
1108 JNI_type_info
const * element_info
;
1109 if (typelib_TypeClass_STRUCT
== element_type
->eTypeClass
||
1110 typelib_TypeClass_EXCEPTION
== element_type
->eTypeClass
||
1111 typelib_TypeClass_INTERFACE
== element_type
->eTypeClass
)
1114 m_jni_info
->get_type_info( jni
, element_td
.get() );
1121 for ( sal_Int32 nPos
= 0; nPos
< nElements
; ++nPos
)
1126 jni
, jni
->GetObjectArrayElement(
1127 (jobjectArray
) java_data
.l
, nPos
) );
1128 jni
.ensure_no_exception();
1132 ((uno_Sequence
*)seq
.get())->elements
+
1133 (nPos
* element_td
.get()->nSize
);
1135 jni
, p
, val
, element_td
.get()->pWeakRef
, element_info
,
1136 false /* no assign */, false /* no out param */ );
1141 for ( sal_Int32 nCleanPos
= 0;
1142 nCleanPos
< nPos
; ++nCleanPos
)
1145 ((uno_Sequence
*)seq
.get())->elements
+
1146 (nCleanPos
* element_td
.get()->nSize
);
1147 uno_destructData( p
, element_td
.get(), 0 );
1156 OUStringBuffer
buf( 128 );
1157 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
1158 buf
.append( OUString::unacquired( &type
->pTypeName
) );
1160 RTL_CONSTASCII_STRINGPARAM("] unsupported sequence element"
1162 buf
.append( OUString::unacquired( &element_type
->pTypeName
) );
1163 buf
.append( jni
.get_stack_trace() );
1164 throw BridgeRuntimeError( buf
.makeStringAndClear() );
1169 uno_destructData( uno_data
, td
.get(), 0 );
1170 *(uno_Sequence
**)uno_data
= (uno_Sequence
*)seq
.release();
1173 case typelib_TypeClass_INTERFACE
:
1175 JLocalAutoRef
jo_out_holder( jni
);
1178 jo_out_holder
.reset(
1179 jni
->GetObjectArrayElement( (jobjectArray
) java_data
.l
, 0 ) );
1180 jni
.ensure_no_exception();
1181 java_data
.l
= jo_out_holder
.get();
1184 if (0 == java_data
.l
) // null-ref
1188 uno_Interface
* p
= *(uno_Interface
**)uno_data
;
1192 *(uno_Interface
**)uno_data
= 0;
1197 info
= m_jni_info
->get_type_info( jni
, type
);
1198 JNI_interface_type_info
const * iface_info
=
1199 static_cast< JNI_interface_type_info
const * >( info
);
1200 uno_Interface
* pUnoI
= map_to_uno( jni
, java_data
.l
, iface_info
);
1203 uno_Interface
* p
= *(uno_Interface
**)uno_data
;
1207 *(uno_Interface
**)uno_data
= pUnoI
;
1213 OUStringBuffer
buf( 128 );
1214 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
1215 buf
.append( OUString::unacquired( &type
->pTypeName
) );
1216 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("] unsupported type!") );
1217 buf
.append( jni
.get_stack_trace() );
1218 throw BridgeRuntimeError( buf
.makeStringAndClear() );
1223 //##############################################################################
1225 //______________________________________________________________________________
1226 void Bridge::map_to_java(
1227 JNI_context
const & jni
,
1228 jvalue
* java_data
, void const * uno_data
,
1229 typelib_TypeDescriptionReference
* type
,
1230 JNI_type_info
const * info
/* maybe 0 */,
1231 bool in_param
, bool out_param
,
1232 bool special_wrapped_integral_types
) const
1234 switch (type
->eTypeClass
)
1236 case typelib_TypeClass_CHAR
:
1239 if (0 == java_data
->l
)
1241 JLocalAutoRef
jo_ar( jni
, jni
->NewCharArray( 1 ) );
1242 jni
.ensure_no_exception();
1245 jni
->SetCharArrayRegion(
1246 (jcharArray
) jo_ar
.get(), 0, 1, (jchar
*) uno_data
);
1247 jni
.ensure_no_exception();
1249 java_data
->l
= jo_ar
.release();
1255 jni
->SetCharArrayRegion(
1256 (jcharArray
) java_data
->l
, 0, 1, (jchar
*) uno_data
);
1257 jni
.ensure_no_exception();
1261 else if (special_wrapped_integral_types
)
1264 arg
.c
= *(jchar
const *) uno_data
;
1265 java_data
->l
= jni
->NewObjectA(
1266 m_jni_info
->m_class_Character
,
1267 m_jni_info
->m_ctor_Character_with_char
, &arg
);
1268 jni
.ensure_no_exception();
1272 java_data
->c
= *(jchar
const *) uno_data
;
1275 case typelib_TypeClass_BOOLEAN
:
1278 if (0 == java_data
->l
)
1280 JLocalAutoRef
jo_ar( jni
, jni
->NewBooleanArray( 1 ) );
1281 jni
.ensure_no_exception();
1284 jni
->SetBooleanArrayRegion(
1285 (jbooleanArray
) jo_ar
.get(),
1286 0, 1, (jboolean
*) uno_data
);
1287 jni
.ensure_no_exception();
1289 java_data
->l
= jo_ar
.release();
1295 jni
->SetBooleanArrayRegion(
1296 (jbooleanArray
) java_data
->l
,
1297 0, 1, (jboolean
*) uno_data
);
1298 jni
.ensure_no_exception();
1302 else if (special_wrapped_integral_types
)
1305 arg
.z
= *(jboolean
const *) uno_data
;
1306 java_data
->l
= jni
->NewObjectA(
1307 m_jni_info
->m_class_Boolean
,
1308 m_jni_info
->m_ctor_Boolean_with_boolean
, &arg
);
1309 jni
.ensure_no_exception();
1313 java_data
->z
= *(jboolean
const *) uno_data
;
1316 case typelib_TypeClass_BYTE
:
1319 if (0 == java_data
->l
)
1321 JLocalAutoRef
jo_ar( jni
, jni
->NewByteArray( 1 ) );
1322 jni
.ensure_no_exception();
1325 jni
->SetByteArrayRegion(
1326 (jbyteArray
) jo_ar
.get(), 0, 1, (jbyte
*) uno_data
);
1327 jni
.ensure_no_exception();
1329 java_data
->l
= jo_ar
.release();
1335 jni
->SetByteArrayRegion(
1336 (jbyteArray
) java_data
->l
, 0, 1, (jbyte
*) uno_data
);
1337 jni
.ensure_no_exception();
1341 else if (special_wrapped_integral_types
)
1344 arg
.b
= *(jbyte
const *) uno_data
;
1345 java_data
->l
= jni
->NewObjectA(
1346 m_jni_info
->m_class_Byte
,
1347 m_jni_info
->m_ctor_Byte_with_byte
, &arg
);
1348 jni
.ensure_no_exception();
1352 java_data
->b
= *(jbyte
const *) uno_data
;
1355 case typelib_TypeClass_SHORT
:
1356 case typelib_TypeClass_UNSIGNED_SHORT
:
1359 if (0 == java_data
->l
)
1361 JLocalAutoRef
jo_ar( jni
, jni
->NewShortArray( 1 ) );
1362 jni
.ensure_no_exception();
1365 jni
->SetShortArrayRegion(
1366 (jshortArray
) jo_ar
.get(), 0, 1, (jshort
*) uno_data
);
1367 jni
.ensure_no_exception();
1369 java_data
->l
= jo_ar
.release();
1375 jni
->SetShortArrayRegion(
1376 (jshortArray
) java_data
->l
, 0, 1, (jshort
*) uno_data
);
1377 jni
.ensure_no_exception();
1381 else if (special_wrapped_integral_types
)
1384 arg
.s
= *(jshort
const *) uno_data
;
1385 java_data
->l
= jni
->NewObjectA(
1386 m_jni_info
->m_class_Short
,
1387 m_jni_info
->m_ctor_Short_with_short
, &arg
);
1388 jni
.ensure_no_exception();
1392 java_data
->s
= *(jshort
const *) uno_data
;
1395 case typelib_TypeClass_LONG
:
1396 case typelib_TypeClass_UNSIGNED_LONG
:
1399 if (0 == java_data
->l
)
1401 JLocalAutoRef
jo_ar( jni
, jni
->NewIntArray( 1 ) );
1402 jni
.ensure_no_exception();
1405 jni
->SetIntArrayRegion(
1406 (jintArray
) jo_ar
.get(), 0, 1, (jint
*) uno_data
);
1407 jni
.ensure_no_exception();
1409 java_data
->l
= jo_ar
.release();
1415 jni
->SetIntArrayRegion(
1416 (jintArray
) java_data
->l
, 0, 1, (jint
*) uno_data
);
1417 jni
.ensure_no_exception();
1421 else if (special_wrapped_integral_types
)
1424 arg
.i
= *(jint
const *) uno_data
;
1425 java_data
->l
= jni
->NewObjectA(
1426 m_jni_info
->m_class_Integer
,
1427 m_jni_info
->m_ctor_Integer_with_int
, &arg
);
1428 jni
.ensure_no_exception();
1432 java_data
->i
= *(jint
const *) uno_data
;
1435 case typelib_TypeClass_HYPER
:
1436 case typelib_TypeClass_UNSIGNED_HYPER
:
1439 if (0 == java_data
->l
)
1441 JLocalAutoRef
jo_ar( jni
, jni
->NewLongArray( 1 ) );
1442 jni
.ensure_no_exception();
1445 jni
->SetLongArrayRegion(
1446 (jlongArray
)jo_ar
.get(), 0, 1, (jlong
*) uno_data
);
1447 jni
.ensure_no_exception();
1449 java_data
->l
= jo_ar
.release();
1455 jni
->SetLongArrayRegion(
1456 (jlongArray
)java_data
->l
, 0, 1, (jlong
*) uno_data
);
1457 jni
.ensure_no_exception();
1461 else if (special_wrapped_integral_types
)
1464 arg
.j
= *(jlong
const *) uno_data
;
1465 java_data
->l
= jni
->NewObjectA(
1466 m_jni_info
->m_class_Long
,
1467 m_jni_info
->m_ctor_Long_with_long
, &arg
);
1468 jni
.ensure_no_exception();
1472 java_data
->j
= *(jlong
const *) uno_data
;
1475 case typelib_TypeClass_FLOAT
:
1478 if (0 == java_data
->l
)
1480 JLocalAutoRef
jo_ar( jni
, jni
->NewFloatArray( 1 ) );
1481 jni
.ensure_no_exception();
1484 jni
->SetFloatArrayRegion(
1485 (jfloatArray
) jo_ar
.get(), 0, 1, (jfloat
*) uno_data
);
1486 jni
.ensure_no_exception();
1488 java_data
->l
= jo_ar
.release();
1494 jni
->SetFloatArrayRegion(
1495 (jfloatArray
) java_data
->l
, 0, 1, (jfloat
*) uno_data
);
1496 jni
.ensure_no_exception();
1500 else if (special_wrapped_integral_types
)
1503 arg
.f
= *(jfloat
const *) uno_data
;
1504 java_data
->l
= jni
->NewObjectA(
1505 m_jni_info
->m_class_Float
,
1506 m_jni_info
->m_ctor_Float_with_float
, &arg
);
1507 jni
.ensure_no_exception();
1511 java_data
->f
= *(jfloat
const *) uno_data
;
1514 case typelib_TypeClass_DOUBLE
:
1517 if (0 == java_data
->l
)
1519 JLocalAutoRef
jo_ar( jni
, jni
->NewDoubleArray( 1 ) );
1520 jni
.ensure_no_exception();
1523 jni
->SetDoubleArrayRegion(
1524 (jdoubleArray
) jo_ar
.get(),
1525 0, 1, (jdouble
*) uno_data
);
1526 jni
.ensure_no_exception();
1528 java_data
->l
= jo_ar
.release();
1534 jni
->SetDoubleArrayRegion(
1535 (jdoubleArray
) java_data
->l
,
1536 0, 1, (jdouble
*) uno_data
);
1537 jni
.ensure_no_exception();
1541 else if (special_wrapped_integral_types
)
1544 arg
.d
= *(double const *)uno_data
;
1545 java_data
->l
= jni
->NewObjectA(
1546 m_jni_info
->m_class_Double
,
1547 m_jni_info
->m_ctor_Double_with_double
, &arg
);
1548 jni
.ensure_no_exception();
1552 java_data
->d
= *(jdouble
const *) uno_data
;
1555 case typelib_TypeClass_STRING
:
1559 JLocalAutoRef
jo_in( jni
);
1564 jni
, *(rtl_uString
* const *) uno_data
) );
1566 if (0 == java_data
->l
)
1568 java_data
->l
= jni
->NewObjectArray(
1569 1, m_jni_info
->m_class_String
, jo_in
.get() );
1570 jni
.ensure_no_exception();
1574 jni
->SetObjectArrayElement(
1575 (jobjectArray
) java_data
->l
, 0, jo_in
.get() );
1576 jni
.ensure_no_exception();
1581 OSL_ASSERT( in_param
);
1583 ustring_to_jstring( jni
, *(rtl_uString
* const *) uno_data
);
1587 case typelib_TypeClass_TYPE
:
1591 JLocalAutoRef
jo_in( jni
);
1597 *(typelib_TypeDescriptionReference
* const *) uno_data
)
1600 if (0 == java_data
->l
)
1602 java_data
->l
= jni
->NewObjectArray(
1603 1, m_jni_info
->m_class_Type
, jo_in
.get() );
1604 jni
.ensure_no_exception();
1608 jni
->SetObjectArrayElement(
1609 (jobjectArray
) java_data
->l
, 0, jo_in
.get() );
1610 jni
.ensure_no_exception();
1615 OSL_ASSERT( in_param
);
1619 *(typelib_TypeDescriptionReference
* const *) uno_data
);
1623 case typelib_TypeClass_ANY
:
1625 JLocalAutoRef
jo_any( jni
);
1628 uno_Any
const * pAny
= (uno_Any
const *)uno_data
;
1630 #if defined BRIDGES_JNI_UNO_FORCE_BOXED_ANY
1631 if (typelib_TypeClass_VOID
== pAny
->pType
->eTypeClass
)
1634 jni
->NewLocalRef( m_jni_info
->m_object_Any_VOID
) );
1640 jni
, &args
[ 1 ], pAny
->pData
, pAny
->pType
, 0,
1641 true /* in */, false /* no out */,
1642 true /* create integral wrappers */ );
1643 jo_any
.reset( args
[ 1 ].l
);
1644 // build up com.sun.star.uno.Any
1645 JLocalAutoRef
jo_type( jni
, create_type( jni
, pAny
->pType
) );
1646 args
[ 0 ].l
= jo_type
.get();
1649 m_jni_info
->m_class_Any
,
1650 m_jni_info
->m_ctor_Any_with_Type_Object
, args
) );
1651 jni
.ensure_no_exception();
1654 switch (pAny
->pType
->eTypeClass
)
1656 case typelib_TypeClass_VOID
:
1658 jni
->NewLocalRef( m_jni_info
->m_object_Any_VOID
) );
1660 case typelib_TypeClass_UNSIGNED_SHORT
:
1663 args
[ 0 ].s
= *(jshort
const *) &pAny
->pReserved
;
1664 JLocalAutoRef
jo_val(
1665 jni
, jni
->NewObjectA(
1666 m_jni_info
->m_class_Short
,
1667 m_jni_info
->m_ctor_Short_with_short
, args
) );
1668 jni
.ensure_no_exception();
1669 // box up in com.sun.star.uno.Any
1670 args
[ 0 ].l
= m_jni_info
->m_object_Type_UNSIGNED_SHORT
;
1671 args
[ 1 ].l
= jo_val
.get();
1674 m_jni_info
->m_class_Any
,
1675 m_jni_info
->m_ctor_Any_with_Type_Object
, args
) );
1676 jni
.ensure_no_exception();
1679 case typelib_TypeClass_UNSIGNED_LONG
:
1682 args
[ 0 ].i
= *(jint
const *) &pAny
->pReserved
;
1683 JLocalAutoRef
jo_val(
1684 jni
, jni
->NewObjectA(
1685 m_jni_info
->m_class_Integer
,
1686 m_jni_info
->m_ctor_Integer_with_int
, args
) );
1687 jni
.ensure_no_exception();
1688 // box up in com.sun.star.uno.Any
1689 args
[ 0 ].l
= m_jni_info
->m_object_Type_UNSIGNED_LONG
;
1690 args
[ 1 ].l
= jo_val
.get();
1693 m_jni_info
->m_class_Any
,
1694 m_jni_info
->m_ctor_Any_with_Type_Object
, args
) );
1695 jni
.ensure_no_exception();
1698 case typelib_TypeClass_UNSIGNED_HYPER
:
1701 args
[ 0 ].j
= *(jlong
const *) pAny
->pData
;
1702 JLocalAutoRef
jo_val(
1703 jni
, jni
->NewObjectA(
1704 m_jni_info
->m_class_Long
,
1705 m_jni_info
->m_ctor_Long_with_long
, args
) );
1706 jni
.ensure_no_exception();
1707 // box up in com.sun.star.uno.Any
1708 args
[ 0 ].l
= m_jni_info
->m_object_Type_UNSIGNED_HYPER
;
1709 args
[ 1 ].l
= jo_val
.get();
1712 m_jni_info
->m_class_Any
,
1713 m_jni_info
->m_ctor_Any_with_Type_Object
, args
) );
1714 jni
.ensure_no_exception();
1717 case typelib_TypeClass_STRING
: // opt strings
1718 jo_any
.reset( ustring_to_jstring(
1719 jni
, (rtl_uString
*) pAny
->pReserved
) );
1721 case typelib_TypeClass_SEQUENCE
:
1724 // prefetch sequence td
1725 TypeDescr
seq_td( pAny
->pType
);
1727 jni
, &java_data2
, pAny
->pData
, seq_td
.get()->pWeakRef
, 0,
1728 true /* in */, false /* no out */,
1729 true /* create integral wrappers */ );
1730 jo_any
.reset( java_data2
.l
);
1732 // determine inner element type
1733 ::com::sun::star::uno::Type
element_type(
1734 ((typelib_IndirectTypeDescription
*)seq_td
.get())->pType
);
1735 while (typelib_TypeClass_SEQUENCE
==
1736 element_type
.getTypeLibType()->eTypeClass
)
1738 TypeDescr
element_td( element_type
.getTypeLibType() );
1739 typelib_typedescriptionreference_assign(
1740 reinterpret_cast< typelib_TypeDescriptionReference
** >(
1742 ((typelib_IndirectTypeDescription
*)element_td
.get())
1745 // box up only if unsigned element type
1746 switch (element_type
.getTypeLibType()->eTypeClass
)
1748 case typelib_TypeClass_UNSIGNED_SHORT
:
1749 case typelib_TypeClass_UNSIGNED_LONG
:
1750 case typelib_TypeClass_UNSIGNED_HYPER
:
1753 JLocalAutoRef
jo_type(
1754 jni
, create_type( jni
, seq_td
.get()->pWeakRef
) );
1755 args
[ 0 ].l
= jo_type
.get();
1756 args
[ 1 ].l
= jo_any
.get();
1759 m_jni_info
->m_class_Any
,
1760 m_jni_info
->m_ctor_Any_with_Type_Object
, args
) );
1761 jni
.ensure_no_exception();
1769 case typelib_TypeClass_INTERFACE
:
1771 uno_Interface
* pUnoI
= (uno_Interface
*)pAny
->pReserved
;
1772 if (is_XInterface( pAny
->pType
))
1779 m_jni_info
->m_XInterface_type_info
) );
1781 // else: empty XInterface ref maps to null-ref
1785 JNI_interface_type_info
const * iface_info
=
1786 static_cast< JNI_interface_type_info
const * >(
1787 m_jni_info
->get_type_info( jni
, pAny
->pType
) );
1790 jo_any
.reset( map_to_java( jni
, pUnoI
, iface_info
) );
1792 // box up in com.sun.star.uno.Any
1794 args
[ 0 ].l
= iface_info
->m_type
;
1795 args
[ 1 ].l
= jo_any
.get();
1798 m_jni_info
->m_class_Any
,
1799 m_jni_info
->m_ctor_Any_with_Type_Object
, args
) );
1800 jni
.ensure_no_exception();
1804 case typelib_TypeClass_STRUCT
:
1806 // Do not lose information about type arguments of instantiated
1807 // polymorphic struct types:
1808 rtl::OUString
const & name
= rtl::OUString::unacquired(
1809 &pAny
->pType
->pTypeName
);
1810 OSL_ASSERT(name
.getLength() > 0);
1811 if (name
[name
.getLength() - 1] == '>')
1813 // Box up in com.sun.star.uno.Any:
1814 JLocalAutoRef
jo_type(jni
, create_type(jni
, pAny
->pType
));
1817 jni
, &java_data2
, pAny
->pData
, pAny
->pType
, 0, true,
1819 jo_any
.reset(java_data2
.l
);
1821 args
[0].l
= jo_type
.get();
1822 args
[1].l
= jo_any
.get();
1825 m_jni_info
->m_class_Any
,
1826 m_jni_info
->m_ctor_Any_with_Type_Object
, args
));
1827 jni
.ensure_no_exception();
1836 jni
, &java_data2
, pAny
->pData
, pAny
->pType
, 0,
1837 true /* in */, false /* no out */,
1838 true /* create integral wrappers */ );
1839 jo_any
.reset( java_data2
.l
);
1848 if (0 == java_data
->l
)
1850 java_data
->l
= jni
->NewObjectArray(
1851 1, m_jni_info
->m_class_Object
, jo_any
.get() );
1852 jni
.ensure_no_exception();
1856 jni
->SetObjectArrayElement(
1857 (jobjectArray
) java_data
->l
, 0, jo_any
.get() );
1858 jni
.ensure_no_exception();
1863 java_data
->l
= jo_any
.release();
1867 case typelib_TypeClass_ENUM
:
1869 OUString
const & type_name
= OUString::unacquired( &type
->pTypeName
);
1871 OUStringToOString( type_name
, RTL_TEXTENCODING_JAVA_UTF8
) );
1872 JLocalAutoRef
jo_enum_class(
1873 jni
, find_class( jni
, class_name
.getStr() ) );
1875 JLocalAutoRef
jo_enum( jni
);
1878 // call static <enum_class>.fromInt( int )
1879 OStringBuffer
sig_buf( 5 + class_name
.getLength() );
1880 sig_buf
.append( RTL_CONSTASCII_STRINGPARAM("(I)L") );
1881 sig_buf
.append( class_name
.replace( '.', '/' ) );
1882 sig_buf
.append( ';' );
1883 OString
sig( sig_buf
.makeStringAndClear() );
1884 jmethodID method_id
= jni
->GetStaticMethodID(
1885 (jclass
) jo_enum_class
.get(), "fromInt", sig
.getStr() );
1886 jni
.ensure_no_exception();
1887 OSL_ASSERT( 0 != method_id
);
1890 arg
.i
= *(jint
const *) uno_data
;
1892 jni
->CallStaticObjectMethodA(
1893 (jclass
) jo_enum_class
.get(), method_id
, &arg
) );
1894 jni
.ensure_no_exception();
1898 if (0 == java_data
->l
)
1900 java_data
->l
= jni
->NewObjectArray(
1901 1, (jclass
) jo_enum_class
.get(), jo_enum
.get() );
1902 jni
.ensure_no_exception();
1906 jni
->SetObjectArrayElement(
1907 (jobjectArray
) java_data
->l
, 0, jo_enum
.get() );
1908 jni
.ensure_no_exception();
1913 java_data
->l
= jo_enum
.release();
1917 case typelib_TypeClass_STRUCT
:
1918 case typelib_TypeClass_EXCEPTION
:
1921 info
= m_jni_info
->get_type_info( jni
, type
);
1922 JNI_compound_type_info
const * comp_info
=
1923 static_cast< JNI_compound_type_info
const * >( info
);
1925 JLocalAutoRef
jo_comp( jni
);
1928 if (typelib_TypeClass_EXCEPTION
== type
->eTypeClass
)
1930 JLocalAutoRef
jo_message(
1931 jni
, ustring_to_jstring( jni
, *(rtl_uString
**)uno_data
) );
1933 arg
.l
= jo_message
.get();
1936 comp_info
->m_class
, comp_info
->m_exc_ctor
, &arg
) );
1937 jni
.ensure_no_exception();
1941 jo_comp
.reset( jni
->AllocObject( comp_info
->m_class
) );
1942 jni
.ensure_no_exception();
1945 for ( JNI_compound_type_info
const * linfo
= comp_info
;
1947 linfo
= static_cast< JNI_compound_type_info
const * >(
1950 typelib_CompoundTypeDescription
* comp_td
=
1951 (typelib_CompoundTypeDescription
*)linfo
->m_td
.get();
1952 typelib_TypeDescriptionReference
** ppMemberTypeRefs
=
1953 comp_td
->ppTypeRefs
;
1954 sal_Int32
* pMemberOffsets
= comp_td
->pMemberOffsets
;
1956 = comp_td
->aBase
.eTypeClass
== typelib_TypeClass_STRUCT
1957 && reinterpret_cast< typelib_StructTypeDescription
* >(
1958 comp_td
)->pParameterizedTypes
!= 0;
1959 for ( sal_Int32 nPos
= comp_td
->nMembers
; nPos
--; )
1961 jfieldID field_id
= linfo
->m_fields
[ nPos
];
1965 (char const *)uno_data
+ pMemberOffsets
[ nPos
];
1966 typelib_TypeDescriptionReference
* member_type
=
1967 ppMemberTypeRefs
[ nPos
];
1968 bool parameterizedType
= polymorphic
1969 && (reinterpret_cast<
1970 typelib_StructTypeDescription
* >(comp_td
)->
1971 pParameterizedTypes
[nPos
]);
1972 switch (member_type
->eTypeClass
)
1974 case typelib_TypeClass_CHAR
:
1975 if (parameterizedType
) {
1977 arg
.c
= *(jchar
const *) p
;
1981 m_jni_info
->m_class_Character
,
1982 m_jni_info
->m_ctor_Character_with_char
,
1984 jni
.ensure_no_exception();
1985 jni
->SetObjectField(
1986 jo_comp
.get(), field_id
, jo
.get() );
1990 field_id
, *(jchar
const *) p
);
1993 case typelib_TypeClass_BOOLEAN
:
1994 if (parameterizedType
) {
1996 arg
.z
= *(jboolean
const *) p
;
2000 m_jni_info
->m_class_Boolean
,
2001 m_jni_info
->m_ctor_Boolean_with_boolean
,
2003 jni
.ensure_no_exception();
2004 jni
->SetObjectField(
2005 jo_comp
.get(), field_id
, jo
.get() );
2007 jni
->SetBooleanField(
2009 field_id
, *(jboolean
const *) p
);
2012 case typelib_TypeClass_BYTE
:
2013 if (parameterizedType
) {
2015 arg
.b
= *(jbyte
const *) p
;
2019 m_jni_info
->m_class_Byte
,
2020 m_jni_info
->m_ctor_Byte_with_byte
,
2022 jni
.ensure_no_exception();
2023 jni
->SetObjectField(
2024 jo_comp
.get(), field_id
, jo
.get() );
2028 field_id
, *(jbyte
const *) p
);
2031 case typelib_TypeClass_SHORT
:
2032 case typelib_TypeClass_UNSIGNED_SHORT
:
2033 if (parameterizedType
) {
2035 arg
.s
= *(jshort
const *) p
;
2039 m_jni_info
->m_class_Short
,
2040 m_jni_info
->m_ctor_Short_with_short
,
2042 jni
.ensure_no_exception();
2043 jni
->SetObjectField(
2044 jo_comp
.get(), field_id
, jo
.get() );
2048 field_id
, *(jshort
const *) p
);
2051 case typelib_TypeClass_LONG
:
2052 case typelib_TypeClass_UNSIGNED_LONG
:
2053 if (parameterizedType
) {
2055 arg
.i
= *(jint
const *) p
;
2059 m_jni_info
->m_class_Integer
,
2060 m_jni_info
->m_ctor_Integer_with_int
,
2062 jni
.ensure_no_exception();
2063 jni
->SetObjectField(
2064 jo_comp
.get(), field_id
, jo
.get() );
2068 field_id
, *(jint
const *) p
);
2071 case typelib_TypeClass_HYPER
:
2072 case typelib_TypeClass_UNSIGNED_HYPER
:
2073 if (parameterizedType
) {
2075 arg
.j
= *(jlong
const *) p
;
2079 m_jni_info
->m_class_Long
,
2080 m_jni_info
->m_ctor_Long_with_long
,
2082 jni
.ensure_no_exception();
2083 jni
->SetObjectField(
2084 jo_comp
.get(), field_id
, jo
.get() );
2088 field_id
, *(jlong
const *) p
);
2091 case typelib_TypeClass_FLOAT
:
2092 if (parameterizedType
) {
2094 arg
.f
= *(jfloat
const *) p
;
2098 m_jni_info
->m_class_Float
,
2099 m_jni_info
->m_ctor_Float_with_float
,
2101 jni
.ensure_no_exception();
2102 jni
->SetObjectField(
2103 jo_comp
.get(), field_id
, jo
.get() );
2107 field_id
, *(jfloat
const *) p
);
2110 case typelib_TypeClass_DOUBLE
:
2111 if (parameterizedType
) {
2113 arg
.d
= *(jdouble
const *) p
;
2117 m_jni_info
->m_class_Double
,
2118 m_jni_info
->m_ctor_Double_with_double
,
2120 jni
.ensure_no_exception();
2121 jni
->SetObjectField(
2122 jo_comp
.get(), field_id
, jo
.get() );
2124 jni
->SetDoubleField(
2126 field_id
, *(jdouble
const *) p
);
2129 case typelib_TypeClass_STRING
: // string opt here
2131 JLocalAutoRef
jo_string(
2132 jni
, ustring_to_jstring(
2133 jni
, *(rtl_uString
* const *) p
) );
2134 jni
->SetObjectField(
2135 jo_comp
.get(), field_id
, jo_string
.get() );
2142 jni
, &java_data2
, p
, member_type
, 0,
2143 true /* in */, false /* no out */ );
2144 JLocalAutoRef
jo_obj( jni
, java_data2
.l
);
2145 jni
->SetObjectField(
2146 jo_comp
.get(), field_id
, jo_obj
.get() );
2156 if (0 == java_data
->l
)
2159 jni
->NewObjectArray( 1, comp_info
->m_class
, jo_comp
.get() );
2160 jni
.ensure_no_exception();
2164 jni
->SetObjectArrayElement(
2165 (jobjectArray
) java_data
->l
, 0, jo_comp
.get() );
2166 jni
.ensure_no_exception();
2171 java_data
->l
= jo_comp
.release();
2175 case typelib_TypeClass_SEQUENCE
:
2177 // xxx todo: possible opt for pure out sequences
2178 JLocalAutoRef
jo_ar( jni
);
2180 sal_Int32 nElements
;
2181 uno_Sequence
const * seq
= 0;
2184 seq
= *(uno_Sequence
* const *)uno_data
;
2185 nElements
= seq
->nElements
;
2192 TypeDescr
td( type
);
2193 typelib_TypeDescriptionReference
* element_type
=
2194 ((typelib_IndirectTypeDescription
*)td
.get())->pType
;
2196 switch (element_type
->eTypeClass
)
2198 case typelib_TypeClass_CHAR
:
2199 jo_ar
.reset( jni
->NewCharArray( nElements
) );
2200 jni
.ensure_no_exception();
2203 jni
->SetCharArrayRegion(
2204 (jcharArray
) jo_ar
.get(),
2205 0, nElements
, (jchar
*) seq
->elements
);
2206 jni
.ensure_no_exception();
2209 case typelib_TypeClass_BOOLEAN
:
2210 jo_ar
.reset( jni
->NewBooleanArray( nElements
) );
2211 jni
.ensure_no_exception();
2214 jni
->SetBooleanArrayRegion(
2215 (jbooleanArray
) jo_ar
.get(),
2216 0, nElements
, (jboolean
*) seq
->elements
);
2217 jni
.ensure_no_exception();
2220 case typelib_TypeClass_BYTE
:
2221 jo_ar
.reset( jni
->NewByteArray( nElements
) );
2222 jni
.ensure_no_exception();
2225 jni
->SetByteArrayRegion(
2226 (jbyteArray
) jo_ar
.get(),
2227 0, nElements
, (jbyte
*) seq
->elements
);
2228 jni
.ensure_no_exception();
2231 case typelib_TypeClass_SHORT
:
2232 case typelib_TypeClass_UNSIGNED_SHORT
:
2233 jo_ar
.reset( jni
->NewShortArray( nElements
) );
2234 jni
.ensure_no_exception();
2237 jni
->SetShortArrayRegion(
2238 (jshortArray
) jo_ar
.get(),
2239 0, nElements
, (jshort
*) seq
->elements
);
2240 jni
.ensure_no_exception();
2243 case typelib_TypeClass_LONG
:
2244 case typelib_TypeClass_UNSIGNED_LONG
:
2245 jo_ar
.reset( jni
->NewIntArray( nElements
) );
2246 jni
.ensure_no_exception();
2249 jni
->SetIntArrayRegion(
2250 (jintArray
) jo_ar
.get(),
2251 0, nElements
, (jint
*) seq
->elements
);
2252 jni
.ensure_no_exception();
2255 case typelib_TypeClass_HYPER
:
2256 case typelib_TypeClass_UNSIGNED_HYPER
:
2257 jo_ar
.reset( jni
->NewLongArray( nElements
) );
2258 jni
.ensure_no_exception();
2261 jni
->SetLongArrayRegion(
2262 (jlongArray
) jo_ar
.get(),
2263 0, nElements
, (jlong
*) seq
->elements
);
2264 jni
.ensure_no_exception();
2267 case typelib_TypeClass_FLOAT
:
2268 jo_ar
.reset( jni
->NewFloatArray( nElements
) );
2269 jni
.ensure_no_exception();
2272 jni
->SetFloatArrayRegion(
2273 (jfloatArray
) jo_ar
.get(),
2274 0, nElements
, (jfloat
*) seq
->elements
);
2275 jni
.ensure_no_exception();
2278 case typelib_TypeClass_DOUBLE
:
2279 jo_ar
.reset( jni
->NewDoubleArray( nElements
) );
2280 jni
.ensure_no_exception();
2283 jni
->SetDoubleArrayRegion(
2284 (jdoubleArray
) jo_ar
.get(),
2285 0, nElements
, (jdouble
*) seq
->elements
);
2286 jni
.ensure_no_exception();
2289 case typelib_TypeClass_STRING
:
2291 jni
->NewObjectArray(
2292 nElements
, m_jni_info
->m_class_String
, 0 ) );
2293 jni
.ensure_no_exception();
2296 rtl_uString
* const * pp
=
2297 (rtl_uString
* const *) seq
->elements
;
2298 for ( sal_Int32 nPos
= 0; nPos
< nElements
; ++nPos
)
2300 JLocalAutoRef
jo_string(
2301 jni
, ustring_to_jstring( jni
, pp
[ nPos
] ) );
2302 jni
->SetObjectArrayElement(
2303 (jobjectArray
) jo_ar
.get(), nPos
, jo_string
.get() );
2304 jni
.ensure_no_exception();
2308 case typelib_TypeClass_TYPE
:
2310 jni
->NewObjectArray( nElements
, m_jni_info
->m_class_Type
, 0 ) );
2311 jni
.ensure_no_exception();
2314 typelib_TypeDescriptionReference
* const * pp
=
2315 (typelib_TypeDescriptionReference
* const *)seq
->elements
;
2316 for ( sal_Int32 nPos
= 0; nPos
< nElements
; ++nPos
)
2320 jni
, &val
, &pp
[ nPos
], element_type
, 0,
2321 true /* in */, false /* no out */ );
2322 JLocalAutoRef
jo_element( jni
, val
.l
);
2323 jni
->SetObjectArrayElement(
2324 (jobjectArray
) jo_ar
.get(), nPos
, jo_element
.get() );
2325 jni
.ensure_no_exception();
2329 case typelib_TypeClass_ANY
:
2331 jni
->NewObjectArray(
2332 nElements
, m_jni_info
->m_class_Object
, 0 ) );
2333 jni
.ensure_no_exception();
2336 uno_Any
const * p
= (uno_Any
const *)seq
->elements
;
2337 for ( sal_Int32 nPos
= 0; nPos
< nElements
; ++nPos
)
2341 jni
, &val
, &p
[ nPos
], element_type
, 0,
2342 true /* in */, false /* no out */ );
2343 JLocalAutoRef
jo_element( jni
, val
.l
);
2344 jni
->SetObjectArrayElement(
2345 (jobjectArray
) jo_ar
.get(), nPos
, jo_element
.get() );
2346 jni
.ensure_no_exception();
2350 case typelib_TypeClass_ENUM
:
2352 OUString
const & element_type_name
=
2353 OUString::unacquired( &element_type
->pTypeName
);
2356 element_type_name
, RTL_TEXTENCODING_JAVA_UTF8
) );
2357 JLocalAutoRef
jo_enum_class(
2358 jni
, find_class( jni
, class_name
.getStr() ) );
2361 jni
->NewObjectArray(
2362 nElements
, (jclass
) jo_enum_class
.get(), 0 ) );
2363 jni
.ensure_no_exception();
2367 // call static <enum_class>.fromInt( int )
2368 OStringBuffer
sig_buf( 5 + class_name
.getLength() );
2369 sig_buf
.append( RTL_CONSTASCII_STRINGPARAM("(I)L") );
2370 sig_buf
.append( class_name
.replace( '.', '/' ) );
2371 sig_buf
.append( ';' );
2372 OString
sig( sig_buf
.makeStringAndClear() );
2373 jmethodID method_id
= jni
->GetStaticMethodID(
2374 (jclass
) jo_enum_class
.get(), "fromInt", sig
.getStr() );
2375 jni
.ensure_no_exception();
2376 OSL_ASSERT( 0 != method_id
);
2378 sal_Int32
const * p
= (sal_Int32
const *)seq
->elements
;
2379 for ( sal_Int32 nPos
= 0; nPos
< nElements
; ++nPos
)
2383 JLocalAutoRef
jo_enum(
2384 jni
, jni
->CallStaticObjectMethodA(
2385 (jclass
) jo_enum_class
.get(), method_id
, &arg
) );
2386 jni
.ensure_no_exception();
2387 jni
->SetObjectArrayElement(
2388 (jobjectArray
) jo_ar
.get(), nPos
, jo_enum
.get() );
2389 jni
.ensure_no_exception();
2394 case typelib_TypeClass_STRUCT
:
2395 case typelib_TypeClass_EXCEPTION
:
2397 JNI_type_info
const * element_info
=
2398 m_jni_info
->get_type_info( jni
, element_type
);
2401 jni
->NewObjectArray( nElements
, element_info
->m_class
, 0 ) );
2402 jni
.ensure_no_exception();
2406 char * p
= (char *)seq
->elements
;
2407 sal_Int32 nSize
= element_info
->m_td
.get()->nSize
;
2408 for ( sal_Int32 nPos
= 0; nPos
< nElements
; ++nPos
)
2412 jni
, &val
, p
+ (nSize
* nPos
),
2413 element_type
, element_info
,
2414 true /* in */, false /* no out */ );
2415 JLocalAutoRef
jo_element( jni
, val
.l
);
2416 jni
->SetObjectArrayElement(
2417 (jobjectArray
) jo_ar
.get(), nPos
, jo_element
.get() );
2418 jni
.ensure_no_exception();
2423 case typelib_TypeClass_SEQUENCE
:
2425 OStringBuffer
buf( 64 );
2426 JNI_info::append_sig(
2427 &buf
, element_type
, false /* use class XInterface */,
2428 false /* '.' instead of '/' */ );
2429 OString
class_name( buf
.makeStringAndClear() );
2430 JLocalAutoRef
jo_seq_class(
2431 jni
, find_class( jni
, class_name
.getStr() ) );
2434 jni
->NewObjectArray(
2435 nElements
, (jclass
) jo_seq_class
.get(), 0 ) );
2436 jni
.ensure_no_exception();
2440 TypeDescr
element_td( element_type
);
2441 uno_Sequence
** elements
= (uno_Sequence
**) seq
->elements
;
2442 for ( sal_Int32 nPos
= 0; nPos
< nElements
; ++nPos
)
2446 jni
, &java_data2
, elements
+ nPos
, element_type
, 0,
2447 true /* in */, false /* no out */ );
2448 JLocalAutoRef
jo_seq( jni
, java_data2
.l
);
2449 jni
->SetObjectArrayElement(
2450 (jobjectArray
) jo_ar
.get(), nPos
, jo_seq
.get() );
2451 jni
.ensure_no_exception();
2456 case typelib_TypeClass_INTERFACE
:
2458 JNI_interface_type_info
const * iface_info
=
2459 static_cast< JNI_interface_type_info
const * >(
2460 m_jni_info
->get_type_info( jni
, element_type
) );
2463 jni
->NewObjectArray( nElements
, iface_info
->m_class
, 0 ) );
2464 jni
.ensure_no_exception();
2468 uno_Interface
** pp
= (uno_Interface
**)seq
->elements
;
2469 for ( sal_Int32 nPos
= 0; nPos
< nElements
; ++nPos
)
2471 uno_Interface
* pUnoI
= pp
[ nPos
];
2474 JLocalAutoRef
jo_element(
2475 jni
, map_to_java( jni
, pUnoI
, iface_info
) );
2476 jni
->SetObjectArrayElement(
2477 (jobjectArray
) jo_ar
.get(),
2478 nPos
, jo_element
.get() );
2479 jni
.ensure_no_exception();
2487 OUStringBuffer
buf( 128 );
2488 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_java():") );
2489 buf
.append( OUString::unacquired( &type
->pTypeName
) );
2491 RTL_CONSTASCII_STRINGPARAM("] unsupported element type: ") );
2492 buf
.append( OUString::unacquired( &element_type
->pTypeName
) );
2493 buf
.append( jni
.get_stack_trace() );
2494 throw BridgeRuntimeError( buf
.makeStringAndClear() );
2500 if (0 == java_data
->l
)
2502 JLocalAutoRef
jo_element_class(
2503 jni
, jni
->GetObjectClass( jo_ar
.get() ) );
2506 java_data
->l
= jni
->NewObjectArray(
2507 1, (jclass
) jo_element_class
.get(), jo_ar
.get() );
2511 java_data
->l
= jni
->NewObjectArray(
2512 1, (jclass
) jo_element_class
.get(), 0 );
2514 jni
.ensure_no_exception();
2518 jni
->SetObjectArrayElement(
2519 (jobjectArray
) java_data
->l
, 0, jo_ar
.get() );
2520 jni
.ensure_no_exception();
2525 java_data
->l
= jo_ar
.release();
2529 case typelib_TypeClass_INTERFACE
:
2531 JLocalAutoRef
jo_iface( jni
);
2534 uno_Interface
* pUnoI
= *(uno_Interface
* const *)uno_data
;
2538 info
= m_jni_info
->get_type_info( jni
, type
);
2539 JNI_interface_type_info
const * iface_info
=
2540 static_cast< JNI_interface_type_info
const * >( info
);
2541 jo_iface
.reset( map_to_java( jni
, pUnoI
, iface_info
) );
2546 if (0 == java_data
->l
)
2549 info
= m_jni_info
->get_type_info( jni
, type
);
2551 jni
->NewObjectArray( 1, info
->m_class
, jo_iface
.get() );
2552 jni
.ensure_no_exception();
2556 jni
->SetObjectArrayElement(
2557 (jobjectArray
) java_data
->l
, 0, jo_iface
.get() );
2558 jni
.ensure_no_exception();
2563 java_data
->l
= jo_iface
.release();
2569 OUStringBuffer
buf( 128 );
2570 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_java():") );
2571 buf
.append( OUString::unacquired( &type
->pTypeName
) );
2572 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("] unsupported type!") );
2573 buf
.append( jni
.get_stack_trace() );
2574 throw BridgeRuntimeError( buf
.makeStringAndClear() );