Bump version to 4.1-6
[LibreOffice.git] / bridges / source / jni_uno / jni_data.cxx
blob2a24f58d73db7552e410062262fcdf2a98043615
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "jni_bridge.h"
23 #include "rtl/strbuf.hxx"
24 #include "rtl/ustrbuf.hxx"
25 #include "uno/sequence2.h"
28 using namespace ::std;
29 using namespace ::rtl;
31 namespace jni_uno
34 //------------------------------------------------------------------------------
35 inline rtl_mem * seq_allocate( sal_Int32 nElements, sal_Int32 nSize )
37 SAL_WNODEPRECATED_DECLARATIONS_PUSH
38 auto_ptr< rtl_mem > seq(
39 rtl_mem::allocate( SAL_SEQUENCE_HEADER_SIZE + (nElements * nSize) ) );
40 SAL_WNODEPRECATED_DECLARATIONS_POP
41 uno_Sequence * p = (uno_Sequence *)seq.get();
42 p->nRefCount = 1;
43 p->nElements = nElements;
44 return seq.release();
47 //______________________________________________________________________________
48 namespace {
50 void createDefaultUnoValue(
51 JNI_context const & jni, void * uno_data,
52 typelib_TypeDescriptionReference * type,
53 JNI_type_info const * info /* maybe 0 */, bool assign)
55 switch (type->eTypeClass) {
56 case typelib_TypeClass_BOOLEAN:
57 *static_cast< sal_Bool * >(uno_data) = false;
58 break;
60 case typelib_TypeClass_BYTE:
61 *static_cast< sal_Int8 * >(uno_data) = 0;
62 break;
64 case typelib_TypeClass_SHORT:
65 *static_cast< sal_Int16 * >(uno_data) = 0;
66 break;
68 case typelib_TypeClass_UNSIGNED_SHORT:
69 *static_cast< sal_uInt16 * >(uno_data) = 0;
70 break;
72 case typelib_TypeClass_LONG:
73 *static_cast< sal_Int32 * >(uno_data) = 0;
74 break;
76 case typelib_TypeClass_UNSIGNED_LONG:
77 *static_cast< sal_uInt32 * >(uno_data) = 0;
78 break;
80 case typelib_TypeClass_HYPER:
81 *static_cast< sal_Int64 * >(uno_data) = 0;
82 break;
84 case typelib_TypeClass_UNSIGNED_HYPER:
85 *static_cast< sal_uInt64 * >(uno_data) = 0;
86 break;
88 case typelib_TypeClass_FLOAT:
89 *static_cast< float * >(uno_data) = 0;
90 break;
92 case typelib_TypeClass_DOUBLE:
93 *static_cast< double * >(uno_data) = 0;
94 break;
96 case typelib_TypeClass_CHAR:
97 *static_cast< sal_Unicode * >(uno_data) = 0;
98 break;
100 case typelib_TypeClass_STRING:
101 if (!assign) {
102 *static_cast< rtl_uString ** >(uno_data) = 0;
104 rtl_uString_new(static_cast< rtl_uString ** >(uno_data));
105 break;
107 case typelib_TypeClass_TYPE:
108 if (assign) {
109 typelib_typedescriptionreference_release(
110 *static_cast< typelib_TypeDescriptionReference ** >(uno_data));
112 *static_cast< typelib_TypeDescriptionReference ** >(uno_data)
113 = *typelib_static_type_getByTypeClass(typelib_TypeClass_VOID);
114 OSL_ASSERT(
115 *static_cast< typelib_TypeDescriptionReference ** >(uno_data) != 0);
116 typelib_typedescriptionreference_acquire(
117 *static_cast< typelib_TypeDescriptionReference ** >(uno_data));
118 break;
120 case typelib_TypeClass_ANY:
121 if (assign) {
122 uno_any_destruct(static_cast< uno_Any * >(uno_data), 0);
124 uno_any_construct(
125 static_cast< uno_Any * >(uno_data), 0,
126 jni.get_info()->m_XInterface_type_info->m_td.get(), 0);
127 break;
129 case typelib_TypeClass_SEQUENCE:
131 SAL_WNODEPRECATED_DECLARATIONS_PUSH
132 auto_ptr< rtl_mem > seq(seq_allocate(0, 0));
133 SAL_WNODEPRECATED_DECLARATIONS_POP
134 if (assign) {
135 uno_type_destructData(uno_data, type, 0);
137 *static_cast< uno_Sequence ** >(uno_data)
138 = reinterpret_cast< uno_Sequence * >(seq.release());
139 break;
142 case typelib_TypeClass_ENUM:
144 typelib_TypeDescription * td = 0;
145 TYPELIB_DANGER_GET(&td, type);
146 *static_cast< sal_Int32 * >(uno_data)
147 = (reinterpret_cast< typelib_EnumTypeDescription * >(td)->
148 nDefaultEnumValue);
149 TYPELIB_DANGER_RELEASE(td);
150 break;
153 case typelib_TypeClass_STRUCT:
155 if (info == 0) {
156 info = jni.get_info()->get_type_info(jni, type);
158 JNI_compound_type_info const * comp_info
159 = static_cast< JNI_compound_type_info const * >(info);
160 typelib_CompoundTypeDescription * comp_td
161 = reinterpret_cast< typelib_CompoundTypeDescription * >(
162 comp_info->m_td.get());
163 sal_Int32 nPos = 0;
164 sal_Int32 nMembers = comp_td->nMembers;
165 try {
166 if (comp_td->pBaseTypeDescription != 0) {
167 createDefaultUnoValue(
168 jni, uno_data,
169 comp_td->pBaseTypeDescription->aBase.pWeakRef,
170 comp_info->m_base, assign);
172 for (; nPos < nMembers; ++nPos) {
173 createDefaultUnoValue(
174 jni,
175 (static_cast< char * >(uno_data)
176 + comp_td->pMemberOffsets[nPos]),
177 comp_td->ppTypeRefs[nPos], 0, assign);
179 } catch (...) {
180 if (!assign) {
181 for (sal_Int32 i = 0; i < nPos; ++i) {
182 uno_type_destructData(
183 (static_cast< char * >(uno_data)
184 + comp_td->pMemberOffsets[i]),
185 comp_td->ppTypeRefs[i], 0);
187 if (comp_td->pBaseTypeDescription != 0) {
188 uno_destructData(
189 uno_data, &comp_td->pBaseTypeDescription->aBase, 0);
192 throw;
195 break;
197 case typelib_TypeClass_INTERFACE:
198 if (assign) {
199 uno_Interface * p = *static_cast< uno_Interface ** >(uno_data);
200 if (p != 0) {
201 (*p->release)(p);
204 *static_cast< uno_Interface ** >(uno_data) = 0;
205 break;
207 default:
208 OSL_ASSERT(false);
209 break;
215 void Bridge::map_to_uno(
216 JNI_context const & jni,
217 void * uno_data, jvalue java_data,
218 typelib_TypeDescriptionReference * type,
219 JNI_type_info const * info /* maybe 0 */,
220 bool assign, bool out_param,
221 bool special_wrapped_integral_types ) const
223 OSL_ASSERT(
224 !out_param ||
225 (1 == jni->GetArrayLength( (jarray) java_data.l )) );
227 switch (type->eTypeClass)
229 case typelib_TypeClass_CHAR:
230 if (out_param)
232 jni->GetCharArrayRegion(
233 (jcharArray) java_data.l, 0, 1, (jchar *) uno_data );
234 jni.ensure_no_exception();
236 else if (special_wrapped_integral_types)
238 *(jchar *) uno_data = jni->CallCharMethodA(
239 java_data.l, m_jni_info->m_method_Character_charValue, 0 );
240 jni.ensure_no_exception();
242 else
244 *(jchar *) uno_data = java_data.c;
246 break;
247 case typelib_TypeClass_BOOLEAN:
248 if (out_param)
250 jni->GetBooleanArrayRegion(
251 (jbooleanArray) java_data.l, 0, 1, (jboolean *) uno_data );
252 jni.ensure_no_exception();
254 else if (special_wrapped_integral_types)
256 *(jboolean *) uno_data = jni->CallBooleanMethodA(
257 java_data.l, m_jni_info->m_method_Boolean_booleanValue, 0 );
258 jni.ensure_no_exception();
260 else
262 *(jboolean *) uno_data = java_data.z;
264 break;
265 case typelib_TypeClass_BYTE:
266 if (out_param)
268 jni->GetByteArrayRegion(
269 (jbyteArray) java_data.l, 0, 1, (jbyte *) uno_data );
270 jni.ensure_no_exception();
272 else if (special_wrapped_integral_types)
274 *(jbyte *) uno_data = jni->CallByteMethodA(
275 java_data.l, m_jni_info->m_method_Byte_byteValue, 0 );
276 jni.ensure_no_exception();
278 else
280 *(jbyte *) uno_data = java_data.b;
282 break;
283 case typelib_TypeClass_SHORT:
284 case typelib_TypeClass_UNSIGNED_SHORT:
285 if (out_param)
287 jni->GetShortArrayRegion(
288 (jshortArray) java_data.l, 0, 1, (jshort *) uno_data );
289 jni.ensure_no_exception();
291 else if (special_wrapped_integral_types)
293 *(jshort *) uno_data = jni->CallShortMethodA(
294 java_data.l, m_jni_info->m_method_Short_shortValue, 0 );
295 jni.ensure_no_exception();
297 else
299 *(jshort *) uno_data = java_data.s;
301 break;
302 case typelib_TypeClass_LONG:
303 case typelib_TypeClass_UNSIGNED_LONG:
304 if (out_param)
306 jni->GetIntArrayRegion(
307 (jintArray) java_data.l, 0, 1, (jint *) uno_data );
308 jni.ensure_no_exception();
310 else if (special_wrapped_integral_types)
312 *(jint *) uno_data = jni->CallIntMethodA(
313 java_data.l, m_jni_info->m_method_Integer_intValue, 0 );
314 jni.ensure_no_exception();
316 else
318 *(jint *) uno_data = java_data.i;
320 break;
321 case typelib_TypeClass_HYPER:
322 case typelib_TypeClass_UNSIGNED_HYPER:
323 if (out_param)
325 jni->GetLongArrayRegion(
326 (jlongArray) java_data.l, 0, 1, (jlong *) uno_data );
327 jni.ensure_no_exception();
329 else if (special_wrapped_integral_types)
331 *(jlong *) uno_data = jni->CallLongMethodA(
332 java_data.l, m_jni_info->m_method_Long_longValue, 0 );
333 jni.ensure_no_exception();
335 else
337 *(jlong *) uno_data = java_data.j;
339 break;
340 case typelib_TypeClass_FLOAT:
341 if (out_param)
343 jni->GetFloatArrayRegion(
344 (jfloatArray) java_data.l, 0, 1, (jfloat *) uno_data );
345 jni.ensure_no_exception();
347 else if (special_wrapped_integral_types)
349 *(jfloat *) uno_data = jni->CallFloatMethodA(
350 java_data.l, m_jni_info->m_method_Float_floatValue, 0 );
351 jni.ensure_no_exception();
353 else
355 *(jfloat *) uno_data = java_data.f;
357 break;
358 case typelib_TypeClass_DOUBLE:
359 if (out_param)
361 jni->GetDoubleArrayRegion(
362 (jdoubleArray) java_data.l, 0, 1, (jdouble *) uno_data );
363 jni.ensure_no_exception();
365 else if (special_wrapped_integral_types)
367 *(jdouble *) uno_data = jni->CallDoubleMethodA(
368 java_data.l, m_jni_info->m_method_Double_doubleValue, 0 );
369 jni.ensure_no_exception();
371 else
373 *(jdouble *) uno_data = java_data.d;
375 break;
376 case typelib_TypeClass_STRING:
378 JLocalAutoRef jo_out_holder( jni );
379 if (out_param)
381 jo_out_holder.reset(
382 jni->GetObjectArrayElement( (jobjectArray) java_data.l, 0 ) );
383 jni.ensure_no_exception();
384 java_data.l = jo_out_holder.get();
386 if (0 == java_data.l)
388 OUStringBuffer buf( 128 );
389 buf.append( "[map_to_uno():" );
390 buf.append( OUString::unacquired( &type->pTypeName ) );
391 buf.append( "] null-ref given!" );
392 buf.append( jni.get_stack_trace() );
393 throw BridgeRuntimeError( buf.makeStringAndClear() );
395 if (! assign)
396 *(rtl_uString **)uno_data = 0;
397 jstring_to_ustring(
398 jni, (rtl_uString **)uno_data, (jstring) java_data.l );
399 break;
401 case typelib_TypeClass_TYPE:
403 JLocalAutoRef jo_out_holder( jni );
404 if (out_param)
406 jo_out_holder.reset(
407 jni->GetObjectArrayElement( (jobjectArray) java_data.l, 0 ) );
408 jni.ensure_no_exception();
409 java_data.l = jo_out_holder.get();
411 if (0 == java_data.l)
413 OUStringBuffer buf( 128 );
414 buf.append( "[map_to_uno():" );
415 buf.append( OUString::unacquired( &type->pTypeName ) );
416 buf.append( "] null-ref given!" );
417 buf.append( jni.get_stack_trace() );
418 throw BridgeRuntimeError( buf.makeStringAndClear() );
421 // type name
422 JLocalAutoRef jo_type_name(
423 jni, jni->GetObjectField(
424 java_data.l, m_jni_info->m_field_Type__typeName ) );
425 if (! jo_type_name.is())
427 OUStringBuffer buf( 128 );
428 buf.append( "[map_to_uno():" );
429 buf.append( OUString::unacquired( &type->pTypeName ) );
430 buf.append("] incomplete type object: "
431 "no type name!" );
432 buf.append( jni.get_stack_trace() );
433 throw BridgeRuntimeError( buf.makeStringAndClear() );
435 OUString type_name(
436 jstring_to_oustring( jni, (jstring) jo_type_name.get() ) );
437 ::com::sun::star::uno::TypeDescription td( type_name );
438 if (! td.is())
440 OUStringBuffer buf( 128 );
441 buf.append( "[map_to_uno():" );
442 buf.append( OUString::unacquired( &type->pTypeName ) );
443 buf.append( "] UNO type not found: " );
444 buf.append( type_name );
445 buf.append( jni.get_stack_trace() );
446 throw BridgeRuntimeError( buf.makeStringAndClear() );
448 typelib_typedescriptionreference_acquire( td.get()->pWeakRef );
449 if (assign)
451 typelib_typedescriptionreference_release(
452 *(typelib_TypeDescriptionReference **)uno_data );
454 *(typelib_TypeDescriptionReference **)uno_data = td.get()->pWeakRef;
455 break;
457 case typelib_TypeClass_ANY:
459 JLocalAutoRef jo_out_holder( jni );
460 if (out_param)
462 jo_out_holder.reset(
463 jni->GetObjectArrayElement( (jobjectArray) java_data.l, 0 ) );
464 jni.ensure_no_exception();
465 java_data.l = jo_out_holder.get();
468 uno_Any * pAny = (uno_Any *)uno_data;
469 if (0 == java_data.l) // null-ref maps to XInterface null-ref
471 if (assign)
472 uno_any_destruct( pAny, 0 );
473 uno_any_construct(
474 pAny, 0, m_jni_info->m_XInterface_type_info->m_td.get(), 0 );
475 break;
478 JLocalAutoRef jo_type( jni );
479 JLocalAutoRef jo_wrapped_holder( jni );
481 if (JNI_FALSE != jni->IsInstanceOf(
482 java_data.l, m_jni_info->m_class_Any ))
484 // boxed any
485 jo_type.reset( jni->GetObjectField(
486 java_data.l, m_jni_info->m_field_Any__type ) );
487 if (! jo_type.is())
489 OUStringBuffer buf( 128 );
490 buf.append( "[map_to_uno():" );
491 buf.append( OUString::unacquired( &type->pTypeName ) );
492 buf.append( "] no type set at " "com.sun.star.uno.Any!" );
493 buf.append( jni.get_stack_trace() );
494 throw BridgeRuntimeError( buf.makeStringAndClear() );
496 // wrapped value
497 jo_wrapped_holder.reset(
498 jni->GetObjectField(
499 java_data.l, m_jni_info->m_field_Any__object ) );
500 java_data.l = jo_wrapped_holder.get();
502 else
504 // create type out of class
505 JLocalAutoRef jo_class( jni, jni->GetObjectClass( java_data.l ) );
506 jo_type.reset( create_type( jni, (jclass) jo_class.get() ) );
507 #if OSL_DEBUG_LEVEL > 1
509 JLocalAutoRef jo_toString(
510 jni, jni->CallObjectMethodA(
511 java_data.l, m_jni_info->m_method_Object_toString, 0 ) );
512 jni.ensure_no_exception();
513 OUString toString(
514 jstring_to_oustring( jni, (jstring) jo_toString.get() ) );
516 #endif
519 // get type name
520 JLocalAutoRef jo_type_name(
521 jni, jni->GetObjectField(
522 jo_type.get(), m_jni_info->m_field_Type__typeName ) );
523 jni.ensure_no_exception();
524 OUString type_name(
525 jstring_to_oustring( jni, (jstring) jo_type_name.get() ) );
527 ::com::sun::star::uno::TypeDescription value_td( type_name );
528 if (! value_td.is())
530 OUStringBuffer buf( 128 );
531 buf.append( "[map_to_uno():" );
532 buf.append( OUString::unacquired( &type->pTypeName ) );
533 buf.append( "] UNO type not found: " );
534 buf.append( type_name );
535 buf.append( jni.get_stack_trace() );
536 throw BridgeRuntimeError( buf.makeStringAndClear() );
538 typelib_TypeClass type_class = value_td.get()->eTypeClass;
540 if (assign)
542 uno_any_destruct( pAny, 0 );
546 switch (type_class)
548 case typelib_TypeClass_VOID:
549 pAny->pData = &pAny->pReserved;
550 break;
551 case typelib_TypeClass_CHAR:
552 pAny->pData = &pAny->pReserved;
553 *(jchar *) pAny->pData = jni->CallCharMethodA(
554 java_data.l, m_jni_info->m_method_Character_charValue, 0 );
555 jni.ensure_no_exception();
556 break;
557 case typelib_TypeClass_BOOLEAN:
558 pAny->pData = &pAny->pReserved;
559 *(jboolean *) pAny->pData = jni->CallBooleanMethodA(
560 java_data.l, m_jni_info->m_method_Boolean_booleanValue, 0 );
561 jni.ensure_no_exception();
562 break;
563 case typelib_TypeClass_BYTE:
564 pAny->pData = &pAny->pReserved;
565 *(jbyte *) pAny->pData = jni->CallByteMethodA(
566 java_data.l, m_jni_info->m_method_Byte_byteValue, 0 );
567 jni.ensure_no_exception();
568 break;
569 case typelib_TypeClass_SHORT:
570 case typelib_TypeClass_UNSIGNED_SHORT:
571 pAny->pData = &pAny->pReserved;
572 *(jshort *) pAny->pData = jni->CallShortMethodA(
573 java_data.l, m_jni_info->m_method_Short_shortValue, 0 );
574 jni.ensure_no_exception();
575 break;
576 case typelib_TypeClass_LONG:
577 case typelib_TypeClass_UNSIGNED_LONG:
578 pAny->pData = &pAny->pReserved;
579 *(jint *) pAny->pData = jni->CallIntMethodA(
580 java_data.l, m_jni_info->m_method_Integer_intValue, 0 );
581 jni.ensure_no_exception();
582 break;
583 case typelib_TypeClass_HYPER:
584 case typelib_TypeClass_UNSIGNED_HYPER:
585 if (sizeof (sal_Int64) <= sizeof (void *))
587 pAny->pData = &pAny->pReserved;
588 *(jlong *) pAny->pData = jni->CallLongMethodA(
589 java_data.l, m_jni_info->m_method_Long_longValue, 0 );
590 jni.ensure_no_exception();
592 else
594 SAL_WNODEPRECATED_DECLARATIONS_PUSH
595 auto_ptr< rtl_mem > mem(
596 rtl_mem::allocate( sizeof (sal_Int64) ) );
597 SAL_WNODEPRECATED_DECLARATIONS_POP
598 *(jlong *) mem.get() = jni->CallLongMethodA(
599 java_data.l, m_jni_info->m_method_Long_longValue, 0 );
600 jni.ensure_no_exception();
601 pAny->pData = mem.release();
603 break;
604 case typelib_TypeClass_FLOAT:
605 if (sizeof (float) <= sizeof (void *))
607 pAny->pData = &pAny->pReserved;
608 *(jfloat *) pAny->pData = jni->CallFloatMethodA(
609 java_data.l, m_jni_info->m_method_Float_floatValue, 0 );
610 jni.ensure_no_exception();
612 else
614 SAL_WNODEPRECATED_DECLARATIONS_PUSH
615 auto_ptr< rtl_mem > mem(
616 rtl_mem::allocate( sizeof (float) ) );
617 SAL_WNODEPRECATED_DECLARATIONS_POP
618 *(jfloat *) mem.get() = jni->CallFloatMethodA(
619 java_data.l, m_jni_info->m_method_Float_floatValue, 0 );
620 jni.ensure_no_exception();
621 pAny->pData = mem.release();
623 break;
624 case typelib_TypeClass_DOUBLE:
625 if (sizeof (double) <= sizeof (void *))
627 pAny->pData = &pAny->pReserved;
628 *(jdouble *) pAny->pData =
629 jni->CallDoubleMethodA(
630 java_data.l,
631 m_jni_info->m_method_Double_doubleValue, 0 );
632 jni.ensure_no_exception();
634 else
636 SAL_WNODEPRECATED_DECLARATIONS_PUSH
637 auto_ptr< rtl_mem > mem(
638 rtl_mem::allocate( sizeof (double) ) );
639 SAL_WNODEPRECATED_DECLARATIONS_POP
640 *(jdouble *) mem.get() =
641 jni->CallDoubleMethodA(
642 java_data.l,
643 m_jni_info->m_method_Double_doubleValue, 0 );
644 jni.ensure_no_exception();
645 pAny->pData = mem.release();
647 break;
648 case typelib_TypeClass_STRING:
649 // opt: anies often contain strings; copy string directly
650 pAny->pReserved = 0;
651 pAny->pData = &pAny->pReserved;
652 jstring_to_ustring(
653 jni, (rtl_uString **)pAny->pData,
654 (jstring) java_data.l );
655 break;
656 case typelib_TypeClass_TYPE:
657 case typelib_TypeClass_ENUM:
658 case typelib_TypeClass_SEQUENCE:
659 case typelib_TypeClass_INTERFACE:
660 pAny->pData = &pAny->pReserved;
661 map_to_uno(
662 jni, pAny->pData, java_data,
663 value_td.get()->pWeakRef, 0,
664 false /* no assign */, false /* no out param */ );
665 break;
666 case typelib_TypeClass_STRUCT:
667 case typelib_TypeClass_EXCEPTION:
669 SAL_WNODEPRECATED_DECLARATIONS_PUSH
670 auto_ptr< rtl_mem > mem(
671 rtl_mem::allocate( value_td.get()->nSize ) );
672 SAL_WNODEPRECATED_DECLARATIONS_POP
673 map_to_uno(
674 jni, mem.get(), java_data, value_td.get()->pWeakRef, 0,
675 false /* no assign */, false /* no out param */ );
676 pAny->pData = mem.release();
677 break;
679 default:
681 OUStringBuffer buf( 128 );
682 buf.append( "[map_to_uno():" );
683 buf.append( type_name );
684 buf.append( "] unsupported value type " "of any!" );
685 buf.append( jni.get_stack_trace() );
686 throw BridgeRuntimeError( buf.makeStringAndClear() );
690 catch (...)
692 if (assign)
694 // restore to valid any
695 uno_any_construct( pAny, 0, 0, 0 );
697 throw;
699 typelib_typedescriptionreference_acquire( value_td.get()->pWeakRef );
700 pAny->pType = value_td.get()->pWeakRef;
701 break;
703 case typelib_TypeClass_ENUM:
705 JLocalAutoRef jo_out_holder( jni );
706 if (out_param)
708 jo_out_holder.reset(
709 jni->GetObjectArrayElement( (jobjectArray) java_data.l, 0 ) );
710 jni.ensure_no_exception();
711 java_data.l = jo_out_holder.get();
713 if (0 == java_data.l)
715 OUStringBuffer buf( 128 );
716 buf.append( "[map_to_uno():" );
717 buf.append( OUString::unacquired( &type->pTypeName ) );
718 buf.append( "] null-ref given!" );
719 buf.append( jni.get_stack_trace() );
720 throw BridgeRuntimeError( buf.makeStringAndClear() );
723 *(jint *) uno_data = jni->GetIntField(
724 java_data.l, m_jni_info->m_field_Enum_m_value );
725 break;
727 case typelib_TypeClass_STRUCT:
728 case typelib_TypeClass_EXCEPTION:
730 JLocalAutoRef jo_out_holder( jni );
731 if (out_param)
733 jo_out_holder.reset(
734 jni->GetObjectArrayElement( (jobjectArray) java_data.l, 0 ) );
735 jni.ensure_no_exception();
736 java_data.l = jo_out_holder.get();
738 if (0 == java_data.l)
740 OUStringBuffer buf( 128 );
741 buf.append( "[map_to_uno():" );
742 buf.append( OUString::unacquired( &type->pTypeName ) );
743 buf.append( "] null-ref given!" );
744 buf.append( jni.get_stack_trace() );
745 throw BridgeRuntimeError( buf.makeStringAndClear() );
748 if (0 == info)
749 info = m_jni_info->get_type_info( jni, type );
750 JNI_compound_type_info const * comp_info =
751 static_cast< JNI_compound_type_info const * >( info );
753 typelib_CompoundTypeDescription * comp_td =
754 (typelib_CompoundTypeDescription *)comp_info->m_td.get();
755 bool polymorphic
756 = comp_td->aBase.eTypeClass == typelib_TypeClass_STRUCT
757 && reinterpret_cast< typelib_StructTypeDescription * >(
758 comp_td)->pParameterizedTypes != 0;
760 sal_Int32 nPos = 0;
761 sal_Int32 nMembers = comp_td->nMembers;
764 if (0 != comp_td->pBaseTypeDescription)
766 map_to_uno(
767 jni, uno_data, java_data,
768 ((typelib_TypeDescription *) comp_td->pBaseTypeDescription)
769 ->pWeakRef,
770 comp_info->m_base,
771 assign, false /* no out param */ );
774 for ( ; nPos < nMembers; ++nPos )
776 void * p = (char *)uno_data + comp_td->pMemberOffsets[ nPos ];
777 typelib_TypeDescriptionReference * member_type =
778 comp_td->ppTypeRefs[ nPos ];
779 jfieldID field_id = comp_info->m_fields[ nPos ];
780 bool parameterizedType = polymorphic
781 && reinterpret_cast< typelib_StructTypeDescription * >(
782 comp_td)->pParameterizedTypes[nPos];
783 switch (member_type->eTypeClass)
785 case typelib_TypeClass_CHAR:
786 if (parameterizedType) {
787 JLocalAutoRef jo(
788 jni, jni->GetObjectField( java_data.l, field_id ) );
789 if ( jo.get() == 0 ) {
790 *(jchar *) p = 0;
791 } else {
792 jvalue val;
793 val.l = jo.get();
794 map_to_uno(
795 jni, p, val, member_type, 0, assign, false,
796 true );
798 } else {
799 *(jchar *) p = jni->GetCharField(
800 java_data.l, field_id );
802 break;
803 case typelib_TypeClass_BOOLEAN:
804 if (parameterizedType) {
805 JLocalAutoRef jo(
806 jni, jni->GetObjectField( java_data.l, field_id ) );
807 if ( jo.get() == 0 ) {
808 *(jboolean *) p = false;
809 } else {
810 jvalue val;
811 val.l = jo.get();
812 map_to_uno(
813 jni, p, val, member_type, 0, assign, false,
814 true );
816 } else {
817 *(jboolean *) p = jni->GetBooleanField(
818 java_data.l, field_id );
820 break;
821 case typelib_TypeClass_BYTE:
822 if (parameterizedType) {
823 JLocalAutoRef jo(
824 jni, jni->GetObjectField( java_data.l, field_id ) );
825 if ( jo.get() == 0 ) {
826 *(jbyte *) p = 0;
827 } else {
828 jvalue val;
829 val.l = jo.get();
830 map_to_uno(
831 jni, p, val, member_type, 0, assign, false,
832 true );
834 } else {
835 *(jbyte *) p = jni->GetByteField(
836 java_data.l, field_id );
838 break;
839 case typelib_TypeClass_SHORT:
840 case typelib_TypeClass_UNSIGNED_SHORT:
841 if (parameterizedType) {
842 JLocalAutoRef jo(
843 jni, jni->GetObjectField( java_data.l, field_id ) );
844 if ( jo.get() == 0 ) {
845 *(jshort *) p = 0;
846 } else {
847 jvalue val;
848 val.l = jo.get();
849 map_to_uno(
850 jni, p, val, member_type, 0, assign, false,
851 true );
853 } else {
854 *(jshort *) p = jni->GetShortField(
855 java_data.l, field_id );
857 break;
858 case typelib_TypeClass_LONG:
859 case typelib_TypeClass_UNSIGNED_LONG:
860 if (parameterizedType) {
861 JLocalAutoRef jo(
862 jni, jni->GetObjectField( java_data.l, field_id ) );
863 if ( jo.get() == 0 ) {
864 *(jint *) p = 0;
865 } else {
866 jvalue val;
867 val.l = jo.get();
868 map_to_uno(
869 jni, p, val, member_type, 0, assign, false,
870 true );
872 } else {
873 *(jint *) p = jni->GetIntField( java_data.l, field_id );
875 break;
876 case typelib_TypeClass_HYPER:
877 case typelib_TypeClass_UNSIGNED_HYPER:
878 if (parameterizedType) {
879 JLocalAutoRef jo(
880 jni, jni->GetObjectField( java_data.l, field_id ) );
881 if ( jo.get() == 0 ) {
882 *(jlong *) p = 0;
883 } else {
884 jvalue val;
885 val.l = jo.get();
886 map_to_uno(
887 jni, p, val, member_type, 0, assign, false,
888 true );
890 } else {
891 *(jlong *) p = jni->GetLongField(
892 java_data.l, field_id );
894 break;
895 case typelib_TypeClass_FLOAT:
896 if (parameterizedType) {
897 JLocalAutoRef jo(
898 jni, jni->GetObjectField( java_data.l, field_id ) );
899 if ( jo.get() == 0 ) {
900 *(jfloat *) p = 0;
901 } else {
902 jvalue val;
903 val.l = jo.get();
904 map_to_uno(
905 jni, p, val, member_type, 0, assign, false,
906 true );
908 } else {
909 *(jfloat *) p = jni->GetFloatField(
910 java_data.l, field_id );
912 break;
913 case typelib_TypeClass_DOUBLE:
914 if (parameterizedType) {
915 JLocalAutoRef jo(
916 jni, jni->GetObjectField( java_data.l, field_id ) );
917 if ( jo.get() == 0 ) {
918 *(jdouble *) p = 0;
919 } else {
920 jvalue val;
921 val.l = jo.get();
922 map_to_uno(
923 jni, p, val, member_type, 0, assign, false,
924 true );
926 } else {
927 *(jdouble *) p = jni->GetDoubleField(
928 java_data.l, field_id );
930 break;
931 default:
933 JLocalAutoRef jo_field( jni );
934 bool checkNull;
935 if (0 == field_id)
937 // special for Message: call Throwable.getMessage()
938 OSL_ASSERT(
939 type_equals(
940 type,
941 m_jni_info->m_Exception_type.getTypeLibType() )
942 || type_equals(
943 type,
944 m_jni_info->m_RuntimeException_type.
945 getTypeLibType() ) );
946 OSL_ASSERT( 0 == nPos ); // first member
947 // call getMessage()
948 jo_field.reset(
949 jni->CallObjectMethodA(
950 java_data.l,
951 m_jni_info->m_method_Throwable_getMessage, 0 )
953 jni.ensure_no_exception();
954 checkNull = true;
956 else
958 jo_field.reset(
959 jni->GetObjectField( java_data.l, field_id ) );
960 checkNull = parameterizedType;
962 if (checkNull && !jo_field.is()) {
963 createDefaultUnoValue(jni, p, member_type, 0, assign);
964 } else {
965 jvalue val;
966 val.l = jo_field.get();
967 map_to_uno(
968 jni, p, val, member_type, 0,
969 assign, false /* no out param */ );
971 break;
976 catch (...)
978 if (! assign)
980 // cleanup
981 for ( sal_Int32 nCleanup = 0; nCleanup < nPos; ++nCleanup )
983 void * p =
984 (char *)uno_data + comp_td->pMemberOffsets[ nCleanup ];
985 uno_type_destructData(
986 p, comp_td->ppTypeRefs[ nCleanup ], 0 );
988 if (0 != comp_td->pBaseTypeDescription)
990 uno_destructData(
991 uno_data,
992 (typelib_TypeDescription *) comp_td
993 ->pBaseTypeDescription, 0 );
996 throw;
998 break;
1000 case typelib_TypeClass_SEQUENCE:
1002 JLocalAutoRef jo_out_holder( jni );
1003 if (out_param)
1005 jo_out_holder.reset(
1006 jni->GetObjectArrayElement( (jobjectArray) java_data.l, 0 ) );
1007 jni.ensure_no_exception();
1008 java_data.l = jo_out_holder.get();
1010 if (0 == java_data.l)
1012 OUStringBuffer buf( 128 );
1013 buf.append( "[map_to_uno():" );
1014 buf.append( OUString::unacquired( &type->pTypeName ) );
1015 buf.append( "] null-ref given!" );
1016 buf.append( jni.get_stack_trace() );
1017 throw BridgeRuntimeError( buf.makeStringAndClear() );
1020 TypeDescr td( type );
1021 typelib_TypeDescriptionReference * element_type =
1022 ((typelib_IndirectTypeDescription *)td.get())->pType;
1024 SAL_WNODEPRECATED_DECLARATIONS_PUSH
1025 auto_ptr< rtl_mem > seq;
1026 SAL_WNODEPRECATED_DECLARATIONS_POP
1027 sal_Int32 nElements = jni->GetArrayLength( (jarray) java_data.l );
1029 switch (element_type->eTypeClass)
1031 case typelib_TypeClass_CHAR:
1032 seq.reset( seq_allocate( nElements, sizeof (sal_Unicode) ) );
1033 jni->GetCharArrayRegion(
1034 (jcharArray) java_data.l, 0, nElements,
1035 (jchar *) ((uno_Sequence *) seq.get())->elements );
1036 jni.ensure_no_exception();
1037 break;
1038 case typelib_TypeClass_BOOLEAN:
1039 seq.reset( seq_allocate( nElements, sizeof (sal_Bool) ) );
1040 jni->GetBooleanArrayRegion(
1041 (jbooleanArray) java_data.l, 0, nElements,
1042 (jboolean *) ((uno_Sequence *) seq.get())->elements );
1043 jni.ensure_no_exception();
1044 break;
1045 case typelib_TypeClass_BYTE:
1046 seq.reset( seq_allocate( nElements, sizeof (sal_Int8) ) );
1047 jni->GetByteArrayRegion(
1048 (jbyteArray) java_data.l, 0, nElements,
1049 (jbyte *) ((uno_Sequence *) seq.get())->elements );
1050 jni.ensure_no_exception();
1051 break;
1052 case typelib_TypeClass_SHORT:
1053 case typelib_TypeClass_UNSIGNED_SHORT:
1054 seq.reset( seq_allocate( nElements, sizeof (sal_Int16) ) );
1055 jni->GetShortArrayRegion(
1056 (jshortArray) java_data.l, 0, nElements,
1057 (jshort *) ((uno_Sequence *) seq.get())->elements );
1058 jni.ensure_no_exception();
1059 break;
1060 case typelib_TypeClass_LONG:
1061 case typelib_TypeClass_UNSIGNED_LONG:
1062 seq.reset( seq_allocate( nElements, sizeof (sal_Int32) ) );
1063 jni->GetIntArrayRegion(
1064 (jintArray) java_data.l, 0, nElements,
1065 (jint *) ((uno_Sequence *) seq.get())->elements );
1066 jni.ensure_no_exception();
1067 break;
1068 case typelib_TypeClass_HYPER:
1069 case typelib_TypeClass_UNSIGNED_HYPER:
1070 seq.reset( seq_allocate( nElements, sizeof (sal_Int64) ) );
1071 jni->GetLongArrayRegion(
1072 (jlongArray) java_data.l, 0, nElements,
1073 (jlong *) ((uno_Sequence *) seq.get())->elements );
1074 jni.ensure_no_exception();
1075 break;
1076 case typelib_TypeClass_FLOAT:
1077 seq.reset( seq_allocate( nElements, sizeof (float) ) );
1078 jni->GetFloatArrayRegion(
1079 (jfloatArray) java_data.l, 0, nElements,
1080 (jfloat *)((uno_Sequence *)seq.get())->elements );
1081 jni.ensure_no_exception();
1082 break;
1083 case typelib_TypeClass_DOUBLE:
1084 seq.reset( seq_allocate( nElements, sizeof (double) ) );
1085 jni->GetDoubleArrayRegion(
1086 (jdoubleArray) java_data.l, 0, nElements,
1087 (jdouble *) ((uno_Sequence *) seq.get())->elements );
1088 jni.ensure_no_exception();
1089 break;
1090 case typelib_TypeClass_STRING:
1091 case typelib_TypeClass_TYPE:
1092 case typelib_TypeClass_ANY:
1093 case typelib_TypeClass_ENUM:
1094 case typelib_TypeClass_STRUCT:
1095 case typelib_TypeClass_EXCEPTION:
1096 case typelib_TypeClass_SEQUENCE:
1097 case typelib_TypeClass_INTERFACE:
1099 TypeDescr element_td( element_type );
1100 seq.reset( seq_allocate( nElements, element_td.get()->nSize ) );
1102 JNI_type_info const * element_info;
1103 if (typelib_TypeClass_STRUCT == element_type->eTypeClass ||
1104 typelib_TypeClass_EXCEPTION == element_type->eTypeClass ||
1105 typelib_TypeClass_INTERFACE == element_type->eTypeClass)
1107 element_info =
1108 m_jni_info->get_type_info( jni, element_td.get() );
1110 else
1112 element_info = 0;
1115 for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos )
1119 JLocalAutoRef jo(
1120 jni, jni->GetObjectArrayElement(
1121 (jobjectArray) java_data.l, nPos ) );
1122 jni.ensure_no_exception();
1123 jvalue val;
1124 val.l = jo.get();
1125 void * p =
1126 ((uno_Sequence *)seq.get())->elements +
1127 (nPos * element_td.get()->nSize);
1128 map_to_uno(
1129 jni, p, val, element_td.get()->pWeakRef, element_info,
1130 false /* no assign */, false /* no out param */ );
1132 catch (...)
1134 // cleanup
1135 for ( sal_Int32 nCleanPos = 0;
1136 nCleanPos < nPos; ++nCleanPos )
1138 void * p =
1139 ((uno_Sequence *)seq.get())->elements +
1140 (nCleanPos * element_td.get()->nSize);
1141 uno_destructData( p, element_td.get(), 0 );
1143 throw;
1146 break;
1148 default:
1150 OUStringBuffer buf( 128 );
1151 buf.append( "[map_to_uno():" );
1152 buf.append( OUString::unacquired( &type->pTypeName ) );
1153 buf.append( "] unsupported sequence element" " type: " );
1154 buf.append( OUString::unacquired( &element_type->pTypeName ) );
1155 buf.append( jni.get_stack_trace() );
1156 throw BridgeRuntimeError( buf.makeStringAndClear() );
1160 if (assign)
1161 uno_destructData( uno_data, td.get(), 0 );
1162 *(uno_Sequence **)uno_data = (uno_Sequence *)seq.release();
1163 break;
1165 case typelib_TypeClass_INTERFACE:
1167 JLocalAutoRef jo_out_holder( jni );
1168 if (out_param)
1170 jo_out_holder.reset(
1171 jni->GetObjectArrayElement( (jobjectArray) java_data.l, 0 ) );
1172 jni.ensure_no_exception();
1173 java_data.l = jo_out_holder.get();
1176 if (0 == java_data.l) // null-ref
1178 if (assign)
1180 uno_Interface * p = *(uno_Interface **)uno_data;
1181 if (0 != p)
1182 (*p->release)( p );
1184 *(uno_Interface **)uno_data = 0;
1186 else
1188 if (0 == info)
1189 info = m_jni_info->get_type_info( jni, type );
1190 JNI_interface_type_info const * iface_info =
1191 static_cast< JNI_interface_type_info const * >( info );
1192 uno_Interface * pUnoI = map_to_uno( jni, java_data.l, iface_info );
1193 if (assign)
1195 uno_Interface * p = *(uno_Interface **)uno_data;
1196 if (0 != p)
1197 (*p->release)( p );
1199 *(uno_Interface **)uno_data = pUnoI;
1201 break;
1203 default:
1205 OUStringBuffer buf( 128 );
1206 buf.append( "[map_to_uno():" );
1207 buf.append( OUString::unacquired( &type->pTypeName ) );
1208 buf.append( "] unsupported type!" );
1209 buf.append( jni.get_stack_trace() );
1210 throw BridgeRuntimeError( buf.makeStringAndClear() );
1215 //##############################################################################
1217 //______________________________________________________________________________
1218 void Bridge::map_to_java(
1219 JNI_context const & jni,
1220 jvalue * java_data, void const * uno_data,
1221 typelib_TypeDescriptionReference * type,
1222 JNI_type_info const * info /* maybe 0 */,
1223 bool in_param, bool out_param,
1224 bool special_wrapped_integral_types ) const
1226 switch (type->eTypeClass)
1228 case typelib_TypeClass_CHAR:
1229 if (out_param)
1231 if (0 == java_data->l)
1233 JLocalAutoRef jo_ar( jni, jni->NewCharArray( 1 ) );
1234 jni.ensure_no_exception();
1235 if (in_param)
1237 jni->SetCharArrayRegion(
1238 (jcharArray) jo_ar.get(), 0, 1, (jchar *) uno_data );
1239 jni.ensure_no_exception();
1241 java_data->l = jo_ar.release();
1243 else
1245 if (in_param)
1247 jni->SetCharArrayRegion(
1248 (jcharArray) java_data->l, 0, 1, (jchar *) uno_data );
1249 jni.ensure_no_exception();
1253 else if (special_wrapped_integral_types)
1255 jvalue arg;
1256 arg.c = *(jchar const *) uno_data;
1257 java_data->l = jni->NewObjectA(
1258 m_jni_info->m_class_Character,
1259 m_jni_info->m_ctor_Character_with_char, &arg );
1260 jni.ensure_no_exception();
1262 else
1264 java_data->c = *(jchar const *) uno_data;
1266 break;
1267 case typelib_TypeClass_BOOLEAN:
1268 if (out_param)
1270 if (0 == java_data->l)
1272 JLocalAutoRef jo_ar( jni, jni->NewBooleanArray( 1 ) );
1273 jni.ensure_no_exception();
1274 if (in_param)
1276 jni->SetBooleanArrayRegion(
1277 (jbooleanArray) jo_ar.get(),
1278 0, 1, (jboolean *) uno_data );
1279 jni.ensure_no_exception();
1281 java_data->l = jo_ar.release();
1283 else
1285 if (in_param)
1287 jni->SetBooleanArrayRegion(
1288 (jbooleanArray) java_data->l,
1289 0, 1, (jboolean *) uno_data );
1290 jni.ensure_no_exception();
1294 else if (special_wrapped_integral_types)
1296 jvalue arg;
1297 arg.z = *(jboolean const *) uno_data;
1298 java_data->l = jni->NewObjectA(
1299 m_jni_info->m_class_Boolean,
1300 m_jni_info->m_ctor_Boolean_with_boolean, &arg );
1301 jni.ensure_no_exception();
1303 else
1305 java_data->z = *(jboolean const *) uno_data;
1307 break;
1308 case typelib_TypeClass_BYTE:
1309 if (out_param)
1311 if (0 == java_data->l)
1313 JLocalAutoRef jo_ar( jni, jni->NewByteArray( 1 ) );
1314 jni.ensure_no_exception();
1315 if (in_param)
1317 jni->SetByteArrayRegion(
1318 (jbyteArray) jo_ar.get(), 0, 1, (jbyte *) uno_data );
1319 jni.ensure_no_exception();
1321 java_data->l = jo_ar.release();
1323 else
1325 if (in_param)
1327 jni->SetByteArrayRegion(
1328 (jbyteArray) java_data->l, 0, 1, (jbyte *) uno_data );
1329 jni.ensure_no_exception();
1333 else if (special_wrapped_integral_types)
1335 jvalue arg;
1336 arg.b = *(jbyte const *) uno_data;
1337 java_data->l = jni->NewObjectA(
1338 m_jni_info->m_class_Byte,
1339 m_jni_info->m_ctor_Byte_with_byte, &arg );
1340 jni.ensure_no_exception();
1342 else
1344 java_data->b = *(jbyte const *) uno_data;
1346 break;
1347 case typelib_TypeClass_SHORT:
1348 case typelib_TypeClass_UNSIGNED_SHORT:
1349 if (out_param)
1351 if (0 == java_data->l)
1353 JLocalAutoRef jo_ar( jni, jni->NewShortArray( 1 ) );
1354 jni.ensure_no_exception();
1355 if (in_param)
1357 jni->SetShortArrayRegion(
1358 (jshortArray) jo_ar.get(), 0, 1, (jshort *) uno_data );
1359 jni.ensure_no_exception();
1361 java_data->l = jo_ar.release();
1363 else
1365 if (in_param)
1367 jni->SetShortArrayRegion(
1368 (jshortArray) java_data->l, 0, 1, (jshort *) uno_data );
1369 jni.ensure_no_exception();
1373 else if (special_wrapped_integral_types)
1375 jvalue arg;
1376 arg.s = *(jshort const *) uno_data;
1377 java_data->l = jni->NewObjectA(
1378 m_jni_info->m_class_Short,
1379 m_jni_info->m_ctor_Short_with_short, &arg );
1380 jni.ensure_no_exception();
1382 else
1384 java_data->s = *(jshort const *) uno_data;
1386 break;
1387 case typelib_TypeClass_LONG:
1388 case typelib_TypeClass_UNSIGNED_LONG:
1389 if (out_param)
1391 if (0 == java_data->l)
1393 JLocalAutoRef jo_ar( jni, jni->NewIntArray( 1 ) );
1394 jni.ensure_no_exception();
1395 if (in_param)
1397 jni->SetIntArrayRegion(
1398 (jintArray) jo_ar.get(), 0, 1, (jint *) uno_data );
1399 jni.ensure_no_exception();
1401 java_data->l = jo_ar.release();
1403 else
1405 if (in_param)
1407 jni->SetIntArrayRegion(
1408 (jintArray) java_data->l, 0, 1, (jint *) uno_data );
1409 jni.ensure_no_exception();
1413 else if (special_wrapped_integral_types)
1415 jvalue arg;
1416 arg.i = *(jint const *) uno_data;
1417 java_data->l = jni->NewObjectA(
1418 m_jni_info->m_class_Integer,
1419 m_jni_info->m_ctor_Integer_with_int, &arg );
1420 jni.ensure_no_exception();
1422 else
1424 java_data->i = *(jint const *) uno_data;
1426 break;
1427 case typelib_TypeClass_HYPER:
1428 case typelib_TypeClass_UNSIGNED_HYPER:
1429 if (out_param)
1431 if (0 == java_data->l)
1433 JLocalAutoRef jo_ar( jni, jni->NewLongArray( 1 ) );
1434 jni.ensure_no_exception();
1435 if (in_param)
1437 jni->SetLongArrayRegion(
1438 (jlongArray)jo_ar.get(), 0, 1, (jlong *) uno_data );
1439 jni.ensure_no_exception();
1441 java_data->l = jo_ar.release();
1443 else
1445 if (in_param)
1447 jni->SetLongArrayRegion(
1448 (jlongArray)java_data->l, 0, 1, (jlong *) uno_data );
1449 jni.ensure_no_exception();
1453 else if (special_wrapped_integral_types)
1455 jvalue arg;
1456 arg.j = *(jlong const *) uno_data;
1457 java_data->l = jni->NewObjectA(
1458 m_jni_info->m_class_Long,
1459 m_jni_info->m_ctor_Long_with_long, &arg );
1460 jni.ensure_no_exception();
1462 else
1464 java_data->j = *(jlong const *) uno_data;
1466 break;
1467 case typelib_TypeClass_FLOAT:
1468 if (out_param)
1470 if (0 == java_data->l)
1472 JLocalAutoRef jo_ar( jni, jni->NewFloatArray( 1 ) );
1473 jni.ensure_no_exception();
1474 if (in_param)
1476 jni->SetFloatArrayRegion(
1477 (jfloatArray) jo_ar.get(), 0, 1, (jfloat *) uno_data );
1478 jni.ensure_no_exception();
1480 java_data->l = jo_ar.release();
1482 else
1484 if (in_param)
1486 jni->SetFloatArrayRegion(
1487 (jfloatArray) java_data->l, 0, 1, (jfloat *) uno_data );
1488 jni.ensure_no_exception();
1492 else if (special_wrapped_integral_types)
1494 jvalue arg;
1495 arg.f = *(jfloat const *) uno_data;
1496 java_data->l = jni->NewObjectA(
1497 m_jni_info->m_class_Float,
1498 m_jni_info->m_ctor_Float_with_float, &arg );
1499 jni.ensure_no_exception();
1501 else
1503 java_data->f = *(jfloat const *) uno_data;
1505 break;
1506 case typelib_TypeClass_DOUBLE:
1507 if (out_param)
1509 if (0 == java_data->l)
1511 JLocalAutoRef jo_ar( jni, jni->NewDoubleArray( 1 ) );
1512 jni.ensure_no_exception();
1513 if (in_param)
1515 jni->SetDoubleArrayRegion(
1516 (jdoubleArray) jo_ar.get(),
1517 0, 1, (jdouble *) uno_data );
1518 jni.ensure_no_exception();
1520 java_data->l = jo_ar.release();
1522 else
1524 if (in_param)
1526 jni->SetDoubleArrayRegion(
1527 (jdoubleArray) java_data->l,
1528 0, 1, (jdouble *) uno_data );
1529 jni.ensure_no_exception();
1533 else if (special_wrapped_integral_types)
1535 jvalue arg;
1536 arg.d = *(double const *)uno_data;
1537 java_data->l = jni->NewObjectA(
1538 m_jni_info->m_class_Double,
1539 m_jni_info->m_ctor_Double_with_double, &arg );
1540 jni.ensure_no_exception();
1542 else
1544 java_data->d = *(jdouble const *) uno_data;
1546 break;
1547 case typelib_TypeClass_STRING:
1549 if (out_param)
1551 JLocalAutoRef jo_in( jni );
1552 if (in_param)
1554 jo_in.reset(
1555 ustring_to_jstring(
1556 jni, *(rtl_uString * const *) uno_data ) );
1558 if (0 == java_data->l)
1560 java_data->l = jni->NewObjectArray(
1561 1, m_jni_info->m_class_String, jo_in.get() );
1562 jni.ensure_no_exception();
1564 else
1566 jni->SetObjectArrayElement(
1567 (jobjectArray) java_data->l, 0, jo_in.get() );
1568 jni.ensure_no_exception();
1571 else
1573 OSL_ASSERT( in_param );
1574 java_data->l =
1575 ustring_to_jstring( jni, *(rtl_uString * const *) uno_data );
1577 break;
1579 case typelib_TypeClass_TYPE:
1581 if (out_param)
1583 JLocalAutoRef jo_in( jni );
1584 if (in_param)
1586 jo_in.reset(
1587 create_type(
1588 jni,
1589 *(typelib_TypeDescriptionReference * const *) uno_data )
1592 if (0 == java_data->l)
1594 java_data->l = jni->NewObjectArray(
1595 1, m_jni_info->m_class_Type, jo_in.get() );
1596 jni.ensure_no_exception();
1598 else
1600 jni->SetObjectArrayElement(
1601 (jobjectArray) java_data->l, 0, jo_in.get() );
1602 jni.ensure_no_exception();
1605 else
1607 OSL_ASSERT( in_param );
1608 java_data->l =
1609 create_type(
1610 jni,
1611 *(typelib_TypeDescriptionReference * const *) uno_data );
1613 break;
1615 case typelib_TypeClass_ANY:
1617 JLocalAutoRef jo_any( jni );
1618 if (in_param)
1620 uno_Any const * pAny = (uno_Any const *)uno_data;
1622 #if defined BRIDGES_JNI_UNO_FORCE_BOXED_ANY
1623 if (typelib_TypeClass_VOID == pAny->pType->eTypeClass)
1625 jo_any.reset(
1626 jni->NewLocalRef( m_jni_info->m_object_Any_VOID ) );
1628 else
1630 jvalue args[ 2 ];
1631 map_to_java(
1632 jni, &args[ 1 ], pAny->pData, pAny->pType, 0,
1633 true /* in */, false /* no out */,
1634 true /* create integral wrappers */ );
1635 jo_any.reset( args[ 1 ].l );
1636 // build up com.sun.star.uno.Any
1637 JLocalAutoRef jo_type( jni, create_type( jni, pAny->pType ) );
1638 args[ 0 ].l = jo_type.get();
1639 jo_any.reset(
1640 jni->NewObjectA(
1641 m_jni_info->m_class_Any,
1642 m_jni_info->m_ctor_Any_with_Type_Object, args ) );
1643 jni.ensure_no_exception();
1645 #else
1646 switch (pAny->pType->eTypeClass)
1648 case typelib_TypeClass_VOID:
1649 jo_any.reset(
1650 jni->NewLocalRef( m_jni_info->m_object_Any_VOID ) );
1651 break;
1652 case typelib_TypeClass_UNSIGNED_SHORT:
1654 jvalue args[ 2 ];
1655 args[ 0 ].s = *(jshort const *) pAny->pData;
1656 JLocalAutoRef jo_val(
1657 jni, jni->NewObjectA(
1658 m_jni_info->m_class_Short,
1659 m_jni_info->m_ctor_Short_with_short, args ) );
1660 jni.ensure_no_exception();
1661 // box up in com.sun.star.uno.Any
1662 args[ 0 ].l = m_jni_info->m_object_Type_UNSIGNED_SHORT;
1663 args[ 1 ].l = jo_val.get();
1664 jo_any.reset(
1665 jni->NewObjectA(
1666 m_jni_info->m_class_Any,
1667 m_jni_info->m_ctor_Any_with_Type_Object, args ) );
1668 jni.ensure_no_exception();
1669 break;
1671 case typelib_TypeClass_UNSIGNED_LONG:
1673 jvalue args[ 2 ];
1674 args[ 0 ].i = *(jint const *) pAny->pData;
1675 JLocalAutoRef jo_val(
1676 jni, jni->NewObjectA(
1677 m_jni_info->m_class_Integer,
1678 m_jni_info->m_ctor_Integer_with_int, args ) );
1679 jni.ensure_no_exception();
1680 // box up in com.sun.star.uno.Any
1681 args[ 0 ].l = m_jni_info->m_object_Type_UNSIGNED_LONG;
1682 args[ 1 ].l = jo_val.get();
1683 jo_any.reset(
1684 jni->NewObjectA(
1685 m_jni_info->m_class_Any,
1686 m_jni_info->m_ctor_Any_with_Type_Object, args ) );
1687 jni.ensure_no_exception();
1688 break;
1690 case typelib_TypeClass_UNSIGNED_HYPER:
1692 jvalue args[ 2 ];
1693 args[ 0 ].j = *(jlong const *) pAny->pData;
1694 JLocalAutoRef jo_val(
1695 jni, jni->NewObjectA(
1696 m_jni_info->m_class_Long,
1697 m_jni_info->m_ctor_Long_with_long, args ) );
1698 jni.ensure_no_exception();
1699 // box up in com.sun.star.uno.Any
1700 args[ 0 ].l = m_jni_info->m_object_Type_UNSIGNED_HYPER;
1701 args[ 1 ].l = jo_val.get();
1702 jo_any.reset(
1703 jni->NewObjectA(
1704 m_jni_info->m_class_Any,
1705 m_jni_info->m_ctor_Any_with_Type_Object, args ) );
1706 jni.ensure_no_exception();
1707 break;
1709 case typelib_TypeClass_STRING: // opt strings
1710 jo_any.reset( ustring_to_jstring(
1711 jni, (rtl_uString *) pAny->pReserved ) );
1712 break;
1713 case typelib_TypeClass_SEQUENCE:
1715 jvalue java_data2;
1716 // prefetch sequence td
1717 TypeDescr seq_td( pAny->pType );
1718 map_to_java(
1719 jni, &java_data2, pAny->pData, seq_td.get()->pWeakRef, 0,
1720 true /* in */, false /* no out */,
1721 true /* create integral wrappers */ );
1722 jo_any.reset( java_data2.l );
1724 // determine inner element type
1725 ::com::sun::star::uno::Type element_type(
1726 ((typelib_IndirectTypeDescription *)seq_td.get())->pType );
1727 while (typelib_TypeClass_SEQUENCE ==
1728 element_type.getTypeLibType()->eTypeClass)
1730 TypeDescr element_td( element_type.getTypeLibType() );
1731 typelib_typedescriptionreference_assign(
1732 reinterpret_cast< typelib_TypeDescriptionReference ** >(
1733 &element_type ),
1734 ((typelib_IndirectTypeDescription *)element_td.get())
1735 ->pType );
1737 // box up only if unsigned element type
1738 switch (element_type.getTypeLibType()->eTypeClass)
1740 case typelib_TypeClass_UNSIGNED_SHORT:
1741 case typelib_TypeClass_UNSIGNED_LONG:
1742 case typelib_TypeClass_UNSIGNED_HYPER:
1744 jvalue args[ 2 ];
1745 JLocalAutoRef jo_type(
1746 jni, create_type( jni, seq_td.get()->pWeakRef ) );
1747 args[ 0 ].l = jo_type.get();
1748 args[ 1 ].l = jo_any.get();
1749 jo_any.reset(
1750 jni->NewObjectA(
1751 m_jni_info->m_class_Any,
1752 m_jni_info->m_ctor_Any_with_Type_Object, args ) );
1753 jni.ensure_no_exception();
1754 break;
1756 default:
1757 break;
1759 break;
1761 case typelib_TypeClass_INTERFACE:
1763 uno_Interface * pUnoI = (uno_Interface *)pAny->pReserved;
1764 if (is_XInterface( pAny->pType ))
1766 if (0 != pUnoI)
1768 jo_any.reset(
1769 map_to_java(
1770 jni, pUnoI,
1771 m_jni_info->m_XInterface_type_info ) );
1773 // else: empty XInterface ref maps to null-ref
1775 else
1777 JNI_interface_type_info const * iface_info =
1778 static_cast< JNI_interface_type_info const * >(
1779 m_jni_info->get_type_info( jni, pAny->pType ) );
1780 if (0 != pUnoI)
1782 jo_any.reset( map_to_java( jni, pUnoI, iface_info ) );
1784 // box up in com.sun.star.uno.Any
1785 jvalue args[ 2 ];
1786 args[ 0 ].l = iface_info->m_type;
1787 args[ 1 ].l = jo_any.get();
1788 jo_any.reset(
1789 jni->NewObjectA(
1790 m_jni_info->m_class_Any,
1791 m_jni_info->m_ctor_Any_with_Type_Object, args ) );
1792 jni.ensure_no_exception();
1794 break;
1796 case typelib_TypeClass_STRUCT:
1798 // Do not lose information about type arguments of instantiated
1799 // polymorphic struct types:
1800 OUString const & name = OUString::unacquired(
1801 &pAny->pType->pTypeName);
1802 OSL_ASSERT(!name.isEmpty());
1803 if (name[name.getLength() - 1] == '>')
1805 // Box up in com.sun.star.uno.Any:
1806 JLocalAutoRef jo_type(jni, create_type(jni, pAny->pType));
1807 jvalue java_data2;
1808 map_to_java(
1809 jni, &java_data2, pAny->pData, pAny->pType, 0, true,
1810 false);
1811 jo_any.reset(java_data2.l);
1812 jvalue args[2];
1813 args[0].l = jo_type.get();
1814 args[1].l = jo_any.get();
1815 jo_any.reset(
1816 jni->NewObjectA(
1817 m_jni_info->m_class_Any,
1818 m_jni_info->m_ctor_Any_with_Type_Object, args));
1819 jni.ensure_no_exception();
1820 break;
1822 // fall through
1824 default:
1826 jvalue java_data2;
1827 map_to_java(
1828 jni, &java_data2, pAny->pData, pAny->pType, 0,
1829 true /* in */, false /* no out */,
1830 true /* create integral wrappers */ );
1831 jo_any.reset( java_data2.l );
1832 break;
1835 #endif
1838 if (out_param)
1840 if (0 == java_data->l)
1842 java_data->l = jni->NewObjectArray(
1843 1, m_jni_info->m_class_Object, jo_any.get() );
1844 jni.ensure_no_exception();
1846 else
1848 jni->SetObjectArrayElement(
1849 (jobjectArray) java_data->l, 0, jo_any.get() );
1850 jni.ensure_no_exception();
1853 else
1855 java_data->l = jo_any.release();
1857 break;
1859 case typelib_TypeClass_ENUM:
1861 OUString const & type_name = OUString::unacquired( &type->pTypeName );
1862 OString class_name(
1863 OUStringToOString( type_name, RTL_TEXTENCODING_JAVA_UTF8 ) );
1864 JLocalAutoRef jo_enum_class(
1865 jni, find_class( jni, class_name.getStr() ) );
1867 JLocalAutoRef jo_enum( jni );
1868 if (in_param)
1870 // call static <enum_class>.fromInt( int )
1871 OStringBuffer sig_buf( 5 + class_name.getLength() );
1872 sig_buf.append( "(I)L" );
1873 sig_buf.append( class_name.replace( '.', '/' ) );
1874 sig_buf.append( ';' );
1875 OString sig( sig_buf.makeStringAndClear() );
1876 jmethodID method_id = jni->GetStaticMethodID(
1877 (jclass) jo_enum_class.get(), "fromInt", sig.getStr() );
1878 jni.ensure_no_exception();
1879 OSL_ASSERT( 0 != method_id );
1881 jvalue arg;
1882 arg.i = *(jint const *) uno_data;
1883 jo_enum.reset(
1884 jni->CallStaticObjectMethodA(
1885 (jclass) jo_enum_class.get(), method_id, &arg ) );
1886 jni.ensure_no_exception();
1888 if (out_param)
1890 if (0 == java_data->l)
1892 java_data->l = jni->NewObjectArray(
1893 1, (jclass) jo_enum_class.get(), jo_enum.get() );
1894 jni.ensure_no_exception();
1896 else
1898 jni->SetObjectArrayElement(
1899 (jobjectArray) java_data->l, 0, jo_enum.get() );
1900 jni.ensure_no_exception();
1903 else
1905 java_data->l = jo_enum.release();
1907 break;
1909 case typelib_TypeClass_STRUCT:
1910 case typelib_TypeClass_EXCEPTION:
1912 if (0 == info)
1913 info = m_jni_info->get_type_info( jni, type );
1914 JNI_compound_type_info const * comp_info =
1915 static_cast< JNI_compound_type_info const * >( info );
1917 JLocalAutoRef jo_comp( jni );
1918 if (in_param)
1920 if (typelib_TypeClass_EXCEPTION == type->eTypeClass)
1922 JLocalAutoRef jo_message(
1923 jni, ustring_to_jstring( jni, *(rtl_uString **)uno_data ) );
1924 jvalue arg;
1925 arg.l = jo_message.get();
1926 jo_comp.reset(
1927 jni->NewObjectA(
1928 comp_info->m_class, comp_info->m_exc_ctor, &arg ) );
1929 jni.ensure_no_exception();
1931 else
1933 jo_comp.reset( jni->AllocObject( comp_info->m_class ) );
1934 jni.ensure_no_exception();
1937 for ( JNI_compound_type_info const * linfo = comp_info;
1938 0 != linfo;
1939 linfo = static_cast< JNI_compound_type_info const * >(
1940 linfo->m_base ) )
1942 typelib_CompoundTypeDescription * comp_td =
1943 (typelib_CompoundTypeDescription *)linfo->m_td.get();
1944 typelib_TypeDescriptionReference ** ppMemberTypeRefs =
1945 comp_td->ppTypeRefs;
1946 sal_Int32 * pMemberOffsets = comp_td->pMemberOffsets;
1947 bool polymorphic
1948 = comp_td->aBase.eTypeClass == typelib_TypeClass_STRUCT
1949 && reinterpret_cast< typelib_StructTypeDescription * >(
1950 comp_td)->pParameterizedTypes != 0;
1951 for ( sal_Int32 nPos = comp_td->nMembers; nPos--; )
1953 jfieldID field_id = linfo->m_fields[ nPos ];
1954 if (0 != field_id)
1956 void const * p =
1957 (char const *)uno_data + pMemberOffsets[ nPos ];
1958 typelib_TypeDescriptionReference * member_type =
1959 ppMemberTypeRefs[ nPos ];
1960 bool parameterizedType = polymorphic
1961 && (reinterpret_cast<
1962 typelib_StructTypeDescription * >(comp_td)->
1963 pParameterizedTypes[nPos]);
1964 switch (member_type->eTypeClass)
1966 case typelib_TypeClass_CHAR:
1967 if (parameterizedType) {
1968 jvalue arg;
1969 arg.c = *(jchar const *) p;
1970 JLocalAutoRef jo(
1971 jni,
1972 jni->NewObjectA(
1973 m_jni_info->m_class_Character,
1974 m_jni_info->m_ctor_Character_with_char,
1975 &arg ) );
1976 jni.ensure_no_exception();
1977 jni->SetObjectField(
1978 jo_comp.get(), field_id, jo.get() );
1979 } else {
1980 jni->SetCharField(
1981 jo_comp.get(),
1982 field_id, *(jchar const *) p );
1984 break;
1985 case typelib_TypeClass_BOOLEAN:
1986 if (parameterizedType) {
1987 jvalue arg;
1988 arg.z = *(jboolean const *) p;
1989 JLocalAutoRef jo(
1990 jni,
1991 jni->NewObjectA(
1992 m_jni_info->m_class_Boolean,
1993 m_jni_info->m_ctor_Boolean_with_boolean,
1994 &arg ) );
1995 jni.ensure_no_exception();
1996 jni->SetObjectField(
1997 jo_comp.get(), field_id, jo.get() );
1998 } else {
1999 jni->SetBooleanField(
2000 jo_comp.get(),
2001 field_id, *(jboolean const *) p );
2003 break;
2004 case typelib_TypeClass_BYTE:
2005 if (parameterizedType) {
2006 jvalue arg;
2007 arg.b = *(jbyte const *) p;
2008 JLocalAutoRef jo(
2009 jni,
2010 jni->NewObjectA(
2011 m_jni_info->m_class_Byte,
2012 m_jni_info->m_ctor_Byte_with_byte,
2013 &arg ) );
2014 jni.ensure_no_exception();
2015 jni->SetObjectField(
2016 jo_comp.get(), field_id, jo.get() );
2017 } else {
2018 jni->SetByteField(
2019 jo_comp.get(),
2020 field_id, *(jbyte const *) p );
2022 break;
2023 case typelib_TypeClass_SHORT:
2024 case typelib_TypeClass_UNSIGNED_SHORT:
2025 if (parameterizedType) {
2026 jvalue arg;
2027 arg.s = *(jshort const *) p;
2028 JLocalAutoRef jo(
2029 jni,
2030 jni->NewObjectA(
2031 m_jni_info->m_class_Short,
2032 m_jni_info->m_ctor_Short_with_short,
2033 &arg ) );
2034 jni.ensure_no_exception();
2035 jni->SetObjectField(
2036 jo_comp.get(), field_id, jo.get() );
2037 } else {
2038 jni->SetShortField(
2039 jo_comp.get(),
2040 field_id, *(jshort const *) p );
2042 break;
2043 case typelib_TypeClass_LONG:
2044 case typelib_TypeClass_UNSIGNED_LONG:
2045 if (parameterizedType) {
2046 jvalue arg;
2047 arg.i = *(jint const *) p;
2048 JLocalAutoRef jo(
2049 jni,
2050 jni->NewObjectA(
2051 m_jni_info->m_class_Integer,
2052 m_jni_info->m_ctor_Integer_with_int,
2053 &arg ) );
2054 jni.ensure_no_exception();
2055 jni->SetObjectField(
2056 jo_comp.get(), field_id, jo.get() );
2057 } else {
2058 jni->SetIntField(
2059 jo_comp.get(),
2060 field_id, *(jint const *) p );
2062 break;
2063 case typelib_TypeClass_HYPER:
2064 case typelib_TypeClass_UNSIGNED_HYPER:
2065 if (parameterizedType) {
2066 jvalue arg;
2067 arg.j = *(jlong const *) p;
2068 JLocalAutoRef jo(
2069 jni,
2070 jni->NewObjectA(
2071 m_jni_info->m_class_Long,
2072 m_jni_info->m_ctor_Long_with_long,
2073 &arg ) );
2074 jni.ensure_no_exception();
2075 jni->SetObjectField(
2076 jo_comp.get(), field_id, jo.get() );
2077 } else {
2078 jni->SetLongField(
2079 jo_comp.get(),
2080 field_id, *(jlong const *) p );
2082 break;
2083 case typelib_TypeClass_FLOAT:
2084 if (parameterizedType) {
2085 jvalue arg;
2086 arg.f = *(jfloat const *) p;
2087 JLocalAutoRef jo(
2088 jni,
2089 jni->NewObjectA(
2090 m_jni_info->m_class_Float,
2091 m_jni_info->m_ctor_Float_with_float,
2092 &arg ) );
2093 jni.ensure_no_exception();
2094 jni->SetObjectField(
2095 jo_comp.get(), field_id, jo.get() );
2096 } else {
2097 jni->SetFloatField(
2098 jo_comp.get(),
2099 field_id, *(jfloat const *) p );
2101 break;
2102 case typelib_TypeClass_DOUBLE:
2103 if (parameterizedType) {
2104 jvalue arg;
2105 arg.d = *(jdouble const *) p;
2106 JLocalAutoRef jo(
2107 jni,
2108 jni->NewObjectA(
2109 m_jni_info->m_class_Double,
2110 m_jni_info->m_ctor_Double_with_double,
2111 &arg ) );
2112 jni.ensure_no_exception();
2113 jni->SetObjectField(
2114 jo_comp.get(), field_id, jo.get() );
2115 } else {
2116 jni->SetDoubleField(
2117 jo_comp.get(),
2118 field_id, *(jdouble const *) p );
2120 break;
2121 case typelib_TypeClass_STRING: // string opt here
2123 JLocalAutoRef jo_string(
2124 jni, ustring_to_jstring(
2125 jni, *(rtl_uString * const *) p ) );
2126 jni->SetObjectField(
2127 jo_comp.get(), field_id, jo_string.get() );
2128 break;
2130 default:
2132 jvalue java_data2;
2133 map_to_java(
2134 jni, &java_data2, p, member_type, 0,
2135 true /* in */, false /* no out */ );
2136 JLocalAutoRef jo_obj( jni, java_data2.l );
2137 jni->SetObjectField(
2138 jo_comp.get(), field_id, jo_obj.get() );
2139 break;
2146 if (out_param)
2148 if (0 == java_data->l)
2150 java_data->l =
2151 jni->NewObjectArray( 1, comp_info->m_class, jo_comp.get() );
2152 jni.ensure_no_exception();
2154 else
2156 jni->SetObjectArrayElement(
2157 (jobjectArray) java_data->l, 0, jo_comp.get() );
2158 jni.ensure_no_exception();
2161 else
2163 java_data->l = jo_comp.release();
2165 break;
2167 case typelib_TypeClass_SEQUENCE:
2169 // xxx todo: possible opt for pure out sequences
2170 JLocalAutoRef jo_ar( jni );
2172 sal_Int32 nElements;
2173 uno_Sequence const * seq = 0;
2174 if (in_param)
2176 seq = *(uno_Sequence * const *)uno_data;
2177 nElements = seq->nElements;
2179 else
2181 nElements = 0;
2184 TypeDescr td( type );
2185 typelib_TypeDescriptionReference * element_type =
2186 ((typelib_IndirectTypeDescription *)td.get())->pType;
2188 switch (element_type->eTypeClass)
2190 case typelib_TypeClass_CHAR:
2191 jo_ar.reset( jni->NewCharArray( nElements ) );
2192 jni.ensure_no_exception();
2193 if (0 < nElements)
2195 jni->SetCharArrayRegion(
2196 (jcharArray) jo_ar.get(),
2197 0, nElements, (jchar *) seq->elements );
2198 jni.ensure_no_exception();
2200 break;
2201 case typelib_TypeClass_BOOLEAN:
2202 jo_ar.reset( jni->NewBooleanArray( nElements ) );
2203 jni.ensure_no_exception();
2204 if (0 < nElements)
2206 jni->SetBooleanArrayRegion(
2207 (jbooleanArray) jo_ar.get(),
2208 0, nElements, (jboolean *) seq->elements );
2209 jni.ensure_no_exception();
2211 break;
2212 case typelib_TypeClass_BYTE:
2213 jo_ar.reset( jni->NewByteArray( nElements ) );
2214 jni.ensure_no_exception();
2215 if (0 < nElements)
2217 jni->SetByteArrayRegion(
2218 (jbyteArray) jo_ar.get(),
2219 0, nElements, (jbyte *) seq->elements );
2220 jni.ensure_no_exception();
2222 break;
2223 case typelib_TypeClass_SHORT:
2224 case typelib_TypeClass_UNSIGNED_SHORT:
2225 jo_ar.reset( jni->NewShortArray( nElements ) );
2226 jni.ensure_no_exception();
2227 if (0 < nElements)
2229 jni->SetShortArrayRegion(
2230 (jshortArray) jo_ar.get(),
2231 0, nElements, (jshort *) seq->elements );
2232 jni.ensure_no_exception();
2234 break;
2235 case typelib_TypeClass_LONG:
2236 case typelib_TypeClass_UNSIGNED_LONG:
2237 jo_ar.reset( jni->NewIntArray( nElements ) );
2238 jni.ensure_no_exception();
2239 if (0 < nElements)
2241 jni->SetIntArrayRegion(
2242 (jintArray) jo_ar.get(),
2243 0, nElements, (jint *) seq->elements );
2244 jni.ensure_no_exception();
2246 break;
2247 case typelib_TypeClass_HYPER:
2248 case typelib_TypeClass_UNSIGNED_HYPER:
2249 jo_ar.reset( jni->NewLongArray( nElements ) );
2250 jni.ensure_no_exception();
2251 if (0 < nElements)
2253 jni->SetLongArrayRegion(
2254 (jlongArray) jo_ar.get(),
2255 0, nElements, (jlong *) seq->elements );
2256 jni.ensure_no_exception();
2258 break;
2259 case typelib_TypeClass_FLOAT:
2260 jo_ar.reset( jni->NewFloatArray( nElements ) );
2261 jni.ensure_no_exception();
2262 if (0 < nElements)
2264 jni->SetFloatArrayRegion(
2265 (jfloatArray) jo_ar.get(),
2266 0, nElements, (jfloat *) seq->elements );
2267 jni.ensure_no_exception();
2269 break;
2270 case typelib_TypeClass_DOUBLE:
2271 jo_ar.reset( jni->NewDoubleArray( nElements ) );
2272 jni.ensure_no_exception();
2273 if (0 < nElements)
2275 jni->SetDoubleArrayRegion(
2276 (jdoubleArray) jo_ar.get(),
2277 0, nElements, (jdouble *) seq->elements );
2278 jni.ensure_no_exception();
2280 break;
2281 case typelib_TypeClass_STRING:
2282 jo_ar.reset(
2283 jni->NewObjectArray(
2284 nElements, m_jni_info->m_class_String, 0 ) );
2285 jni.ensure_no_exception();
2286 if (in_param)
2288 rtl_uString * const * pp =
2289 (rtl_uString * const *) seq->elements;
2290 for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos )
2292 JLocalAutoRef jo_string(
2293 jni, ustring_to_jstring( jni, pp[ nPos ] ) );
2294 jni->SetObjectArrayElement(
2295 (jobjectArray) jo_ar.get(), nPos, jo_string.get() );
2296 jni.ensure_no_exception();
2299 break;
2300 case typelib_TypeClass_TYPE:
2301 jo_ar.reset(
2302 jni->NewObjectArray( nElements, m_jni_info->m_class_Type, 0 ) );
2303 jni.ensure_no_exception();
2304 if (in_param)
2306 typelib_TypeDescriptionReference * const * pp =
2307 (typelib_TypeDescriptionReference * const *)seq->elements;
2308 for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos )
2310 jvalue val;
2311 map_to_java(
2312 jni, &val, &pp[ nPos ], element_type, 0,
2313 true /* in */, false /* no out */ );
2314 JLocalAutoRef jo_element( jni, val.l );
2315 jni->SetObjectArrayElement(
2316 (jobjectArray) jo_ar.get(), nPos, jo_element.get() );
2317 jni.ensure_no_exception();
2320 break;
2321 case typelib_TypeClass_ANY:
2322 jo_ar.reset(
2323 jni->NewObjectArray(
2324 nElements, m_jni_info->m_class_Object, 0 ) );
2325 jni.ensure_no_exception();
2326 if (in_param)
2328 uno_Any const * p = (uno_Any const *)seq->elements;
2329 for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos )
2331 jvalue val;
2332 map_to_java(
2333 jni, &val, &p[ nPos ], element_type, 0,
2334 true /* in */, false /* no out */ );
2335 JLocalAutoRef jo_element( jni, val.l );
2336 jni->SetObjectArrayElement(
2337 (jobjectArray) jo_ar.get(), nPos, jo_element.get() );
2338 jni.ensure_no_exception();
2341 break;
2342 case typelib_TypeClass_ENUM:
2344 OUString const & element_type_name =
2345 OUString::unacquired( &element_type->pTypeName );
2346 OString class_name(
2347 OUStringToOString(
2348 element_type_name, RTL_TEXTENCODING_JAVA_UTF8 ) );
2349 JLocalAutoRef jo_enum_class(
2350 jni, find_class( jni, class_name.getStr() ) );
2352 jo_ar.reset(
2353 jni->NewObjectArray(
2354 nElements, (jclass) jo_enum_class.get(), 0 ) );
2355 jni.ensure_no_exception();
2357 if (0 < nElements)
2359 // call static <enum_class>.fromInt( int )
2360 OStringBuffer sig_buf( 5 + class_name.getLength() );
2361 sig_buf.append( "(I)L" );
2362 sig_buf.append( class_name.replace( '.', '/' ) );
2363 sig_buf.append( ';' );
2364 OString sig( sig_buf.makeStringAndClear() );
2365 jmethodID method_id = jni->GetStaticMethodID(
2366 (jclass) jo_enum_class.get(), "fromInt", sig.getStr() );
2367 jni.ensure_no_exception();
2368 OSL_ASSERT( 0 != method_id );
2370 sal_Int32 const * p = (sal_Int32 const *)seq->elements;
2371 for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos )
2373 jvalue arg;
2374 arg.i = p[ nPos ];
2375 JLocalAutoRef jo_enum(
2376 jni, jni->CallStaticObjectMethodA(
2377 (jclass) jo_enum_class.get(), method_id, &arg ) );
2378 jni.ensure_no_exception();
2379 jni->SetObjectArrayElement(
2380 (jobjectArray) jo_ar.get(), nPos, jo_enum.get() );
2381 jni.ensure_no_exception();
2384 break;
2386 case typelib_TypeClass_STRUCT:
2387 case typelib_TypeClass_EXCEPTION:
2389 JNI_type_info const * element_info =
2390 m_jni_info->get_type_info( jni, element_type );
2392 jo_ar.reset(
2393 jni->NewObjectArray( nElements, element_info->m_class, 0 ) );
2394 jni.ensure_no_exception();
2396 if (0 < nElements)
2398 char * p = (char *)seq->elements;
2399 sal_Int32 nSize = element_info->m_td.get()->nSize;
2400 for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos )
2402 jvalue val;
2403 map_to_java(
2404 jni, &val, p + (nSize * nPos),
2405 element_type, element_info,
2406 true /* in */, false /* no out */ );
2407 JLocalAutoRef jo_element( jni, val.l );
2408 jni->SetObjectArrayElement(
2409 (jobjectArray) jo_ar.get(), nPos, jo_element.get() );
2410 jni.ensure_no_exception();
2413 break;
2415 case typelib_TypeClass_SEQUENCE:
2417 OStringBuffer buf( 64 );
2418 JNI_info::append_sig(
2419 &buf, element_type, false /* use class XInterface */,
2420 false /* '.' instead of '/' */ );
2421 OString class_name( buf.makeStringAndClear() );
2422 JLocalAutoRef jo_seq_class(
2423 jni, find_class( jni, class_name.getStr() ) );
2425 jo_ar.reset(
2426 jni->NewObjectArray(
2427 nElements, (jclass) jo_seq_class.get(), 0 ) );
2428 jni.ensure_no_exception();
2430 if (0 < nElements)
2432 TypeDescr element_td( element_type );
2433 uno_Sequence ** elements = (uno_Sequence **) seq->elements;
2434 for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos )
2436 jvalue java_data2;
2437 map_to_java(
2438 jni, &java_data2, elements + nPos, element_type, 0,
2439 true /* in */, false /* no out */ );
2440 JLocalAutoRef jo_seq( jni, java_data2.l );
2441 jni->SetObjectArrayElement(
2442 (jobjectArray) jo_ar.get(), nPos, jo_seq.get() );
2443 jni.ensure_no_exception();
2446 break;
2448 case typelib_TypeClass_INTERFACE:
2450 JNI_interface_type_info const * iface_info =
2451 static_cast< JNI_interface_type_info const * >(
2452 m_jni_info->get_type_info( jni, element_type ) );
2454 jo_ar.reset(
2455 jni->NewObjectArray( nElements, iface_info->m_class, 0 ) );
2456 jni.ensure_no_exception();
2458 if (0 < nElements)
2460 uno_Interface ** pp = (uno_Interface **)seq->elements;
2461 for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos )
2463 uno_Interface * pUnoI = pp[ nPos ];
2464 if (0 != pUnoI)
2466 JLocalAutoRef jo_element(
2467 jni, map_to_java( jni, pUnoI, iface_info ) );
2468 jni->SetObjectArrayElement(
2469 (jobjectArray) jo_ar.get(),
2470 nPos, jo_element.get() );
2471 jni.ensure_no_exception();
2475 break;
2477 default:
2479 OUStringBuffer buf( 128 );
2480 buf.append( "[map_to_java():" );
2481 buf.append( OUString::unacquired( &type->pTypeName ) );
2482 buf.append( "] unsupported element type: " );
2483 buf.append( OUString::unacquired( &element_type->pTypeName ) );
2484 buf.append( jni.get_stack_trace() );
2485 throw BridgeRuntimeError( buf.makeStringAndClear() );
2489 if (out_param)
2491 if (0 == java_data->l)
2493 JLocalAutoRef jo_element_class(
2494 jni, jni->GetObjectClass( jo_ar.get() ) );
2495 if (in_param)
2497 java_data->l = jni->NewObjectArray(
2498 1, (jclass) jo_element_class.get(), jo_ar.get() );
2500 else
2502 java_data->l = jni->NewObjectArray(
2503 1, (jclass) jo_element_class.get(), 0 );
2505 jni.ensure_no_exception();
2507 else
2509 jni->SetObjectArrayElement(
2510 (jobjectArray) java_data->l, 0, jo_ar.get() );
2511 jni.ensure_no_exception();
2514 else
2516 java_data->l = jo_ar.release();
2518 break;
2520 case typelib_TypeClass_INTERFACE:
2522 JLocalAutoRef jo_iface( jni );
2523 if (in_param)
2525 uno_Interface * pUnoI = *(uno_Interface * const *)uno_data;
2526 if (0 != pUnoI)
2528 if (0 == info)
2529 info = m_jni_info->get_type_info( jni, type );
2530 JNI_interface_type_info const * iface_info =
2531 static_cast< JNI_interface_type_info const * >( info );
2532 jo_iface.reset( map_to_java( jni, pUnoI, iface_info ) );
2535 if (out_param)
2537 if (0 == java_data->l)
2539 if (0 == info)
2540 info = m_jni_info->get_type_info( jni, type );
2541 java_data->l =
2542 jni->NewObjectArray( 1, info->m_class, jo_iface.get() );
2543 jni.ensure_no_exception();
2545 else
2547 jni->SetObjectArrayElement(
2548 (jobjectArray) java_data->l, 0, jo_iface.get() );
2549 jni.ensure_no_exception();
2552 else
2554 java_data->l = jo_iface.release();
2556 break;
2558 default:
2560 OUStringBuffer buf( 128 );
2561 buf.append( "[map_to_java():" );
2562 buf.append( OUString::unacquired( &type->pTypeName ) );
2563 buf.appendAscii( "] unsupported type!" );
2564 buf.append( jni.get_stack_trace() );
2565 throw BridgeRuntimeError( buf.makeStringAndClear() );
2572 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */