1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "jni_bridge.h"
32 #include "rtl/strbuf.hxx"
33 #include "rtl/ustrbuf.hxx"
34 #include "uno/sequence2.h"
37 using namespace ::std
;
38 using namespace ::rtl
;
43 //------------------------------------------------------------------------------
44 inline rtl_mem
* seq_allocate( sal_Int32 nElements
, sal_Int32 nSize
)
46 SAL_WNODEPRECATED_DECLARATIONS_PUSH
47 auto_ptr
< rtl_mem
> seq(
48 rtl_mem::allocate( SAL_SEQUENCE_HEADER_SIZE
+ (nElements
* nSize
) ) );
49 SAL_WNODEPRECATED_DECLARATIONS_POP
50 uno_Sequence
* p
= (uno_Sequence
*)seq
.get();
52 p
->nElements
= nElements
;
56 //______________________________________________________________________________
59 void createDefaultUnoValue(
60 JNI_context
const & jni
, void * uno_data
,
61 typelib_TypeDescriptionReference
* type
,
62 JNI_type_info
const * info
/* maybe 0 */, bool assign
)
64 switch (type
->eTypeClass
) {
65 case typelib_TypeClass_BOOLEAN
:
66 *static_cast< sal_Bool
* >(uno_data
) = false;
69 case typelib_TypeClass_BYTE
:
70 *static_cast< sal_Int8
* >(uno_data
) = 0;
73 case typelib_TypeClass_SHORT
:
74 *static_cast< sal_Int16
* >(uno_data
) = 0;
77 case typelib_TypeClass_UNSIGNED_SHORT
:
78 *static_cast< sal_uInt16
* >(uno_data
) = 0;
81 case typelib_TypeClass_LONG
:
82 *static_cast< sal_Int32
* >(uno_data
) = 0;
85 case typelib_TypeClass_UNSIGNED_LONG
:
86 *static_cast< sal_uInt32
* >(uno_data
) = 0;
89 case typelib_TypeClass_HYPER
:
90 *static_cast< sal_Int64
* >(uno_data
) = 0;
93 case typelib_TypeClass_UNSIGNED_HYPER
:
94 *static_cast< sal_uInt64
* >(uno_data
) = 0;
97 case typelib_TypeClass_FLOAT
:
98 *static_cast< float * >(uno_data
) = 0;
101 case typelib_TypeClass_DOUBLE
:
102 *static_cast< double * >(uno_data
) = 0;
105 case typelib_TypeClass_CHAR
:
106 *static_cast< sal_Unicode
* >(uno_data
) = 0;
109 case typelib_TypeClass_STRING
:
111 *static_cast< rtl_uString
** >(uno_data
) = 0;
113 rtl_uString_new(static_cast< rtl_uString
** >(uno_data
));
116 case typelib_TypeClass_TYPE
:
118 typelib_typedescriptionreference_release(
119 *static_cast< typelib_TypeDescriptionReference
** >(uno_data
));
121 *static_cast< typelib_TypeDescriptionReference
** >(uno_data
)
122 = *typelib_static_type_getByTypeClass(typelib_TypeClass_VOID
);
124 *static_cast< typelib_TypeDescriptionReference
** >(uno_data
) != 0);
125 typelib_typedescriptionreference_acquire(
126 *static_cast< typelib_TypeDescriptionReference
** >(uno_data
));
129 case typelib_TypeClass_ANY
:
131 uno_any_destruct(static_cast< uno_Any
* >(uno_data
), 0);
134 static_cast< uno_Any
* >(uno_data
), 0,
135 jni
.get_info()->m_XInterface_type_info
->m_td
.get(), 0);
138 case typelib_TypeClass_SEQUENCE
:
140 SAL_WNODEPRECATED_DECLARATIONS_PUSH
141 auto_ptr
< rtl_mem
> seq(seq_allocate(0, 0));
142 SAL_WNODEPRECATED_DECLARATIONS_POP
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 pAny
->pData
= &pAny
->pReserved
;
567 *(jchar
*) pAny
->pData
= jni
->CallCharMethodA(
568 java_data
.l
, m_jni_info
->m_method_Character_charValue
, 0 );
569 jni
.ensure_no_exception();
571 case typelib_TypeClass_BOOLEAN
:
572 pAny
->pData
= &pAny
->pReserved
;
573 *(jboolean
*) pAny
->pData
= jni
->CallBooleanMethodA(
574 java_data
.l
, m_jni_info
->m_method_Boolean_booleanValue
, 0 );
575 jni
.ensure_no_exception();
577 case typelib_TypeClass_BYTE
:
578 pAny
->pData
= &pAny
->pReserved
;
579 *(jbyte
*) pAny
->pData
= jni
->CallByteMethodA(
580 java_data
.l
, m_jni_info
->m_method_Byte_byteValue
, 0 );
581 jni
.ensure_no_exception();
583 case typelib_TypeClass_SHORT
:
584 case typelib_TypeClass_UNSIGNED_SHORT
:
585 pAny
->pData
= &pAny
->pReserved
;
586 *(jshort
*) pAny
->pData
= jni
->CallShortMethodA(
587 java_data
.l
, m_jni_info
->m_method_Short_shortValue
, 0 );
588 jni
.ensure_no_exception();
590 case typelib_TypeClass_LONG
:
591 case typelib_TypeClass_UNSIGNED_LONG
:
592 pAny
->pData
= &pAny
->pReserved
;
593 *(jint
*) pAny
->pData
= jni
->CallIntMethodA(
594 java_data
.l
, m_jni_info
->m_method_Integer_intValue
, 0 );
595 jni
.ensure_no_exception();
597 case typelib_TypeClass_HYPER
:
598 case typelib_TypeClass_UNSIGNED_HYPER
:
599 if (sizeof (sal_Int64
) <= sizeof (void *))
601 pAny
->pData
= &pAny
->pReserved
;
602 *(jlong
*) pAny
->pData
= jni
->CallLongMethodA(
603 java_data
.l
, m_jni_info
->m_method_Long_longValue
, 0 );
604 jni
.ensure_no_exception();
608 SAL_WNODEPRECATED_DECLARATIONS_PUSH
609 auto_ptr
< rtl_mem
> mem(
610 rtl_mem::allocate( sizeof (sal_Int64
) ) );
611 SAL_WNODEPRECATED_DECLARATIONS_POP
612 *(jlong
*) mem
.get() = jni
->CallLongMethodA(
613 java_data
.l
, m_jni_info
->m_method_Long_longValue
, 0 );
614 jni
.ensure_no_exception();
615 pAny
->pData
= mem
.release();
618 case typelib_TypeClass_FLOAT
:
619 if (sizeof (float) <= sizeof (void *))
621 pAny
->pData
= &pAny
->pReserved
;
622 *(jfloat
*) pAny
->pData
= jni
->CallFloatMethodA(
623 java_data
.l
, m_jni_info
->m_method_Float_floatValue
, 0 );
624 jni
.ensure_no_exception();
628 SAL_WNODEPRECATED_DECLARATIONS_PUSH
629 auto_ptr
< rtl_mem
> mem(
630 rtl_mem::allocate( sizeof (float) ) );
631 SAL_WNODEPRECATED_DECLARATIONS_POP
632 *(jfloat
*) mem
.get() = jni
->CallFloatMethodA(
633 java_data
.l
, m_jni_info
->m_method_Float_floatValue
, 0 );
634 jni
.ensure_no_exception();
635 pAny
->pData
= mem
.release();
638 case typelib_TypeClass_DOUBLE
:
639 if (sizeof (double) <= sizeof (void *))
641 pAny
->pData
= &pAny
->pReserved
;
642 *(jdouble
*) pAny
->pData
=
643 jni
->CallDoubleMethodA(
645 m_jni_info
->m_method_Double_doubleValue
, 0 );
646 jni
.ensure_no_exception();
650 SAL_WNODEPRECATED_DECLARATIONS_PUSH
651 auto_ptr
< rtl_mem
> mem(
652 rtl_mem::allocate( sizeof (double) ) );
653 SAL_WNODEPRECATED_DECLARATIONS_POP
654 *(jdouble
*) mem
.get() =
655 jni
->CallDoubleMethodA(
657 m_jni_info
->m_method_Double_doubleValue
, 0 );
658 jni
.ensure_no_exception();
659 pAny
->pData
= mem
.release();
662 case typelib_TypeClass_STRING
:
663 // opt: anies often contain strings; copy string directly
665 pAny
->pData
= &pAny
->pReserved
;
667 jni
, (rtl_uString
**)pAny
->pData
,
668 (jstring
) java_data
.l
);
670 case typelib_TypeClass_TYPE
:
671 case typelib_TypeClass_ENUM
:
672 case typelib_TypeClass_SEQUENCE
:
673 case typelib_TypeClass_INTERFACE
:
674 pAny
->pData
= &pAny
->pReserved
;
676 jni
, pAny
->pData
, java_data
,
677 value_td
.get()->pWeakRef
, 0,
678 false /* no assign */, false /* no out param */ );
680 case typelib_TypeClass_STRUCT
:
681 case typelib_TypeClass_EXCEPTION
:
683 SAL_WNODEPRECATED_DECLARATIONS_PUSH
684 auto_ptr
< rtl_mem
> mem(
685 rtl_mem::allocate( value_td
.get()->nSize
) );
686 SAL_WNODEPRECATED_DECLARATIONS_POP
688 jni
, mem
.get(), java_data
, value_td
.get()->pWeakRef
, 0,
689 false /* no assign */, false /* no out param */ );
690 pAny
->pData
= mem
.release();
695 OUStringBuffer
buf( 128 );
696 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
697 buf
.append( type_name
);
699 RTL_CONSTASCII_STRINGPARAM("] unsupported value type "
701 buf
.append( jni
.get_stack_trace() );
702 throw BridgeRuntimeError( buf
.makeStringAndClear() );
710 // restore to valid any
711 uno_any_construct( pAny
, 0, 0, 0 );
715 typelib_typedescriptionreference_acquire( value_td
.get()->pWeakRef
);
716 pAny
->pType
= value_td
.get()->pWeakRef
;
719 case typelib_TypeClass_ENUM
:
721 JLocalAutoRef
jo_out_holder( jni
);
725 jni
->GetObjectArrayElement( (jobjectArray
) java_data
.l
, 0 ) );
726 jni
.ensure_no_exception();
727 java_data
.l
= jo_out_holder
.get();
729 if (0 == java_data
.l
)
731 OUStringBuffer
buf( 128 );
732 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
733 buf
.append( OUString::unacquired( &type
->pTypeName
) );
734 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("] null-ref given!") );
735 buf
.append( jni
.get_stack_trace() );
736 throw BridgeRuntimeError( buf
.makeStringAndClear() );
739 *(jint
*) uno_data
= jni
->GetIntField(
740 java_data
.l
, m_jni_info
->m_field_Enum_m_value
);
743 case typelib_TypeClass_STRUCT
:
744 case typelib_TypeClass_EXCEPTION
:
746 JLocalAutoRef
jo_out_holder( jni
);
750 jni
->GetObjectArrayElement( (jobjectArray
) java_data
.l
, 0 ) );
751 jni
.ensure_no_exception();
752 java_data
.l
= jo_out_holder
.get();
754 if (0 == java_data
.l
)
756 OUStringBuffer
buf( 128 );
757 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
758 buf
.append( OUString::unacquired( &type
->pTypeName
) );
759 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("] null-ref given!") );
760 buf
.append( jni
.get_stack_trace() );
761 throw BridgeRuntimeError( buf
.makeStringAndClear() );
765 info
= m_jni_info
->get_type_info( jni
, type
);
766 JNI_compound_type_info
const * comp_info
=
767 static_cast< JNI_compound_type_info
const * >( info
);
769 typelib_CompoundTypeDescription
* comp_td
=
770 (typelib_CompoundTypeDescription
*)comp_info
->m_td
.get();
772 = comp_td
->aBase
.eTypeClass
== typelib_TypeClass_STRUCT
773 && reinterpret_cast< typelib_StructTypeDescription
* >(
774 comp_td
)->pParameterizedTypes
!= 0;
777 sal_Int32 nMembers
= comp_td
->nMembers
;
780 if (0 != comp_td
->pBaseTypeDescription
)
783 jni
, uno_data
, java_data
,
784 ((typelib_TypeDescription
*) comp_td
->pBaseTypeDescription
)
787 assign
, false /* no out param */ );
790 for ( ; nPos
< nMembers
; ++nPos
)
792 void * p
= (char *)uno_data
+ comp_td
->pMemberOffsets
[ nPos
];
793 typelib_TypeDescriptionReference
* member_type
=
794 comp_td
->ppTypeRefs
[ nPos
];
795 jfieldID field_id
= comp_info
->m_fields
[ nPos
];
796 bool parameterizedType
= polymorphic
797 && reinterpret_cast< typelib_StructTypeDescription
* >(
798 comp_td
)->pParameterizedTypes
[nPos
];
799 switch (member_type
->eTypeClass
)
801 case typelib_TypeClass_CHAR
:
802 if (parameterizedType
) {
804 jni
, jni
->GetObjectField( java_data
.l
, field_id
) );
805 if ( jo
.get() == 0 ) {
811 jni
, p
, val
, member_type
, 0, assign
, false,
815 *(jchar
*) p
= jni
->GetCharField(
816 java_data
.l
, field_id
);
819 case typelib_TypeClass_BOOLEAN
:
820 if (parameterizedType
) {
822 jni
, jni
->GetObjectField( java_data
.l
, field_id
) );
823 if ( jo
.get() == 0 ) {
824 *(jboolean
*) p
= false;
829 jni
, p
, val
, member_type
, 0, assign
, false,
833 *(jboolean
*) p
= jni
->GetBooleanField(
834 java_data
.l
, field_id
);
837 case typelib_TypeClass_BYTE
:
838 if (parameterizedType
) {
840 jni
, jni
->GetObjectField( java_data
.l
, field_id
) );
841 if ( jo
.get() == 0 ) {
847 jni
, p
, val
, member_type
, 0, assign
, false,
851 *(jbyte
*) p
= jni
->GetByteField(
852 java_data
.l
, field_id
);
855 case typelib_TypeClass_SHORT
:
856 case typelib_TypeClass_UNSIGNED_SHORT
:
857 if (parameterizedType
) {
859 jni
, jni
->GetObjectField( java_data
.l
, field_id
) );
860 if ( jo
.get() == 0 ) {
866 jni
, p
, val
, member_type
, 0, assign
, false,
870 *(jshort
*) p
= jni
->GetShortField(
871 java_data
.l
, field_id
);
874 case typelib_TypeClass_LONG
:
875 case typelib_TypeClass_UNSIGNED_LONG
:
876 if (parameterizedType
) {
878 jni
, jni
->GetObjectField( java_data
.l
, field_id
) );
879 if ( jo
.get() == 0 ) {
885 jni
, p
, val
, member_type
, 0, assign
, false,
889 *(jint
*) p
= jni
->GetIntField( java_data
.l
, field_id
);
892 case typelib_TypeClass_HYPER
:
893 case typelib_TypeClass_UNSIGNED_HYPER
:
894 if (parameterizedType
) {
896 jni
, jni
->GetObjectField( java_data
.l
, field_id
) );
897 if ( jo
.get() == 0 ) {
903 jni
, p
, val
, member_type
, 0, assign
, false,
907 *(jlong
*) p
= jni
->GetLongField(
908 java_data
.l
, field_id
);
911 case typelib_TypeClass_FLOAT
:
912 if (parameterizedType
) {
914 jni
, jni
->GetObjectField( java_data
.l
, field_id
) );
915 if ( jo
.get() == 0 ) {
921 jni
, p
, val
, member_type
, 0, assign
, false,
925 *(jfloat
*) p
= jni
->GetFloatField(
926 java_data
.l
, field_id
);
929 case typelib_TypeClass_DOUBLE
:
930 if (parameterizedType
) {
932 jni
, jni
->GetObjectField( java_data
.l
, field_id
) );
933 if ( jo
.get() == 0 ) {
939 jni
, p
, val
, member_type
, 0, assign
, false,
943 *(jdouble
*) p
= jni
->GetDoubleField(
944 java_data
.l
, field_id
);
949 JLocalAutoRef
jo_field( jni
);
953 // special for Message: call Throwable.getMessage()
957 m_jni_info
->m_Exception_type
.getTypeLibType() )
960 m_jni_info
->m_RuntimeException_type
.
961 getTypeLibType() ) );
962 OSL_ASSERT( 0 == nPos
); // first member
965 jni
->CallObjectMethodA(
967 m_jni_info
->m_method_Throwable_getMessage
, 0 )
969 jni
.ensure_no_exception();
975 jni
->GetObjectField( java_data
.l
, field_id
) );
976 checkNull
= parameterizedType
;
978 if (checkNull
&& !jo_field
.is()) {
979 createDefaultUnoValue(jni
, p
, member_type
, 0, assign
);
982 val
.l
= jo_field
.get();
984 jni
, p
, val
, member_type
, 0,
985 assign
, false /* no out param */ );
997 for ( sal_Int32 nCleanup
= 0; nCleanup
< nPos
; ++nCleanup
)
1000 (char *)uno_data
+ comp_td
->pMemberOffsets
[ nCleanup
];
1001 uno_type_destructData(
1002 p
, comp_td
->ppTypeRefs
[ nCleanup
], 0 );
1004 if (0 != comp_td
->pBaseTypeDescription
)
1008 (typelib_TypeDescription
*) comp_td
1009 ->pBaseTypeDescription
, 0 );
1016 case typelib_TypeClass_SEQUENCE
:
1018 JLocalAutoRef
jo_out_holder( jni
);
1021 jo_out_holder
.reset(
1022 jni
->GetObjectArrayElement( (jobjectArray
) java_data
.l
, 0 ) );
1023 jni
.ensure_no_exception();
1024 java_data
.l
= jo_out_holder
.get();
1026 if (0 == java_data
.l
)
1028 OUStringBuffer
buf( 128 );
1029 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
1030 buf
.append( OUString::unacquired( &type
->pTypeName
) );
1031 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("] null-ref given!") );
1032 buf
.append( jni
.get_stack_trace() );
1033 throw BridgeRuntimeError( buf
.makeStringAndClear() );
1036 TypeDescr
td( type
);
1037 typelib_TypeDescriptionReference
* element_type
=
1038 ((typelib_IndirectTypeDescription
*)td
.get())->pType
;
1040 SAL_WNODEPRECATED_DECLARATIONS_PUSH
1041 auto_ptr
< rtl_mem
> seq
;
1042 SAL_WNODEPRECATED_DECLARATIONS_POP
1043 sal_Int32 nElements
= jni
->GetArrayLength( (jarray
) java_data
.l
);
1045 switch (element_type
->eTypeClass
)
1047 case typelib_TypeClass_CHAR
:
1048 seq
.reset( seq_allocate( nElements
, sizeof (sal_Unicode
) ) );
1049 jni
->GetCharArrayRegion(
1050 (jcharArray
) java_data
.l
, 0, nElements
,
1051 (jchar
*) ((uno_Sequence
*) seq
.get())->elements
);
1052 jni
.ensure_no_exception();
1054 case typelib_TypeClass_BOOLEAN
:
1055 seq
.reset( seq_allocate( nElements
, sizeof (sal_Bool
) ) );
1056 jni
->GetBooleanArrayRegion(
1057 (jbooleanArray
) java_data
.l
, 0, nElements
,
1058 (jboolean
*) ((uno_Sequence
*) seq
.get())->elements
);
1059 jni
.ensure_no_exception();
1061 case typelib_TypeClass_BYTE
:
1062 seq
.reset( seq_allocate( nElements
, sizeof (sal_Int8
) ) );
1063 jni
->GetByteArrayRegion(
1064 (jbyteArray
) java_data
.l
, 0, nElements
,
1065 (jbyte
*) ((uno_Sequence
*) seq
.get())->elements
);
1066 jni
.ensure_no_exception();
1068 case typelib_TypeClass_SHORT
:
1069 case typelib_TypeClass_UNSIGNED_SHORT
:
1070 seq
.reset( seq_allocate( nElements
, sizeof (sal_Int16
) ) );
1071 jni
->GetShortArrayRegion(
1072 (jshortArray
) java_data
.l
, 0, nElements
,
1073 (jshort
*) ((uno_Sequence
*) seq
.get())->elements
);
1074 jni
.ensure_no_exception();
1076 case typelib_TypeClass_LONG
:
1077 case typelib_TypeClass_UNSIGNED_LONG
:
1078 seq
.reset( seq_allocate( nElements
, sizeof (sal_Int32
) ) );
1079 jni
->GetIntArrayRegion(
1080 (jintArray
) java_data
.l
, 0, nElements
,
1081 (jint
*) ((uno_Sequence
*) seq
.get())->elements
);
1082 jni
.ensure_no_exception();
1084 case typelib_TypeClass_HYPER
:
1085 case typelib_TypeClass_UNSIGNED_HYPER
:
1086 seq
.reset( seq_allocate( nElements
, sizeof (sal_Int64
) ) );
1087 jni
->GetLongArrayRegion(
1088 (jlongArray
) java_data
.l
, 0, nElements
,
1089 (jlong
*) ((uno_Sequence
*) seq
.get())->elements
);
1090 jni
.ensure_no_exception();
1092 case typelib_TypeClass_FLOAT
:
1093 seq
.reset( seq_allocate( nElements
, sizeof (float) ) );
1094 jni
->GetFloatArrayRegion(
1095 (jfloatArray
) java_data
.l
, 0, nElements
,
1096 (jfloat
*)((uno_Sequence
*)seq
.get())->elements
);
1097 jni
.ensure_no_exception();
1099 case typelib_TypeClass_DOUBLE
:
1100 seq
.reset( seq_allocate( nElements
, sizeof (double) ) );
1101 jni
->GetDoubleArrayRegion(
1102 (jdoubleArray
) java_data
.l
, 0, nElements
,
1103 (jdouble
*) ((uno_Sequence
*) seq
.get())->elements
);
1104 jni
.ensure_no_exception();
1106 case typelib_TypeClass_STRING
:
1107 case typelib_TypeClass_TYPE
:
1108 case typelib_TypeClass_ANY
:
1109 case typelib_TypeClass_ENUM
:
1110 case typelib_TypeClass_STRUCT
:
1111 case typelib_TypeClass_EXCEPTION
:
1112 case typelib_TypeClass_SEQUENCE
:
1113 case typelib_TypeClass_INTERFACE
:
1115 TypeDescr
element_td( element_type
);
1116 seq
.reset( seq_allocate( nElements
, element_td
.get()->nSize
) );
1118 JNI_type_info
const * element_info
;
1119 if (typelib_TypeClass_STRUCT
== element_type
->eTypeClass
||
1120 typelib_TypeClass_EXCEPTION
== element_type
->eTypeClass
||
1121 typelib_TypeClass_INTERFACE
== element_type
->eTypeClass
)
1124 m_jni_info
->get_type_info( jni
, element_td
.get() );
1131 for ( sal_Int32 nPos
= 0; nPos
< nElements
; ++nPos
)
1136 jni
, jni
->GetObjectArrayElement(
1137 (jobjectArray
) java_data
.l
, nPos
) );
1138 jni
.ensure_no_exception();
1142 ((uno_Sequence
*)seq
.get())->elements
+
1143 (nPos
* element_td
.get()->nSize
);
1145 jni
, p
, val
, element_td
.get()->pWeakRef
, element_info
,
1146 false /* no assign */, false /* no out param */ );
1151 for ( sal_Int32 nCleanPos
= 0;
1152 nCleanPos
< nPos
; ++nCleanPos
)
1155 ((uno_Sequence
*)seq
.get())->elements
+
1156 (nCleanPos
* element_td
.get()->nSize
);
1157 uno_destructData( p
, element_td
.get(), 0 );
1166 OUStringBuffer
buf( 128 );
1167 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
1168 buf
.append( OUString::unacquired( &type
->pTypeName
) );
1170 RTL_CONSTASCII_STRINGPARAM("] unsupported sequence element"
1172 buf
.append( OUString::unacquired( &element_type
->pTypeName
) );
1173 buf
.append( jni
.get_stack_trace() );
1174 throw BridgeRuntimeError( buf
.makeStringAndClear() );
1179 uno_destructData( uno_data
, td
.get(), 0 );
1180 *(uno_Sequence
**)uno_data
= (uno_Sequence
*)seq
.release();
1183 case typelib_TypeClass_INTERFACE
:
1185 JLocalAutoRef
jo_out_holder( jni
);
1188 jo_out_holder
.reset(
1189 jni
->GetObjectArrayElement( (jobjectArray
) java_data
.l
, 0 ) );
1190 jni
.ensure_no_exception();
1191 java_data
.l
= jo_out_holder
.get();
1194 if (0 == java_data
.l
) // null-ref
1198 uno_Interface
* p
= *(uno_Interface
**)uno_data
;
1202 *(uno_Interface
**)uno_data
= 0;
1207 info
= m_jni_info
->get_type_info( jni
, type
);
1208 JNI_interface_type_info
const * iface_info
=
1209 static_cast< JNI_interface_type_info
const * >( info
);
1210 uno_Interface
* pUnoI
= map_to_uno( jni
, java_data
.l
, iface_info
);
1213 uno_Interface
* p
= *(uno_Interface
**)uno_data
;
1217 *(uno_Interface
**)uno_data
= pUnoI
;
1223 OUStringBuffer
buf( 128 );
1224 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
1225 buf
.append( OUString::unacquired( &type
->pTypeName
) );
1226 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("] unsupported type!") );
1227 buf
.append( jni
.get_stack_trace() );
1228 throw BridgeRuntimeError( buf
.makeStringAndClear() );
1233 //##############################################################################
1235 //______________________________________________________________________________
1236 void Bridge::map_to_java(
1237 JNI_context
const & jni
,
1238 jvalue
* java_data
, void const * uno_data
,
1239 typelib_TypeDescriptionReference
* type
,
1240 JNI_type_info
const * info
/* maybe 0 */,
1241 bool in_param
, bool out_param
,
1242 bool special_wrapped_integral_types
) const
1244 switch (type
->eTypeClass
)
1246 case typelib_TypeClass_CHAR
:
1249 if (0 == java_data
->l
)
1251 JLocalAutoRef
jo_ar( jni
, jni
->NewCharArray( 1 ) );
1252 jni
.ensure_no_exception();
1255 jni
->SetCharArrayRegion(
1256 (jcharArray
) jo_ar
.get(), 0, 1, (jchar
*) uno_data
);
1257 jni
.ensure_no_exception();
1259 java_data
->l
= jo_ar
.release();
1265 jni
->SetCharArrayRegion(
1266 (jcharArray
) java_data
->l
, 0, 1, (jchar
*) uno_data
);
1267 jni
.ensure_no_exception();
1271 else if (special_wrapped_integral_types
)
1274 arg
.c
= *(jchar
const *) uno_data
;
1275 java_data
->l
= jni
->NewObjectA(
1276 m_jni_info
->m_class_Character
,
1277 m_jni_info
->m_ctor_Character_with_char
, &arg
);
1278 jni
.ensure_no_exception();
1282 java_data
->c
= *(jchar
const *) uno_data
;
1285 case typelib_TypeClass_BOOLEAN
:
1288 if (0 == java_data
->l
)
1290 JLocalAutoRef
jo_ar( jni
, jni
->NewBooleanArray( 1 ) );
1291 jni
.ensure_no_exception();
1294 jni
->SetBooleanArrayRegion(
1295 (jbooleanArray
) jo_ar
.get(),
1296 0, 1, (jboolean
*) uno_data
);
1297 jni
.ensure_no_exception();
1299 java_data
->l
= jo_ar
.release();
1305 jni
->SetBooleanArrayRegion(
1306 (jbooleanArray
) java_data
->l
,
1307 0, 1, (jboolean
*) uno_data
);
1308 jni
.ensure_no_exception();
1312 else if (special_wrapped_integral_types
)
1315 arg
.z
= *(jboolean
const *) uno_data
;
1316 java_data
->l
= jni
->NewObjectA(
1317 m_jni_info
->m_class_Boolean
,
1318 m_jni_info
->m_ctor_Boolean_with_boolean
, &arg
);
1319 jni
.ensure_no_exception();
1323 java_data
->z
= *(jboolean
const *) uno_data
;
1326 case typelib_TypeClass_BYTE
:
1329 if (0 == java_data
->l
)
1331 JLocalAutoRef
jo_ar( jni
, jni
->NewByteArray( 1 ) );
1332 jni
.ensure_no_exception();
1335 jni
->SetByteArrayRegion(
1336 (jbyteArray
) jo_ar
.get(), 0, 1, (jbyte
*) uno_data
);
1337 jni
.ensure_no_exception();
1339 java_data
->l
= jo_ar
.release();
1345 jni
->SetByteArrayRegion(
1346 (jbyteArray
) java_data
->l
, 0, 1, (jbyte
*) uno_data
);
1347 jni
.ensure_no_exception();
1351 else if (special_wrapped_integral_types
)
1354 arg
.b
= *(jbyte
const *) uno_data
;
1355 java_data
->l
= jni
->NewObjectA(
1356 m_jni_info
->m_class_Byte
,
1357 m_jni_info
->m_ctor_Byte_with_byte
, &arg
);
1358 jni
.ensure_no_exception();
1362 java_data
->b
= *(jbyte
const *) uno_data
;
1365 case typelib_TypeClass_SHORT
:
1366 case typelib_TypeClass_UNSIGNED_SHORT
:
1369 if (0 == java_data
->l
)
1371 JLocalAutoRef
jo_ar( jni
, jni
->NewShortArray( 1 ) );
1372 jni
.ensure_no_exception();
1375 jni
->SetShortArrayRegion(
1376 (jshortArray
) jo_ar
.get(), 0, 1, (jshort
*) uno_data
);
1377 jni
.ensure_no_exception();
1379 java_data
->l
= jo_ar
.release();
1385 jni
->SetShortArrayRegion(
1386 (jshortArray
) java_data
->l
, 0, 1, (jshort
*) uno_data
);
1387 jni
.ensure_no_exception();
1391 else if (special_wrapped_integral_types
)
1394 arg
.s
= *(jshort
const *) uno_data
;
1395 java_data
->l
= jni
->NewObjectA(
1396 m_jni_info
->m_class_Short
,
1397 m_jni_info
->m_ctor_Short_with_short
, &arg
);
1398 jni
.ensure_no_exception();
1402 java_data
->s
= *(jshort
const *) uno_data
;
1405 case typelib_TypeClass_LONG
:
1406 case typelib_TypeClass_UNSIGNED_LONG
:
1409 if (0 == java_data
->l
)
1411 JLocalAutoRef
jo_ar( jni
, jni
->NewIntArray( 1 ) );
1412 jni
.ensure_no_exception();
1415 jni
->SetIntArrayRegion(
1416 (jintArray
) jo_ar
.get(), 0, 1, (jint
*) uno_data
);
1417 jni
.ensure_no_exception();
1419 java_data
->l
= jo_ar
.release();
1425 jni
->SetIntArrayRegion(
1426 (jintArray
) java_data
->l
, 0, 1, (jint
*) uno_data
);
1427 jni
.ensure_no_exception();
1431 else if (special_wrapped_integral_types
)
1434 arg
.i
= *(jint
const *) uno_data
;
1435 java_data
->l
= jni
->NewObjectA(
1436 m_jni_info
->m_class_Integer
,
1437 m_jni_info
->m_ctor_Integer_with_int
, &arg
);
1438 jni
.ensure_no_exception();
1442 java_data
->i
= *(jint
const *) uno_data
;
1445 case typelib_TypeClass_HYPER
:
1446 case typelib_TypeClass_UNSIGNED_HYPER
:
1449 if (0 == java_data
->l
)
1451 JLocalAutoRef
jo_ar( jni
, jni
->NewLongArray( 1 ) );
1452 jni
.ensure_no_exception();
1455 jni
->SetLongArrayRegion(
1456 (jlongArray
)jo_ar
.get(), 0, 1, (jlong
*) uno_data
);
1457 jni
.ensure_no_exception();
1459 java_data
->l
= jo_ar
.release();
1465 jni
->SetLongArrayRegion(
1466 (jlongArray
)java_data
->l
, 0, 1, (jlong
*) uno_data
);
1467 jni
.ensure_no_exception();
1471 else if (special_wrapped_integral_types
)
1474 arg
.j
= *(jlong
const *) uno_data
;
1475 java_data
->l
= jni
->NewObjectA(
1476 m_jni_info
->m_class_Long
,
1477 m_jni_info
->m_ctor_Long_with_long
, &arg
);
1478 jni
.ensure_no_exception();
1482 java_data
->j
= *(jlong
const *) uno_data
;
1485 case typelib_TypeClass_FLOAT
:
1488 if (0 == java_data
->l
)
1490 JLocalAutoRef
jo_ar( jni
, jni
->NewFloatArray( 1 ) );
1491 jni
.ensure_no_exception();
1494 jni
->SetFloatArrayRegion(
1495 (jfloatArray
) jo_ar
.get(), 0, 1, (jfloat
*) uno_data
);
1496 jni
.ensure_no_exception();
1498 java_data
->l
= jo_ar
.release();
1504 jni
->SetFloatArrayRegion(
1505 (jfloatArray
) java_data
->l
, 0, 1, (jfloat
*) uno_data
);
1506 jni
.ensure_no_exception();
1510 else if (special_wrapped_integral_types
)
1513 arg
.f
= *(jfloat
const *) uno_data
;
1514 java_data
->l
= jni
->NewObjectA(
1515 m_jni_info
->m_class_Float
,
1516 m_jni_info
->m_ctor_Float_with_float
, &arg
);
1517 jni
.ensure_no_exception();
1521 java_data
->f
= *(jfloat
const *) uno_data
;
1524 case typelib_TypeClass_DOUBLE
:
1527 if (0 == java_data
->l
)
1529 JLocalAutoRef
jo_ar( jni
, jni
->NewDoubleArray( 1 ) );
1530 jni
.ensure_no_exception();
1533 jni
->SetDoubleArrayRegion(
1534 (jdoubleArray
) jo_ar
.get(),
1535 0, 1, (jdouble
*) uno_data
);
1536 jni
.ensure_no_exception();
1538 java_data
->l
= jo_ar
.release();
1544 jni
->SetDoubleArrayRegion(
1545 (jdoubleArray
) java_data
->l
,
1546 0, 1, (jdouble
*) uno_data
);
1547 jni
.ensure_no_exception();
1551 else if (special_wrapped_integral_types
)
1554 arg
.d
= *(double const *)uno_data
;
1555 java_data
->l
= jni
->NewObjectA(
1556 m_jni_info
->m_class_Double
,
1557 m_jni_info
->m_ctor_Double_with_double
, &arg
);
1558 jni
.ensure_no_exception();
1562 java_data
->d
= *(jdouble
const *) uno_data
;
1565 case typelib_TypeClass_STRING
:
1569 JLocalAutoRef
jo_in( jni
);
1574 jni
, *(rtl_uString
* const *) uno_data
) );
1576 if (0 == java_data
->l
)
1578 java_data
->l
= jni
->NewObjectArray(
1579 1, m_jni_info
->m_class_String
, jo_in
.get() );
1580 jni
.ensure_no_exception();
1584 jni
->SetObjectArrayElement(
1585 (jobjectArray
) java_data
->l
, 0, jo_in
.get() );
1586 jni
.ensure_no_exception();
1591 OSL_ASSERT( in_param
);
1593 ustring_to_jstring( jni
, *(rtl_uString
* const *) uno_data
);
1597 case typelib_TypeClass_TYPE
:
1601 JLocalAutoRef
jo_in( jni
);
1607 *(typelib_TypeDescriptionReference
* const *) uno_data
)
1610 if (0 == java_data
->l
)
1612 java_data
->l
= jni
->NewObjectArray(
1613 1, m_jni_info
->m_class_Type
, jo_in
.get() );
1614 jni
.ensure_no_exception();
1618 jni
->SetObjectArrayElement(
1619 (jobjectArray
) java_data
->l
, 0, jo_in
.get() );
1620 jni
.ensure_no_exception();
1625 OSL_ASSERT( in_param
);
1629 *(typelib_TypeDescriptionReference
* const *) uno_data
);
1633 case typelib_TypeClass_ANY
:
1635 JLocalAutoRef
jo_any( jni
);
1638 uno_Any
const * pAny
= (uno_Any
const *)uno_data
;
1640 #if defined BRIDGES_JNI_UNO_FORCE_BOXED_ANY
1641 if (typelib_TypeClass_VOID
== pAny
->pType
->eTypeClass
)
1644 jni
->NewLocalRef( m_jni_info
->m_object_Any_VOID
) );
1650 jni
, &args
[ 1 ], pAny
->pData
, pAny
->pType
, 0,
1651 true /* in */, false /* no out */,
1652 true /* create integral wrappers */ );
1653 jo_any
.reset( args
[ 1 ].l
);
1654 // build up com.sun.star.uno.Any
1655 JLocalAutoRef
jo_type( jni
, create_type( jni
, pAny
->pType
) );
1656 args
[ 0 ].l
= jo_type
.get();
1659 m_jni_info
->m_class_Any
,
1660 m_jni_info
->m_ctor_Any_with_Type_Object
, args
) );
1661 jni
.ensure_no_exception();
1664 switch (pAny
->pType
->eTypeClass
)
1666 case typelib_TypeClass_VOID
:
1668 jni
->NewLocalRef( m_jni_info
->m_object_Any_VOID
) );
1670 case typelib_TypeClass_UNSIGNED_SHORT
:
1673 args
[ 0 ].s
= *(jshort
const *) pAny
->pData
;
1674 JLocalAutoRef
jo_val(
1675 jni
, jni
->NewObjectA(
1676 m_jni_info
->m_class_Short
,
1677 m_jni_info
->m_ctor_Short_with_short
, args
) );
1678 jni
.ensure_no_exception();
1679 // box up in com.sun.star.uno.Any
1680 args
[ 0 ].l
= m_jni_info
->m_object_Type_UNSIGNED_SHORT
;
1681 args
[ 1 ].l
= jo_val
.get();
1684 m_jni_info
->m_class_Any
,
1685 m_jni_info
->m_ctor_Any_with_Type_Object
, args
) );
1686 jni
.ensure_no_exception();
1689 case typelib_TypeClass_UNSIGNED_LONG
:
1692 args
[ 0 ].i
= *(jint
const *) pAny
->pData
;
1693 JLocalAutoRef
jo_val(
1694 jni
, jni
->NewObjectA(
1695 m_jni_info
->m_class_Integer
,
1696 m_jni_info
->m_ctor_Integer_with_int
, args
) );
1697 jni
.ensure_no_exception();
1698 // box up in com.sun.star.uno.Any
1699 args
[ 0 ].l
= m_jni_info
->m_object_Type_UNSIGNED_LONG
;
1700 args
[ 1 ].l
= jo_val
.get();
1703 m_jni_info
->m_class_Any
,
1704 m_jni_info
->m_ctor_Any_with_Type_Object
, args
) );
1705 jni
.ensure_no_exception();
1708 case typelib_TypeClass_UNSIGNED_HYPER
:
1711 args
[ 0 ].j
= *(jlong
const *) pAny
->pData
;
1712 JLocalAutoRef
jo_val(
1713 jni
, jni
->NewObjectA(
1714 m_jni_info
->m_class_Long
,
1715 m_jni_info
->m_ctor_Long_with_long
, args
) );
1716 jni
.ensure_no_exception();
1717 // box up in com.sun.star.uno.Any
1718 args
[ 0 ].l
= m_jni_info
->m_object_Type_UNSIGNED_HYPER
;
1719 args
[ 1 ].l
= jo_val
.get();
1722 m_jni_info
->m_class_Any
,
1723 m_jni_info
->m_ctor_Any_with_Type_Object
, args
) );
1724 jni
.ensure_no_exception();
1727 case typelib_TypeClass_STRING
: // opt strings
1728 jo_any
.reset( ustring_to_jstring(
1729 jni
, (rtl_uString
*) pAny
->pReserved
) );
1731 case typelib_TypeClass_SEQUENCE
:
1734 // prefetch sequence td
1735 TypeDescr
seq_td( pAny
->pType
);
1737 jni
, &java_data2
, pAny
->pData
, seq_td
.get()->pWeakRef
, 0,
1738 true /* in */, false /* no out */,
1739 true /* create integral wrappers */ );
1740 jo_any
.reset( java_data2
.l
);
1742 // determine inner element type
1743 ::com::sun::star::uno::Type
element_type(
1744 ((typelib_IndirectTypeDescription
*)seq_td
.get())->pType
);
1745 while (typelib_TypeClass_SEQUENCE
==
1746 element_type
.getTypeLibType()->eTypeClass
)
1748 TypeDescr
element_td( element_type
.getTypeLibType() );
1749 typelib_typedescriptionreference_assign(
1750 reinterpret_cast< typelib_TypeDescriptionReference
** >(
1752 ((typelib_IndirectTypeDescription
*)element_td
.get())
1755 // box up only if unsigned element type
1756 switch (element_type
.getTypeLibType()->eTypeClass
)
1758 case typelib_TypeClass_UNSIGNED_SHORT
:
1759 case typelib_TypeClass_UNSIGNED_LONG
:
1760 case typelib_TypeClass_UNSIGNED_HYPER
:
1763 JLocalAutoRef
jo_type(
1764 jni
, create_type( jni
, seq_td
.get()->pWeakRef
) );
1765 args
[ 0 ].l
= jo_type
.get();
1766 args
[ 1 ].l
= jo_any
.get();
1769 m_jni_info
->m_class_Any
,
1770 m_jni_info
->m_ctor_Any_with_Type_Object
, args
) );
1771 jni
.ensure_no_exception();
1779 case typelib_TypeClass_INTERFACE
:
1781 uno_Interface
* pUnoI
= (uno_Interface
*)pAny
->pReserved
;
1782 if (is_XInterface( pAny
->pType
))
1789 m_jni_info
->m_XInterface_type_info
) );
1791 // else: empty XInterface ref maps to null-ref
1795 JNI_interface_type_info
const * iface_info
=
1796 static_cast< JNI_interface_type_info
const * >(
1797 m_jni_info
->get_type_info( jni
, pAny
->pType
) );
1800 jo_any
.reset( map_to_java( jni
, pUnoI
, iface_info
) );
1802 // box up in com.sun.star.uno.Any
1804 args
[ 0 ].l
= iface_info
->m_type
;
1805 args
[ 1 ].l
= jo_any
.get();
1808 m_jni_info
->m_class_Any
,
1809 m_jni_info
->m_ctor_Any_with_Type_Object
, args
) );
1810 jni
.ensure_no_exception();
1814 case typelib_TypeClass_STRUCT
:
1816 // Do not lose information about type arguments of instantiated
1817 // polymorphic struct types:
1818 rtl::OUString
const & name
= rtl::OUString::unacquired(
1819 &pAny
->pType
->pTypeName
);
1820 OSL_ASSERT(!name
.isEmpty());
1821 if (name
[name
.getLength() - 1] == '>')
1823 // Box up in com.sun.star.uno.Any:
1824 JLocalAutoRef
jo_type(jni
, create_type(jni
, pAny
->pType
));
1827 jni
, &java_data2
, pAny
->pData
, pAny
->pType
, 0, true,
1829 jo_any
.reset(java_data2
.l
);
1831 args
[0].l
= jo_type
.get();
1832 args
[1].l
= jo_any
.get();
1835 m_jni_info
->m_class_Any
,
1836 m_jni_info
->m_ctor_Any_with_Type_Object
, args
));
1837 jni
.ensure_no_exception();
1846 jni
, &java_data2
, pAny
->pData
, pAny
->pType
, 0,
1847 true /* in */, false /* no out */,
1848 true /* create integral wrappers */ );
1849 jo_any
.reset( java_data2
.l
);
1858 if (0 == java_data
->l
)
1860 java_data
->l
= jni
->NewObjectArray(
1861 1, m_jni_info
->m_class_Object
, jo_any
.get() );
1862 jni
.ensure_no_exception();
1866 jni
->SetObjectArrayElement(
1867 (jobjectArray
) java_data
->l
, 0, jo_any
.get() );
1868 jni
.ensure_no_exception();
1873 java_data
->l
= jo_any
.release();
1877 case typelib_TypeClass_ENUM
:
1879 OUString
const & type_name
= OUString::unacquired( &type
->pTypeName
);
1881 OUStringToOString( type_name
, RTL_TEXTENCODING_JAVA_UTF8
) );
1882 JLocalAutoRef
jo_enum_class(
1883 jni
, find_class( jni
, class_name
.getStr() ) );
1885 JLocalAutoRef
jo_enum( jni
);
1888 // call static <enum_class>.fromInt( int )
1889 OStringBuffer
sig_buf( 5 + class_name
.getLength() );
1890 sig_buf
.append( RTL_CONSTASCII_STRINGPARAM("(I)L") );
1891 sig_buf
.append( class_name
.replace( '.', '/' ) );
1892 sig_buf
.append( ';' );
1893 OString
sig( sig_buf
.makeStringAndClear() );
1894 jmethodID method_id
= jni
->GetStaticMethodID(
1895 (jclass
) jo_enum_class
.get(), "fromInt", sig
.getStr() );
1896 jni
.ensure_no_exception();
1897 OSL_ASSERT( 0 != method_id
);
1900 arg
.i
= *(jint
const *) uno_data
;
1902 jni
->CallStaticObjectMethodA(
1903 (jclass
) jo_enum_class
.get(), method_id
, &arg
) );
1904 jni
.ensure_no_exception();
1908 if (0 == java_data
->l
)
1910 java_data
->l
= jni
->NewObjectArray(
1911 1, (jclass
) jo_enum_class
.get(), jo_enum
.get() );
1912 jni
.ensure_no_exception();
1916 jni
->SetObjectArrayElement(
1917 (jobjectArray
) java_data
->l
, 0, jo_enum
.get() );
1918 jni
.ensure_no_exception();
1923 java_data
->l
= jo_enum
.release();
1927 case typelib_TypeClass_STRUCT
:
1928 case typelib_TypeClass_EXCEPTION
:
1931 info
= m_jni_info
->get_type_info( jni
, type
);
1932 JNI_compound_type_info
const * comp_info
=
1933 static_cast< JNI_compound_type_info
const * >( info
);
1935 JLocalAutoRef
jo_comp( jni
);
1938 if (typelib_TypeClass_EXCEPTION
== type
->eTypeClass
)
1940 JLocalAutoRef
jo_message(
1941 jni
, ustring_to_jstring( jni
, *(rtl_uString
**)uno_data
) );
1943 arg
.l
= jo_message
.get();
1946 comp_info
->m_class
, comp_info
->m_exc_ctor
, &arg
) );
1947 jni
.ensure_no_exception();
1951 jo_comp
.reset( jni
->AllocObject( comp_info
->m_class
) );
1952 jni
.ensure_no_exception();
1955 for ( JNI_compound_type_info
const * linfo
= comp_info
;
1957 linfo
= static_cast< JNI_compound_type_info
const * >(
1960 typelib_CompoundTypeDescription
* comp_td
=
1961 (typelib_CompoundTypeDescription
*)linfo
->m_td
.get();
1962 typelib_TypeDescriptionReference
** ppMemberTypeRefs
=
1963 comp_td
->ppTypeRefs
;
1964 sal_Int32
* pMemberOffsets
= comp_td
->pMemberOffsets
;
1966 = comp_td
->aBase
.eTypeClass
== typelib_TypeClass_STRUCT
1967 && reinterpret_cast< typelib_StructTypeDescription
* >(
1968 comp_td
)->pParameterizedTypes
!= 0;
1969 for ( sal_Int32 nPos
= comp_td
->nMembers
; nPos
--; )
1971 jfieldID field_id
= linfo
->m_fields
[ nPos
];
1975 (char const *)uno_data
+ pMemberOffsets
[ nPos
];
1976 typelib_TypeDescriptionReference
* member_type
=
1977 ppMemberTypeRefs
[ nPos
];
1978 bool parameterizedType
= polymorphic
1979 && (reinterpret_cast<
1980 typelib_StructTypeDescription
* >(comp_td
)->
1981 pParameterizedTypes
[nPos
]);
1982 switch (member_type
->eTypeClass
)
1984 case typelib_TypeClass_CHAR
:
1985 if (parameterizedType
) {
1987 arg
.c
= *(jchar
const *) p
;
1991 m_jni_info
->m_class_Character
,
1992 m_jni_info
->m_ctor_Character_with_char
,
1994 jni
.ensure_no_exception();
1995 jni
->SetObjectField(
1996 jo_comp
.get(), field_id
, jo
.get() );
2000 field_id
, *(jchar
const *) p
);
2003 case typelib_TypeClass_BOOLEAN
:
2004 if (parameterizedType
) {
2006 arg
.z
= *(jboolean
const *) p
;
2010 m_jni_info
->m_class_Boolean
,
2011 m_jni_info
->m_ctor_Boolean_with_boolean
,
2013 jni
.ensure_no_exception();
2014 jni
->SetObjectField(
2015 jo_comp
.get(), field_id
, jo
.get() );
2017 jni
->SetBooleanField(
2019 field_id
, *(jboolean
const *) p
);
2022 case typelib_TypeClass_BYTE
:
2023 if (parameterizedType
) {
2025 arg
.b
= *(jbyte
const *) p
;
2029 m_jni_info
->m_class_Byte
,
2030 m_jni_info
->m_ctor_Byte_with_byte
,
2032 jni
.ensure_no_exception();
2033 jni
->SetObjectField(
2034 jo_comp
.get(), field_id
, jo
.get() );
2038 field_id
, *(jbyte
const *) p
);
2041 case typelib_TypeClass_SHORT
:
2042 case typelib_TypeClass_UNSIGNED_SHORT
:
2043 if (parameterizedType
) {
2045 arg
.s
= *(jshort
const *) p
;
2049 m_jni_info
->m_class_Short
,
2050 m_jni_info
->m_ctor_Short_with_short
,
2052 jni
.ensure_no_exception();
2053 jni
->SetObjectField(
2054 jo_comp
.get(), field_id
, jo
.get() );
2058 field_id
, *(jshort
const *) p
);
2061 case typelib_TypeClass_LONG
:
2062 case typelib_TypeClass_UNSIGNED_LONG
:
2063 if (parameterizedType
) {
2065 arg
.i
= *(jint
const *) p
;
2069 m_jni_info
->m_class_Integer
,
2070 m_jni_info
->m_ctor_Integer_with_int
,
2072 jni
.ensure_no_exception();
2073 jni
->SetObjectField(
2074 jo_comp
.get(), field_id
, jo
.get() );
2078 field_id
, *(jint
const *) p
);
2081 case typelib_TypeClass_HYPER
:
2082 case typelib_TypeClass_UNSIGNED_HYPER
:
2083 if (parameterizedType
) {
2085 arg
.j
= *(jlong
const *) p
;
2089 m_jni_info
->m_class_Long
,
2090 m_jni_info
->m_ctor_Long_with_long
,
2092 jni
.ensure_no_exception();
2093 jni
->SetObjectField(
2094 jo_comp
.get(), field_id
, jo
.get() );
2098 field_id
, *(jlong
const *) p
);
2101 case typelib_TypeClass_FLOAT
:
2102 if (parameterizedType
) {
2104 arg
.f
= *(jfloat
const *) p
;
2108 m_jni_info
->m_class_Float
,
2109 m_jni_info
->m_ctor_Float_with_float
,
2111 jni
.ensure_no_exception();
2112 jni
->SetObjectField(
2113 jo_comp
.get(), field_id
, jo
.get() );
2117 field_id
, *(jfloat
const *) p
);
2120 case typelib_TypeClass_DOUBLE
:
2121 if (parameterizedType
) {
2123 arg
.d
= *(jdouble
const *) p
;
2127 m_jni_info
->m_class_Double
,
2128 m_jni_info
->m_ctor_Double_with_double
,
2130 jni
.ensure_no_exception();
2131 jni
->SetObjectField(
2132 jo_comp
.get(), field_id
, jo
.get() );
2134 jni
->SetDoubleField(
2136 field_id
, *(jdouble
const *) p
);
2139 case typelib_TypeClass_STRING
: // string opt here
2141 JLocalAutoRef
jo_string(
2142 jni
, ustring_to_jstring(
2143 jni
, *(rtl_uString
* const *) p
) );
2144 jni
->SetObjectField(
2145 jo_comp
.get(), field_id
, jo_string
.get() );
2152 jni
, &java_data2
, p
, member_type
, 0,
2153 true /* in */, false /* no out */ );
2154 JLocalAutoRef
jo_obj( jni
, java_data2
.l
);
2155 jni
->SetObjectField(
2156 jo_comp
.get(), field_id
, jo_obj
.get() );
2166 if (0 == java_data
->l
)
2169 jni
->NewObjectArray( 1, comp_info
->m_class
, jo_comp
.get() );
2170 jni
.ensure_no_exception();
2174 jni
->SetObjectArrayElement(
2175 (jobjectArray
) java_data
->l
, 0, jo_comp
.get() );
2176 jni
.ensure_no_exception();
2181 java_data
->l
= jo_comp
.release();
2185 case typelib_TypeClass_SEQUENCE
:
2187 // xxx todo: possible opt for pure out sequences
2188 JLocalAutoRef
jo_ar( jni
);
2190 sal_Int32 nElements
;
2191 uno_Sequence
const * seq
= 0;
2194 seq
= *(uno_Sequence
* const *)uno_data
;
2195 nElements
= seq
->nElements
;
2202 TypeDescr
td( type
);
2203 typelib_TypeDescriptionReference
* element_type
=
2204 ((typelib_IndirectTypeDescription
*)td
.get())->pType
;
2206 switch (element_type
->eTypeClass
)
2208 case typelib_TypeClass_CHAR
:
2209 jo_ar
.reset( jni
->NewCharArray( nElements
) );
2210 jni
.ensure_no_exception();
2213 jni
->SetCharArrayRegion(
2214 (jcharArray
) jo_ar
.get(),
2215 0, nElements
, (jchar
*) seq
->elements
);
2216 jni
.ensure_no_exception();
2219 case typelib_TypeClass_BOOLEAN
:
2220 jo_ar
.reset( jni
->NewBooleanArray( nElements
) );
2221 jni
.ensure_no_exception();
2224 jni
->SetBooleanArrayRegion(
2225 (jbooleanArray
) jo_ar
.get(),
2226 0, nElements
, (jboolean
*) seq
->elements
);
2227 jni
.ensure_no_exception();
2230 case typelib_TypeClass_BYTE
:
2231 jo_ar
.reset( jni
->NewByteArray( nElements
) );
2232 jni
.ensure_no_exception();
2235 jni
->SetByteArrayRegion(
2236 (jbyteArray
) jo_ar
.get(),
2237 0, nElements
, (jbyte
*) seq
->elements
);
2238 jni
.ensure_no_exception();
2241 case typelib_TypeClass_SHORT
:
2242 case typelib_TypeClass_UNSIGNED_SHORT
:
2243 jo_ar
.reset( jni
->NewShortArray( nElements
) );
2244 jni
.ensure_no_exception();
2247 jni
->SetShortArrayRegion(
2248 (jshortArray
) jo_ar
.get(),
2249 0, nElements
, (jshort
*) seq
->elements
);
2250 jni
.ensure_no_exception();
2253 case typelib_TypeClass_LONG
:
2254 case typelib_TypeClass_UNSIGNED_LONG
:
2255 jo_ar
.reset( jni
->NewIntArray( nElements
) );
2256 jni
.ensure_no_exception();
2259 jni
->SetIntArrayRegion(
2260 (jintArray
) jo_ar
.get(),
2261 0, nElements
, (jint
*) seq
->elements
);
2262 jni
.ensure_no_exception();
2265 case typelib_TypeClass_HYPER
:
2266 case typelib_TypeClass_UNSIGNED_HYPER
:
2267 jo_ar
.reset( jni
->NewLongArray( nElements
) );
2268 jni
.ensure_no_exception();
2271 jni
->SetLongArrayRegion(
2272 (jlongArray
) jo_ar
.get(),
2273 0, nElements
, (jlong
*) seq
->elements
);
2274 jni
.ensure_no_exception();
2277 case typelib_TypeClass_FLOAT
:
2278 jo_ar
.reset( jni
->NewFloatArray( nElements
) );
2279 jni
.ensure_no_exception();
2282 jni
->SetFloatArrayRegion(
2283 (jfloatArray
) jo_ar
.get(),
2284 0, nElements
, (jfloat
*) seq
->elements
);
2285 jni
.ensure_no_exception();
2288 case typelib_TypeClass_DOUBLE
:
2289 jo_ar
.reset( jni
->NewDoubleArray( nElements
) );
2290 jni
.ensure_no_exception();
2293 jni
->SetDoubleArrayRegion(
2294 (jdoubleArray
) jo_ar
.get(),
2295 0, nElements
, (jdouble
*) seq
->elements
);
2296 jni
.ensure_no_exception();
2299 case typelib_TypeClass_STRING
:
2301 jni
->NewObjectArray(
2302 nElements
, m_jni_info
->m_class_String
, 0 ) );
2303 jni
.ensure_no_exception();
2306 rtl_uString
* const * pp
=
2307 (rtl_uString
* const *) seq
->elements
;
2308 for ( sal_Int32 nPos
= 0; nPos
< nElements
; ++nPos
)
2310 JLocalAutoRef
jo_string(
2311 jni
, ustring_to_jstring( jni
, pp
[ nPos
] ) );
2312 jni
->SetObjectArrayElement(
2313 (jobjectArray
) jo_ar
.get(), nPos
, jo_string
.get() );
2314 jni
.ensure_no_exception();
2318 case typelib_TypeClass_TYPE
:
2320 jni
->NewObjectArray( nElements
, m_jni_info
->m_class_Type
, 0 ) );
2321 jni
.ensure_no_exception();
2324 typelib_TypeDescriptionReference
* const * pp
=
2325 (typelib_TypeDescriptionReference
* const *)seq
->elements
;
2326 for ( sal_Int32 nPos
= 0; nPos
< nElements
; ++nPos
)
2330 jni
, &val
, &pp
[ nPos
], element_type
, 0,
2331 true /* in */, false /* no out */ );
2332 JLocalAutoRef
jo_element( jni
, val
.l
);
2333 jni
->SetObjectArrayElement(
2334 (jobjectArray
) jo_ar
.get(), nPos
, jo_element
.get() );
2335 jni
.ensure_no_exception();
2339 case typelib_TypeClass_ANY
:
2341 jni
->NewObjectArray(
2342 nElements
, m_jni_info
->m_class_Object
, 0 ) );
2343 jni
.ensure_no_exception();
2346 uno_Any
const * p
= (uno_Any
const *)seq
->elements
;
2347 for ( sal_Int32 nPos
= 0; nPos
< nElements
; ++nPos
)
2351 jni
, &val
, &p
[ nPos
], element_type
, 0,
2352 true /* in */, false /* no out */ );
2353 JLocalAutoRef
jo_element( jni
, val
.l
);
2354 jni
->SetObjectArrayElement(
2355 (jobjectArray
) jo_ar
.get(), nPos
, jo_element
.get() );
2356 jni
.ensure_no_exception();
2360 case typelib_TypeClass_ENUM
:
2362 OUString
const & element_type_name
=
2363 OUString::unacquired( &element_type
->pTypeName
);
2366 element_type_name
, RTL_TEXTENCODING_JAVA_UTF8
) );
2367 JLocalAutoRef
jo_enum_class(
2368 jni
, find_class( jni
, class_name
.getStr() ) );
2371 jni
->NewObjectArray(
2372 nElements
, (jclass
) jo_enum_class
.get(), 0 ) );
2373 jni
.ensure_no_exception();
2377 // call static <enum_class>.fromInt( int )
2378 OStringBuffer
sig_buf( 5 + class_name
.getLength() );
2379 sig_buf
.append( RTL_CONSTASCII_STRINGPARAM("(I)L") );
2380 sig_buf
.append( class_name
.replace( '.', '/' ) );
2381 sig_buf
.append( ';' );
2382 OString
sig( sig_buf
.makeStringAndClear() );
2383 jmethodID method_id
= jni
->GetStaticMethodID(
2384 (jclass
) jo_enum_class
.get(), "fromInt", sig
.getStr() );
2385 jni
.ensure_no_exception();
2386 OSL_ASSERT( 0 != method_id
);
2388 sal_Int32
const * p
= (sal_Int32
const *)seq
->elements
;
2389 for ( sal_Int32 nPos
= 0; nPos
< nElements
; ++nPos
)
2393 JLocalAutoRef
jo_enum(
2394 jni
, jni
->CallStaticObjectMethodA(
2395 (jclass
) jo_enum_class
.get(), method_id
, &arg
) );
2396 jni
.ensure_no_exception();
2397 jni
->SetObjectArrayElement(
2398 (jobjectArray
) jo_ar
.get(), nPos
, jo_enum
.get() );
2399 jni
.ensure_no_exception();
2404 case typelib_TypeClass_STRUCT
:
2405 case typelib_TypeClass_EXCEPTION
:
2407 JNI_type_info
const * element_info
=
2408 m_jni_info
->get_type_info( jni
, element_type
);
2411 jni
->NewObjectArray( nElements
, element_info
->m_class
, 0 ) );
2412 jni
.ensure_no_exception();
2416 char * p
= (char *)seq
->elements
;
2417 sal_Int32 nSize
= element_info
->m_td
.get()->nSize
;
2418 for ( sal_Int32 nPos
= 0; nPos
< nElements
; ++nPos
)
2422 jni
, &val
, p
+ (nSize
* nPos
),
2423 element_type
, element_info
,
2424 true /* in */, false /* no out */ );
2425 JLocalAutoRef
jo_element( jni
, val
.l
);
2426 jni
->SetObjectArrayElement(
2427 (jobjectArray
) jo_ar
.get(), nPos
, jo_element
.get() );
2428 jni
.ensure_no_exception();
2433 case typelib_TypeClass_SEQUENCE
:
2435 OStringBuffer
buf( 64 );
2436 JNI_info::append_sig(
2437 &buf
, element_type
, false /* use class XInterface */,
2438 false /* '.' instead of '/' */ );
2439 OString
class_name( buf
.makeStringAndClear() );
2440 JLocalAutoRef
jo_seq_class(
2441 jni
, find_class( jni
, class_name
.getStr() ) );
2444 jni
->NewObjectArray(
2445 nElements
, (jclass
) jo_seq_class
.get(), 0 ) );
2446 jni
.ensure_no_exception();
2450 TypeDescr
element_td( element_type
);
2451 uno_Sequence
** elements
= (uno_Sequence
**) seq
->elements
;
2452 for ( sal_Int32 nPos
= 0; nPos
< nElements
; ++nPos
)
2456 jni
, &java_data2
, elements
+ nPos
, element_type
, 0,
2457 true /* in */, false /* no out */ );
2458 JLocalAutoRef
jo_seq( jni
, java_data2
.l
);
2459 jni
->SetObjectArrayElement(
2460 (jobjectArray
) jo_ar
.get(), nPos
, jo_seq
.get() );
2461 jni
.ensure_no_exception();
2466 case typelib_TypeClass_INTERFACE
:
2468 JNI_interface_type_info
const * iface_info
=
2469 static_cast< JNI_interface_type_info
const * >(
2470 m_jni_info
->get_type_info( jni
, element_type
) );
2473 jni
->NewObjectArray( nElements
, iface_info
->m_class
, 0 ) );
2474 jni
.ensure_no_exception();
2478 uno_Interface
** pp
= (uno_Interface
**)seq
->elements
;
2479 for ( sal_Int32 nPos
= 0; nPos
< nElements
; ++nPos
)
2481 uno_Interface
* pUnoI
= pp
[ nPos
];
2484 JLocalAutoRef
jo_element(
2485 jni
, map_to_java( jni
, pUnoI
, iface_info
) );
2486 jni
->SetObjectArrayElement(
2487 (jobjectArray
) jo_ar
.get(),
2488 nPos
, jo_element
.get() );
2489 jni
.ensure_no_exception();
2497 OUStringBuffer
buf( 128 );
2498 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_java():") );
2499 buf
.append( OUString::unacquired( &type
->pTypeName
) );
2501 RTL_CONSTASCII_STRINGPARAM("] unsupported element type: ") );
2502 buf
.append( OUString::unacquired( &element_type
->pTypeName
) );
2503 buf
.append( jni
.get_stack_trace() );
2504 throw BridgeRuntimeError( buf
.makeStringAndClear() );
2510 if (0 == java_data
->l
)
2512 JLocalAutoRef
jo_element_class(
2513 jni
, jni
->GetObjectClass( jo_ar
.get() ) );
2516 java_data
->l
= jni
->NewObjectArray(
2517 1, (jclass
) jo_element_class
.get(), jo_ar
.get() );
2521 java_data
->l
= jni
->NewObjectArray(
2522 1, (jclass
) jo_element_class
.get(), 0 );
2524 jni
.ensure_no_exception();
2528 jni
->SetObjectArrayElement(
2529 (jobjectArray
) java_data
->l
, 0, jo_ar
.get() );
2530 jni
.ensure_no_exception();
2535 java_data
->l
= jo_ar
.release();
2539 case typelib_TypeClass_INTERFACE
:
2541 JLocalAutoRef
jo_iface( jni
);
2544 uno_Interface
* pUnoI
= *(uno_Interface
* const *)uno_data
;
2548 info
= m_jni_info
->get_type_info( jni
, type
);
2549 JNI_interface_type_info
const * iface_info
=
2550 static_cast< JNI_interface_type_info
const * >( info
);
2551 jo_iface
.reset( map_to_java( jni
, pUnoI
, iface_info
) );
2556 if (0 == java_data
->l
)
2559 info
= m_jni_info
->get_type_info( jni
, type
);
2561 jni
->NewObjectArray( 1, info
->m_class
, jo_iface
.get() );
2562 jni
.ensure_no_exception();
2566 jni
->SetObjectArrayElement(
2567 (jobjectArray
) java_data
->l
, 0, jo_iface
.get() );
2568 jni
.ensure_no_exception();
2573 java_data
->l
= jo_iface
.release();
2579 OUStringBuffer
buf( 128 );
2580 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_java():") );
2581 buf
.append( OUString::unacquired( &type
->pTypeName
) );
2582 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("] unsupported type!") );
2583 buf
.append( jni
.get_stack_trace() );
2584 throw BridgeRuntimeError( buf
.makeStringAndClear() );
2591 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */