merge the formfield patch from ooo-build
[ooovba.git] / bridges / source / jni_uno / jni_data.cxx
blob033f3d1c15c9e1ac92225dfd932d51d3eddfac83
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: jni_data.cxx,v $
10 * $Revision: 1.23 $
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;
44 namespace jni_uno
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();
53 p->nRefCount = 1;
54 p->nElements = nElements;
55 return seq.release();
58 //______________________________________________________________________________
59 namespace {
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;
69 break;
71 case typelib_TypeClass_BYTE:
72 *static_cast< sal_Int8 * >(uno_data) = 0;
73 break;
75 case typelib_TypeClass_SHORT:
76 *static_cast< sal_Int16 * >(uno_data) = 0;
77 break;
79 case typelib_TypeClass_UNSIGNED_SHORT:
80 *static_cast< sal_uInt16 * >(uno_data) = 0;
81 break;
83 case typelib_TypeClass_LONG:
84 *static_cast< sal_Int32 * >(uno_data) = 0;
85 break;
87 case typelib_TypeClass_UNSIGNED_LONG:
88 *static_cast< sal_uInt32 * >(uno_data) = 0;
89 break;
91 case typelib_TypeClass_HYPER:
92 *static_cast< sal_Int64 * >(uno_data) = 0;
93 break;
95 case typelib_TypeClass_UNSIGNED_HYPER:
96 *static_cast< sal_uInt64 * >(uno_data) = 0;
97 break;
99 case typelib_TypeClass_FLOAT:
100 *static_cast< float * >(uno_data) = 0;
101 break;
103 case typelib_TypeClass_DOUBLE:
104 *static_cast< double * >(uno_data) = 0;
105 break;
107 case typelib_TypeClass_CHAR:
108 *static_cast< sal_Unicode * >(uno_data) = 0;
109 break;
111 case typelib_TypeClass_STRING:
112 if (!assign) {
113 *static_cast< rtl_uString ** >(uno_data) = 0;
115 rtl_uString_new(static_cast< rtl_uString ** >(uno_data));
116 break;
118 case typelib_TypeClass_TYPE:
119 if (assign) {
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);
125 OSL_ASSERT(
126 *static_cast< typelib_TypeDescriptionReference ** >(uno_data) != 0);
127 typelib_typedescriptionreference_acquire(
128 *static_cast< typelib_TypeDescriptionReference ** >(uno_data));
129 break;
131 case typelib_TypeClass_ANY:
132 if (assign) {
133 uno_any_destruct(static_cast< uno_Any * >(uno_data), 0);
135 uno_any_construct(
136 static_cast< uno_Any * >(uno_data), 0,
137 jni.get_info()->m_XInterface_type_info->m_td.get(), 0);
138 break;
140 case typelib_TypeClass_SEQUENCE:
142 auto_ptr< rtl_mem > seq(seq_allocate(0, 0));
143 if (assign) {
144 uno_type_destructData(uno_data, type, 0);
146 *static_cast< uno_Sequence ** >(uno_data)
147 = reinterpret_cast< uno_Sequence * >(seq.release());
148 break;
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)->
157 nDefaultEnumValue);
158 TYPELIB_DANGER_RELEASE(td);
159 break;
162 case typelib_TypeClass_STRUCT:
164 if (info == 0) {
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());
172 sal_Int32 nPos = 0;
173 sal_Int32 nMembers = comp_td->nMembers;
174 try {
175 if (comp_td->pBaseTypeDescription != 0) {
176 createDefaultUnoValue(
177 jni, uno_data,
178 comp_td->pBaseTypeDescription->aBase.pWeakRef,
179 comp_info->m_base, assign);
181 for (; nPos < nMembers; ++nPos) {
182 createDefaultUnoValue(
183 jni,
184 (static_cast< char * >(uno_data)
185 + comp_td->pMemberOffsets[nPos]),
186 comp_td->ppTypeRefs[nPos], 0, assign);
188 } catch (...) {
189 if (!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) {
197 uno_destructData(
198 uno_data, &comp_td->pBaseTypeDescription->aBase, 0);
201 throw;
204 break;
206 case typelib_TypeClass_INTERFACE:
207 if (assign) {
208 uno_Interface * p = *static_cast< uno_Interface ** >(uno_data);
209 if (p != 0) {
210 (*p->release)(p);
213 *static_cast< uno_Interface ** >(uno_data) = 0;
214 break;
216 default:
217 OSL_ASSERT(false);
218 break;
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
232 OSL_ASSERT(
233 !out_param ||
234 (1 == jni->GetArrayLength( (jarray) java_data.l )) );
236 switch (type->eTypeClass)
238 case typelib_TypeClass_CHAR:
239 if (out_param)
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();
251 else
253 *(jchar *) uno_data = java_data.c;
255 break;
256 case typelib_TypeClass_BOOLEAN:
257 if (out_param)
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();
269 else
271 *(jboolean *) uno_data = java_data.z;
273 break;
274 case typelib_TypeClass_BYTE:
275 if (out_param)
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();
287 else
289 *(jbyte *) uno_data = java_data.b;
291 break;
292 case typelib_TypeClass_SHORT:
293 case typelib_TypeClass_UNSIGNED_SHORT:
294 if (out_param)
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();
306 else
308 *(jshort *) uno_data = java_data.s;
310 break;
311 case typelib_TypeClass_LONG:
312 case typelib_TypeClass_UNSIGNED_LONG:
313 if (out_param)
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();
325 else
327 *(jint *) uno_data = java_data.i;
329 break;
330 case typelib_TypeClass_HYPER:
331 case typelib_TypeClass_UNSIGNED_HYPER:
332 if (out_param)
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();
344 else
346 *(jlong *) uno_data = java_data.j;
348 break;
349 case typelib_TypeClass_FLOAT:
350 if (out_param)
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();
362 else
364 *(jfloat *) uno_data = java_data.f;
366 break;
367 case typelib_TypeClass_DOUBLE:
368 if (out_param)
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();
380 else
382 *(jdouble *) uno_data = java_data.d;
384 break;
385 case typelib_TypeClass_STRING:
387 JLocalAutoRef jo_out_holder( jni );
388 if (out_param)
390 jo_out_holder.reset(
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() );
404 if (! assign)
405 *(rtl_uString **)uno_data = 0;
406 jstring_to_ustring(
407 jni, (rtl_uString **)uno_data, (jstring) java_data.l );
408 break;
410 case typelib_TypeClass_TYPE:
412 JLocalAutoRef jo_out_holder( jni );
413 if (out_param)
415 jo_out_holder.reset(
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() );
430 // type name
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 ) );
439 buf.appendAscii(
440 RTL_CONSTASCII_STRINGPARAM("] incomplete type object: "
441 "no type name!") );
442 buf.append( jni.get_stack_trace() );
443 throw BridgeRuntimeError( buf.makeStringAndClear() );
445 OUString type_name(
446 jstring_to_oustring( jni, (jstring) jo_type_name.get() ) );
447 ::com::sun::star::uno::TypeDescription td( type_name );
448 if (! td.is())
450 OUStringBuffer buf( 128 );
451 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
452 buf.append( OUString::unacquired( &type->pTypeName ) );
453 buf.appendAscii(
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 );
460 if (assign)
462 typelib_typedescriptionreference_release(
463 *(typelib_TypeDescriptionReference **)uno_data );
465 *(typelib_TypeDescriptionReference **)uno_data = td.get()->pWeakRef;
466 break;
468 case typelib_TypeClass_ANY:
470 JLocalAutoRef jo_out_holder( jni );
471 if (out_param)
473 jo_out_holder.reset(
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
482 if (assign)
483 uno_any_destruct( pAny, 0 );
484 uno_any_construct(
485 pAny, 0, m_jni_info->m_XInterface_type_info->m_td.get(), 0 );
486 break;
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 ))
495 // boxed any
496 jo_type.reset( jni->GetObjectField(
497 java_data.l, m_jni_info->m_field_Any__type ) );
498 if (! jo_type.is())
500 OUStringBuffer buf( 128 );
501 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
502 buf.append( OUString::unacquired( &type->pTypeName ) );
503 buf.appendAscii(
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() );
509 // wrapped value
510 jo_wrapped_holder.reset(
511 jni->GetObjectField(
512 java_data.l, m_jni_info->m_field_Any__object ) );
513 java_data.l = jo_wrapped_holder.get();
515 else
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();
526 OUString toString(
527 jstring_to_oustring( jni, (jstring) jo_toString.get() ) );
529 #endif
532 // get type name
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();
537 OUString type_name(
538 jstring_to_oustring( jni, (jstring) jo_type_name.get() ) );
540 ::com::sun::star::uno::TypeDescription value_td( type_name );
541 if (! value_td.is())
543 OUStringBuffer buf( 128 );
544 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
545 buf.append( OUString::unacquired( &type->pTypeName ) );
546 buf.appendAscii(
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;
554 if (assign)
556 uno_any_destruct( pAny, 0 );
560 switch (type_class)
562 case typelib_TypeClass_VOID:
563 pAny->pData = &pAny->pReserved;
564 break;
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;
570 break;
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;
576 break;
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;
582 break;
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;
589 break;
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;
596 break;
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;
606 else
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();
615 break;
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;
624 else
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();
633 break;
634 case typelib_TypeClass_DOUBLE:
635 if (sizeof (double) <= sizeof (void *))
637 *(jdouble *) &pAny->pReserved =
638 jni->CallDoubleMethodA(
639 java_data.l,
640 m_jni_info->m_method_Double_doubleValue, 0 );
641 jni.ensure_no_exception();
642 pAny->pData = &pAny->pReserved;
644 else
646 auto_ptr< rtl_mem > mem(
647 rtl_mem::allocate( sizeof (double) ) );
648 *(jdouble *) mem.get() =
649 jni->CallDoubleMethodA(
650 java_data.l,
651 m_jni_info->m_method_Double_doubleValue, 0 );
652 jni.ensure_no_exception();
653 pAny->pData = mem.release();
655 break;
656 case typelib_TypeClass_STRING:
657 // opt: anies often contain strings; copy string directly
658 pAny->pReserved = 0;
659 jstring_to_ustring(
660 jni, (rtl_uString **)&pAny->pReserved,
661 (jstring) java_data.l );
662 pAny->pData = &pAny->pReserved;
663 break;
664 case typelib_TypeClass_TYPE:
665 case typelib_TypeClass_ENUM:
666 case typelib_TypeClass_SEQUENCE:
667 case typelib_TypeClass_INTERFACE:
668 map_to_uno(
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;
673 break;
674 case typelib_TypeClass_STRUCT:
675 case typelib_TypeClass_EXCEPTION:
677 auto_ptr< rtl_mem > mem(
678 rtl_mem::allocate( value_td.get()->nSize ) );
679 map_to_uno(
680 jni, mem.get(), java_data, value_td.get()->pWeakRef, 0,
681 false /* no assign */, false /* no out param */ );
682 pAny->pData = mem.release();
683 break;
685 default:
687 OUStringBuffer buf( 128 );
688 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
689 buf.append( type_name );
690 buf.appendAscii(
691 RTL_CONSTASCII_STRINGPARAM("] unsupported value type "
692 "of any!") );
693 buf.append( jni.get_stack_trace() );
694 throw BridgeRuntimeError( buf.makeStringAndClear() );
698 catch (...)
700 if (assign)
702 // restore to valid any
703 uno_any_construct( pAny, 0, 0, 0 );
705 throw;
707 typelib_typedescriptionreference_acquire( value_td.get()->pWeakRef );
708 pAny->pType = value_td.get()->pWeakRef;
709 break;
711 case typelib_TypeClass_ENUM:
713 JLocalAutoRef jo_out_holder( jni );
714 if (out_param)
716 jo_out_holder.reset(
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 );
733 break;
735 case typelib_TypeClass_STRUCT:
736 case typelib_TypeClass_EXCEPTION:
738 JLocalAutoRef jo_out_holder( jni );
739 if (out_param)
741 jo_out_holder.reset(
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() );
756 if (0 == info)
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();
763 bool polymorphic
764 = comp_td->aBase.eTypeClass == typelib_TypeClass_STRUCT
765 && reinterpret_cast< typelib_StructTypeDescription * >(
766 comp_td)->pParameterizedTypes != 0;
768 sal_Int32 nPos = 0;
769 sal_Int32 nMembers = comp_td->nMembers;
772 if (0 != comp_td->pBaseTypeDescription)
774 map_to_uno(
775 jni, uno_data, java_data,
776 ((typelib_TypeDescription *) comp_td->pBaseTypeDescription)
777 ->pWeakRef,
778 comp_info->m_base,
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) {
795 JLocalAutoRef jo(
796 jni, jni->GetObjectField( java_data.l, field_id ) );
797 if ( jo.get() == 0 ) {
798 *(jchar *) p = 0;
799 } else {
800 jvalue val;
801 val.l = jo.get();
802 map_to_uno(
803 jni, p, val, member_type, 0, assign, false,
804 true );
806 } else {
807 *(jchar *) p = jni->GetCharField(
808 java_data.l, field_id );
810 break;
811 case typelib_TypeClass_BOOLEAN:
812 if (parameterizedType) {
813 JLocalAutoRef jo(
814 jni, jni->GetObjectField( java_data.l, field_id ) );
815 if ( jo.get() == 0 ) {
816 *(jboolean *) p = false;
817 } else {
818 jvalue val;
819 val.l = jo.get();
820 map_to_uno(
821 jni, p, val, member_type, 0, assign, false,
822 true );
824 } else {
825 *(jboolean *) p = jni->GetBooleanField(
826 java_data.l, field_id );
828 break;
829 case typelib_TypeClass_BYTE:
830 if (parameterizedType) {
831 JLocalAutoRef jo(
832 jni, jni->GetObjectField( java_data.l, field_id ) );
833 if ( jo.get() == 0 ) {
834 *(jbyte *) p = 0;
835 } else {
836 jvalue val;
837 val.l = jo.get();
838 map_to_uno(
839 jni, p, val, member_type, 0, assign, false,
840 true );
842 } else {
843 *(jbyte *) p = jni->GetByteField(
844 java_data.l, field_id );
846 break;
847 case typelib_TypeClass_SHORT:
848 case typelib_TypeClass_UNSIGNED_SHORT:
849 if (parameterizedType) {
850 JLocalAutoRef jo(
851 jni, jni->GetObjectField( java_data.l, field_id ) );
852 if ( jo.get() == 0 ) {
853 *(jshort *) p = 0;
854 } else {
855 jvalue val;
856 val.l = jo.get();
857 map_to_uno(
858 jni, p, val, member_type, 0, assign, false,
859 true );
861 } else {
862 *(jshort *) p = jni->GetShortField(
863 java_data.l, field_id );
865 break;
866 case typelib_TypeClass_LONG:
867 case typelib_TypeClass_UNSIGNED_LONG:
868 if (parameterizedType) {
869 JLocalAutoRef jo(
870 jni, jni->GetObjectField( java_data.l, field_id ) );
871 if ( jo.get() == 0 ) {
872 *(jint *) p = 0;
873 } else {
874 jvalue val;
875 val.l = jo.get();
876 map_to_uno(
877 jni, p, val, member_type, 0, assign, false,
878 true );
880 } else {
881 *(jint *) p = jni->GetIntField( java_data.l, field_id );
883 break;
884 case typelib_TypeClass_HYPER:
885 case typelib_TypeClass_UNSIGNED_HYPER:
886 if (parameterizedType) {
887 JLocalAutoRef jo(
888 jni, jni->GetObjectField( java_data.l, field_id ) );
889 if ( jo.get() == 0 ) {
890 *(jlong *) p = 0;
891 } else {
892 jvalue val;
893 val.l = jo.get();
894 map_to_uno(
895 jni, p, val, member_type, 0, assign, false,
896 true );
898 } else {
899 *(jlong *) p = jni->GetLongField(
900 java_data.l, field_id );
902 break;
903 case typelib_TypeClass_FLOAT:
904 if (parameterizedType) {
905 JLocalAutoRef jo(
906 jni, jni->GetObjectField( java_data.l, field_id ) );
907 if ( jo.get() == 0 ) {
908 *(jfloat *) p = 0;
909 } else {
910 jvalue val;
911 val.l = jo.get();
912 map_to_uno(
913 jni, p, val, member_type, 0, assign, false,
914 true );
916 } else {
917 *(jfloat *) p = jni->GetFloatField(
918 java_data.l, field_id );
920 break;
921 case typelib_TypeClass_DOUBLE:
922 if (parameterizedType) {
923 JLocalAutoRef jo(
924 jni, jni->GetObjectField( java_data.l, field_id ) );
925 if ( jo.get() == 0 ) {
926 *(jdouble *) p = 0;
927 } else {
928 jvalue val;
929 val.l = jo.get();
930 map_to_uno(
931 jni, p, val, member_type, 0, assign, false,
932 true );
934 } else {
935 *(jdouble *) p = jni->GetDoubleField(
936 java_data.l, field_id );
938 break;
939 default:
941 JLocalAutoRef jo_field( jni );
942 bool checkNull;
943 if (0 == field_id)
945 // special for Message: call Throwable.getMessage()
946 OSL_ASSERT(
947 type_equals(
948 type,
949 m_jni_info->m_Exception_type.getTypeLibType() )
950 || type_equals(
951 type,
952 m_jni_info->m_RuntimeException_type.
953 getTypeLibType() ) );
954 OSL_ASSERT( 0 == nPos ); // first member
955 // call getMessage()
956 jo_field.reset(
957 jni->CallObjectMethodA(
958 java_data.l,
959 m_jni_info->m_method_Throwable_getMessage, 0 )
961 jni.ensure_no_exception();
962 checkNull = true;
964 else
966 jo_field.reset(
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);
972 } else {
973 jvalue val;
974 val.l = jo_field.get();
975 map_to_uno(
976 jni, p, val, member_type, 0,
977 assign, false /* no out param */ );
979 break;
984 catch (...)
986 if (! assign)
988 // cleanup
989 for ( sal_Int32 nCleanup = 0; nCleanup < nPos; ++nCleanup )
991 void * p =
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)
998 uno_destructData(
999 uno_data,
1000 (typelib_TypeDescription *) comp_td
1001 ->pBaseTypeDescription, 0 );
1004 throw;
1006 break;
1008 case typelib_TypeClass_SEQUENCE:
1010 JLocalAutoRef jo_out_holder( jni );
1011 if (out_param)
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();
1043 break;
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();
1050 break;
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();
1057 break;
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();
1065 break;
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();
1073 break;
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();
1081 break;
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();
1088 break;
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();
1095 break;
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)
1113 element_info =
1114 m_jni_info->get_type_info( jni, element_td.get() );
1116 else
1118 element_info = 0;
1121 for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos )
1125 JLocalAutoRef jo(
1126 jni, jni->GetObjectArrayElement(
1127 (jobjectArray) java_data.l, nPos ) );
1128 jni.ensure_no_exception();
1129 jvalue val;
1130 val.l = jo.get();
1131 void * p =
1132 ((uno_Sequence *)seq.get())->elements +
1133 (nPos * element_td.get()->nSize);
1134 map_to_uno(
1135 jni, p, val, element_td.get()->pWeakRef, element_info,
1136 false /* no assign */, false /* no out param */ );
1138 catch (...)
1140 // cleanup
1141 for ( sal_Int32 nCleanPos = 0;
1142 nCleanPos < nPos; ++nCleanPos )
1144 void * p =
1145 ((uno_Sequence *)seq.get())->elements +
1146 (nCleanPos * element_td.get()->nSize);
1147 uno_destructData( p, element_td.get(), 0 );
1149 throw;
1152 break;
1154 default:
1156 OUStringBuffer buf( 128 );
1157 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
1158 buf.append( OUString::unacquired( &type->pTypeName ) );
1159 buf.appendAscii(
1160 RTL_CONSTASCII_STRINGPARAM("] unsupported sequence element"
1161 " type: ") );
1162 buf.append( OUString::unacquired( &element_type->pTypeName ) );
1163 buf.append( jni.get_stack_trace() );
1164 throw BridgeRuntimeError( buf.makeStringAndClear() );
1168 if (assign)
1169 uno_destructData( uno_data, td.get(), 0 );
1170 *(uno_Sequence **)uno_data = (uno_Sequence *)seq.release();
1171 break;
1173 case typelib_TypeClass_INTERFACE:
1175 JLocalAutoRef jo_out_holder( jni );
1176 if (out_param)
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
1186 if (assign)
1188 uno_Interface * p = *(uno_Interface **)uno_data;
1189 if (0 != p)
1190 (*p->release)( p );
1192 *(uno_Interface **)uno_data = 0;
1194 else
1196 if (0 == info)
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 );
1201 if (assign)
1203 uno_Interface * p = *(uno_Interface **)uno_data;
1204 if (0 != p)
1205 (*p->release)( p );
1207 *(uno_Interface **)uno_data = pUnoI;
1209 break;
1211 default:
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:
1237 if (out_param)
1239 if (0 == java_data->l)
1241 JLocalAutoRef jo_ar( jni, jni->NewCharArray( 1 ) );
1242 jni.ensure_no_exception();
1243 if (in_param)
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();
1251 else
1253 if (in_param)
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)
1263 jvalue arg;
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();
1270 else
1272 java_data->c = *(jchar const *) uno_data;
1274 break;
1275 case typelib_TypeClass_BOOLEAN:
1276 if (out_param)
1278 if (0 == java_data->l)
1280 JLocalAutoRef jo_ar( jni, jni->NewBooleanArray( 1 ) );
1281 jni.ensure_no_exception();
1282 if (in_param)
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();
1291 else
1293 if (in_param)
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)
1304 jvalue arg;
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();
1311 else
1313 java_data->z = *(jboolean const *) uno_data;
1315 break;
1316 case typelib_TypeClass_BYTE:
1317 if (out_param)
1319 if (0 == java_data->l)
1321 JLocalAutoRef jo_ar( jni, jni->NewByteArray( 1 ) );
1322 jni.ensure_no_exception();
1323 if (in_param)
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();
1331 else
1333 if (in_param)
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)
1343 jvalue arg;
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();
1350 else
1352 java_data->b = *(jbyte const *) uno_data;
1354 break;
1355 case typelib_TypeClass_SHORT:
1356 case typelib_TypeClass_UNSIGNED_SHORT:
1357 if (out_param)
1359 if (0 == java_data->l)
1361 JLocalAutoRef jo_ar( jni, jni->NewShortArray( 1 ) );
1362 jni.ensure_no_exception();
1363 if (in_param)
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();
1371 else
1373 if (in_param)
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)
1383 jvalue arg;
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();
1390 else
1392 java_data->s = *(jshort const *) uno_data;
1394 break;
1395 case typelib_TypeClass_LONG:
1396 case typelib_TypeClass_UNSIGNED_LONG:
1397 if (out_param)
1399 if (0 == java_data->l)
1401 JLocalAutoRef jo_ar( jni, jni->NewIntArray( 1 ) );
1402 jni.ensure_no_exception();
1403 if (in_param)
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();
1411 else
1413 if (in_param)
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)
1423 jvalue arg;
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();
1430 else
1432 java_data->i = *(jint const *) uno_data;
1434 break;
1435 case typelib_TypeClass_HYPER:
1436 case typelib_TypeClass_UNSIGNED_HYPER:
1437 if (out_param)
1439 if (0 == java_data->l)
1441 JLocalAutoRef jo_ar( jni, jni->NewLongArray( 1 ) );
1442 jni.ensure_no_exception();
1443 if (in_param)
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();
1451 else
1453 if (in_param)
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)
1463 jvalue arg;
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();
1470 else
1472 java_data->j = *(jlong const *) uno_data;
1474 break;
1475 case typelib_TypeClass_FLOAT:
1476 if (out_param)
1478 if (0 == java_data->l)
1480 JLocalAutoRef jo_ar( jni, jni->NewFloatArray( 1 ) );
1481 jni.ensure_no_exception();
1482 if (in_param)
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();
1490 else
1492 if (in_param)
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)
1502 jvalue arg;
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();
1509 else
1511 java_data->f = *(jfloat const *) uno_data;
1513 break;
1514 case typelib_TypeClass_DOUBLE:
1515 if (out_param)
1517 if (0 == java_data->l)
1519 JLocalAutoRef jo_ar( jni, jni->NewDoubleArray( 1 ) );
1520 jni.ensure_no_exception();
1521 if (in_param)
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();
1530 else
1532 if (in_param)
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)
1543 jvalue arg;
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();
1550 else
1552 java_data->d = *(jdouble const *) uno_data;
1554 break;
1555 case typelib_TypeClass_STRING:
1557 if (out_param)
1559 JLocalAutoRef jo_in( jni );
1560 if (in_param)
1562 jo_in.reset(
1563 ustring_to_jstring(
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();
1572 else
1574 jni->SetObjectArrayElement(
1575 (jobjectArray) java_data->l, 0, jo_in.get() );
1576 jni.ensure_no_exception();
1579 else
1581 OSL_ASSERT( in_param );
1582 java_data->l =
1583 ustring_to_jstring( jni, *(rtl_uString * const *) uno_data );
1585 break;
1587 case typelib_TypeClass_TYPE:
1589 if (out_param)
1591 JLocalAutoRef jo_in( jni );
1592 if (in_param)
1594 jo_in.reset(
1595 create_type(
1596 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();
1606 else
1608 jni->SetObjectArrayElement(
1609 (jobjectArray) java_data->l, 0, jo_in.get() );
1610 jni.ensure_no_exception();
1613 else
1615 OSL_ASSERT( in_param );
1616 java_data->l =
1617 create_type(
1618 jni,
1619 *(typelib_TypeDescriptionReference * const *) uno_data );
1621 break;
1623 case typelib_TypeClass_ANY:
1625 JLocalAutoRef jo_any( jni );
1626 if (in_param)
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)
1633 jo_any.reset(
1634 jni->NewLocalRef( m_jni_info->m_object_Any_VOID ) );
1636 else
1638 jvalue args[ 2 ];
1639 map_to_java(
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();
1647 jo_any.reset(
1648 jni->NewObjectA(
1649 m_jni_info->m_class_Any,
1650 m_jni_info->m_ctor_Any_with_Type_Object, args ) );
1651 jni.ensure_no_exception();
1653 #else
1654 switch (pAny->pType->eTypeClass)
1656 case typelib_TypeClass_VOID:
1657 jo_any.reset(
1658 jni->NewLocalRef( m_jni_info->m_object_Any_VOID ) );
1659 break;
1660 case typelib_TypeClass_UNSIGNED_SHORT:
1662 jvalue args[ 2 ];
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();
1672 jo_any.reset(
1673 jni->NewObjectA(
1674 m_jni_info->m_class_Any,
1675 m_jni_info->m_ctor_Any_with_Type_Object, args ) );
1676 jni.ensure_no_exception();
1677 break;
1679 case typelib_TypeClass_UNSIGNED_LONG:
1681 jvalue args[ 2 ];
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();
1691 jo_any.reset(
1692 jni->NewObjectA(
1693 m_jni_info->m_class_Any,
1694 m_jni_info->m_ctor_Any_with_Type_Object, args ) );
1695 jni.ensure_no_exception();
1696 break;
1698 case typelib_TypeClass_UNSIGNED_HYPER:
1700 jvalue args[ 2 ];
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();
1710 jo_any.reset(
1711 jni->NewObjectA(
1712 m_jni_info->m_class_Any,
1713 m_jni_info->m_ctor_Any_with_Type_Object, args ) );
1714 jni.ensure_no_exception();
1715 break;
1717 case typelib_TypeClass_STRING: // opt strings
1718 jo_any.reset( ustring_to_jstring(
1719 jni, (rtl_uString *) pAny->pReserved ) );
1720 break;
1721 case typelib_TypeClass_SEQUENCE:
1723 jvalue java_data2;
1724 // prefetch sequence td
1725 TypeDescr seq_td( pAny->pType );
1726 map_to_java(
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 ** >(
1741 &element_type ),
1742 ((typelib_IndirectTypeDescription *)element_td.get())
1743 ->pType );
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:
1752 jvalue args[ 2 ];
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();
1757 jo_any.reset(
1758 jni->NewObjectA(
1759 m_jni_info->m_class_Any,
1760 m_jni_info->m_ctor_Any_with_Type_Object, args ) );
1761 jni.ensure_no_exception();
1762 break;
1764 default:
1765 break;
1767 break;
1769 case typelib_TypeClass_INTERFACE:
1771 uno_Interface * pUnoI = (uno_Interface *)pAny->pReserved;
1772 if (is_XInterface( pAny->pType ))
1774 if (0 != pUnoI)
1776 jo_any.reset(
1777 map_to_java(
1778 jni, pUnoI,
1779 m_jni_info->m_XInterface_type_info ) );
1781 // else: empty XInterface ref maps to null-ref
1783 else
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 ) );
1788 if (0 != pUnoI)
1790 jo_any.reset( map_to_java( jni, pUnoI, iface_info ) );
1792 // box up in com.sun.star.uno.Any
1793 jvalue args[ 2 ];
1794 args[ 0 ].l = iface_info->m_type;
1795 args[ 1 ].l = jo_any.get();
1796 jo_any.reset(
1797 jni->NewObjectA(
1798 m_jni_info->m_class_Any,
1799 m_jni_info->m_ctor_Any_with_Type_Object, args ) );
1800 jni.ensure_no_exception();
1802 break;
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));
1815 jvalue java_data2;
1816 map_to_java(
1817 jni, &java_data2, pAny->pData, pAny->pType, 0, true,
1818 false);
1819 jo_any.reset(java_data2.l);
1820 jvalue args[2];
1821 args[0].l = jo_type.get();
1822 args[1].l = jo_any.get();
1823 jo_any.reset(
1824 jni->NewObjectA(
1825 m_jni_info->m_class_Any,
1826 m_jni_info->m_ctor_Any_with_Type_Object, args));
1827 jni.ensure_no_exception();
1828 break;
1830 // fall through
1832 default:
1834 jvalue java_data2;
1835 map_to_java(
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 );
1840 break;
1843 #endif
1846 if (out_param)
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();
1854 else
1856 jni->SetObjectArrayElement(
1857 (jobjectArray) java_data->l, 0, jo_any.get() );
1858 jni.ensure_no_exception();
1861 else
1863 java_data->l = jo_any.release();
1865 break;
1867 case typelib_TypeClass_ENUM:
1869 OUString const & type_name = OUString::unacquired( &type->pTypeName );
1870 OString class_name(
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 );
1876 if (in_param)
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 );
1889 jvalue arg;
1890 arg.i = *(jint const *) uno_data;
1891 jo_enum.reset(
1892 jni->CallStaticObjectMethodA(
1893 (jclass) jo_enum_class.get(), method_id, &arg ) );
1894 jni.ensure_no_exception();
1896 if (out_param)
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();
1904 else
1906 jni->SetObjectArrayElement(
1907 (jobjectArray) java_data->l, 0, jo_enum.get() );
1908 jni.ensure_no_exception();
1911 else
1913 java_data->l = jo_enum.release();
1915 break;
1917 case typelib_TypeClass_STRUCT:
1918 case typelib_TypeClass_EXCEPTION:
1920 if (0 == info)
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 );
1926 if (in_param)
1928 if (typelib_TypeClass_EXCEPTION == type->eTypeClass)
1930 JLocalAutoRef jo_message(
1931 jni, ustring_to_jstring( jni, *(rtl_uString **)uno_data ) );
1932 jvalue arg;
1933 arg.l = jo_message.get();
1934 jo_comp.reset(
1935 jni->NewObjectA(
1936 comp_info->m_class, comp_info->m_exc_ctor, &arg ) );
1937 jni.ensure_no_exception();
1939 else
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;
1946 0 != linfo;
1947 linfo = static_cast< JNI_compound_type_info const * >(
1948 linfo->m_base ) )
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;
1955 bool polymorphic
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 ];
1962 if (0 != field_id)
1964 void const * p =
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) {
1976 jvalue arg;
1977 arg.c = *(jchar const *) p;
1978 JLocalAutoRef jo(
1979 jni,
1980 jni->NewObjectA(
1981 m_jni_info->m_class_Character,
1982 m_jni_info->m_ctor_Character_with_char,
1983 &arg ) );
1984 jni.ensure_no_exception();
1985 jni->SetObjectField(
1986 jo_comp.get(), field_id, jo.get() );
1987 } else {
1988 jni->SetCharField(
1989 jo_comp.get(),
1990 field_id, *(jchar const *) p );
1992 break;
1993 case typelib_TypeClass_BOOLEAN:
1994 if (parameterizedType) {
1995 jvalue arg;
1996 arg.z = *(jboolean const *) p;
1997 JLocalAutoRef jo(
1998 jni,
1999 jni->NewObjectA(
2000 m_jni_info->m_class_Boolean,
2001 m_jni_info->m_ctor_Boolean_with_boolean,
2002 &arg ) );
2003 jni.ensure_no_exception();
2004 jni->SetObjectField(
2005 jo_comp.get(), field_id, jo.get() );
2006 } else {
2007 jni->SetBooleanField(
2008 jo_comp.get(),
2009 field_id, *(jboolean const *) p );
2011 break;
2012 case typelib_TypeClass_BYTE:
2013 if (parameterizedType) {
2014 jvalue arg;
2015 arg.b = *(jbyte const *) p;
2016 JLocalAutoRef jo(
2017 jni,
2018 jni->NewObjectA(
2019 m_jni_info->m_class_Byte,
2020 m_jni_info->m_ctor_Byte_with_byte,
2021 &arg ) );
2022 jni.ensure_no_exception();
2023 jni->SetObjectField(
2024 jo_comp.get(), field_id, jo.get() );
2025 } else {
2026 jni->SetByteField(
2027 jo_comp.get(),
2028 field_id, *(jbyte const *) p );
2030 break;
2031 case typelib_TypeClass_SHORT:
2032 case typelib_TypeClass_UNSIGNED_SHORT:
2033 if (parameterizedType) {
2034 jvalue arg;
2035 arg.s = *(jshort const *) p;
2036 JLocalAutoRef jo(
2037 jni,
2038 jni->NewObjectA(
2039 m_jni_info->m_class_Short,
2040 m_jni_info->m_ctor_Short_with_short,
2041 &arg ) );
2042 jni.ensure_no_exception();
2043 jni->SetObjectField(
2044 jo_comp.get(), field_id, jo.get() );
2045 } else {
2046 jni->SetShortField(
2047 jo_comp.get(),
2048 field_id, *(jshort const *) p );
2050 break;
2051 case typelib_TypeClass_LONG:
2052 case typelib_TypeClass_UNSIGNED_LONG:
2053 if (parameterizedType) {
2054 jvalue arg;
2055 arg.i = *(jint const *) p;
2056 JLocalAutoRef jo(
2057 jni,
2058 jni->NewObjectA(
2059 m_jni_info->m_class_Integer,
2060 m_jni_info->m_ctor_Integer_with_int,
2061 &arg ) );
2062 jni.ensure_no_exception();
2063 jni->SetObjectField(
2064 jo_comp.get(), field_id, jo.get() );
2065 } else {
2066 jni->SetIntField(
2067 jo_comp.get(),
2068 field_id, *(jint const *) p );
2070 break;
2071 case typelib_TypeClass_HYPER:
2072 case typelib_TypeClass_UNSIGNED_HYPER:
2073 if (parameterizedType) {
2074 jvalue arg;
2075 arg.j = *(jlong const *) p;
2076 JLocalAutoRef jo(
2077 jni,
2078 jni->NewObjectA(
2079 m_jni_info->m_class_Long,
2080 m_jni_info->m_ctor_Long_with_long,
2081 &arg ) );
2082 jni.ensure_no_exception();
2083 jni->SetObjectField(
2084 jo_comp.get(), field_id, jo.get() );
2085 } else {
2086 jni->SetLongField(
2087 jo_comp.get(),
2088 field_id, *(jlong const *) p );
2090 break;
2091 case typelib_TypeClass_FLOAT:
2092 if (parameterizedType) {
2093 jvalue arg;
2094 arg.f = *(jfloat const *) p;
2095 JLocalAutoRef jo(
2096 jni,
2097 jni->NewObjectA(
2098 m_jni_info->m_class_Float,
2099 m_jni_info->m_ctor_Float_with_float,
2100 &arg ) );
2101 jni.ensure_no_exception();
2102 jni->SetObjectField(
2103 jo_comp.get(), field_id, jo.get() );
2104 } else {
2105 jni->SetFloatField(
2106 jo_comp.get(),
2107 field_id, *(jfloat const *) p );
2109 break;
2110 case typelib_TypeClass_DOUBLE:
2111 if (parameterizedType) {
2112 jvalue arg;
2113 arg.d = *(jdouble const *) p;
2114 JLocalAutoRef jo(
2115 jni,
2116 jni->NewObjectA(
2117 m_jni_info->m_class_Double,
2118 m_jni_info->m_ctor_Double_with_double,
2119 &arg ) );
2120 jni.ensure_no_exception();
2121 jni->SetObjectField(
2122 jo_comp.get(), field_id, jo.get() );
2123 } else {
2124 jni->SetDoubleField(
2125 jo_comp.get(),
2126 field_id, *(jdouble const *) p );
2128 break;
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() );
2136 break;
2138 default:
2140 jvalue java_data2;
2141 map_to_java(
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() );
2147 break;
2154 if (out_param)
2156 if (0 == java_data->l)
2158 java_data->l =
2159 jni->NewObjectArray( 1, comp_info->m_class, jo_comp.get() );
2160 jni.ensure_no_exception();
2162 else
2164 jni->SetObjectArrayElement(
2165 (jobjectArray) java_data->l, 0, jo_comp.get() );
2166 jni.ensure_no_exception();
2169 else
2171 java_data->l = jo_comp.release();
2173 break;
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;
2182 if (in_param)
2184 seq = *(uno_Sequence * const *)uno_data;
2185 nElements = seq->nElements;
2187 else
2189 nElements = 0;
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();
2201 if (0 < nElements)
2203 jni->SetCharArrayRegion(
2204 (jcharArray) jo_ar.get(),
2205 0, nElements, (jchar *) seq->elements );
2206 jni.ensure_no_exception();
2208 break;
2209 case typelib_TypeClass_BOOLEAN:
2210 jo_ar.reset( jni->NewBooleanArray( nElements ) );
2211 jni.ensure_no_exception();
2212 if (0 < nElements)
2214 jni->SetBooleanArrayRegion(
2215 (jbooleanArray) jo_ar.get(),
2216 0, nElements, (jboolean *) seq->elements );
2217 jni.ensure_no_exception();
2219 break;
2220 case typelib_TypeClass_BYTE:
2221 jo_ar.reset( jni->NewByteArray( nElements ) );
2222 jni.ensure_no_exception();
2223 if (0 < nElements)
2225 jni->SetByteArrayRegion(
2226 (jbyteArray) jo_ar.get(),
2227 0, nElements, (jbyte *) seq->elements );
2228 jni.ensure_no_exception();
2230 break;
2231 case typelib_TypeClass_SHORT:
2232 case typelib_TypeClass_UNSIGNED_SHORT:
2233 jo_ar.reset( jni->NewShortArray( nElements ) );
2234 jni.ensure_no_exception();
2235 if (0 < nElements)
2237 jni->SetShortArrayRegion(
2238 (jshortArray) jo_ar.get(),
2239 0, nElements, (jshort *) seq->elements );
2240 jni.ensure_no_exception();
2242 break;
2243 case typelib_TypeClass_LONG:
2244 case typelib_TypeClass_UNSIGNED_LONG:
2245 jo_ar.reset( jni->NewIntArray( nElements ) );
2246 jni.ensure_no_exception();
2247 if (0 < nElements)
2249 jni->SetIntArrayRegion(
2250 (jintArray) jo_ar.get(),
2251 0, nElements, (jint *) seq->elements );
2252 jni.ensure_no_exception();
2254 break;
2255 case typelib_TypeClass_HYPER:
2256 case typelib_TypeClass_UNSIGNED_HYPER:
2257 jo_ar.reset( jni->NewLongArray( nElements ) );
2258 jni.ensure_no_exception();
2259 if (0 < nElements)
2261 jni->SetLongArrayRegion(
2262 (jlongArray) jo_ar.get(),
2263 0, nElements, (jlong *) seq->elements );
2264 jni.ensure_no_exception();
2266 break;
2267 case typelib_TypeClass_FLOAT:
2268 jo_ar.reset( jni->NewFloatArray( nElements ) );
2269 jni.ensure_no_exception();
2270 if (0 < nElements)
2272 jni->SetFloatArrayRegion(
2273 (jfloatArray) jo_ar.get(),
2274 0, nElements, (jfloat *) seq->elements );
2275 jni.ensure_no_exception();
2277 break;
2278 case typelib_TypeClass_DOUBLE:
2279 jo_ar.reset( jni->NewDoubleArray( nElements ) );
2280 jni.ensure_no_exception();
2281 if (0 < nElements)
2283 jni->SetDoubleArrayRegion(
2284 (jdoubleArray) jo_ar.get(),
2285 0, nElements, (jdouble *) seq->elements );
2286 jni.ensure_no_exception();
2288 break;
2289 case typelib_TypeClass_STRING:
2290 jo_ar.reset(
2291 jni->NewObjectArray(
2292 nElements, m_jni_info->m_class_String, 0 ) );
2293 jni.ensure_no_exception();
2294 if (in_param)
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();
2307 break;
2308 case typelib_TypeClass_TYPE:
2309 jo_ar.reset(
2310 jni->NewObjectArray( nElements, m_jni_info->m_class_Type, 0 ) );
2311 jni.ensure_no_exception();
2312 if (in_param)
2314 typelib_TypeDescriptionReference * const * pp =
2315 (typelib_TypeDescriptionReference * const *)seq->elements;
2316 for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos )
2318 jvalue val;
2319 map_to_java(
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();
2328 break;
2329 case typelib_TypeClass_ANY:
2330 jo_ar.reset(
2331 jni->NewObjectArray(
2332 nElements, m_jni_info->m_class_Object, 0 ) );
2333 jni.ensure_no_exception();
2334 if (in_param)
2336 uno_Any const * p = (uno_Any const *)seq->elements;
2337 for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos )
2339 jvalue val;
2340 map_to_java(
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();
2349 break;
2350 case typelib_TypeClass_ENUM:
2352 OUString const & element_type_name =
2353 OUString::unacquired( &element_type->pTypeName );
2354 OString class_name(
2355 OUStringToOString(
2356 element_type_name, RTL_TEXTENCODING_JAVA_UTF8 ) );
2357 JLocalAutoRef jo_enum_class(
2358 jni, find_class( jni, class_name.getStr() ) );
2360 jo_ar.reset(
2361 jni->NewObjectArray(
2362 nElements, (jclass) jo_enum_class.get(), 0 ) );
2363 jni.ensure_no_exception();
2365 if (0 < nElements)
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 )
2381 jvalue arg;
2382 arg.i = p[ 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();
2392 break;
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 );
2400 jo_ar.reset(
2401 jni->NewObjectArray( nElements, element_info->m_class, 0 ) );
2402 jni.ensure_no_exception();
2404 if (0 < nElements)
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 )
2410 jvalue val;
2411 map_to_java(
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();
2421 break;
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() ) );
2433 jo_ar.reset(
2434 jni->NewObjectArray(
2435 nElements, (jclass) jo_seq_class.get(), 0 ) );
2436 jni.ensure_no_exception();
2438 if (0 < nElements)
2440 TypeDescr element_td( element_type );
2441 uno_Sequence ** elements = (uno_Sequence **) seq->elements;
2442 for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos )
2444 jvalue java_data2;
2445 map_to_java(
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();
2454 break;
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 ) );
2462 jo_ar.reset(
2463 jni->NewObjectArray( nElements, iface_info->m_class, 0 ) );
2464 jni.ensure_no_exception();
2466 if (0 < nElements)
2468 uno_Interface ** pp = (uno_Interface **)seq->elements;
2469 for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos )
2471 uno_Interface * pUnoI = pp[ nPos ];
2472 if (0 != pUnoI)
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();
2483 break;
2485 default:
2487 OUStringBuffer buf( 128 );
2488 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_java():") );
2489 buf.append( OUString::unacquired( &type->pTypeName ) );
2490 buf.appendAscii(
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() );
2498 if (out_param)
2500 if (0 == java_data->l)
2502 JLocalAutoRef jo_element_class(
2503 jni, jni->GetObjectClass( jo_ar.get() ) );
2504 if (in_param)
2506 java_data->l = jni->NewObjectArray(
2507 1, (jclass) jo_element_class.get(), jo_ar.get() );
2509 else
2511 java_data->l = jni->NewObjectArray(
2512 1, (jclass) jo_element_class.get(), 0 );
2514 jni.ensure_no_exception();
2516 else
2518 jni->SetObjectArrayElement(
2519 (jobjectArray) java_data->l, 0, jo_ar.get() );
2520 jni.ensure_no_exception();
2523 else
2525 java_data->l = jo_ar.release();
2527 break;
2529 case typelib_TypeClass_INTERFACE:
2531 JLocalAutoRef jo_iface( jni );
2532 if (in_param)
2534 uno_Interface * pUnoI = *(uno_Interface * const *)uno_data;
2535 if (0 != pUnoI)
2537 if (0 == info)
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 ) );
2544 if (out_param)
2546 if (0 == java_data->l)
2548 if (0 == info)
2549 info = m_jni_info->get_type_info( jni, type );
2550 java_data->l =
2551 jni->NewObjectArray( 1, info->m_class, jo_iface.get() );
2552 jni.ensure_no_exception();
2554 else
2556 jni->SetObjectArrayElement(
2557 (jobjectArray) java_data->l, 0, jo_iface.get() );
2558 jni.ensure_no_exception();
2561 else
2563 java_data->l = jo_iface.release();
2565 break;
2567 default:
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() );