Bump for 3.6-28
[LibreOffice.git] / bridges / source / jni_uno / jni_data.cxx
blob9d77812ada04f74e98fd282364265c634cb89496
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;
40 namespace jni_uno
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();
51 p->nRefCount = 1;
52 p->nElements = nElements;
53 return seq.release();
56 //______________________________________________________________________________
57 namespace {
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;
67 break;
69 case typelib_TypeClass_BYTE:
70 *static_cast< sal_Int8 * >(uno_data) = 0;
71 break;
73 case typelib_TypeClass_SHORT:
74 *static_cast< sal_Int16 * >(uno_data) = 0;
75 break;
77 case typelib_TypeClass_UNSIGNED_SHORT:
78 *static_cast< sal_uInt16 * >(uno_data) = 0;
79 break;
81 case typelib_TypeClass_LONG:
82 *static_cast< sal_Int32 * >(uno_data) = 0;
83 break;
85 case typelib_TypeClass_UNSIGNED_LONG:
86 *static_cast< sal_uInt32 * >(uno_data) = 0;
87 break;
89 case typelib_TypeClass_HYPER:
90 *static_cast< sal_Int64 * >(uno_data) = 0;
91 break;
93 case typelib_TypeClass_UNSIGNED_HYPER:
94 *static_cast< sal_uInt64 * >(uno_data) = 0;
95 break;
97 case typelib_TypeClass_FLOAT:
98 *static_cast< float * >(uno_data) = 0;
99 break;
101 case typelib_TypeClass_DOUBLE:
102 *static_cast< double * >(uno_data) = 0;
103 break;
105 case typelib_TypeClass_CHAR:
106 *static_cast< sal_Unicode * >(uno_data) = 0;
107 break;
109 case typelib_TypeClass_STRING:
110 if (!assign) {
111 *static_cast< rtl_uString ** >(uno_data) = 0;
113 rtl_uString_new(static_cast< rtl_uString ** >(uno_data));
114 break;
116 case typelib_TypeClass_TYPE:
117 if (assign) {
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);
123 OSL_ASSERT(
124 *static_cast< typelib_TypeDescriptionReference ** >(uno_data) != 0);
125 typelib_typedescriptionreference_acquire(
126 *static_cast< typelib_TypeDescriptionReference ** >(uno_data));
127 break;
129 case typelib_TypeClass_ANY:
130 if (assign) {
131 uno_any_destruct(static_cast< uno_Any * >(uno_data), 0);
133 uno_any_construct(
134 static_cast< uno_Any * >(uno_data), 0,
135 jni.get_info()->m_XInterface_type_info->m_td.get(), 0);
136 break;
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
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 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();
570 break;
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();
576 break;
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();
582 break;
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();
589 break;
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();
596 break;
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();
606 else
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();
617 break;
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();
626 else
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();
637 break;
638 case typelib_TypeClass_DOUBLE:
639 if (sizeof (double) <= sizeof (void *))
641 pAny->pData = &pAny->pReserved;
642 *(jdouble *) pAny->pData =
643 jni->CallDoubleMethodA(
644 java_data.l,
645 m_jni_info->m_method_Double_doubleValue, 0 );
646 jni.ensure_no_exception();
648 else
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(
656 java_data.l,
657 m_jni_info->m_method_Double_doubleValue, 0 );
658 jni.ensure_no_exception();
659 pAny->pData = mem.release();
661 break;
662 case typelib_TypeClass_STRING:
663 // opt: anies often contain strings; copy string directly
664 pAny->pReserved = 0;
665 pAny->pData = &pAny->pReserved;
666 jstring_to_ustring(
667 jni, (rtl_uString **)pAny->pData,
668 (jstring) java_data.l );
669 break;
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;
675 map_to_uno(
676 jni, pAny->pData, java_data,
677 value_td.get()->pWeakRef, 0,
678 false /* no assign */, false /* no out param */ );
679 break;
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
687 map_to_uno(
688 jni, mem.get(), java_data, value_td.get()->pWeakRef, 0,
689 false /* no assign */, false /* no out param */ );
690 pAny->pData = mem.release();
691 break;
693 default:
695 OUStringBuffer buf( 128 );
696 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
697 buf.append( type_name );
698 buf.appendAscii(
699 RTL_CONSTASCII_STRINGPARAM("] unsupported value type "
700 "of any!") );
701 buf.append( jni.get_stack_trace() );
702 throw BridgeRuntimeError( buf.makeStringAndClear() );
706 catch (...)
708 if (assign)
710 // restore to valid any
711 uno_any_construct( pAny, 0, 0, 0 );
713 throw;
715 typelib_typedescriptionreference_acquire( value_td.get()->pWeakRef );
716 pAny->pType = value_td.get()->pWeakRef;
717 break;
719 case typelib_TypeClass_ENUM:
721 JLocalAutoRef jo_out_holder( jni );
722 if (out_param)
724 jo_out_holder.reset(
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 );
741 break;
743 case typelib_TypeClass_STRUCT:
744 case typelib_TypeClass_EXCEPTION:
746 JLocalAutoRef jo_out_holder( jni );
747 if (out_param)
749 jo_out_holder.reset(
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() );
764 if (0 == info)
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();
771 bool polymorphic
772 = comp_td->aBase.eTypeClass == typelib_TypeClass_STRUCT
773 && reinterpret_cast< typelib_StructTypeDescription * >(
774 comp_td)->pParameterizedTypes != 0;
776 sal_Int32 nPos = 0;
777 sal_Int32 nMembers = comp_td->nMembers;
780 if (0 != comp_td->pBaseTypeDescription)
782 map_to_uno(
783 jni, uno_data, java_data,
784 ((typelib_TypeDescription *) comp_td->pBaseTypeDescription)
785 ->pWeakRef,
786 comp_info->m_base,
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) {
803 JLocalAutoRef jo(
804 jni, jni->GetObjectField( java_data.l, field_id ) );
805 if ( jo.get() == 0 ) {
806 *(jchar *) p = 0;
807 } else {
808 jvalue val;
809 val.l = jo.get();
810 map_to_uno(
811 jni, p, val, member_type, 0, assign, false,
812 true );
814 } else {
815 *(jchar *) p = jni->GetCharField(
816 java_data.l, field_id );
818 break;
819 case typelib_TypeClass_BOOLEAN:
820 if (parameterizedType) {
821 JLocalAutoRef jo(
822 jni, jni->GetObjectField( java_data.l, field_id ) );
823 if ( jo.get() == 0 ) {
824 *(jboolean *) p = false;
825 } else {
826 jvalue val;
827 val.l = jo.get();
828 map_to_uno(
829 jni, p, val, member_type, 0, assign, false,
830 true );
832 } else {
833 *(jboolean *) p = jni->GetBooleanField(
834 java_data.l, field_id );
836 break;
837 case typelib_TypeClass_BYTE:
838 if (parameterizedType) {
839 JLocalAutoRef jo(
840 jni, jni->GetObjectField( java_data.l, field_id ) );
841 if ( jo.get() == 0 ) {
842 *(jbyte *) p = 0;
843 } else {
844 jvalue val;
845 val.l = jo.get();
846 map_to_uno(
847 jni, p, val, member_type, 0, assign, false,
848 true );
850 } else {
851 *(jbyte *) p = jni->GetByteField(
852 java_data.l, field_id );
854 break;
855 case typelib_TypeClass_SHORT:
856 case typelib_TypeClass_UNSIGNED_SHORT:
857 if (parameterizedType) {
858 JLocalAutoRef jo(
859 jni, jni->GetObjectField( java_data.l, field_id ) );
860 if ( jo.get() == 0 ) {
861 *(jshort *) p = 0;
862 } else {
863 jvalue val;
864 val.l = jo.get();
865 map_to_uno(
866 jni, p, val, member_type, 0, assign, false,
867 true );
869 } else {
870 *(jshort *) p = jni->GetShortField(
871 java_data.l, field_id );
873 break;
874 case typelib_TypeClass_LONG:
875 case typelib_TypeClass_UNSIGNED_LONG:
876 if (parameterizedType) {
877 JLocalAutoRef jo(
878 jni, jni->GetObjectField( java_data.l, field_id ) );
879 if ( jo.get() == 0 ) {
880 *(jint *) p = 0;
881 } else {
882 jvalue val;
883 val.l = jo.get();
884 map_to_uno(
885 jni, p, val, member_type, 0, assign, false,
886 true );
888 } else {
889 *(jint *) p = jni->GetIntField( java_data.l, field_id );
891 break;
892 case typelib_TypeClass_HYPER:
893 case typelib_TypeClass_UNSIGNED_HYPER:
894 if (parameterizedType) {
895 JLocalAutoRef jo(
896 jni, jni->GetObjectField( java_data.l, field_id ) );
897 if ( jo.get() == 0 ) {
898 *(jlong *) p = 0;
899 } else {
900 jvalue val;
901 val.l = jo.get();
902 map_to_uno(
903 jni, p, val, member_type, 0, assign, false,
904 true );
906 } else {
907 *(jlong *) p = jni->GetLongField(
908 java_data.l, field_id );
910 break;
911 case typelib_TypeClass_FLOAT:
912 if (parameterizedType) {
913 JLocalAutoRef jo(
914 jni, jni->GetObjectField( java_data.l, field_id ) );
915 if ( jo.get() == 0 ) {
916 *(jfloat *) p = 0;
917 } else {
918 jvalue val;
919 val.l = jo.get();
920 map_to_uno(
921 jni, p, val, member_type, 0, assign, false,
922 true );
924 } else {
925 *(jfloat *) p = jni->GetFloatField(
926 java_data.l, field_id );
928 break;
929 case typelib_TypeClass_DOUBLE:
930 if (parameterizedType) {
931 JLocalAutoRef jo(
932 jni, jni->GetObjectField( java_data.l, field_id ) );
933 if ( jo.get() == 0 ) {
934 *(jdouble *) p = 0;
935 } else {
936 jvalue val;
937 val.l = jo.get();
938 map_to_uno(
939 jni, p, val, member_type, 0, assign, false,
940 true );
942 } else {
943 *(jdouble *) p = jni->GetDoubleField(
944 java_data.l, field_id );
946 break;
947 default:
949 JLocalAutoRef jo_field( jni );
950 bool checkNull;
951 if (0 == field_id)
953 // special for Message: call Throwable.getMessage()
954 OSL_ASSERT(
955 type_equals(
956 type,
957 m_jni_info->m_Exception_type.getTypeLibType() )
958 || type_equals(
959 type,
960 m_jni_info->m_RuntimeException_type.
961 getTypeLibType() ) );
962 OSL_ASSERT( 0 == nPos ); // first member
963 // call getMessage()
964 jo_field.reset(
965 jni->CallObjectMethodA(
966 java_data.l,
967 m_jni_info->m_method_Throwable_getMessage, 0 )
969 jni.ensure_no_exception();
970 checkNull = true;
972 else
974 jo_field.reset(
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);
980 } else {
981 jvalue val;
982 val.l = jo_field.get();
983 map_to_uno(
984 jni, p, val, member_type, 0,
985 assign, false /* no out param */ );
987 break;
992 catch (...)
994 if (! assign)
996 // cleanup
997 for ( sal_Int32 nCleanup = 0; nCleanup < nPos; ++nCleanup )
999 void * p =
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)
1006 uno_destructData(
1007 uno_data,
1008 (typelib_TypeDescription *) comp_td
1009 ->pBaseTypeDescription, 0 );
1012 throw;
1014 break;
1016 case typelib_TypeClass_SEQUENCE:
1018 JLocalAutoRef jo_out_holder( jni );
1019 if (out_param)
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();
1053 break;
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();
1060 break;
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();
1067 break;
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();
1075 break;
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();
1083 break;
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();
1091 break;
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();
1098 break;
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();
1105 break;
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)
1123 element_info =
1124 m_jni_info->get_type_info( jni, element_td.get() );
1126 else
1128 element_info = 0;
1131 for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos )
1135 JLocalAutoRef jo(
1136 jni, jni->GetObjectArrayElement(
1137 (jobjectArray) java_data.l, nPos ) );
1138 jni.ensure_no_exception();
1139 jvalue val;
1140 val.l = jo.get();
1141 void * p =
1142 ((uno_Sequence *)seq.get())->elements +
1143 (nPos * element_td.get()->nSize);
1144 map_to_uno(
1145 jni, p, val, element_td.get()->pWeakRef, element_info,
1146 false /* no assign */, false /* no out param */ );
1148 catch (...)
1150 // cleanup
1151 for ( sal_Int32 nCleanPos = 0;
1152 nCleanPos < nPos; ++nCleanPos )
1154 void * p =
1155 ((uno_Sequence *)seq.get())->elements +
1156 (nCleanPos * element_td.get()->nSize);
1157 uno_destructData( p, element_td.get(), 0 );
1159 throw;
1162 break;
1164 default:
1166 OUStringBuffer buf( 128 );
1167 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
1168 buf.append( OUString::unacquired( &type->pTypeName ) );
1169 buf.appendAscii(
1170 RTL_CONSTASCII_STRINGPARAM("] unsupported sequence element"
1171 " type: ") );
1172 buf.append( OUString::unacquired( &element_type->pTypeName ) );
1173 buf.append( jni.get_stack_trace() );
1174 throw BridgeRuntimeError( buf.makeStringAndClear() );
1178 if (assign)
1179 uno_destructData( uno_data, td.get(), 0 );
1180 *(uno_Sequence **)uno_data = (uno_Sequence *)seq.release();
1181 break;
1183 case typelib_TypeClass_INTERFACE:
1185 JLocalAutoRef jo_out_holder( jni );
1186 if (out_param)
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
1196 if (assign)
1198 uno_Interface * p = *(uno_Interface **)uno_data;
1199 if (0 != p)
1200 (*p->release)( p );
1202 *(uno_Interface **)uno_data = 0;
1204 else
1206 if (0 == info)
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 );
1211 if (assign)
1213 uno_Interface * p = *(uno_Interface **)uno_data;
1214 if (0 != p)
1215 (*p->release)( p );
1217 *(uno_Interface **)uno_data = pUnoI;
1219 break;
1221 default:
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:
1247 if (out_param)
1249 if (0 == java_data->l)
1251 JLocalAutoRef jo_ar( jni, jni->NewCharArray( 1 ) );
1252 jni.ensure_no_exception();
1253 if (in_param)
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();
1261 else
1263 if (in_param)
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)
1273 jvalue arg;
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();
1280 else
1282 java_data->c = *(jchar const *) uno_data;
1284 break;
1285 case typelib_TypeClass_BOOLEAN:
1286 if (out_param)
1288 if (0 == java_data->l)
1290 JLocalAutoRef jo_ar( jni, jni->NewBooleanArray( 1 ) );
1291 jni.ensure_no_exception();
1292 if (in_param)
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();
1301 else
1303 if (in_param)
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)
1314 jvalue arg;
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();
1321 else
1323 java_data->z = *(jboolean const *) uno_data;
1325 break;
1326 case typelib_TypeClass_BYTE:
1327 if (out_param)
1329 if (0 == java_data->l)
1331 JLocalAutoRef jo_ar( jni, jni->NewByteArray( 1 ) );
1332 jni.ensure_no_exception();
1333 if (in_param)
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();
1341 else
1343 if (in_param)
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)
1353 jvalue arg;
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();
1360 else
1362 java_data->b = *(jbyte const *) uno_data;
1364 break;
1365 case typelib_TypeClass_SHORT:
1366 case typelib_TypeClass_UNSIGNED_SHORT:
1367 if (out_param)
1369 if (0 == java_data->l)
1371 JLocalAutoRef jo_ar( jni, jni->NewShortArray( 1 ) );
1372 jni.ensure_no_exception();
1373 if (in_param)
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();
1381 else
1383 if (in_param)
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)
1393 jvalue arg;
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();
1400 else
1402 java_data->s = *(jshort const *) uno_data;
1404 break;
1405 case typelib_TypeClass_LONG:
1406 case typelib_TypeClass_UNSIGNED_LONG:
1407 if (out_param)
1409 if (0 == java_data->l)
1411 JLocalAutoRef jo_ar( jni, jni->NewIntArray( 1 ) );
1412 jni.ensure_no_exception();
1413 if (in_param)
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();
1421 else
1423 if (in_param)
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)
1433 jvalue arg;
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();
1440 else
1442 java_data->i = *(jint const *) uno_data;
1444 break;
1445 case typelib_TypeClass_HYPER:
1446 case typelib_TypeClass_UNSIGNED_HYPER:
1447 if (out_param)
1449 if (0 == java_data->l)
1451 JLocalAutoRef jo_ar( jni, jni->NewLongArray( 1 ) );
1452 jni.ensure_no_exception();
1453 if (in_param)
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();
1461 else
1463 if (in_param)
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)
1473 jvalue arg;
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();
1480 else
1482 java_data->j = *(jlong const *) uno_data;
1484 break;
1485 case typelib_TypeClass_FLOAT:
1486 if (out_param)
1488 if (0 == java_data->l)
1490 JLocalAutoRef jo_ar( jni, jni->NewFloatArray( 1 ) );
1491 jni.ensure_no_exception();
1492 if (in_param)
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();
1500 else
1502 if (in_param)
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)
1512 jvalue arg;
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();
1519 else
1521 java_data->f = *(jfloat const *) uno_data;
1523 break;
1524 case typelib_TypeClass_DOUBLE:
1525 if (out_param)
1527 if (0 == java_data->l)
1529 JLocalAutoRef jo_ar( jni, jni->NewDoubleArray( 1 ) );
1530 jni.ensure_no_exception();
1531 if (in_param)
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();
1540 else
1542 if (in_param)
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)
1553 jvalue arg;
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();
1560 else
1562 java_data->d = *(jdouble const *) uno_data;
1564 break;
1565 case typelib_TypeClass_STRING:
1567 if (out_param)
1569 JLocalAutoRef jo_in( jni );
1570 if (in_param)
1572 jo_in.reset(
1573 ustring_to_jstring(
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();
1582 else
1584 jni->SetObjectArrayElement(
1585 (jobjectArray) java_data->l, 0, jo_in.get() );
1586 jni.ensure_no_exception();
1589 else
1591 OSL_ASSERT( in_param );
1592 java_data->l =
1593 ustring_to_jstring( jni, *(rtl_uString * const *) uno_data );
1595 break;
1597 case typelib_TypeClass_TYPE:
1599 if (out_param)
1601 JLocalAutoRef jo_in( jni );
1602 if (in_param)
1604 jo_in.reset(
1605 create_type(
1606 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();
1616 else
1618 jni->SetObjectArrayElement(
1619 (jobjectArray) java_data->l, 0, jo_in.get() );
1620 jni.ensure_no_exception();
1623 else
1625 OSL_ASSERT( in_param );
1626 java_data->l =
1627 create_type(
1628 jni,
1629 *(typelib_TypeDescriptionReference * const *) uno_data );
1631 break;
1633 case typelib_TypeClass_ANY:
1635 JLocalAutoRef jo_any( jni );
1636 if (in_param)
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)
1643 jo_any.reset(
1644 jni->NewLocalRef( m_jni_info->m_object_Any_VOID ) );
1646 else
1648 jvalue args[ 2 ];
1649 map_to_java(
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();
1657 jo_any.reset(
1658 jni->NewObjectA(
1659 m_jni_info->m_class_Any,
1660 m_jni_info->m_ctor_Any_with_Type_Object, args ) );
1661 jni.ensure_no_exception();
1663 #else
1664 switch (pAny->pType->eTypeClass)
1666 case typelib_TypeClass_VOID:
1667 jo_any.reset(
1668 jni->NewLocalRef( m_jni_info->m_object_Any_VOID ) );
1669 break;
1670 case typelib_TypeClass_UNSIGNED_SHORT:
1672 jvalue args[ 2 ];
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();
1682 jo_any.reset(
1683 jni->NewObjectA(
1684 m_jni_info->m_class_Any,
1685 m_jni_info->m_ctor_Any_with_Type_Object, args ) );
1686 jni.ensure_no_exception();
1687 break;
1689 case typelib_TypeClass_UNSIGNED_LONG:
1691 jvalue args[ 2 ];
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();
1701 jo_any.reset(
1702 jni->NewObjectA(
1703 m_jni_info->m_class_Any,
1704 m_jni_info->m_ctor_Any_with_Type_Object, args ) );
1705 jni.ensure_no_exception();
1706 break;
1708 case typelib_TypeClass_UNSIGNED_HYPER:
1710 jvalue args[ 2 ];
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();
1720 jo_any.reset(
1721 jni->NewObjectA(
1722 m_jni_info->m_class_Any,
1723 m_jni_info->m_ctor_Any_with_Type_Object, args ) );
1724 jni.ensure_no_exception();
1725 break;
1727 case typelib_TypeClass_STRING: // opt strings
1728 jo_any.reset( ustring_to_jstring(
1729 jni, (rtl_uString *) pAny->pReserved ) );
1730 break;
1731 case typelib_TypeClass_SEQUENCE:
1733 jvalue java_data2;
1734 // prefetch sequence td
1735 TypeDescr seq_td( pAny->pType );
1736 map_to_java(
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 ** >(
1751 &element_type ),
1752 ((typelib_IndirectTypeDescription *)element_td.get())
1753 ->pType );
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:
1762 jvalue args[ 2 ];
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();
1767 jo_any.reset(
1768 jni->NewObjectA(
1769 m_jni_info->m_class_Any,
1770 m_jni_info->m_ctor_Any_with_Type_Object, args ) );
1771 jni.ensure_no_exception();
1772 break;
1774 default:
1775 break;
1777 break;
1779 case typelib_TypeClass_INTERFACE:
1781 uno_Interface * pUnoI = (uno_Interface *)pAny->pReserved;
1782 if (is_XInterface( pAny->pType ))
1784 if (0 != pUnoI)
1786 jo_any.reset(
1787 map_to_java(
1788 jni, pUnoI,
1789 m_jni_info->m_XInterface_type_info ) );
1791 // else: empty XInterface ref maps to null-ref
1793 else
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 ) );
1798 if (0 != pUnoI)
1800 jo_any.reset( map_to_java( jni, pUnoI, iface_info ) );
1802 // box up in com.sun.star.uno.Any
1803 jvalue args[ 2 ];
1804 args[ 0 ].l = iface_info->m_type;
1805 args[ 1 ].l = jo_any.get();
1806 jo_any.reset(
1807 jni->NewObjectA(
1808 m_jni_info->m_class_Any,
1809 m_jni_info->m_ctor_Any_with_Type_Object, args ) );
1810 jni.ensure_no_exception();
1812 break;
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));
1825 jvalue java_data2;
1826 map_to_java(
1827 jni, &java_data2, pAny->pData, pAny->pType, 0, true,
1828 false);
1829 jo_any.reset(java_data2.l);
1830 jvalue args[2];
1831 args[0].l = jo_type.get();
1832 args[1].l = jo_any.get();
1833 jo_any.reset(
1834 jni->NewObjectA(
1835 m_jni_info->m_class_Any,
1836 m_jni_info->m_ctor_Any_with_Type_Object, args));
1837 jni.ensure_no_exception();
1838 break;
1840 // fall through
1842 default:
1844 jvalue java_data2;
1845 map_to_java(
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 );
1850 break;
1853 #endif
1856 if (out_param)
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();
1864 else
1866 jni->SetObjectArrayElement(
1867 (jobjectArray) java_data->l, 0, jo_any.get() );
1868 jni.ensure_no_exception();
1871 else
1873 java_data->l = jo_any.release();
1875 break;
1877 case typelib_TypeClass_ENUM:
1879 OUString const & type_name = OUString::unacquired( &type->pTypeName );
1880 OString class_name(
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 );
1886 if (in_param)
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 );
1899 jvalue arg;
1900 arg.i = *(jint const *) uno_data;
1901 jo_enum.reset(
1902 jni->CallStaticObjectMethodA(
1903 (jclass) jo_enum_class.get(), method_id, &arg ) );
1904 jni.ensure_no_exception();
1906 if (out_param)
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();
1914 else
1916 jni->SetObjectArrayElement(
1917 (jobjectArray) java_data->l, 0, jo_enum.get() );
1918 jni.ensure_no_exception();
1921 else
1923 java_data->l = jo_enum.release();
1925 break;
1927 case typelib_TypeClass_STRUCT:
1928 case typelib_TypeClass_EXCEPTION:
1930 if (0 == info)
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 );
1936 if (in_param)
1938 if (typelib_TypeClass_EXCEPTION == type->eTypeClass)
1940 JLocalAutoRef jo_message(
1941 jni, ustring_to_jstring( jni, *(rtl_uString **)uno_data ) );
1942 jvalue arg;
1943 arg.l = jo_message.get();
1944 jo_comp.reset(
1945 jni->NewObjectA(
1946 comp_info->m_class, comp_info->m_exc_ctor, &arg ) );
1947 jni.ensure_no_exception();
1949 else
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;
1956 0 != linfo;
1957 linfo = static_cast< JNI_compound_type_info const * >(
1958 linfo->m_base ) )
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;
1965 bool polymorphic
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 ];
1972 if (0 != field_id)
1974 void const * p =
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) {
1986 jvalue arg;
1987 arg.c = *(jchar const *) p;
1988 JLocalAutoRef jo(
1989 jni,
1990 jni->NewObjectA(
1991 m_jni_info->m_class_Character,
1992 m_jni_info->m_ctor_Character_with_char,
1993 &arg ) );
1994 jni.ensure_no_exception();
1995 jni->SetObjectField(
1996 jo_comp.get(), field_id, jo.get() );
1997 } else {
1998 jni->SetCharField(
1999 jo_comp.get(),
2000 field_id, *(jchar const *) p );
2002 break;
2003 case typelib_TypeClass_BOOLEAN:
2004 if (parameterizedType) {
2005 jvalue arg;
2006 arg.z = *(jboolean const *) p;
2007 JLocalAutoRef jo(
2008 jni,
2009 jni->NewObjectA(
2010 m_jni_info->m_class_Boolean,
2011 m_jni_info->m_ctor_Boolean_with_boolean,
2012 &arg ) );
2013 jni.ensure_no_exception();
2014 jni->SetObjectField(
2015 jo_comp.get(), field_id, jo.get() );
2016 } else {
2017 jni->SetBooleanField(
2018 jo_comp.get(),
2019 field_id, *(jboolean const *) p );
2021 break;
2022 case typelib_TypeClass_BYTE:
2023 if (parameterizedType) {
2024 jvalue arg;
2025 arg.b = *(jbyte const *) p;
2026 JLocalAutoRef jo(
2027 jni,
2028 jni->NewObjectA(
2029 m_jni_info->m_class_Byte,
2030 m_jni_info->m_ctor_Byte_with_byte,
2031 &arg ) );
2032 jni.ensure_no_exception();
2033 jni->SetObjectField(
2034 jo_comp.get(), field_id, jo.get() );
2035 } else {
2036 jni->SetByteField(
2037 jo_comp.get(),
2038 field_id, *(jbyte const *) p );
2040 break;
2041 case typelib_TypeClass_SHORT:
2042 case typelib_TypeClass_UNSIGNED_SHORT:
2043 if (parameterizedType) {
2044 jvalue arg;
2045 arg.s = *(jshort const *) p;
2046 JLocalAutoRef jo(
2047 jni,
2048 jni->NewObjectA(
2049 m_jni_info->m_class_Short,
2050 m_jni_info->m_ctor_Short_with_short,
2051 &arg ) );
2052 jni.ensure_no_exception();
2053 jni->SetObjectField(
2054 jo_comp.get(), field_id, jo.get() );
2055 } else {
2056 jni->SetShortField(
2057 jo_comp.get(),
2058 field_id, *(jshort const *) p );
2060 break;
2061 case typelib_TypeClass_LONG:
2062 case typelib_TypeClass_UNSIGNED_LONG:
2063 if (parameterizedType) {
2064 jvalue arg;
2065 arg.i = *(jint const *) p;
2066 JLocalAutoRef jo(
2067 jni,
2068 jni->NewObjectA(
2069 m_jni_info->m_class_Integer,
2070 m_jni_info->m_ctor_Integer_with_int,
2071 &arg ) );
2072 jni.ensure_no_exception();
2073 jni->SetObjectField(
2074 jo_comp.get(), field_id, jo.get() );
2075 } else {
2076 jni->SetIntField(
2077 jo_comp.get(),
2078 field_id, *(jint const *) p );
2080 break;
2081 case typelib_TypeClass_HYPER:
2082 case typelib_TypeClass_UNSIGNED_HYPER:
2083 if (parameterizedType) {
2084 jvalue arg;
2085 arg.j = *(jlong const *) p;
2086 JLocalAutoRef jo(
2087 jni,
2088 jni->NewObjectA(
2089 m_jni_info->m_class_Long,
2090 m_jni_info->m_ctor_Long_with_long,
2091 &arg ) );
2092 jni.ensure_no_exception();
2093 jni->SetObjectField(
2094 jo_comp.get(), field_id, jo.get() );
2095 } else {
2096 jni->SetLongField(
2097 jo_comp.get(),
2098 field_id, *(jlong const *) p );
2100 break;
2101 case typelib_TypeClass_FLOAT:
2102 if (parameterizedType) {
2103 jvalue arg;
2104 arg.f = *(jfloat const *) p;
2105 JLocalAutoRef jo(
2106 jni,
2107 jni->NewObjectA(
2108 m_jni_info->m_class_Float,
2109 m_jni_info->m_ctor_Float_with_float,
2110 &arg ) );
2111 jni.ensure_no_exception();
2112 jni->SetObjectField(
2113 jo_comp.get(), field_id, jo.get() );
2114 } else {
2115 jni->SetFloatField(
2116 jo_comp.get(),
2117 field_id, *(jfloat const *) p );
2119 break;
2120 case typelib_TypeClass_DOUBLE:
2121 if (parameterizedType) {
2122 jvalue arg;
2123 arg.d = *(jdouble const *) p;
2124 JLocalAutoRef jo(
2125 jni,
2126 jni->NewObjectA(
2127 m_jni_info->m_class_Double,
2128 m_jni_info->m_ctor_Double_with_double,
2129 &arg ) );
2130 jni.ensure_no_exception();
2131 jni->SetObjectField(
2132 jo_comp.get(), field_id, jo.get() );
2133 } else {
2134 jni->SetDoubleField(
2135 jo_comp.get(),
2136 field_id, *(jdouble const *) p );
2138 break;
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() );
2146 break;
2148 default:
2150 jvalue java_data2;
2151 map_to_java(
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() );
2157 break;
2164 if (out_param)
2166 if (0 == java_data->l)
2168 java_data->l =
2169 jni->NewObjectArray( 1, comp_info->m_class, jo_comp.get() );
2170 jni.ensure_no_exception();
2172 else
2174 jni->SetObjectArrayElement(
2175 (jobjectArray) java_data->l, 0, jo_comp.get() );
2176 jni.ensure_no_exception();
2179 else
2181 java_data->l = jo_comp.release();
2183 break;
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;
2192 if (in_param)
2194 seq = *(uno_Sequence * const *)uno_data;
2195 nElements = seq->nElements;
2197 else
2199 nElements = 0;
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();
2211 if (0 < nElements)
2213 jni->SetCharArrayRegion(
2214 (jcharArray) jo_ar.get(),
2215 0, nElements, (jchar *) seq->elements );
2216 jni.ensure_no_exception();
2218 break;
2219 case typelib_TypeClass_BOOLEAN:
2220 jo_ar.reset( jni->NewBooleanArray( nElements ) );
2221 jni.ensure_no_exception();
2222 if (0 < nElements)
2224 jni->SetBooleanArrayRegion(
2225 (jbooleanArray) jo_ar.get(),
2226 0, nElements, (jboolean *) seq->elements );
2227 jni.ensure_no_exception();
2229 break;
2230 case typelib_TypeClass_BYTE:
2231 jo_ar.reset( jni->NewByteArray( nElements ) );
2232 jni.ensure_no_exception();
2233 if (0 < nElements)
2235 jni->SetByteArrayRegion(
2236 (jbyteArray) jo_ar.get(),
2237 0, nElements, (jbyte *) seq->elements );
2238 jni.ensure_no_exception();
2240 break;
2241 case typelib_TypeClass_SHORT:
2242 case typelib_TypeClass_UNSIGNED_SHORT:
2243 jo_ar.reset( jni->NewShortArray( nElements ) );
2244 jni.ensure_no_exception();
2245 if (0 < nElements)
2247 jni->SetShortArrayRegion(
2248 (jshortArray) jo_ar.get(),
2249 0, nElements, (jshort *) seq->elements );
2250 jni.ensure_no_exception();
2252 break;
2253 case typelib_TypeClass_LONG:
2254 case typelib_TypeClass_UNSIGNED_LONG:
2255 jo_ar.reset( jni->NewIntArray( nElements ) );
2256 jni.ensure_no_exception();
2257 if (0 < nElements)
2259 jni->SetIntArrayRegion(
2260 (jintArray) jo_ar.get(),
2261 0, nElements, (jint *) seq->elements );
2262 jni.ensure_no_exception();
2264 break;
2265 case typelib_TypeClass_HYPER:
2266 case typelib_TypeClass_UNSIGNED_HYPER:
2267 jo_ar.reset( jni->NewLongArray( nElements ) );
2268 jni.ensure_no_exception();
2269 if (0 < nElements)
2271 jni->SetLongArrayRegion(
2272 (jlongArray) jo_ar.get(),
2273 0, nElements, (jlong *) seq->elements );
2274 jni.ensure_no_exception();
2276 break;
2277 case typelib_TypeClass_FLOAT:
2278 jo_ar.reset( jni->NewFloatArray( nElements ) );
2279 jni.ensure_no_exception();
2280 if (0 < nElements)
2282 jni->SetFloatArrayRegion(
2283 (jfloatArray) jo_ar.get(),
2284 0, nElements, (jfloat *) seq->elements );
2285 jni.ensure_no_exception();
2287 break;
2288 case typelib_TypeClass_DOUBLE:
2289 jo_ar.reset( jni->NewDoubleArray( nElements ) );
2290 jni.ensure_no_exception();
2291 if (0 < nElements)
2293 jni->SetDoubleArrayRegion(
2294 (jdoubleArray) jo_ar.get(),
2295 0, nElements, (jdouble *) seq->elements );
2296 jni.ensure_no_exception();
2298 break;
2299 case typelib_TypeClass_STRING:
2300 jo_ar.reset(
2301 jni->NewObjectArray(
2302 nElements, m_jni_info->m_class_String, 0 ) );
2303 jni.ensure_no_exception();
2304 if (in_param)
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();
2317 break;
2318 case typelib_TypeClass_TYPE:
2319 jo_ar.reset(
2320 jni->NewObjectArray( nElements, m_jni_info->m_class_Type, 0 ) );
2321 jni.ensure_no_exception();
2322 if (in_param)
2324 typelib_TypeDescriptionReference * const * pp =
2325 (typelib_TypeDescriptionReference * const *)seq->elements;
2326 for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos )
2328 jvalue val;
2329 map_to_java(
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();
2338 break;
2339 case typelib_TypeClass_ANY:
2340 jo_ar.reset(
2341 jni->NewObjectArray(
2342 nElements, m_jni_info->m_class_Object, 0 ) );
2343 jni.ensure_no_exception();
2344 if (in_param)
2346 uno_Any const * p = (uno_Any const *)seq->elements;
2347 for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos )
2349 jvalue val;
2350 map_to_java(
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();
2359 break;
2360 case typelib_TypeClass_ENUM:
2362 OUString const & element_type_name =
2363 OUString::unacquired( &element_type->pTypeName );
2364 OString class_name(
2365 OUStringToOString(
2366 element_type_name, RTL_TEXTENCODING_JAVA_UTF8 ) );
2367 JLocalAutoRef jo_enum_class(
2368 jni, find_class( jni, class_name.getStr() ) );
2370 jo_ar.reset(
2371 jni->NewObjectArray(
2372 nElements, (jclass) jo_enum_class.get(), 0 ) );
2373 jni.ensure_no_exception();
2375 if (0 < nElements)
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 )
2391 jvalue arg;
2392 arg.i = p[ 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();
2402 break;
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 );
2410 jo_ar.reset(
2411 jni->NewObjectArray( nElements, element_info->m_class, 0 ) );
2412 jni.ensure_no_exception();
2414 if (0 < nElements)
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 )
2420 jvalue val;
2421 map_to_java(
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();
2431 break;
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() ) );
2443 jo_ar.reset(
2444 jni->NewObjectArray(
2445 nElements, (jclass) jo_seq_class.get(), 0 ) );
2446 jni.ensure_no_exception();
2448 if (0 < nElements)
2450 TypeDescr element_td( element_type );
2451 uno_Sequence ** elements = (uno_Sequence **) seq->elements;
2452 for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos )
2454 jvalue java_data2;
2455 map_to_java(
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();
2464 break;
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 ) );
2472 jo_ar.reset(
2473 jni->NewObjectArray( nElements, iface_info->m_class, 0 ) );
2474 jni.ensure_no_exception();
2476 if (0 < nElements)
2478 uno_Interface ** pp = (uno_Interface **)seq->elements;
2479 for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos )
2481 uno_Interface * pUnoI = pp[ nPos ];
2482 if (0 != pUnoI)
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();
2493 break;
2495 default:
2497 OUStringBuffer buf( 128 );
2498 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_java():") );
2499 buf.append( OUString::unacquired( &type->pTypeName ) );
2500 buf.appendAscii(
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() );
2508 if (out_param)
2510 if (0 == java_data->l)
2512 JLocalAutoRef jo_element_class(
2513 jni, jni->GetObjectClass( jo_ar.get() ) );
2514 if (in_param)
2516 java_data->l = jni->NewObjectArray(
2517 1, (jclass) jo_element_class.get(), jo_ar.get() );
2519 else
2521 java_data->l = jni->NewObjectArray(
2522 1, (jclass) jo_element_class.get(), 0 );
2524 jni.ensure_no_exception();
2526 else
2528 jni->SetObjectArrayElement(
2529 (jobjectArray) java_data->l, 0, jo_ar.get() );
2530 jni.ensure_no_exception();
2533 else
2535 java_data->l = jo_ar.release();
2537 break;
2539 case typelib_TypeClass_INTERFACE:
2541 JLocalAutoRef jo_iface( jni );
2542 if (in_param)
2544 uno_Interface * pUnoI = *(uno_Interface * const *)uno_data;
2545 if (0 != pUnoI)
2547 if (0 == info)
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 ) );
2554 if (out_param)
2556 if (0 == java_data->l)
2558 if (0 == info)
2559 info = m_jni_info->get_type_info( jni, type );
2560 java_data->l =
2561 jni->NewObjectArray( 1, info->m_class, jo_iface.get() );
2562 jni.ensure_no_exception();
2564 else
2566 jni->SetObjectArrayElement(
2567 (jobjectArray) java_data->l, 0, jo_iface.get() );
2568 jni.ensure_no_exception();
2571 else
2573 java_data->l = jo_iface.release();
2575 break;
2577 default:
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: */