1
2
3
4
5
6
7
8 package it.imolinfo.jbi4corba.webservice.runtime;
9
10 import it.imolinfo.jbi4corba.Logger;
11 import it.imolinfo.jbi4corba.LoggerFactory;
12 import it.imolinfo.jbi4corba.exception.Jbi4CorbaRuntimeException;
13 import it.imolinfo.jbi4corba.jbi.Messages;
14 import it.imolinfo.jbi4corba.jbi.component.Jbi4CorbaSUManager;
15 import it.imolinfo.jbi4corba.jbi.endpoint.Jbi4CorbaEndpoint;
16 import it.imolinfo.jbi4corba.jbi.endpoint.ProviderEndpoint;
17 import it.imolinfo.jbi4corba.utils.HelperEPRUtils;
18 import it.imolinfo.jbi4corba.webservice.descriptor.ProviderServiceDescriptor;
19 import it.imolinfo.jbi4corba.webservice.generator.AnyType;
20 import it.imolinfo.jbi4corba.webservice.generator.AnyTypeWrapper;
21 import it.imolinfo.jbi4corba.webservice.generator.InterfaceType;
22 import it.imolinfo.jbi4corba.webservice.generator.MethodSignature;
23 import it.imolinfo.jbi4corba.webservice.generator.Param;
24 import it.imolinfo.jbi4corba.webservice.generator.SearchedType;
25 import it.imolinfo.jbi4corba.webservice.generator.TypeUtils;
26 import it.imolinfo.jbi4corba.webservice.generator.UnionType;
27 import it.imolinfo.jbi4corba.webservice.generator.UnionTypeUtils;
28 import it.imolinfo.jbi4corba.webservice.generator.typedef.TypeDef;
29 import it.imolinfo.jbi4corba.webservice.generator.typedef.TypeDefUtil;
30
31 import java.lang.reflect.Array;
32 import java.lang.reflect.Field;
33 import java.lang.reflect.InvocationTargetException;
34 import java.lang.reflect.Method;
35 import java.lang.reflect.Modifier;
36 import java.math.BigDecimal;
37 import java.math.BigInteger;
38 import java.net.URLClassLoader;
39 import java.util.ArrayList;
40 import java.util.Arrays;
41 import java.util.HashSet;
42 import java.util.List;
43 import java.util.Set;
44
45 import javax.xml.namespace.QName;
46 import javax.xml.ws.Holder;
47 import javax.xml.ws.wsaddressing.W3CEndpointReference;
48 import javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder;
49
50 import org.apache.commons.lang.ArrayUtils;
51 import org.apache.commons.lang.builder.ToStringBuilder;
52 import org.omg.CORBA.Any;
53 import org.omg.CORBA.AnySeqHelper;
54 import org.omg.CORBA.BooleanSeqHelper;
55 import org.omg.CORBA.CharSeqHelper;
56 import org.omg.CORBA.DoubleSeqHelper;
57 import org.omg.CORBA.FloatSeqHelper;
58 import org.omg.CORBA.LongLongSeqHelper;
59 import org.omg.CORBA.LongSeqHelper;
60 import org.omg.CORBA.ORB;
61 import org.omg.CORBA.OctetSeqHelper;
62 import org.omg.CORBA.ShortSeqHelper;
63 import org.omg.CORBA.StringSeqHelper;
64 import org.omg.CORBA.TCKind;
65 import org.omg.CORBA.TypeCode;
66 import org.omg.CORBA.ULongLongSeqHelper;
67 import org.omg.CORBA.ULongSeqHelper;
68 import org.omg.CORBA.UShortSeqHelper;
69 import org.omg.CORBA.WCharSeqHelper;
70 import org.omg.CORBA.WStringSeqHelper;
71 import org.omg.CORBA.TypeCodePackage.BadKind;
72 import org.omg.CORBA.portable.InputStream;
73
74
75
76
77
78 public class CorbaTransformationUtils {
79
80
81
82
83 private static final Logger LOG = LoggerFactory.getLogger(CorbaTransformationUtils.class);
84
85
86
87 private static final Messages MESSAGES = Messages.getMessages(CorbaTransformationUtils.class);
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107 public static Object changeFromCorbaToServiceObject(Object corbaObject,
108 RuntimeInformation runtimeInfo, Class objectType)
109 throws SecurityException, IllegalArgumentException,
110 ClassNotFoundException, NoSuchFieldException,
111 IllegalAccessException, InvocationTargetException,
112 InstantiationException, NoSuchMethodException {
113
114 if (corbaObject == null) {
115 return null;
116 }
117
118 Object crbObject = corbaObject;
119
120 Object serviceObject = null;
121 int dimensions[] = null;
122 LOG.debug("ObjectType ==>" + objectType);
123
124 if (TypeUtils.isPrimitive(objectType.getName()) || TypeUtils.isJavaType(objectType.getName()) || TypeUtils.isPrimitiveParamSign(objectType.getName())) {
125 return corbaObject;
126 }
127
128 if (TypeUtils.isEnumType(objectType, runtimeInfo.getAllEnumTypes().keySet())) {
129 return transformEnumType(corbaObject, runtimeInfo.getCorbaClassLoader(),
130 runtimeInfo.getServiceClassLoader());
131 }
132
133 boolean returnTypeIsArray = corbaObject.getClass().isArray();
134 if (returnTypeIsArray) {
135 dimensions = TypeUtils.getObjectDimensions(corbaObject);
136 LOG.debug("ISARRAY" + corbaObject.getClass().getName());
137
138 }
139
140 LOG.debug(runtimeInfo.getAllCorbaTypes().toString());
141
142 SearchedType sType = TypeUtils.isSearchedTypeAll(TypeUtils.getTypeNameWithoutBrackets(objectType), false, runtimeInfo.getAllCorbaTypes());
143 if (sType == null) {
144 if (AnyType.isAnyType(TypeUtils.getTypeNameWithoutBrackets(objectType))) {
145 sType = new AnyType();
146 }
147 }
148 if (sType != null) {
149
150
151 if (sType instanceof UnionType) {
152 String utWrapper = sType.getTypeName() + "Wrapper";
153 Class utWrapperClass = runtimeInfo.getServiceClassLoader().loadClass(utWrapper);
154 if (returnTypeIsArray) {
155 serviceObject = Array.newInstance(utWrapperClass,
156 dimensions);
157 } else {
158 serviceObject = utWrapperClass.newInstance();
159 }
160 transformFromCorbaType(serviceObject, sType, crbObject,
161 runtimeInfo, true, null, null);
162 }
163 if (sType instanceof InterfaceType) {
164
165 serviceObject = objectToEPR(crbObject, runtimeInfo.getJbi4CorbaEndpoint(), objectType);
166 }
167 if (sType instanceof AnyType) {
168 AnyTypeWrapper anyWr = new AnyTypeWrapper();
169 transformFromCorbaType(anyWr, sType, crbObject, runtimeInfo,
170 true, null, null);
171 serviceObject = anyWr.getValue();
172 }
173 } else {
174
175 if (returnTypeIsArray) {
176 serviceObject = Array.newInstance(
177 runtimeInfo.getServiceClassLoader().loadClass(
178 TypeUtils.getTypeNameWithoutBrackets(objectType)),
179 dimensions);
180 } else {
181 serviceObject = runtimeInfo.getServiceClassLoader().loadClass(objectType.getName()).newInstance();
182 }
183 LOG.debug("Modified Object===>" + serviceObject.getClass());
184 LOG.debug("Orig Object===>" + crbObject.getClass());
185 LOG.debug("Modified Object===>" + serviceObject.getClass().getClassLoader());
186 LOG.debug("Orig Object===>" + crbObject.getClass().getClassLoader());
187 buildServiceObjectfromCorbaObject(serviceObject, crbObject, runtimeInfo);
188 }
189 return serviceObject;
190 }
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209 public static Object[] changeFromServiceToCorbaObjects(Object[] serviceParams,
210 RuntimeInformation runtimeInfo, MethodSignature methodSignature)
211 throws ClassNotFoundException, InstantiationException,
212 IllegalAccessException, SecurityException, NoSuchFieldException,
213 IllegalArgumentException, InvocationTargetException,
214 NoSuchMethodException {
215 int idx = 0;
216 Object[] corbaParams = new Object[serviceParams.length];
217 for (Param paramSig : methodSignature.getParameters()) {
218
219 LOG.debug("RecursiveInvokationAdapter Params ==>" + serviceParams.length);
220 LOG.debug(" Paramsig ==>" + paramSig.toString());
221 LOG.debug(" Paramsig ==>" + paramSig.getName());
222 LOG.debug(" Paramsig ==>" + paramSig.getTypeName());
223 LOG.debug(" OriginalClassLoader==>" + runtimeInfo.getCorbaClassLoader());
224 LOG.debug("Params ClassLoader" + serviceParams.getClass().getClassLoader());
225 if (paramSig.isHolder()) {
226
227 corbaParams[idx] = serviceParams[idx];
228
229 } else {
230 corbaParams[idx] = changeFromServiceToCorbaObject(serviceParams[idx], runtimeInfo, paramSig.getType());
231 }
232 idx++;
233 }
234
235 return corbaParams;
236 }
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256 public static Object[] changeFromCorbaToServiceObjects(Object[] corbaParams,
257 RuntimeInformation runtimeInfo, MethodSignature methodSignature)
258 throws ClassNotFoundException, InstantiationException,
259 IllegalAccessException, SecurityException, NoSuchFieldException,
260 IllegalArgumentException, InvocationTargetException,
261 NoSuchMethodException {
262 int idx = 0;
263 Object[] serviceParams = new Object[corbaParams.length];
264 for (Param paramSig : methodSignature.getParameters()) {
265
266 Object serviceObject = null;
267 int dimensions[] = null;
268
269 LOG.debug("ObjectType ==>" + paramSig.getType());
270
271 if (paramSig.isHolder()) {
272
273 serviceParams[idx] = corbaParams[idx];
274 } else {
275 serviceParams[idx] = changeFromCorbaToServiceObject(corbaParams[idx], runtimeInfo, paramSig.getType());
276 }
277 idx++;
278 }
279
280 return serviceParams;
281 }
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301 public static Object changeFromServiceToCorbaObject(Object serviceObject,
302 RuntimeInformation runtimeInfo, Class objectType)
303 throws SecurityException, IllegalArgumentException,
304 ClassNotFoundException, NoSuchFieldException,
305 IllegalAccessException, InvocationTargetException,
306 InstantiationException, NoSuchMethodException {
307
308 if (serviceObject == null) {
309 return null;
310 }
311
312 if (TypeUtils.isPrimitive(objectType.getName()) || TypeUtils.isJavaType(objectType.getName()) || TypeUtils.isPrimitiveParamSign(objectType.getName())) {
313 return serviceObject;
314 } else if (TypeUtils.isEnumType(objectType, runtimeInfo.getAllEnumTypes().keySet())) {
315 return transformEnumType(serviceObject, runtimeInfo.getServiceClassLoader(), runtimeInfo.getCorbaClassLoader());
316 } else {
317
318
319 Class corbaClass = null;
320 if (AnyType.isAnyType(TypeUtils.getTypeNameWithoutBrackets(objectType))) {
321 corbaClass = Any.class;
322 } else {
323 corbaClass = runtimeInfo.getCorbaClassLoader().loadClass(
324 TypeUtils.getTypeNameWithoutBrackets(objectType));
325 }
326 if (LOG.isDebugEnabled()) {
327 if (serviceObject == null) {
328 LOG.debug(" =========> SERVICE OBJECT NULL <========");
329 }
330 }
331
332
333
334
335 LOG.debug(" ====>" + serviceObject.getClass().getName());
336 LOG.debug(" ====>" + serviceObject.getClass().getClassLoader());
337
338 LOG.debug("OriginalClass ==>" + corbaClass.toString());
339 LOG.debug("ModifiedClass ==>" + serviceObject.toString());
340
341 Object crbObject = null;
342
343 if (serviceObject.getClass().isArray()) {
344 if (AnyType.isAnyType(TypeUtils.getTypeNameWithoutBrackets(objectType))) {
345 LOG.debug("IS ANY, we have to put an array inside an ANY");
346
347 crbObject = runtimeInfo.getOrb().create_any();
348 } else {
349 int dimentions[] = TypeUtils.getObjectDimensions(serviceObject);
350 crbObject = Array.newInstance(corbaClass, dimentions);
351 }
352
353 } else {
354 if (AnyType.isAnyType(TypeUtils.getTypeNameWithoutBrackets(objectType))) {
355 crbObject = runtimeInfo.getOrb().create_any();
356 } else {
357 try {
358 crbObject = corbaClass.newInstance();
359 } catch (InstantiationException e) {
360 LOG.debug("errore istanziando corba object", e);
361 }
362 }
363 }
364
365 LOG.debug("OrigiObject ==>" + crbObject);
366
367 boolean isArray = objectType.isArray();
368 LOG.debug("objectType.isArray() ==>" + isArray);
369 LOG.debug("objectType.getName() ==>" + objectType.getName());
370
371 SearchedType ut = TypeUtils.isSearchedTypeAll(objectType.getName(), isArray,
372 runtimeInfo.getAllCorbaTypes());
373
374 LOG.debug("ut: ==>" + ut);
375 if (ut == null) {
376 if (AnyType.isAnyType(TypeUtils.getTypeNameWithoutBrackets(objectType))) {
377 ut = new AnyType();
378 }
379 }
380 if (ut != null) {
381
382 LOG.debug("Transform=====>" + crbObject);
383 LOG.debug("CLASSLOADER=====>" + serviceObject.getClass().getClassLoader());
384
385 if (ut instanceof InterfaceType) {
386 String ior = null;
387 if (serviceObject != null && serviceObject instanceof W3CEndpointReference) {
388 W3CEndpointReference epr = (W3CEndpointReference) serviceObject;
389
390 LOG.debug("Document Fragment EPR ===> " + epr.toString());
391 ior = HelperEPRUtils.readAddressFromEPR(epr.toString());
392 LOG.debug("IOR ===> " + ior);
393
394 }
395
396 LOG.debug("IOR ===> " + ior);
397
398
399
400
401 if (!ior.equals("")) {
402 Class helperClass = loadHelperbyName(
403 corbaClass.getName(),
404 runtimeInfo.getCorbaClassLoader());
405 crbObject = narrowObjbyIOR(helperClass,
406 ior, runtimeInfo.getOrb());
407 }
408 } else {
409 LOG.debug("ut before transformToCorbaType ==>" + ut);
410 transformToCorbaType(crbObject, ut, serviceObject,
411 runtimeInfo, true);
412 }
413 } else {
414
415 LOG.debug("Fill=====>" + crbObject);
416 LOG.debug("CLASSLOADER=====>" + serviceObject.getClass().getClassLoader());
417
418 if (TypeUtils.isPrimitive(crbObject.getClass().getName()) || TypeUtils.isJavaType(crbObject.getClass().getName()) || TypeUtils.isPrimitiveParamSign(crbObject.getClass().getName())) {
419 crbObject = serviceObject;
420 } else if (TypeUtils.isEnumType(crbObject.getClass(),
421 runtimeInfo.getAllEnumTypes().keySet())) {
422 crbObject = transformEnumType(serviceObject, runtimeInfo.getServiceClassLoader(), runtimeInfo.getCorbaClassLoader());
423 } else {
424 buildCorbaObjectfromServiceObject(crbObject, serviceObject,
425 runtimeInfo);
426 }
427 }
428 return crbObject;
429 }
430
431 }
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449 public static Object[] changeHoldersFromServiceToCorbaObjects(
450 MethodSignature methodSignature, List<Object> params,
451 RuntimeInformation runtimeInfo) throws InstantiationException,
452 IllegalAccessException, SecurityException, NoSuchFieldException,
453 ClassNotFoundException, IllegalArgumentException,
454 InvocationTargetException, NoSuchMethodException {
455
456
457
458
459
460
461
462
463 ArrayList<Object> corbaParams = new ArrayList<Object>();
464
465 for (int i = 0; i < methodSignature.getParameters().size(); i++) {
466 Param paramSig = (Param) methodSignature.getParameters().get(i);
467
468
469 Object value = null;
470 if (paramSig.isHolder()) {
471
472
473 Holder jaxwsHolder = (Holder) params.get(i);
474 if (jaxwsHolder.value == null) {
475 LOG.debug("Holder is Null!!!!");
476
477 if (paramSig.getHolderValueType().isArray()) {
478
479 value = Array.newInstance(paramSig.getType(), 0);
480 }
481 } else {
482 value = jaxwsHolder.value;
483 }
484 Object corbaHolder = null;
485 Object actualHolderValueObject = null;
486
487 Class corbaHolderType = runtimeInfo.getCorbaClassLoader().loadClass(paramSig.getHolderType().getName());
488
489 corbaHolder = corbaHolderType.newInstance();
490
491
492 Field corbaHolderValueField = corbaHolderType.getField("value");
493 corbaHolderValueField.setAccessible(true);
494
495 if (TypeUtils.isPrimitive(paramSig.getHolderValueType().getName()) || TypeUtils.isJavaType(paramSig.getHolderValueType().getName()) || TypeUtils.isPrimitiveParamSign(paramSig.getHolderValueType().getName())) {
496 LOG.debug("Holder value type is PRIMITIVE or JAVA class");
497 actualHolderValueObject = value;
498 } else if (TypeUtils.isEnumType(paramSig.getHolderValueType(),
499 runtimeInfo.getAllEnumTypes().keySet())) {
500 actualHolderValueObject = transformEnumType(value,
501 runtimeInfo.getServiceClassLoader(), runtimeInfo.getCorbaClassLoader());
502 } else {
503
504 String holderValueTypeStr = TypeUtils.getTypeNameWithoutBrackets(paramSig.getHolderValueType());
505 SearchedType sType = TypeUtils.isSearchedTypeAll(
506 holderValueTypeStr, false, runtimeInfo.getAllCorbaTypes());
507 if (AnyType.isAnyType(holderValueTypeStr)) {
508 sType = new AnyType();
509 }
510
511
512
513
514
515
516 if (sType instanceof InterfaceType) {
517 String ior = null;
518 if (value instanceof W3CEndpointReference && value != null) {
519 W3CEndpointReference epr = (W3CEndpointReference) value;
520
521 LOG.debug("Document Fragment EPR ===> " + epr.toString());
522 ior = HelperEPRUtils.readAddressFromEPR(epr.toString());
523 LOG.debug("IOR ===> " + ior);
524
525 }
526
527 LOG.debug("IOR ===> " + ior);
528
529
530
531
532 if (!ior.equals("")) {
533 Class helperClass = loadHelperbyName(
534 corbaHolderValueField.getType().getName(),
535 runtimeInfo.getCorbaClassLoader());
536 actualHolderValueObject = narrowObjbyIOR(helperClass,
537 ior, runtimeInfo.getOrb());
538 }
539
540 } else {
541
542 if (sType instanceof AnyType) {
543 actualHolderValueObject = runtimeInfo.getOrb().create_any();
544 } else {
545 Class origHolderValueClass = runtimeInfo.getCorbaClassLoader().loadClass(
546 TypeUtils.getTypeNameWithoutBrackets(corbaHolderValueField.getType()));
547
548 if (value.getClass().isArray()) {
549
550
551 if (value == null) {
552 actualHolderValueObject = Array.newInstance(
553 origHolderValueClass, 0);
554 LOG.debug("!!!!!>>> Is Empty array: ");
555 }
556 else {
557 int dimentions[] = TypeUtils.getObjectDimensions(value);
558 actualHolderValueObject = Array.newInstance(
559 origHolderValueClass, dimentions);
560 if (LOG.isDebugEnabled()) {
561 LOG.debug("!!!!!>>> Is array: " + Arrays.toString(dimentions));
562 }
563 }
564
565 } else {
566 actualHolderValueObject = origHolderValueClass.newInstance();
567 }
568
569 }
570
571
572 LOG.debug("!!!!!!!!! >>>>>orig holder: " + actualHolderValueObject);
573 LOG.debug("!!!!!!!!! >>>>>mod holder: " + value);
574 if (sType != null) {
575 transformToCorbaType(actualHolderValueObject,
576 sType, value, runtimeInfo, true);
577 } else {
578 if (TypeUtils.isPrimitive(actualHolderValueObject.getClass().getName()) || TypeUtils.isJavaType(actualHolderValueObject.getClass().getName()) || TypeUtils.isPrimitiveParamSign(actualHolderValueObject.getClass().getName())) {
579 actualHolderValueObject = value;
580 } else if (TypeUtils.isEnumType(
581 actualHolderValueObject.getClass(),
582 runtimeInfo.getAllEnumTypes().keySet())) {
583 actualHolderValueObject = transformEnumType(
584 value, runtimeInfo.getServiceClassLoader(),
585 runtimeInfo.getCorbaClassLoader());
586 } else {
587 buildCorbaObjectfromServiceObject(
588 actualHolderValueObject, value,
589 runtimeInfo);
590 }
591 }
592 }
593 }
594 corbaHolderValueField.set(corbaHolder, actualHolderValueObject);
595
596 corbaParams.add(corbaHolder);
597
598 } else {
599 corbaParams.add(params.get(i));
600 }
601
602 }
603 return corbaParams.toArray();
604 }
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626 public static void changeHoldersFromCorbaToServiceObjects(
627 MethodSignature methodSignature, List<Object> params,
628 Object[] paramArrayAfterInvocation, RuntimeInformation runtimeInfo)
629 throws InstantiationException, IllegalAccessException,
630 SecurityException, NoSuchFieldException, IllegalArgumentException,
631 ClassNotFoundException, InvocationTargetException,
632 NoSuchMethodException {
633
634 int idx = 0;
635 for (int i = 0; i < methodSignature.getParameters().size(); i++) {
636 Param paramSig = (Param) methodSignature.getParameters().get(i);
637
638
639 if (paramSig.isHolder()) {
640
641
642 String holderValueTypeStr = TypeUtils.getTypeNameWithoutBrackets(paramSig.getHolderValueType());
643 SearchedType sType = TypeUtils.isSearchedTypeAll(
644 holderValueTypeStr, false, runtimeInfo.getAllCorbaTypes());
645 if (AnyType.isAnyType(holderValueTypeStr)) {
646 sType = new AnyType();
647 }
648
649
650
651 Field valueCorbaField = (paramArrayAfterInvocation[i]).getClass().getField("value");
652 Object value = valueCorbaField.get(paramArrayAfterInvocation[i]);
653 LOG.debug("corba holder value type: " + (value != null ? value.getClass() : "null value"));
654
655 Holder holder = (Holder) params.get(i);
656
657
658
659 if (value == null) {
660 holder.value = null;
661 continue;
662 }
663
664 if (sType != null) {
665 if (sType instanceof AnyType) {
666 AnyTypeWrapper anyWr = new AnyTypeWrapper();
667 transformFromCorbaType(anyWr, sType, value,
668 runtimeInfo, true, null, null);
669 holder.value = anyWr.getValue();
670 }
671
672
673 else if (sType instanceof InterfaceType) {
674
675 holder.value = objectToEPR(value, runtimeInfo.getJbi4CorbaEndpoint(), holder.getClass());
676 } else {
677 if (sType instanceof UnionType) {
678 Class srvClass = runtimeInfo.getServiceClassLoader().loadClass(
679 holderValueTypeStr + "Wrapper");
680 holder.value = srvClass.newInstance();
681 }
682 transformFromCorbaType(holder.value, sType, value,
683 runtimeInfo, true, null, null);
684 }
685 } else {
686 if (TypeUtils.isPrimitive(value.getClass().getName()) || TypeUtils.isJavaType(value.getClass().getName()) || TypeUtils.isPrimitiveParamSign(value.getClass().getName())) {
687 holder.value = value;
688 } else if (TypeUtils.isEnumType(value.getClass(),
689 runtimeInfo.getAllEnumTypes().keySet())) {
690 holder.value = transformEnumType(value, runtimeInfo.getCorbaClassLoader(), runtimeInfo.getServiceClassLoader());
691 } else {
692
693 if (value.getClass().isArray()) {
694 holder.value = Array.newInstance(
695 runtimeInfo.getServiceClassLoader().loadClass(TypeUtils.getTypeNameWithoutBrackets(value.getClass())), TypeUtils.getObjectDimensions(value));
696 } else {
697 holder.value = runtimeInfo.getServiceClassLoader().loadClass(TypeUtils.getTypeNameWithoutBrackets(value.getClass())).newInstance();
698 }
699 buildServiceObjectfromCorbaObject(holder.value, value,
700 runtimeInfo);
701 }
702
703 }
704 LOG.debug("Holder After---->" + holder.value.getClass());
705 LOG.debug("Holder After---->" + holder.value.toString());
706 paramArrayAfterInvocation[idx] = holder;
707 }
708 idx++;
709 }
710 }
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728 private static void buildServiceObjectfromCorbaObject(Object serviceObject,
729 Object corbaObject, RuntimeInformation runtimeInfo)
730 throws ClassNotFoundException, SecurityException,
731 NoSuchFieldException, IllegalArgumentException,
732 IllegalAccessException, InvocationTargetException,
733 InstantiationException, NoSuchMethodException {
734
735 LOG.debug("ORIG OBJECT ==>" + corbaObject);
736 LOG.debug("MODIFIED OBJECT ==>" + serviceObject);
737
738 if (serviceObject.getClass().isArray()) {
739 LOG.debug("!!!!>>>>>> IsARRAY");
740 Object[] corbaObjectArray = (Object[]) corbaObject;
741 Object[] serviceObjectArray = (Object[]) serviceObject;
742 LOG.debug("!!!!>>>>>> arrayLent: " + corbaObjectArray.length);
743 LOG.debug("!!!!>>>>>> component type: " + corbaObject.getClass().getComponentType());
744 for (int i = 0; i < corbaObjectArray.length; i++) {
745
746 if (corbaObjectArray[i].getClass().isArray()) {
747 serviceObjectArray[i] = Array.newInstance(
748 runtimeInfo.getServiceClassLoader().loadClass(
749 TypeUtils.getTypeNameWithoutBrackets(serviceObject.getClass())),
750 TypeUtils.getObjectDimensions(corbaObjectArray[i]));
751 } else if (TypeUtils.isEnumType(corbaObjectArray[i].getClass(),
752 runtimeInfo.getAllEnumTypes().keySet())) {
753
754 serviceObjectArray[i] = transformEnumType(corbaObjectArray[i], runtimeInfo.getCorbaClassLoader(),
755 runtimeInfo.getServiceClassLoader());
756
757 } else {
758 serviceObjectArray[i] = serviceObject.getClass().getComponentType().newInstance();
759 }
760
761
762 if (TypeUtils.isPrimitive(corbaObjectArray[i].getClass().getName()) || TypeUtils.isJavaType(corbaObjectArray[i].getClass().getName()) || TypeUtils.isPrimitiveParamSign(corbaObjectArray[i].getClass().getName())) {
763 serviceObjectArray[i] = corbaObjectArray[i];
764 } else if (TypeUtils.isEnumType(corbaObjectArray[i].getClass(),
765 runtimeInfo.getAllEnumTypes().keySet())) {
766 serviceObjectArray[i] = transformEnumType(
767 corbaObjectArray[i], runtimeInfo.getCorbaClassLoader(), runtimeInfo.getServiceClassLoader());
768 } else {
769 buildServiceObjectfromCorbaObject(serviceObjectArray[i],
770 corbaObjectArray[i], runtimeInfo);
771 }
772 LOG.debug("!!!!>>>>>> service component type object: " + serviceObjectArray[i]);
773 }
774
775 } else {
776
777 Class corbaClass = runtimeInfo.getCorbaClassLoader().loadClass(
778 TypeUtils.getTypeNameWithoutBrackets(corbaObject.getClass()));
779 Class serviceClass = runtimeInfo.getServiceClassLoader().loadClass(
780 TypeUtils.getTypeNameWithoutBrackets(serviceObject.getClass()));
781
782 List<Field> allCrbFields = new ArrayList<Field>();
783 getAllFields(corbaClass, allCrbFields);
784 Field[] crbFields = allCrbFields.toArray(new Field[allCrbFields.size()]);
785 LOG.debug("ORIGFIELDS LENGHT" + crbFields.length);
786 LOG.debug("MODIFIED OBJECT" + serviceObject);
787
788 LOG.debug("ORIG OBJECT" + corbaObject);
789 LOG.debug("MODIFIED CLASS" + serviceClass);
790 for (int i = 0; i < crbFields.length; i++) {
791 crbFields[i].setAccessible(true);
792 Field srvField = getField(serviceClass, crbFields[i].getName());
793 srvField.setAccessible(true);
794 LOG.debug("ORIG FIELD" + crbFields[i].getName());
795 LOG.debug("MOD FIELD" + srvField.getName());
796 LOG.debug("ORIG FIELD VALUE" + crbFields[i].get(corbaObject));
797
798 if (srvField.getName().equals(crbFields[i].getName())) {
799
800 LOG.debug(">>>>>>>>>>>" + crbFields[i].getType().getName());
801 if (TypeUtils.isPrimitive(crbFields[i].getType().getName()) || TypeUtils.isJavaType(crbFields[i].getType().getName()) || TypeUtils.isPrimitiveParamSign(crbFields[i].getType().getName())) {
802
803 LOG.debug("PRIMITIVE");
804 srvField.set(serviceObject, crbFields[i].get(corbaObject));
805
806 } else if (TypeUtils.isEnumType(crbFields[i].getType(),
807 runtimeInfo.getAllEnumTypes().keySet())) {
808 srvField.set(serviceObject, transformEnumType(
809 crbFields[i].get(corbaObject), runtimeInfo.getCorbaClassLoader(), runtimeInfo.getServiceClassLoader()));
810 }
811 else {
812
813 Class crbFieldClass = crbFields[i].getType();
814 LOG.debug("FieldType====>" + crbFieldClass.getName());
815 SearchedType sType = TypeUtils.isSearchedTypeAll(
816 TypeUtils.getTypeNameWithoutBrackets(crbFieldClass),
817 false, runtimeInfo.getAllCorbaTypes());
818 if (AnyType.isAnyType(TypeUtils.getTypeNameWithoutBrackets(crbFieldClass))) {
819 sType = new AnyType();
820 }
821 if (sType != null) {
822 LOG.debug("CORBA ");
823 if (sType instanceof InterfaceType) {
824
825
826
827
828 srvField.set(serviceObject, objectToEPR(crbFields[i].get(corbaObject), runtimeInfo.getJbi4CorbaEndpoint(), corbaClass));
829 } else {
830 Object srvFieldObj = null;
831 if (sType instanceof AnyType) {
832 AnyTypeWrapper anyWr = new AnyTypeWrapper();
833
834 transformFromCorbaType(anyWr, sType,
835 crbFields[i].get(corbaObject),
836 runtimeInfo, false, srvField,
837 serviceObject);
838
839 srvFieldObj = anyWr.getValue();
840 srvField.set(serviceObject, srvFieldObj);
841 } else {
842 if (crbFieldClass.isArray()) {
843 srvFieldObj = Array.newInstance(
844 runtimeInfo.getServiceClassLoader().loadClass(
845 TypeUtils.getTypeNameWithoutBrackets(srvField.getType())),
846 TypeUtils.getObjectDimensions(crbFields[i].get(corbaObject)));
847 } else {
848 srvFieldObj = runtimeInfo.getServiceClassLoader().loadClass(
849 srvField.getType().getName()).newInstance();
850
851 }
852 LOG.debug("Union field: " + srvField.getName() + " -> " + srvFieldObj);
853 transformFromCorbaType(srvFieldObj,
854 sType, crbFields[i].get(corbaObject),
855 runtimeInfo, false, srvField,
856 serviceObject);
857 }
858
859
860
861 }
862 } else {
863
864 LOG.debug("COMPLEX ");
865 LOG.debug(" TYPE==>" + crbFields[i].getType());
866
867
868 if (srvField.getType().getName().startsWith("[")) {
869 Object[] obj = (Object[]) crbFields[i].get(corbaObject);
870 LOG.debug("Modifield Fild Array Lenght" + obj.length);
871 srvField.set(serviceObject,
872 Array.newInstance(srvField.getType().getComponentType(),
873 obj.length));
874 } else {
875 srvField.set(serviceObject, srvField.getType().newInstance());
876 }
877
878 if (crbFields[i].get(corbaObject) == null) {
879 continue;
880 }
881 if (TypeUtils.isPrimitive(crbFields[i].get(
882 corbaObject).getClass().getName()) || TypeUtils.isJavaType(crbFields[i].get(
883 corbaObject).getClass().getName()) || TypeUtils.isPrimitiveParamSign(crbFields[i].get(corbaObject).getClass().getName())) {
884 srvField.set(serviceObject, crbFields[i].get(corbaObject));
885 } else if (TypeUtils.isEnumType(crbFields[i].get(
886 corbaObject).getClass(), runtimeInfo.getAllEnumTypes().keySet())) {
887 srvField.set(
888 serviceObject,
889 transformEnumType(
890 crbFields[i].get(corbaObject),
891 runtimeInfo.getCorbaClassLoader(),
892 runtimeInfo.getServiceClassLoader()));
893 } else {
894 buildServiceObjectfromCorbaObject(srvField.get(serviceObject), crbFields[i].get(corbaObject), runtimeInfo);
895 }
896 }
897 }
898
899 }
900 }
901
902 }
903 }
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925 private static void transformFromCorbaType(Object serviceObject,
926 SearchedType sType, Object corbaObject,
927 RuntimeInformation runtimeInfo, boolean isParam, Field parentField,
928 Object parentObject) throws SecurityException,
929 NoSuchFieldException, IllegalArgumentException,
930 IllegalAccessException, ClassNotFoundException,
931 InvocationTargetException, InstantiationException,
932 NoSuchMethodException {
933 LOG.debug("Transform From Corba Type");
934 if (serviceObject.getClass().isArray()) {
935 LOG.debug("!!!!>>>>>> IsARRAY");
936 Object[] corbaObjectArray = (Object[]) corbaObject;
937 Object[] serviceObjectArray = (Object[]) serviceObject;
938 LOG.debug("!!!!>>>>>> arrayLent: " + corbaObjectArray.length);
939 LOG.debug("!!!!>>>>>> component type: " + corbaObject.getClass().getComponentType());
940 for (int i = 0; i < corbaObjectArray.length; i++) {
941
942 serviceObjectArray[i] = serviceObject.getClass().getComponentType().newInstance();
943
944
945 transformFromCorbaType(serviceObjectArray[i], sType,
946 corbaObjectArray[i], runtimeInfo, isParam, parentField,
947 parentObject);
948 LOG.debug("!!!!>>>>>> component type object: " + corbaObjectArray[i]);
949 }
950
951 } else {
952 if (sType instanceof UnionType) {
953
954 Object fieldValue = serviceObject;
955 Field utWrapperField = null;
956
957 Class srvObject = runtimeInfo.getServiceClassLoader().loadClass(
958 TypeUtils.getTypeNameWithoutBrackets(serviceObject.getClass()));
959 utWrapperField = srvObject.getDeclaredField(UnionTypeUtils.UNION_WRAPPER_FIELD);
960 utWrapperField.setAccessible(true);
961
962
963
964
965 for (String fieldName : ((UnionType) sType).getTypeFieldNameList()) {
966 Class corbaObjectClass = runtimeInfo.getCorbaClassLoader().loadClass(
967 TypeUtils.getTypeNameWithoutBrackets(corbaObject.getClass()));
968 Method crbObjectMeth = corbaObjectClass.getMethod(fieldName);
969
970 try {
971 Object unionFieldObject = crbObjectMeth.invoke(corbaObject);
972 boolean isFound = false;
973 if (TypeUtils.isPrimitive(unionFieldObject.getClass().getName()) || TypeUtils.isJavaType(unionFieldObject.getClass().getName()) || TypeUtils.isPrimitiveParamSign(unionFieldObject.getClass().getName())) {
974 utWrapperField.set(serviceObject,
975 unionFieldObject);
976 isFound = true;
977 } else if (TypeUtils.isEnumType(unionFieldObject.getClass(), runtimeInfo.getAllEnumTypes().keySet())) {
978 utWrapperField.set(
979 serviceObject,
980 transformEnumType(
981 unionFieldObject,
982 runtimeInfo.getCorbaClassLoader(),
983 runtimeInfo.getServiceClassLoader()));
984 isFound = true;
985 } else {
986 if (AnyType.isAnyType(TypeUtils.getTypeNameWithoutBrackets(
987 unionFieldObject.getClass()))) {
988 fieldValue = new AnyTypeWrapper();
989 } else {
990 if (unionFieldObject.getClass().isArray()) {
991 fieldValue = Array.newInstance(
992 runtimeInfo.getServiceClassLoader().loadClass(
993 TypeUtils.getTypeNameWithoutBrackets(unionFieldObject.getClass())),
994 TypeUtils.getObjectDimensions(unionFieldObject));
995 } else {
996 fieldValue = runtimeInfo.getServiceClassLoader().loadClass(
997 unionFieldObject.getClass().getName()).newInstance();
998
999 }
1000 utWrapperField.set(serviceObject,
1001 fieldValue);
1002 }
1003 }
1004
1005 if (!isParam) {
1006 parentField.set(parentObject, serviceObject);
1007 }
1008 if (isFound) {
1009 break;
1010 }
1011 LOG.debug("!!!!>>>>>> union field inited: " + fieldName + " value: " + unionFieldObject);
1012 SearchedType searchedType = TypeUtils.isSearchedTypeAll(
1013 TypeUtils.getTypeNameWithoutBrackets(unionFieldObject.getClass()), false,
1014 runtimeInfo.getAllCorbaTypes());
1015 if (AnyType.isAnyType(TypeUtils.getTypeNameWithoutBrackets(
1016 unionFieldObject.getClass()))) {
1017 searchedType = new AnyType();
1018 }
1019 if (searchedType != null) {
1020
1021 transformFromCorbaType(fieldValue, searchedType,
1022 unionFieldObject, runtimeInfo, false,
1023 parentField, parentObject);
1024
1025 if (AnyType.isAnyType(TypeUtils.getTypeNameWithoutBrackets(
1026 unionFieldObject.getClass()))) {
1027
1028 utWrapperField.set(serviceObject,
1029 ((AnyTypeWrapper) fieldValue).getValue());
1030 if (!isParam) {
1031 parentField.set(parentObject,
1032 ((AnyTypeWrapper) fieldValue).getValue());
1033 }
1034 }
1035 } else {
1036 buildServiceObjectfromCorbaObject(fieldValue,
1037 unionFieldObject, runtimeInfo);
1038 }
1039 break;
1040
1041 } catch (InvocationTargetException ex) {
1042
1043
1044
1045 LOG.debug("EXCEPTION: " + ex.getClass() + " message: " + ex.getMessage());
1046 }
1047 }
1048 }
1049
1050
1051
1052
1053
1054
1055
1056 if (sType instanceof AnyType) {
1057 LOG.debug(">>>> Is Any:");
1058 if (corbaObject.getClass().isArray()) {
1059 Object result = Array.newInstance(Object.class, TypeUtils.getObjectDimensions(corbaObject));
1060 Object[] resultArray = (Object[]) result;
1061 Object[] corbaObjectArray = (Object[]) corbaObject;
1062 for (int i = 0; i < resultArray.length; i++) {
1063 AnyTypeWrapper anyWr = new AnyTypeWrapper();
1064 transformFromCorbaType(anyWr, sType, corbaObjectArray[i], runtimeInfo, isParam, parentField, parentObject);
1065 resultArray[i] = anyWr.getValue();
1066 }
1067 ((AnyTypeWrapper) serviceObject).setValue(resultArray);
1068 } else {
1069 Object result = transformFromAny((Any) corbaObject, null, null, runtimeInfo);
1070 ((AnyTypeWrapper) serviceObject).setValue(result);
1071 }
1072
1073 }
1074 }
1075 }
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092 private static Object transformFromAny(Any paramAny, TypeCode typeCode, InputStream anyInputStream,
1093 RuntimeInformation runtimeInfo) throws SecurityException,
1094 NoSuchFieldException, IllegalArgumentException,
1095 IllegalAccessException, ClassNotFoundException,
1096 InvocationTargetException, InstantiationException,
1097 NoSuchMethodException {
1098 Object localObject = null;
1099
1100
1101
1102
1103 if (typeCode == null) {
1104 try {
1105 String typeId = paramAny.type().id();
1106 TypeDef typeDef = TypeDefUtil.getTypeDefFromID(runtimeInfo.getTypeDefs(), typeId);
1107 if (LOG.isDebugEnabled()) {
1108 LOG.debug("ID found: " + typeId);
1109 }
1110 LOG.debug("TypeDef found: " + typeDef);
1111
1112 if (typeDef != null) {
1113 LOG.debug(">>>> typedef, value: " + paramAny);
1114 TypeCode localTypeCode1 = null;
1115 try {
1116 localTypeCode1 = paramAny.type().content_type();
1117 } catch (BadKind b) {
1118 LOG.debug("Not a type with an ID...see CORBA specs. Cannot be a typedef...");
1119 }
1120
1121 localObject = transformFromAny(paramAny, localTypeCode1, anyInputStream, runtimeInfo);
1122
1123 if (LOG.isDebugEnabled()) {
1124 LOG.debug("Found TypeDef of class: " + localObject.getClass().getName() + "with ID:" + typeId);
1125 }
1126
1127 Object obj = typeDef.getTypeDefObject(runtimeInfo.getServiceClassLoader(), localObject);
1128 return obj;
1129 }
1130 } catch (BadKind b) {
1131 LOG.debug("Not a type with an ID...see CORBA specs. Cannot be a typedef...");
1132 }
1133 }
1134
1135
1136 TCKind localTCKind = (typeCode == null) ? paramAny.type().kind() : typeCode.kind();
1137 if (localTCKind.equals(TCKind.tk_string)) {
1138 if (anyInputStream == null) {
1139 LOG.debug("REading string from any");
1140 localObject = paramAny.extract_string();
1141 } else {
1142 LOG.debug("REading string from inputstream");
1143 localObject = anyInputStream.read_string();
1144 }
1145 LOG.debug(">>>> type: string, value: " + localObject);
1146 } else if (localTCKind.equals(TCKind.tk_long)) {
1147 if (anyInputStream == null) {
1148 localObject = new Integer(paramAny.extract_long());
1149 } else {
1150 localObject = new Integer(anyInputStream.read_long());
1151 }
1152
1153 LOG.debug(">>>> type: long, value: " + localObject);
1154 } else if (localTCKind.equals(TCKind.tk_double)) {
1155 if (anyInputStream == null) {
1156 localObject = new Double(paramAny.extract_double());
1157 } else {
1158 localObject = new Double(anyInputStream.read_long());
1159 }
1160
1161 LOG.debug(">>>> type: double, value: " + localObject);
1162 } else if (localTCKind.equals(TCKind.tk_boolean)) {
1163 if (anyInputStream == null) {
1164 localObject = new Boolean(paramAny.extract_boolean());
1165 } else {
1166 localObject = new Boolean(anyInputStream.read_boolean());
1167 }
1168
1169 LOG.debug(">>>> type: boolean, value: " + localObject);
1170 } else if (localTCKind.equals(TCKind.tk_float)) {
1171 if (anyInputStream == null) {
1172 localObject = new Float(paramAny.extract_float());
1173 } else {
1174 localObject = new Float(anyInputStream.read_float());
1175 }
1176
1177 LOG.debug(">>>> type: float, value: " + localObject);
1178 } else if (localTCKind.equals(TCKind.tk_char)) {
1179 if (anyInputStream == null) {
1180 localObject = new Character(paramAny.extract_char());
1181 } else {
1182 localObject = new Character(anyInputStream.read_char());
1183 }
1184
1185 LOG.debug(">>>> type: char, value: " + localObject);
1186 } else if (localTCKind.equals(TCKind.tk_fixed)) {
1187 if (anyInputStream == null) {
1188 localObject = paramAny.extract_fixed();
1189 } else {
1190 localObject = anyInputStream.read_fixed();
1191 }
1192
1193 LOG.debug(">>>> type: fixed, value: " + localObject);
1194 } else if (localTCKind.equals(TCKind.tk_longdouble))
1195 {
1196 if (anyInputStream == null) {
1197 localObject = new Double(paramAny.extract_double());
1198 } else {
1199 localObject = new Double(anyInputStream.read_double());
1200 }
1201
1202 LOG.debug(">>>> type: longDouble, value: " + localObject);
1203 } else if (localTCKind.equals(TCKind.tk_longlong)) {
1204 if (anyInputStream == null) {
1205 localObject = new Long(paramAny.extract_longlong());
1206 } else {
1207 localObject = new Long(anyInputStream.read_longlong());
1208 }
1209
1210 LOG.debug(">>>> type: longlong, value: " + localObject);
1211 } else if (localTCKind.equals(TCKind.tk_null)) {
1212 localObject = null;
1213 LOG.debug(">>>> type: null, value: " + localObject);
1214 } else if (localTCKind.equals(TCKind.tk_octet)) {
1215 if (anyInputStream == null) {
1216 localObject = new Byte(paramAny.extract_octet());
1217 } else {
1218 localObject = new Byte(anyInputStream.read_octet());
1219 }
1220
1221 LOG.debug(">>>> type: octet, value: " + localObject);
1222 } else if (localTCKind.equals(TCKind.tk_short)) {
1223 if (anyInputStream == null) {
1224 localObject = new Short(paramAny.extract_short());
1225 } else {
1226 localObject = new Short(anyInputStream.read_short());
1227 }
1228
1229 LOG.debug(">>>> type: ushort, value: " + localObject);
1230 } else if (localTCKind.equals(TCKind.tk_ushort)) {
1231 if (anyInputStream == null) {
1232 localObject = new Short(paramAny.extract_ushort());
1233 } else {
1234 localObject = new Short(anyInputStream.read_ushort());
1235 }
1236
1237 LOG.debug(">>>> type: ushort, value: " + localObject);
1238 } else if (localTCKind.equals(TCKind.tk_ulong)) {
1239 if (anyInputStream == null) {
1240 localObject = new Long(paramAny.extract_ulong());
1241 } else {
1242 localObject = new Long(anyInputStream.read_ulong());
1243 }
1244
1245 LOG.debug(">>>> type: ushort, value: " + localObject);
1246 } else if (localTCKind.equals(TCKind.tk_ulonglong)) {
1247 if (anyInputStream == null) {
1248 localObject = new Long(paramAny.extract_ulonglong());
1249 } else {
1250 localObject = new Long(anyInputStream.read_ulonglong());
1251 }
1252
1253 LOG.debug(">>>> type: ushort, value: " + localObject);
1254 } else if (localTCKind.equals(TCKind.tk_wchar)) {
1255 if (anyInputStream == null) {
1256 localObject = new Character(paramAny.extract_wchar());
1257 } else {
1258 localObject = new Character(anyInputStream.read_wchar());
1259 }
1260
1261 LOG.debug(">>>> type: wchar, value: " + localObject);
1262 } else if (localTCKind.equals(TCKind.tk_wstring)) {
1263 if (anyInputStream == null) {
1264 localObject = new String(paramAny.extract_wstring());
1265 } else {
1266 localObject = new String(anyInputStream.read_wstring());
1267 }
1268
1269 LOG.debug(">>>> type: wstring, value: " + localObject);
1270 } else if (localTCKind.equals(TCKind.tk_any)) {
1271 if (anyInputStream == null) {
1272 localObject = transformFromAny(paramAny.extract_any(), null, null, runtimeInfo);
1273 } else {
1274 localObject = transformFromAny(anyInputStream.read_any(), null, null, runtimeInfo);
1275 }
1276
1277 LOG.debug(">>>> type: any, value: " + localObject);
1278 } else if ((localTCKind.equals(TCKind.tk_array))) {
1279
1280 LOG.debug(">>>> type: array, value: " + paramAny);
1281 TypeCode localTypeCode1 = null;
1282 try {
1283
1284
1285 if (typeCode == null) {
1286 localTypeCode1 = paramAny.type();
1287 } else {
1288 localTypeCode1 = typeCode;
1289 }
1290 List<Integer> idxs = new ArrayList<Integer>();
1291
1292 while (localTypeCode1.kind().equals(TCKind.tk_array)) {
1293 idxs.add(localTypeCode1.length());
1294 LOG.debug(">>>> type: array length: " + localTypeCode1);
1295 LOG.debug(">>>> type: array length: " + localTypeCode1.length());
1296 localTypeCode1 = localTypeCode1.content_type();
1297 }
1298
1299 LOG.debug(">>>> TYPE array(Content) " + localTypeCode1.kind().value());
1300
1301 Integer[] arrayIndexes = idxs.toArray(new Integer[]{});
1302 int[] arrayIndexesInt = new int[arrayIndexes.length];
1303 for (int i = 0; i < arrayIndexes.length; i++) {
1304 arrayIndexesInt[i] = arrayIndexes[i].intValue();
1305 }
1306 int totalArrayLentgh = 1;
1307 for (Integer leng : idxs) {
1308 totalArrayLentgh = totalArrayLentgh * leng;
1309 }
1310 if (LOG.isDebugEnabled()) {
1311 LOG.debug(">>>> type: array TOTAL length: " + totalArrayLentgh);
1312 LOG.debug("Array dimensions: " + ArrayUtils.toString(arrayIndexesInt));
1313 LOG.debug("Array first dimensions: " + arrayIndexes.length);
1314 }
1315
1316
1317 InputStream inpStream = paramAny.create_input_stream();
1318
1319 if (localTypeCode1.kind().equals(TCKind.tk_union) || localTypeCode1.kind().equals(TCKind.tk_struct) || localTypeCode1.kind().equals(TCKind.tk_value) || localTypeCode1.kind().equals(TCKind.tk_value_box) || localTypeCode1.kind().equals(TCKind.tk_enum) || localTypeCode1.kind().equals(TCKind.tk_except) || localTypeCode1.kind().equals(TCKind.tk_native) || localTypeCode1.kind().equals(TCKind.tk_abstract_interface)) {
1320
1321 localObject = transformFromAny(paramAny, localTypeCode1, inpStream, runtimeInfo);
1322
1323 } else {
1324 Object[] objects = new Object[totalArrayLentgh];
1325 for (int i = 0; i < totalArrayLentgh; i++) {
1326 LOG.debug("--->TransForm Array -->" + i);
1327
1328 Object object = transformFromAny(paramAny, localTypeCode1, inpStream, runtimeInfo);
1329 LOG.debug("Recovered form array: " + object);
1330 objects[i] = object;
1331 }
1332
1333
1334 Object myArray = Array.newInstance(Object.class, arrayIndexesInt);
1335 delinearizeArray(objects, myArray, 0);
1336
1337 localObject = myArray;
1338 }
1339
1340
1341 } catch (BadKind e) {
1342
1343 e.printStackTrace();
1344 }
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373 } else if (localTCKind.equals(TCKind.tk_sequence)) {
1374 try {
1375
1376 LOG.debug(">>>> type: sequence, value: " + paramAny);
1377
1378 TCKind localTCKind2 = paramAny.type().content_type().content_type().kind();
1379
1380 if (localTCKind2.equals(TCKind.tk_string)) {
1381 localObject = StringSeqHelper.extract(paramAny);
1382 LOG.debug(">>>> type: sequence - string, value: " + localObject);
1383 } else if (localTCKind2.equals(TCKind.tk_long)) {
1384 localObject = LongSeqHelper.extract(paramAny);
1385 LOG.debug(">>>> type: sequence - long, value: " + localObject);
1386 } else if (localTCKind2.equals(TCKind.tk_double)) {
1387 localObject = DoubleSeqHelper.extract(paramAny);
1388 LOG.debug(">>>> type: sequence - double, value: " + localObject);
1389 } else if (localTCKind2.equals(TCKind.tk_boolean)) {
1390 localObject = BooleanSeqHelper.extract(paramAny);
1391 LOG.debug(">>>> type: sequence - boolean, value: " + localObject);
1392 } else if (localTCKind2.equals(TCKind.tk_float)) {
1393 localObject = FloatSeqHelper.extract(paramAny);
1394 LOG.debug(">>>> type: sequence - float, value: " + localObject);
1395 } else if (localTCKind2.equals(TCKind.tk_char)) {
1396 localObject = CharSeqHelper.extract(paramAny);
1397 LOG.debug(">>>> type: sequence - char, value: " + localObject);
1398
1399 } else if (localTCKind2.equals(TCKind.tk_longdouble))
1400 {
1401 localObject = DoubleSeqHelper.extract(paramAny);
1402 LOG.debug(">>>> type: sequence - longDouble, value: " + localObject);
1403 } else if (localTCKind2.equals(TCKind.tk_longlong)) {
1404 localObject = LongLongSeqHelper.extract(paramAny);
1405 LOG.debug(">>>> type: sequence - longlong, value: " + localObject);
1406 } else if (localTCKind2.equals(TCKind.tk_null)) {
1407 localObject = null;
1408 LOG.debug(">>>> type: null, value: " + localObject);
1409 } else if (localTCKind2.equals(TCKind.tk_octet)) {
1410 localObject = OctetSeqHelper.extract(paramAny);
1411 LOG.debug(">>>> type: sequence - octet, value: " + localObject);
1412 } else if (localTCKind2.equals(TCKind.tk_short)) {
1413 localObject = ShortSeqHelper.extract(paramAny);
1414 LOG.debug(">>>> type: sequence - ushort, value: " + localObject);
1415 } else if (localTCKind2.equals(TCKind.tk_ushort)) {
1416 localObject = UShortSeqHelper.extract(paramAny);
1417 LOG.debug(">>>> type: sequence - ushort, value: " + localObject);
1418 } else if (localTCKind2.equals(TCKind.tk_ulong)) {
1419 localObject = ULongSeqHelper.extract(paramAny);
1420 LOG.debug(">>>> type: sequence - ushort, value: " + localObject);
1421 } else if (localTCKind2.equals(TCKind.tk_ulonglong)) {
1422 localObject = ULongLongSeqHelper.extract(paramAny);
1423 LOG.debug(">>>> type: sequence - ushort, value: " + localObject);
1424 } else if (localTCKind2.equals(TCKind.tk_wchar)) {
1425 localObject = WCharSeqHelper.extract(paramAny);
1426 LOG.debug(">>>> type: sequence - wchar, value: " + localObject);
1427 } else if (localTCKind2.equals(TCKind.tk_wstring)) {
1428 localObject = WStringSeqHelper.extract(paramAny);
1429 LOG.debug(">>>> type: sequence - wstring, value: " + localObject);
1430 } else if (localTCKind2.equals(TCKind.tk_any)) {
1431
1432 Any[] anys = AnySeqHelper.extract(paramAny);
1433
1434 Object[] arrayOfObject = new Object[anys.length];
1435
1436 for (int j = 0; j < anys.length; ++j) {
1437 arrayOfObject[j] = transformFromAny(
1438 anys[j], null, null, runtimeInfo);
1439 }
1440
1441 localObject = arrayOfObject;
1442 LOG.debug(">>>> type: sequence - any, value: " + localObject);
1443 } else {
1444 LOG.debug(">>>> type: sequence - complex, value: " + localObject);
1445
1446
1447 String corbaObjClassStr = null;
1448 /
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630 private static void buildCorbaObjectfromServiceObject(Object corbaObject,
1631 Object serviceObject, RuntimeInformation runtimeInfo)
1632 throws SecurityException, NoSuchFieldException,
1633 IllegalArgumentException, IllegalAccessException,
1634 InvocationTargetException, ClassNotFoundException,
1635 NoSuchMethodException, InstantiationException {
1636
1637 LOG.debug("Oirginal Object Class Loader ===>" + corbaObject.getClass().getClassLoader());
1638 LOG.debug("Modified Object Class Loader ===>" + serviceObject.getClass().getClassLoader());
1639
1640
1641 LOG.debug("!!!!>>>>>> origObject: " + corbaObject + " class: " + corbaObject.getClass() + " classloader: " + corbaObject.getClass().getClassLoader());
1642 LOG.debug("!!!!>>>>>> modifiedObject: " + serviceObject + " class: " + serviceObject.getClass() + " classloader: " + serviceObject.getClass().getClassLoader());
1643 if (corbaObject.getClass().isArray()) {
1644 LOG.debug("!!!!>>>>>> IsARRAY");
1645 Object[] corbaObjectArray = (Object[]) corbaObject;
1646 Object[] serviceObjectArray = (Object[]) serviceObject;
1647 LOG.debug("!!!!>>>>>> arrayLent: " + corbaObjectArray.length);
1648 LOG.debug("!!!!>>>>>> component type: " + corbaObject.getClass().getComponentType());
1649 for (int i = 0; i < corbaObjectArray.length; i++) {
1650 if (serviceObjectArray[i].getClass().isArray()) {
1651 LOG.debug("!!!!>>>>>> embeded arrayLent: " + ((Object[]) serviceObjectArray[i]).length);
1652 for (int j = 0; j < ((Object[]) serviceObjectArray[i]).length; j++) {
1653 LOG.debug("!!!!>>>>>> embeded array: value " + j + " - " + ((Object[]) serviceObjectArray[i])[j]);
1654 }
1655 corbaObjectArray[i] = Array.newInstance(
1656 runtimeInfo.getCorbaClassLoader().loadClass(
1657 TypeUtils.getTypeNameWithoutBrackets(corbaObject.getClass())),
1658 TypeUtils.getObjectDimensions(serviceObjectArray[i]));
1659 } else {
1660 corbaObjectArray[i] = corbaObject.getClass().getComponentType().newInstance();
1661 }
1662
1663 if (TypeUtils.isPrimitive(corbaObjectArray[i].getClass().getName()) || TypeUtils.isJavaType(corbaObjectArray[i].getClass().getName()) || TypeUtils.isPrimitiveParamSign(corbaObjectArray[i].getClass().getName())) {
1664 corbaObjectArray[i] = serviceObjectArray[i];
1665 }
1666
1667
1668
1669
1670
1671
1672 else {
1673 buildCorbaObjectfromServiceObject(corbaObjectArray[i],
1674 serviceObjectArray[i], runtimeInfo);
1675 }
1676 LOG.debug("!!!!>>>>>> component type object: " + corbaObjectArray[i]);
1677 }
1678
1679 } else {
1680
1681 Class corbaClass = runtimeInfo.getCorbaClassLoader().loadClass(
1682 TypeUtils.getTypeNameWithoutBrackets(corbaObject.getClass()));
1683 Class serviceClass = runtimeInfo.getServiceClassLoader().loadClass(
1684 TypeUtils.getTypeNameWithoutBrackets(serviceObject.getClass()));
1685
1686 List<Field> allCrbFields = new ArrayList<Field>();
1687 getAllFields(corbaClass, allCrbFields);
1688 Field[] crbFields = allCrbFields.toArray(new Field[allCrbFields.size()]);
1689 for (int i = 0; i < crbFields.length; i++) {
1690 crbFields[i].setAccessible(true);
1691 Field srvField = getField(serviceClass, crbFields[i].getName());
1692 srvField.setAccessible(true);
1693 if (srvField.get(serviceObject) == null) {
1694 LOG.warn("Warning: Field " + srvField.getName() + " from service object " + serviceObject + " is null");
1695 continue;
1696 }
1697
1698 LOG.debug("!!!!>>>>>> origFieldTypeName: " + crbFields[i].getType().getName());
1699 LOG.debug("!!!!>>>>>> modifField: " + srvField.getType().getName());
1700 if (crbFields[i].isAccessible()) {
1701 if (TypeUtils.isPrimitive(crbFields[i].getType().getName()) || TypeUtils.isJavaType(crbFields[i].getType().getName()) || TypeUtils.isPrimitiveParamSign(crbFields[i].getType().getName())) {
1702 LOG.debug("PRIMITIVE OR JAVATYPE");
1703 crbFields[i].set(corbaObject, srvField.get(serviceObject));
1704 } else if (TypeUtils.isEnumType(crbFields[i].getType(),
1705 runtimeInfo.getAllEnumTypes().keySet())) {
1706 crbFields[i].set(corbaObject, transformEnumType(srvField.get(serviceObject), runtimeInfo.getServiceClassLoader(), runtimeInfo.getCorbaClassLoader()));
1707
1708 }
1709 else {
1710
1711 String crbFieldTypeName = crbFields[i].getType().getName();
1712 SearchedType ut = TypeUtils.isSearchedTypeAll(
1713 crbFieldTypeName, crbFieldTypeName.startsWith("["), runtimeInfo.getAllCorbaTypes());
1714 if (AnyType.isAnyType(TypeUtils.getTypeNameWithoutBrackets(
1715 crbFields[i].getType()))) {
1716 ut = new AnyType();
1717 }
1718
1719
1720 if (ut != null) {
1721 LOG.debug("TRANSFORM==>2 *****************************************");
1722 LOG.debug("===>" + crbFields[i].toString());
1723 LOG.debug("===>" + corbaObject.toString());
1724 LOG.debug("===>" + crbFields[i].getGenericType());
1725 LOG.debug("===>" + crbFields[i].getName());
1726
1727 LOG.debug("===>" + ut.getClass());
1728 LOG.debug("===>" + serviceObject.toString());
1729 LOG.debug("*******************************************************");
1730
1731 if (ut instanceof InterfaceType) {
1732 String ior = null;
1733 if (srvField.get(serviceObject) instanceof W3CEndpointReference) {
1734 W3CEndpointReference epr = (W3CEndpointReference) srvField.get(serviceObject);
1735
1736 LOG.debug("Document Fragment EPR ===> " + epr.toString());
1737 ior = HelperEPRUtils.readAddressFromEPR(epr.toString());
1738 LOG.debug("IOR ===> " + ior);
1739
1740 }
1741
1742
1743 LOG.debug("IOR ===> " + ior);
1744
1745
1746
1747
1748
1749 Class helperClass = loadHelperbyName(crbFields[i].getType().getName(), runtimeInfo.getCorbaClassLoader());
1750 crbFields[i].set(corbaObject, narrowObjbyIOR(
1751 helperClass, ior, runtimeInfo.getOrb()));
1752
1753 } else {
1754
1755 Object fieldValue = null;
1756 if (AnyType.isAnyType(TypeUtils.getTypeNameWithoutBrackets(
1757 crbFields[i].getType()))) {
1758 if (crbFields[i].getType().isArray()) {
1759 fieldValue = new Any[((Object[]) srvField.get(serviceObject)).length];
1760
1761
1762
1763
1764
1765 } else {
1766 fieldValue = runtimeInfo.getOrb().create_any();
1767
1768 }
1769 } else {
1770 if (crbFields[i].getType().isArray()) {
1771 fieldValue = Array.newInstance(
1772 runtimeInfo.getCorbaClassLoader().loadClass(
1773 TypeUtils.getTypeNameWithoutBrackets(crbFields[i].getType())),
1774 TypeUtils.getObjectDimensions(serviceObject));
1775 } else {
1776 fieldValue = runtimeInfo.getCorbaClassLoader().loadClass(
1777 crbFields[i].getType().getName()).newInstance();
1778
1779 }
1780 }
1781 crbFields[i].set(corbaObject, fieldValue);
1782 transformToCorbaType(fieldValue, ut, srvField.get(serviceObject), runtimeInfo, false);
1783 }
1784 }
1785 else {
1786
1787 LOG.debug(" TYPE==>" + crbFields[i].getType());
1788 LOG.debug(" TYPE NAME==>" + crbFields[i].getType().getName());
1789 LOG.debug(" MODIFIED OBJECT==>" + srvField.getType().getName());
1790
1791
1792 if (crbFields[i].getType().getName().startsWith("[")) {
1793 Object[] obj = (Object[]) srvField.get(serviceObject);
1794 LOG.debug("Modifield Fild Array Lenght" + obj.length);
1795 LOG.debug(crbFields[i].getType().getComponentType().toString());
1796 crbFields[i].set(corbaObject, Array.newInstance(
1797 crbFields[i].getType().getComponentType(),
1798 obj.length));
1799 } else {
1800 crbFields[i].set(corbaObject, crbFields[i].getType().newInstance());
1801 }
1802 if (TypeUtils.isPrimitive(crbFields[i].get(corbaObject).getClass().getName()) || TypeUtils.isJavaType(crbFields[i].get(
1803 corbaObject).getClass().getName()) || TypeUtils.isPrimitiveParamSign(crbFields[i].get(corbaObject).getClass().getName())) {
1804 crbFields[i].set(corbaObject, srvField.get(serviceObject));
1805 } else if (TypeUtils.isEnumType(crbFields[i].get(
1806 corbaObject).getClass(), runtimeInfo.getAllEnumTypes().keySet())) {
1807 crbFields[i].set(corbaObject, transformEnumType(
1808 srvField.get(serviceObject), runtimeInfo.getServiceClassLoader(),
1809 runtimeInfo.getCorbaClassLoader()));
1810
1811 } else {
1812 buildCorbaObjectfromServiceObject(crbFields[i].get(corbaObject), srvField.get(serviceObject), runtimeInfo);
1813 }
1814 }
1815 }
1816 }
1817 }
1818 }
1819
1820 }
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840 private static void transformToCorbaType(Object corbaObject,
1841 SearchedType ut, Object serviceObject,
1842 RuntimeInformation runtimeInfo, boolean isParam)
1843 throws ClassNotFoundException, SecurityException,
1844 NoSuchFieldException, IllegalArgumentException,
1845 IllegalAccessException, InvocationTargetException,
1846 NoSuchMethodException, InstantiationException {
1847
1848 if (corbaObject.getClass().isArray()) {
1849 LOG.debug("!!!!>>>>>> IsARRAY");
1850 Object[] corbaObjectArray = (Object[]) corbaObject;
1851 Object[] serviceObjectArray = (Object[]) serviceObject;
1852 LOG.debug("!!!!>>>>>> arrayLent: " + corbaObjectArray.length);
1853 LOG.debug("!!!!>>>>>> modif arrayLent: " + serviceObjectArray.length);
1854 LOG.debug("!!!!>>>>>> component type: " + corbaObject.getClass().getComponentType());
1855 LOG.debug("!!!!>>>>>> modif component type: " + serviceObjectArray.getClass().getComponentType());
1856 for (int i = 0; i < corbaObjectArray.length; i++) {
1857 if (AnyType.isAnyType(corbaObject.getClass().getComponentType().getName())) {
1858 corbaObjectArray[i] = runtimeInfo.getOrb().create_any();
1859 } else {
1860 corbaObjectArray[i] = corbaObject.getClass().getComponentType().newInstance();
1861 }
1862 transformToCorbaType(corbaObjectArray[i], ut,
1863 serviceObjectArray[i], runtimeInfo, isParam);
1864 LOG.debug("!!!!>>>>>> component type object: " + corbaObjectArray[i]);
1865 }
1866
1867 } else {
1868
1869 if (ut instanceof UnionType) {
1870
1871 LOG.debug("!!!!!>>> Instance of uniontype");
1872 Object fieldValue = serviceObject;
1873
1874 String utWrapper = ut.getTypeName() + "Wrapper";
1875 Class utWrapperClass = runtimeInfo.getServiceClassLoader().loadClass(utWrapper);
1876
1877 Field utWrapperField = utWrapperClass.getDeclaredField(UnionTypeUtils.UNION_WRAPPER_FIELD);
1878 LOG.debug("utWrapperClassString: " + utWrapper + " utWrapperClass: " + utWrapperClass + " utWrapperField: " + utWrapperField);
1879 utWrapperField.setAccessible(true);
1880 fieldValue = utWrapperField.get(serviceObject);
1881 LOG.debug("!!!!!>>> Field type" + fieldValue.getClass() + " value: " + fieldValue);
1882
1883 LOG.debug("!!!!!>>> UnionFields: ");
1884 boolean fieldFound = false;
1885 String fieldAny = null;
1886 for (String fieldName : ((UnionType) ut).getTypeFieldNameList()) {
1887 Class fieldType = ((UnionType) ut).getFieldType(fieldName);
1888
1889
1890 if (fieldType != null) {
1891
1892 Class typeToCompare = fieldType;
1893 LOG.debug("!!!!!>>> Field type of union: " + fieldType);
1894
1895 Class primitiveJavaLangType = TypeUtils.getJavaLangClassPrimitive(fieldType.getName());
1896 if (primitiveJavaLangType != null) {
1897 typeToCompare = primitiveJavaLangType;
1898 }
1899 LOG.debug("!!!!!>>> Field type to compare: " + typeToCompare);
1900 if (fieldValue.getClass().equals(typeToCompare)) {
1901 LOG.debug("!!!!!>>> Field name: " + fieldName);
1902 Class corbaClass = runtimeInfo.getCorbaClassLoader().loadClass(
1903 TypeUtils.getTypeNameWithoutBrackets(corbaObject.getClass()));
1904 LOG.debug("!!!!!>>> CORBA class: " + corbaClass);
1905 Method methodForfieldToFill = corbaClass.getMethod(
1906 fieldName, fieldType);
1907 LOG.debug("!!!!!>>> methodForfieldToFill class: " + methodForfieldToFill);
1908 LOG.debug("!!!!!>>> fieldValue: " + fieldValue);
1909
1910 methodForfieldToFill.invoke(corbaObject, fieldValue);
1911 fieldFound = true;
1912 break;
1913
1914 } else {
1915 boolean isUnion = false;
1916 String fieldTypeStr = TypeUtils.getTypeNameWithoutBrackets(fieldType);
1917 String fieldValueTypeStr = TypeUtils.getTypeNameWithoutBrackets(fieldValue.getClass());
1918 LOG.debug("!!!!!>>> Field type str: " + fieldTypeStr);
1919 LOG.debug("!!!!!>>> Field Value type str: " + fieldValueTypeStr);
1920
1921 SearchedType st = TypeUtils.isSearchedTypeAll(
1922 fieldTypeStr, false, runtimeInfo.getAllCorbaTypes());
1923
1924 if (st == null && fieldTypeStr.endsWith("Wrapper")) {
1925 String tempFieldTypeStr = fieldTypeStr.substring(0, fieldTypeStr.length() - 7);
1926 st = TypeUtils.isSearchedTypeAll(
1927 tempFieldTypeStr, false, runtimeInfo.getAllCorbaTypes());
1928 if (st != null) {
1929 fieldTypeStr = tempFieldTypeStr;
1930 isUnion = true;
1931 }
1932 }
1933 if (AnyType.isAnyType(fieldTypeStr)) {
1934 st = new AnyType();
1935 fieldAny = fieldName;
1936 }
1937 if (st != null) {
1938 if (fieldValueTypeStr.equals("java.lang.Object") || isUnion) {
1939 LOG.debug("!!!!!>>> Is embeded anytype: " + st);
1940 Class corbaClass = runtimeInfo.getCorbaClassLoader().loadClass(
1941 TypeUtils.getTypeNameWithoutBrackets(corbaObject.getClass()));
1942 Class crbFieldClass = null;
1943 if (AnyType.isAnyType(fieldTypeStr)) {
1944 crbFieldClass = Any.class;
1945 } else {
1946 crbFieldClass = runtimeInfo.getCorbaClassLoader().loadClass(
1947 fieldTypeStr);
1948 }
1949
1950 Object fieldSTValue = null;
1951 if (fieldValue.getClass().isArray()) {
1952 if (AnyType.isAnyType(fieldTypeStr)) {
1953 fieldSTValue = new Any[((Object[]) fieldValue).length];
1954 } else {
1955 int dimentions[] = TypeUtils.getObjectDimensions(fieldValue);
1956 fieldSTValue = Array.newInstance(
1957 crbFieldClass, dimentions);
1958 LOG.debug("!!!!!>>> Is array: " + dimentions);
1959 }
1960 } else {
1961 if (AnyType.isAnyType(fieldTypeStr)) {
1962 fieldSTValue = runtimeInfo.getOrb().create_any();
1963 } else {
1964 fieldSTValue = fieldType.newInstance();
1965 }
1966 }
1967 transformToCorbaType(fieldSTValue, st, fieldValue,
1968 runtimeInfo, false);
1969 LOG.debug("!!!!!>>> Transformed: " + fieldSTValue);
1970 Method methodForfieldToFill = corbaClass.getMethod(
1971 fieldName, fieldSTValue.getClass());
1972 methodForfieldToFill.invoke(corbaObject,
1973 fieldSTValue);
1974 LOG.debug("!!!!!>>> Transformed full: " + corbaObject);
1975 fieldFound = true;
1976 }
1977 }
1978 }
1979 }
1980 }
1981
1982 if (!fieldFound && fieldAny != null) {
1983 LOG.debug("!!!!!>>>ANY in Union: " + fieldAny + " value: " + fieldValue);
1984 Class fieldType = ((UnionType) ut).getFieldType(fieldAny);
1985 Class corbaClass = runtimeInfo.getCorbaClassLoader().loadClass(
1986 TypeUtils.getTypeNameWithoutBrackets(corbaObject.getClass()));
1987 Method methodForfieldToFill = corbaClass.getMethod(
1988 fieldAny, fieldType);
1989
1990 methodForfieldToFill.invoke(corbaObject, transformToAny(fieldValue, null, runtimeInfo));
1991 }
1992 }
1993
1994 if (ut instanceof AnyType) {
1995
1996 LOG.debug("!!!!!>>> Is ANY type: Value " + serviceObject);
1997
1998 transformToAny(serviceObject, ((org.omg.CORBA.Any) corbaObject),
1999 runtimeInfo);
2000 }
2001 }
2002
2003 }
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022 public static Any transformToAny(Object serviceObject, Any any,
2023 RuntimeInformation runtimeInfo) throws ClassNotFoundException,
2024 SecurityException, IllegalArgumentException, NoSuchFieldException,
2025 IllegalAccessException, InvocationTargetException,
2026 NoSuchMethodException, InstantiationException {
2027 Any paramAny = runtimeInfo.getOrb().create_any();
2028 if (any != null) {
2029 paramAny = any;
2030 }
2031 if (serviceObject instanceof String) {
2032 paramAny.insert_string((String) serviceObject);
2033 } else if (serviceObject instanceof Long) {
2034 paramAny.insert_long(((Long) serviceObject).intValue());
2035 } else if (serviceObject instanceof Integer) {
2036 paramAny.insert_long(((Integer) serviceObject).intValue());
2037 } else if (serviceObject instanceof Double) {
2038 paramAny.insert_double(((Double) serviceObject).doubleValue());
2039 } else if (serviceObject instanceof Float) {
2040 paramAny.insert_float(((Float) serviceObject).floatValue());
2041 } else if (serviceObject instanceof Boolean) {
2042 paramAny.insert_boolean(((Boolean) serviceObject).booleanValue());
2043 } else if (serviceObject instanceof Character) {
2044 paramAny.insert_char(((Character) serviceObject).charValue());
2045 } else if (serviceObject instanceof Byte) {
2046 paramAny.insert_octet(((Byte) serviceObject).byteValue());
2047 LOG.debug(">>>> type: octet, value: " + serviceObject);
2048 } else if (serviceObject instanceof Short) {
2049 paramAny.insert_short(((Short) serviceObject).shortValue());
2050 LOG.debug(">>>> type: ushort, value: " + serviceObject);
2051 } else if (serviceObject instanceof BigInteger) {
2052 if (((BigInteger) serviceObject).toString().startsWith("-")) {
2053 paramAny.insert_string(((BigInteger) serviceObject).toString());
2054 } else {
2055 paramAny.insert_fixed(new BigDecimal((BigInteger) serviceObject));
2056 }
2057
2058 LOG.debug(">>>> type: BigInteger -> fixed, value: " + serviceObject);
2059 } else if (serviceObject instanceof BigDecimal) {
2060 if (((BigDecimal) serviceObject).toString().startsWith("-")) {
2061 paramAny.insert_string(((BigDecimal) serviceObject).toString());
2062 } else {
2063 paramAny.insert_fixed((BigDecimal) serviceObject);
2064 }
2065
2066 LOG.debug(">>>> type: BigInteger -> fixed, value: " + serviceObject);
2067
2068 } else {
2069 LOG.debug(">>>> type: Other type(complex?), value: " + serviceObject);
2070 LOG.debug(">>>> Service Object Class ----> " + serviceObject.getClass());
2071 String paramObjectTypeStr = TypeUtils.getTypeNameWithoutBrackets(serviceObject.getClass());
2072 int dimentions[] = null;
2073 boolean isArray = serviceObject.getClass().isArray();
2074 if (isArray) {
2075 dimentions = TypeUtils.getObjectDimensions(serviceObject);
2076 }
2077 Class corbaClass = null;
2078 Object serviceObj = null;
2079 boolean classFound = false;
2080
2081 for (Class type : runtimeInfo.getAllIDLTypes()) {
2082 if (LOG.isDebugEnabled()) {
2083 LOG.debug("****Search Class for Any assignement************************");
2084 LOG.debug("Check for type paramObjectTypeStr --->" + paramObjectTypeStr);
2085 LOG.debug("Check for type type.getName--->" + type.getName());
2086 }
2087 if (paramObjectTypeStr.equals(type.getName())) {
2088
2089 corbaClass = runtimeInfo.getCorbaClassLoader().loadClass(paramObjectTypeStr);
2090
2091 if (TypeUtils.isEnumType(corbaClass, runtimeInfo.getAllEnumTypes().keySet()) && !isArray) {
2092 LOG.debug("is Enum");
2093 serviceObj = transformEnumType(serviceObject, runtimeInfo.getServiceClassLoader(), runtimeInfo.getCorbaClassLoader());
2094 } else {
2095 if (isArray) {
2096 serviceObj = Array.newInstance(corbaClass, dimentions);
2097
2098 } else {
2099 serviceObj = corbaClass.newInstance();
2100 }
2101
2102 buildCorbaObjectfromServiceObject(serviceObj, serviceObject,
2103 runtimeInfo);
2104 }
2105 if (LOG.isDebugEnabled()) {
2106 LOG.debug(">>>> type: Complex, value: " + serviceObj);
2107 }
2108 classFound = true;
2109 break;
2110 }
2111 }
2112 if (!classFound) {
2113 SearchedType st = TypeUtils.isSearchedTypeAll(
2114 paramObjectTypeStr, false, runtimeInfo.getAllCorbaTypes());
2115
2116 if (st == null) {
2117 if (paramObjectTypeStr.endsWith("Wrapper")) {
2118
2119 paramObjectTypeStr = paramObjectTypeStr.substring(0, paramObjectTypeStr.length() - 7);
2120 st = TypeUtils.isSearchedTypeAll(
2121 paramObjectTypeStr, false, runtimeInfo.getAllCorbaTypes());
2122 }
2123 }
2124 if (st != null) {
2125 corbaClass = runtimeInfo.getCorbaClassLoader().loadClass(paramObjectTypeStr);
2126 if (isArray) {
2127 serviceObj = Array.newInstance(corbaClass, dimentions);
2128 } else {
2129 serviceObj = corbaClass.newInstance();
2130 }
2131
2132 transformToCorbaType(serviceObj, st, serviceObject,
2133 runtimeInfo, true);
2134 LOG.debug(">>>> type: CorbaType(union, interface), value: " + serviceObj);
2135 classFound = true;
2136 }
2137 }
2138 if (!classFound) {
2139
2140 LOG.debug(">>>>!!!! type: Unknown, value: " + serviceObject);
2141 } else {
2142 TypeUtils.encloseCorbaTypeInAny(paramAny, serviceObj, corbaClass, runtimeInfo, runtimeInfo.getTypeDefs());
2143 LOG.debug(">>>> ANY : " + paramAny);
2144 LOG.debug(">>>> ANY kind: " + paramAny.type().kind());
2145
2146 }
2147
2148 }
2149 return paramAny;
2150 }
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162 private static W3CEndpointReference objectToEPR(Object obj,
2163 Jbi4CorbaEndpoint jbi4corbaEndPoint, Class objectType) throws ClassNotFoundException {
2164
2165 Jbi4CorbaSUManager su = jbi4corbaEndPoint.getSuManager();
2166 ProviderServiceDescriptor serviceDesc = null;
2167 Set<String> keys = new HashSet<String>();
2168 Set<String> classes = new HashSet<String>();
2169 String className = null;
2170 ProviderEndpoint pes = null;
2171
2172
2173
2174 if (jbi4corbaEndPoint instanceof ProviderEndpoint) {
2175 pes = (ProviderEndpoint) jbi4corbaEndPoint;
2176 keys = pes.getServiceDescriptor().getIdToClassNameMap().keySet();
2177 }
2178
2179
2180 if (objectType.equals(org.omg.CORBA.Object.class)) {
2181
2182 if (obj instanceof org.omg.CORBA.Object) {
2183 for (String s : keys) {
2184 LOG.debug("Check class with name" + s);
2185 if (((org.omg.CORBA.Object) obj)._is_a(s)) {
2186 className = pes.getServiceDescriptor().getIdToClassNameMap().get(s);
2187
2188 className = className.substring(0, className.length() - 6);
2189
2190 if (LOG.isDebugEnabled()) {
2191 LOG.debug("----------------------------------------------------------------");
2192 LOG.debug("Object Is A -->" + className);
2193 LOG.debug("----------------------------------------------------------------");
2194 }
2195
2196 classes.add(className);
2197 }
2198 }
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223 className = "interface " + className;
2224 }
2225 } else {
2226 className = obj.getClass().getInterfaces()[0].toString();
2227 }
2228
2229 if (className == null) {
2230 throw new Jbi4CorbaRuntimeException("CRB--- The Interface don't exist in the SU");
2231 }
2232
2233
2234
2235
2236 for (Jbi4CorbaEndpoint endp : su.getDeployedEndpoints()) {
2237
2238 if (endp instanceof ProviderEndpoint) {
2239
2240 ProviderEndpoint pe = (ProviderEndpoint) endp;
2241
2242
2243
2244
2245
2246 String op = "Operations";
2247 String intName = pe.getServiceDescriptor().getServiceInterface().toString().substring(
2248 0,
2249 pe.getServiceDescriptor().getServiceInterface().toString().length() - op.length());
2250 if (LOG.isDebugEnabled()) {
2251 LOG.debug("----------------------------------------------------------------");
2252 LOG.debug("Result Interface -->" + className);
2253 LOG.debug("Current Endpoint Interface -->" + intName);
2254 LOG.debug("----------------------------------------------------------------");
2255 }
2256
2257 if (className.equals(intName)) {
2258 serviceDesc = pe.getServiceDescriptor();
2259
2260
2261 jbi4corbaEndPoint = endp;
2262 break;
2263 }
2264 }
2265 }
2266
2267 ORB orb = serviceDesc.getEndpoint().getOrb();
2268
2269 String ior = orb.object_to_string((org.omg.CORBA.Object) obj);
2270
2271 return createEPR(ior, jbi4corbaEndPoint);
2272
2273 }
2274
2275 private static void getHierachy(Class clazz, Set<String> classHierarchy) throws ClassNotFoundException {
2276
2277 if (clazz.getSuperclass() != null) {
2278 classHierarchy.add(clazz.getName());
2279 getHierachy(clazz.getSuperclass(), classHierarchy);
2280 }
2281 return;
2282 }
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293 private static W3CEndpointReference createEPR(String ior,
2294 Jbi4CorbaEndpoint psd) {
2295
2296 W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
2297
2298
2299
2300 QName serviceName = psd.getServiceName();
2301 QName endPointName = new QName(psd.getEndpointName());
2302
2303 builder.address("jbi4corba:" + ior);
2304 builder.serviceName(serviceName);
2305 builder.endpointName(endPointName);
2306 LOG.debug("GENERATED EPR WITH >>>> address --> jbi4corba:" + ior + "\n serviceName -->" + serviceName.toString() + "\n endpointName -->" + endPointName.toString());
2307 W3CEndpointReference epr = builder.build();
2308
2309 return epr;
2310
2311 }
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325 private static Object narrowObjbyIOR(Class helperClass, String ior, ORB orb)
2326 throws NoSuchMethodException, IllegalAccessException,
2327 IllegalArgumentException, InvocationTargetException {
2328
2329 Object narrowedObj = helperClass.getDeclaredMethod("narrow",
2330 org.omg.CORBA.Object.class).invoke(helperClass,
2331 orb.string_to_object(ior));
2332 return narrowedObj;
2333 }
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347 private static Class loadHelperbyName(String interfaceName,
2348 URLClassLoader originalClassLoader)
2349 throws ClassNotFoundException {
2350
2351 return originalClassLoader.loadClass(interfaceName + "Helper");
2352
2353 }
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368 private static Object transformEnumType(Object enumObj,
2369 URLClassLoader fromClassLoader, URLClassLoader toClassLoader)
2370 throws SecurityException, NoSuchMethodException,
2371 ClassNotFoundException, IllegalArgumentException,
2372 IllegalAccessException, InvocationTargetException {
2373
2374 Class fromEnumClass = fromClassLoader.loadClass(TypeUtils.getTypeNameWithoutBrackets(enumObj.getClass()));
2375 Class toEnumClass = toClassLoader.loadClass(TypeUtils.getTypeNameWithoutBrackets(enumObj.getClass()));
2376
2377 if (enumObj.getClass().isArray()) {
2378 int dimentions[] = TypeUtils.getObjectDimensions(enumObj);
2379 Object enumArray = Array.newInstance(toEnumClass, dimentions);
2380 Object[] fromEnumArray = (Object[]) enumObj;
2381 Object[] toEnumArray = (Object[]) enumArray;
2382 for (int i = 0; i < fromEnumArray.length; i++) {
2383 toEnumArray[i] = transformEnumType(fromEnumArray[i],
2384 fromClassLoader, toClassLoader);
2385 }
2386
2387 return toEnumArray;
2388 } else {
2389
2390 Method valueMethod = fromEnumClass.getMethod("value");
2391 Object value = valueMethod.invoke(enumObj);
2392
2393 Method from_intMethod = toEnumClass.getMethod("from_int", int.class);
2394
2395 return from_intMethod.invoke(null, ((Integer) value).intValue());
2396 }
2397 }
2398
2399
2400
2401
2402
2403
2404
2405 private static void getAllFields(Class cls, List<Field> fields) {
2406 if (cls == null || cls.getName().startsWith("java.lang.")) {
2407 return;
2408 }
2409
2410 Field[] clsFields = cls.getDeclaredFields();
2411 for (Field field : clsFields) {
2412 if (!ignoreField(field)) {
2413 fields.add(field);
2414 }
2415 }
2416
2417 getAllFields(cls.getSuperclass(), fields);
2418
2419 }
2420
2421
2422
2423
2424
2425
2426
2427 private static boolean ignoreField(Field field) {
2428 int fieldMofidiers = field.getModifiers();
2429
2430
2431 if (field.getName().equals("_truncatable_ids") && Modifier.isPrivate(fieldMofidiers) && Modifier.isStatic(fieldMofidiers)) {
2432 return true;
2433 }
2434
2435 return false;
2436 }
2437
2438
2439
2440
2441
2442
2443
2444
2445 private static Field getField(Class cls, String fieldName) {
2446 Field[] clsFields = cls.getDeclaredFields();
2447 for (Field field : clsFields) {
2448 if (field.getName().equals(fieldName)) {
2449 return field;
2450 }
2451 }
2452
2453 return getField(cls.getSuperclass(), fieldName);
2454 }
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464 public static MethodSignature getMetodSignatureFromMethod(Method method, List<MethodSignature> methodSignatures) {
2465
2466 MethodSignature methodSignature = null;
2467 for (int i = 0; i < methodSignatures.size(); i++) {
2468 methodSignature = (MethodSignature) methodSignatures.get(i);
2469 LOG.debug("METHOD SIGNATURE ===>" + methodSignature);
2470 if (compareMethodsWithNameAndParameters(method, methodSignature.getMethod())) {
2471 return methodSignature;
2472 }
2473 }
2474 String msg = MESSAGES.getString(
2475 "CRB000765_No_method_signature_found_for_method",
2476 new Object[]{method.toGenericString()});
2477 LOG.warn(msg);
2478 return null;
2479 }
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489 private static boolean compareMethodsWithNameAndParameters(Method methodA,
2490 Method methodB) {
2491 boolean ret = false;
2492
2493 boolean paramEquals = compareParameterTypes(
2494 methodA.getParameterTypes(), methodB.getParameterTypes());
2495
2496 if ((paramEquals) && (methodA.getName().equals(methodB.getName()))) {
2497 ret = true;
2498 }
2499 return ret;
2500 }
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510 private static boolean compareParameterTypes(Class[] typesA, Class[] typesB) {
2511 boolean ret = true;
2512
2513 if (typesA.length != typesB.length) {
2514 ret = false;
2515 } else {
2516 for (int i = 0; i < typesA.length; i++) {
2517 if (!(typesA[i].getName().equals(typesB[i].getName()))) {
2518
2519 ret = false;
2520 break;
2521 }
2522 }
2523 }
2524 return ret;
2525 }
2526
2527
2528
2529
2530
2531
2532
2533 public static int delinearizeArray(Object[] objects, Object myArray, int actualElement) {
2534
2535 LOG.debug("Delinearizing array called with array: "
2536 + ArrayUtils.toString(myArray) + " and actualElement: " + actualElement);
2537
2538 Object arrEl = myArray;
2539 int arrLen = Array.getLength(arrEl);
2540 LOG.debug("myArray.getClass().getComponentType():" + myArray.getClass().getComponentType());
2541 LOG.debug("arrEl:" + ArrayUtils.toString(arrEl));
2542 LOG.debug("myArray.getClass().getComponentType().isArray:" + myArray.getClass().getComponentType().isArray());
2543 if (myArray.getClass().getComponentType().isArray()) {
2544 for (int k = 0; k < arrLen; k++) {
2545 actualElement = delinearizeArray(objects, Array.get(arrEl, k) , actualElement);
2546 }
2547 } else {
2548 for (int i = 0; i < arrLen; i++) {
2549 LOG.debug("totIndex:" + actualElement + " Object: " +objects[actualElement]);
2550 Array.set(myArray,i, objects[actualElement]);
2551 actualElement ++;
2552 }
2553 }
2554 return actualElement;
2555 }
2556
2557
2558 }