KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > registry > ui > ReflectionHelper


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.websvc.registry.ui;
21
22 import com.sun.xml.rpc.processor.model.java.JavaParameter;
23 import com.sun.xml.rpc.processor.model.java.JavaType;
24 import com.sun.xml.rpc.processor.model.java.JavaMethod;
25 import com.sun.xml.rpc.processor.model.java.JavaArrayType;
26 import com.sun.xml.rpc.processor.model.java.JavaStructureMember;
27 import com.sun.xml.rpc.processor.model.java.JavaSimpleType;
28 import com.sun.xml.rpc.processor.model.java.JavaStructureType;
29 import com.sun.xml.rpc.processor.model.java.JavaEnumerationEntry;
30 import com.sun.xml.rpc.processor.model.java.JavaEnumerationType;
31
32
33 import java.lang.reflect.Method JavaDoc;
34 import java.lang.reflect.Array JavaDoc;
35
36 import java.lang.reflect.InvocationTargetException JavaDoc;
37
38 import java.util.Iterator JavaDoc;
39 import java.util.LinkedList JavaDoc;
40 import java.net.URL JavaDoc;
41 import java.util.ArrayList JavaDoc;
42 import java.util.List JavaDoc;
43
44 import java.rmi.RemoteException JavaDoc;
45
46 import java.net.URLClassLoader JavaDoc;
47
48 /**
49  *
50  * @author david
51  */

52 public class ReflectionHelper {
53     
54     
55     public static Object JavaDoc makeStructureType(JavaStructureType inType,URLClassLoader JavaDoc urlClassLoader,String JavaDoc inPackageName)
56     throws WebServiceReflectionException {
57         Class JavaDoc typeClass = null;
58         if(null == urlClassLoader) return null;
59         /**
60          * We need to save off the current classLoader and set the context to the one passed in for
61          * executing the method.
62          */

63         
64         ClassLoader JavaDoc savedLoader = Thread.currentThread().getContextClassLoader();
65         
66         /**
67          * Now set the new classLoader to the one passed in.
68          */

69         Thread.currentThread().setContextClassLoader(urlClassLoader);
70         String JavaDoc className = inPackageName + "." + inType.getFormalName();
71         
72         Object JavaDoc returnValue = null;
73         try {
74             typeClass = Class.forName(className,true,urlClassLoader);
75         } catch(ClassNotFoundException JavaDoc cnfe) {
76             /**
77              * Make sure to reset the classloader
78              */

79             Thread.currentThread().setContextClassLoader(savedLoader);
80             throw new WebServiceReflectionException("ClassNotFoundException",cnfe);
81         }
82         
83         try {
84             returnValue = typeClass.newInstance();
85         } catch(InstantiationException JavaDoc ia) {
86             /**
87              * Make sure to reset the classloader
88              */

89             Thread.currentThread().setContextClassLoader(savedLoader);
90             throw new WebServiceReflectionException("InstantiationException",ia);
91         } catch(IllegalAccessException JavaDoc iae) {
92             /**
93              * Make sure to reset the classloader
94              */

95             Thread.currentThread().setContextClassLoader(savedLoader);
96             throw new WebServiceReflectionException("IllegalAccessException",iae);
97         }
98         
99         /**
100          * Make sure to reset the classloader
101          */

102         Thread.currentThread().setContextClassLoader(savedLoader);
103         
104         return returnValue;
105     }
106     
107     public static Object JavaDoc makeEnumerationType(JavaEnumerationType inType,URLClassLoader JavaDoc urlClassLoader,String JavaDoc inPackageName, Object JavaDoc value)
108     throws WebServiceReflectionException {
109         Class JavaDoc typeClass = null;
110         if(null == urlClassLoader) return null;
111         
112         try {
113             typeClass = Class.forName(inPackageName + "." + inType.getFormalName(),
114             true,
115             urlClassLoader);
116         } catch(ClassNotFoundException JavaDoc cnfe) {
117             throw new WebServiceReflectionException("ClassNotFoundException",cnfe);
118         }
119         
120         /**
121          * Now get the static method "fromString" for the class.
122          * TODO: make sure this get's specified included as a requirements spec for JAXRPC
123          */

124         
125         Method method = null;
126         try {
127             Class JavaDoc [] paramClasses = new Class JavaDoc[] {String JavaDoc.class};
128             method = typeClass.getMethod("fromString", paramClasses);
129             
130         } catch(NoSuchMethodException JavaDoc nsme) {
131             throw new WebServiceReflectionException("NoSuchMethodException",nsme);
132         }
133         
134         String JavaDoc literalValue=null;
135         if (value!=null && value instanceof String JavaDoc) {
136             literalValue = (String JavaDoc)value;
137         } else {
138             /**
139              * Get the first Enumeration entry and us it to get the Enumeration instance.
140              */

141             JavaEnumerationEntry entry = (JavaEnumerationEntry)((JavaEnumerationType)inType).getEntriesList().get(0);
142             literalValue = entry.getLiteralValue();
143         }
144         
145         Object JavaDoc returnObject = null;
146         try {
147             String JavaDoc [] params = new String JavaDoc[1];
148             params[0] = literalValue;
149             returnObject = method.invoke(typeClass,params);
150         } catch(InvocationTargetException JavaDoc ite) {
151             throw new WebServiceReflectionException("InvocationTargetException",ite);
152             
153         } catch(IllegalArgumentException JavaDoc ia) {
154             throw new WebServiceReflectionException("IllegalArgumentException",ia);
155             
156         } catch(IllegalAccessException JavaDoc iae) {
157             throw new WebServiceReflectionException("IllegalAccessException",iae);
158         }
159         
160         return returnObject;
161         
162         
163     }
164     
165     public static Object JavaDoc makeEnumerationType(JavaEnumerationType inType,URLClassLoader JavaDoc urlClassLoader,String JavaDoc inPackageName)
166     throws WebServiceReflectionException {
167         return makeEnumerationType(inType, urlClassLoader, inPackageName, null);
168     }
169     
170     public static void setStructureValue(TypeNodeData inParentData, TypeNodeData inChildData,
171     URLClassLoader JavaDoc urlClassLoader,String JavaDoc inPackageName )
172     throws WebServiceReflectionException {
173         Class JavaDoc typeClass = null;
174         if(null == urlClassLoader) return;
175         
176         JavaType parentType = inParentData.getParameterType();
177         Object JavaDoc parentValue = inParentData.getParameterValue();
178         try {
179             typeClass = Class.forName(inPackageName + "." + parentType.getFormalName(),
180             true,
181             urlClassLoader);
182         } catch(ClassNotFoundException JavaDoc cnfe) {
183             throw new WebServiceReflectionException("ClassNotFoundException",cnfe);
184         }
185         
186         /**
187          * Now get the "setter" for the child's field name.
188          * TODO: make sure this get's specified included as a requirements spec for JAXRPC
189          */

190         /**
191          * The parent type, JavaStructureType should have the setter method name in the JavaStructureMember for
192          * the child.
193          */

194         JavaStructureMember member = ((JavaStructureType)parentType).getMemberByName(inChildData.getParameterName());
195         String JavaDoc setterName = member.getWriteMethod();
196         
197         /**
198          * Now we have to create a class for the child type to use in looking for the Method.
199          */

200         Class JavaDoc childClass = null;
201         String JavaDoc originalChildClassName = inChildData.getParameterType().getFormalName();
202         JavaType childType = inChildData.getParameterType();
203         String JavaDoc childClassName = originalChildClassName;
204         Method method = null;
205         Object JavaDoc childValue = null;
206         if(childType instanceof JavaArrayType) {
207             /**
208              * If the child is an array, strip off the [] to get the class name.
209              */

210             if(childClassName.indexOf("[") > 0) {
211                 childClassName = childClassName.substring(0,childClassName.indexOf("["));
212             }
213             
214             if(!ReflectionHelper.isPrimitiveClass(childClassName)) {
215                 try {
216                     if(childClassName.indexOf(".") == -1) {
217                         childClassName = inPackageName + "." + childClassName;
218                     }
219                     childClass = Class.forName(childClassName,true,urlClassLoader);
220                 } catch(ClassNotFoundException JavaDoc cnfe) {
221                     throw new WebServiceReflectionException("ClassNotFoundException",cnfe);
222                 }
223             } else {
224                 childClass = ReflectionHelper.primitiveType2PrimitiveClass(childClassName);
225             }
226             
227             /**
228              * If the child is an array type, we've stored it as an ArrayList. Now we need
229              * to create an array of the correct type and populate it with the values.
230              */

231             Object JavaDoc childArrayObject = null;
232             if(null != inChildData.getParameterValue() &&
233             inChildData.getParameterValue() instanceof ArrayList JavaDoc) {
234                 
235                 Object JavaDoc [] childObjects = ((ArrayList JavaDoc)inChildData.getParameterValue()).toArray();
236                 if(null == childObjects) {
237                     childArrayObject = Array.newInstance(childClass,1);
238                     
239                 } else {
240                     childArrayObject = Array.newInstance(childClass,childObjects.length);
241                     /**
242                      * now set the values in the array.
243                      */

244                     for(int ii=0; ii < childObjects.length;ii++ ) {
245                         Array.set(childArrayObject, ii, childObjects[ii]);
246                     }
247                 }
248                 
249                 childValue = childArrayObject;
250                 
251             } else {
252                 childArrayObject = Array.newInstance(childClass,1);
253             }
254             try {
255                 Class JavaDoc [] paramClasses = new Class JavaDoc[] {childArrayObject.getClass()};
256                 method = typeClass.getMethod(setterName, paramClasses);
257                 
258             } catch(NoSuchMethodException JavaDoc nsme) {
259                 throw new WebServiceReflectionException("NoSuchMethodException",nsme);
260             }
261             
262         } else {
263             childValue = inChildData.getParameterValue();
264             if(!ReflectionHelper.isPrimitiveClass(childClassName)) {
265                 /**
266                  * If the class type of the child value is not primitive, we want to use reflection to load
267                  * the class so we can use the runtime class loader.
268                  */

269                 try {
270                     if(childClassName.indexOf(".") == -1) {
271                         childClassName = inPackageName + "." + childClassName;
272                     }
273                     childClass = Class.forName(childClassName,true,urlClassLoader);
274                 } catch(ClassNotFoundException JavaDoc cnfe) {
275                     throw new WebServiceReflectionException("ClassNotFoundException",cnfe);
276                 }
277             } else {
278                 /**
279                  * Now we need to get the Primitive class from the Object representation (e.g. for Float we need
280                  * float).
281                  */

282                 childClass = ReflectionHelper.referenceClass2PrimitiveClass(childValue.getClass());
283             }
284             
285             
286             try {
287                 Class JavaDoc [] paramClasses = new Class JavaDoc[] {childClass};
288                 method = typeClass.getMethod(setterName, paramClasses);
289                 
290             } catch(NoSuchMethodException JavaDoc nsme) {
291                 throw new WebServiceReflectionException("NoSuchMethodException",nsme);
292             }
293         }
294         
295         
296         Object JavaDoc returnObject = null;
297         try {
298             Object JavaDoc [] params = new Object JavaDoc[1];
299             params[0] = childValue;
300             returnObject = method.invoke(parentValue,params);
301         } catch(InvocationTargetException JavaDoc ite) {
302             throw new WebServiceReflectionException("InvocationTargetException",ite);
303             
304         } catch(IllegalArgumentException JavaDoc ia) {
305             throw new WebServiceReflectionException("IllegalArgumentException",ia);
306             
307         } catch(IllegalAccessException JavaDoc iae) {
308             throw new WebServiceReflectionException("IllegalAccessException",iae);
309         }
310         
311     }
312     
313     public static Object JavaDoc getTypedParameterArray(ArrayList JavaDoc inArrayList, JavaType inType, URLClassLoader JavaDoc urlClassLoader, String JavaDoc inPackageName)
314     throws WebServiceReflectionException {
315         if(null == urlClassLoader) return null;
316         /**
317          * First, strip off the "[]".
318          */

319         
320         String JavaDoc parameterClassName = inType.getFormalName();
321         if(parameterClassName.indexOf("[") > 0) {
322             parameterClassName = parameterClassName.substring(0,parameterClassName.indexOf("["));
323         }
324         
325         Class JavaDoc parameterClass = null;
326         try {
327             if ("java.lang.String".equals(parameterClassName))
328                 parameterClass = String JavaDoc.class;
329             else if ("int".equals(parameterClassName) || "java.lang.Integer".equals(parameterClassName)) //NOI18N
330
parameterClass = Integer JavaDoc.class;
331             else if ("long".equals(parameterClassName) || "java.lang.Long".equals(parameterClassName)) //NOI18N
332
parameterClass = Long JavaDoc.class;
333             else if ("byte".equals(parameterClassName) || "java.lang.Byte".equals(parameterClassName)) //NOI18N
334
parameterClass = Byte JavaDoc.class;
335             else if ("float".equals(parameterClassName) || "java.lang.Float".equals(parameterClassName)) //NOI18N
336
parameterClass = Float JavaDoc.class;
337             else if ("double".equals(parameterClassName) || "java.lang.Double".equals(parameterClassName)) //NOI18N
338
parameterClass = Double JavaDoc.class;
339             else if ("boolean".equals(parameterClassName) || "java.lang.Boolean".equals(parameterClassName)) //NOI18N
340
parameterClass = Boolean JavaDoc.class;
341             else if ("char".equals(parameterClassName) || "java.lang.Character".equals(parameterClassName)) //NOI18N
342
parameterClass = Character JavaDoc.class;
343             else if ("java.util.Calendar".equals(parameterClassName)) //NOI18N
344
parameterClass = java.util.Calendar JavaDoc.class;
345             else
346                 parameterClass = Class.forName(inPackageName + "." + parameterClassName,true,urlClassLoader);
347         } catch(ClassNotFoundException JavaDoc cnfe) {
348             throw new WebServiceReflectionException("ClassNotFoundException",cnfe);
349         }
350         /**
351          * First we need to create a typed array for the return type.
352          */

353         Object JavaDoc typedArrayObject = Array.newInstance(parameterClass, new int[]{0});
354         
355         /**
356          * Now get the array parameter.
357          */

358         Object JavaDoc typedArray = inArrayList.toArray((Object JavaDoc [])typedArrayObject);
359         
360         return typedArray;
361         
362     }
363     
364     public static Object JavaDoc callMethodWithParams(String JavaDoc inClassName, LinkedList JavaDoc inParamList, JavaMethod inMethod,
365     URLClassLoader JavaDoc urlClassLoader, String JavaDoc inMethodName)
366     throws WebServiceReflectionException {
367         Class JavaDoc clazz = null;
368         if(null == urlClassLoader) return null;
369         
370 // ClassLoader parent = urlClassLoader;
371
// while(null!=parent) {
372
// System.out.println("ClassLoader=" + parent);
373
// if(parent instanceof URLClassLoader) {
374
// URL [] urls = ((URLClassLoader)parent).getURLs();
375
// for(int ii=0; urls != null && ii < urls.length; ii++) {
376
// System.out.println("\t\t URL[" + ii + "]=" + urls[ii].toString());
377
// }
378
// }
379
// parent = parent.getParent();
380
//
381
// }
382

383         /**
384          * We need to save off the current classLoader and set the context to the one passed in for
385          * executing the method.
386          */

387         
388         ClassLoader JavaDoc savedLoader = Thread.currentThread().getContextClassLoader();
389         
390         /**
391          * Now set the new classLoader to the one passed in.
392          */

393         Thread.currentThread().setContextClassLoader(urlClassLoader);
394         
395         /**
396          * Get an instance of the Class
397          */

398         try {
399             clazz = Class.forName(inClassName,true,urlClassLoader);
400         } catch(ClassNotFoundException JavaDoc cnfe) {
401             /**
402              * Make sure to reset the classloader
403              */

404             Thread.currentThread().setContextClassLoader(savedLoader);
405             
406             throw new WebServiceReflectionException("ClassNotFoundException",cnfe);
407         }
408         
409         /**
410          * Instantiate the Class so we can call the method on it.
411          */

412         Object JavaDoc classInstance = null;
413         try {
414             classInstance = clazz.newInstance();
415         } catch(InstantiationException JavaDoc ia) {
416             /**
417              * Make sure to reset the classloader
418              */

419             Thread.currentThread().setContextClassLoader(savedLoader);
420             throw new WebServiceReflectionException("InstantiationExceptoin",ia);
421         } catch(IllegalAccessException JavaDoc iae) {
422             /**
423              * Make sure to reset the classloader
424              */

425             Thread.currentThread().setContextClassLoader(savedLoader);
426             throw new WebServiceReflectionException("IllegalAccessException",iae);
427         }
428         
429         
430         Method method = null;
431         Object JavaDoc [] paramValues = inParamList.toArray();
432         /**
433          * Take the parameters and make an array of Classes based on the type of each Object.
434          * For each parameter, we need to have the type of the original parameter for the JavaMethod
435          * and do the following conversions:
436          * 1. from ArrayList to a typed array. (done prior)
437          * 2. from objects to primitives
438          */

439         LinkedList JavaDoc classList = new LinkedList JavaDoc();
440         List JavaDoc parameterList = inMethod.getParametersList();
441         for(int ii=0; null != paramValues && ii < paramValues.length; ii++ ) {
442             
443             /**
444              * If the parameter type is a primitive, we've stored the value as a reference
445              * type and need to convert it back to a primitive.
446              */

447             Class JavaDoc classToAdd = null;
448             if(null != parameterList && ii < parameterList.size()) {
449                 JavaParameter actualParameter = (JavaParameter)parameterList.get(ii);
450                 if(isPrimitiveClass(actualParameter.getType().getFormalName())){
451                     classToAdd = referenceClass2PrimitiveClass(paramValues[ii].getClass());
452                 } else if(actualParameter.getType().getFormalName().equals("java.util.Calendar")) {
453                     classToAdd = java.util.Calendar JavaDoc.class;
454                 } else {
455                     classToAdd = paramValues[ii].getClass();
456                 }
457             }
458             classList.add(classToAdd);
459         }
460         Class JavaDoc [] paramClasses = (Class JavaDoc [])classList.toArray(new Class JavaDoc[0]);
461         // /**
462
// * list out the methods.
463
// */
464
// Method [] methods = clazz.getMethods();
465
// String methodName = null;
466
// for(int ii=0; ii < methods.length ;ii++){
467
// methodName = methods[ii].toString();
468
// System.err.println("Method [" + ii + "]=" + methodName);
469
// }
470
/**
471          * Now instantiate the method to call.
472          */

473         try {
474             method = clazz.getMethod(inMethodName, paramClasses);
475             
476         } catch(NoSuchMethodException JavaDoc nsme) {
477             try {
478                 Class JavaDoc [] newClasses = new Class JavaDoc[paramClasses.length];
479                 for (int i=0;i<newClasses.length;i++) {
480                     if (Integer JavaDoc[].class==paramClasses[i])
481                         newClasses[i]=int[].class;
482                     else if (Long JavaDoc[].class==paramClasses[i])
483                         newClasses[i]=long[].class;
484                     else if (Byte JavaDoc[].class==paramClasses[i])
485                         newClasses[i]=byte[].class;
486                     else if (Short JavaDoc[].class==paramClasses[i])
487                         newClasses[i]=short[].class;
488                     else if (Float JavaDoc[].class==paramClasses[i])
489                         newClasses[i]=float[].class;
490                     else if (Double JavaDoc[].class==paramClasses[i])
491                         newClasses[i]=double[].class;
492                     else if (Boolean JavaDoc[].class==paramClasses[i])
493                         newClasses[i]=boolean[].class;
494                     else if (Character JavaDoc[].class==paramClasses[i])
495                         newClasses[i]=char[].class;
496                     else
497                         newClasses[i]=paramClasses[i];
498                 }
499                 method = clazz.getMethod(inMethodName, newClasses);
500             } catch(NoSuchMethodException JavaDoc nsmex) {
501                 /**
502                  * Make sure to reset the classloader
503                  */

504                 Thread.currentThread().setContextClassLoader(savedLoader);
505                 throw new WebServiceReflectionException("NoSuchMethodException",nsmex);
506             }
507         }
508         
509         
510         Object JavaDoc returnObject = null;
511         try {
512             returnObject = method.invoke(classInstance,paramValues);
513         } catch(InvocationTargetException JavaDoc ite) {
514             /**
515              * Make sure to reset the classloader
516              */

517             Thread.currentThread().setContextClassLoader(savedLoader);
518             throw new WebServiceReflectionException("InvocationTargetException",ite);
519             
520         } catch(IllegalArgumentException JavaDoc ia) {
521             try {
522                 Object JavaDoc[] newParamValues = new Object JavaDoc[paramValues.length];
523                 for (int i=0;i<newParamValues.length;i++) {
524                     newParamValues[i] = convertToPrimitiveArrayType(paramValues[i]);
525                 }
526                 returnObject = method.invoke(classInstance,newParamValues);
527             } catch (IllegalArgumentException JavaDoc iaex) {
528                 /**
529                  * Make sure to reset the classloader
530                  */

531                 Thread.currentThread().setContextClassLoader(savedLoader);
532                 throw new WebServiceReflectionException("IllegalArgumentException",ia);
533             } catch(IllegalAccessException JavaDoc iae) {
534                 /**
535                  * Make sure to reset the classloader
536                  */

537                 Thread.currentThread().setContextClassLoader(savedLoader);
538                 throw new WebServiceReflectionException("IllegalAccessException",iae);
539             } catch(InvocationTargetException JavaDoc ite) {
540                 /**
541                  * Make sure to reset the classloader
542                  */

543                 Thread.currentThread().setContextClassLoader(savedLoader);
544                 throw new WebServiceReflectionException("InvocationTargetException",ite);
545             }
546             
547         } catch(IllegalAccessException JavaDoc iae) {
548             /**
549              * Make sure to reset the classloader
550              */

551             Thread.currentThread().setContextClassLoader(savedLoader);
552             throw new WebServiceReflectionException("IllegalAccessException",iae);
553         } catch(Exception JavaDoc e) {
554             /**
555              * Make sure to reset the classloader
556              */

557             Thread.currentThread().setContextClassLoader(savedLoader);
558             throw new WebServiceReflectionException("Exception",e);
559             
560         }
561         
562         /**
563          * Make sure to reset the classloader
564          */

565         Thread.currentThread().setContextClassLoader(savedLoader);
566         
567         return returnObject;
568         
569     }
570     
571     public static Object JavaDoc getStructureValue(ResultNodeData inParentData, JavaStructureMember inMember,
572     URLClassLoader JavaDoc urlClassLoader,String JavaDoc inPackageName)
573     throws WebServiceReflectionException {
574         
575         Class JavaDoc typeClass = null;
576         if(null == urlClassLoader) return null;
577         /**
578          * Get the class of the parent structure to look for the getter method on
579          */

580         JavaType parentType = inParentData.getResultType();
581         Object JavaDoc parentValue = inParentData.getResultValue();
582         try {
583             typeClass = Class.forName(inPackageName + "." + parentType.getFormalName(),
584             true,
585             urlClassLoader);
586         } catch(ClassNotFoundException JavaDoc cnfe) {
587             throw new WebServiceReflectionException("ClassNotFoundException",cnfe);
588         }
589         
590         /**
591          * Now get the "getter" for the child's field name.
592          * TODO: make sure this get's specified included as a requirements spec for JAXRPC
593          */

594         /**
595          * The parent type, JavaStructureType should have the setter method name in the JavaStructureMember for
596          * the child.
597          */

598         String JavaDoc getterName = inMember.getReadMethod();
599         
600         
601         Method method = null;
602         try {
603             method = typeClass.getMethod(getterName, new Class JavaDoc[0]);
604             
605         } catch(NoSuchMethodException JavaDoc nsme) {
606             throw new WebServiceReflectionException("NoSuchMethodException",nsme);
607         }
608         
609         /**
610          * Now use the getter to get the value of the subtype.
611          */

612         Object JavaDoc returnObject = null;
613         try {
614             returnObject = method.invoke(parentValue,new Object JavaDoc[0]);
615         } catch(InvocationTargetException JavaDoc ite) {
616             throw new WebServiceReflectionException("InvocationTargetException",ite);
617             
618         } catch(IllegalArgumentException JavaDoc ia) {
619             throw new WebServiceReflectionException("IllegalArgumentException",ia);
620             
621         } catch(IllegalAccessException JavaDoc iae) {
622             throw new WebServiceReflectionException("IllegalAccessException",iae);
623         }
624         
625         return returnObject;
626     }
627     
628     public static boolean isPrimitiveClass(String JavaDoc inType) {
629         if(inType.equalsIgnoreCase("int")) {
630             return true;
631         } else if(inType.equalsIgnoreCase("byte")) {
632             return true;
633         } else if(inType.equalsIgnoreCase("boolean")) {
634             return true;
635         } else if(inType.equalsIgnoreCase("float")) {
636             return true;
637         } else if(inType.equalsIgnoreCase("double")) {
638             return true;
639         } else if(inType.equalsIgnoreCase("long")) {
640             return true;
641         } else if(inType.equalsIgnoreCase("short")) {
642             return true;
643         } else return false;
644     }
645     
646     public static Class JavaDoc referenceClass2PrimitiveClass(Class JavaDoc inClass) {
647         if(null == inClass) return inClass;
648         if(inClass.getName().equalsIgnoreCase("java.lang.Boolean")) {
649             return boolean.class;
650         } else if(inClass.getName().equalsIgnoreCase("java.lang.Byte")) {
651             return byte.class;
652         } else if(inClass.getName().equalsIgnoreCase("java.lang.Double")) {
653             return double.class;
654         } else if(inClass.getName().equalsIgnoreCase("java.lang.Float")) {
655             return float.class;
656         } else if(inClass.getName().equalsIgnoreCase("java.lang.Integer")) {
657             return int.class;
658         } else if(inClass.getName().equalsIgnoreCase("java.lang.Long")) {
659             return long.class;
660         } else if(inClass.getName().equalsIgnoreCase("java.lang.Short")) {
661             return short.class;
662         } else if(inClass.getName().equalsIgnoreCase("java.lang.Character")) {
663             return char.class;
664         } else return inClass;
665     }
666     
667     public static Class JavaDoc primitiveType2PrimitiveClass(String JavaDoc typeName) {
668         if("boolean".equals(typeName)) {
669             return boolean.class;
670         } else if("int".equals(typeName)) {
671             return int.class;
672         } else if("long".equals(typeName)) {
673             return long.class;
674         } else if("double".equals(typeName)) {
675             return double.class;
676         } else if("byte".equals(typeName)) {
677             return byte.class;
678         } else if("float".equals(typeName)) {
679             return float.class;
680         } else if("short".equals(typeName)) {
681             return short.class;
682         } else if("char".equals(typeName)) {
683             return char.class;
684         }
685         return null;
686     }
687     
688     private static Object JavaDoc convertToPrimitiveArrayType(Object JavaDoc arrayObject) {
689         Object JavaDoc result=null;
690         if (arrayObject instanceof Integer JavaDoc[]) {
691             Integer JavaDoc[] val = (Integer JavaDoc[])arrayObject;
692             result = new int[val.length];
693             for (int j=0;j<val.length;j++) {
694                 ((int[])result)[j] = val[j].intValue();
695             }
696         } else if (arrayObject instanceof Long JavaDoc[]) {
697             Long JavaDoc[] val = (Long JavaDoc[])arrayObject;
698             result = new long[val.length];
699             for (int j=0;j<val.length;j++) {
700                 ((long[])result)[j] = val[j].longValue();
701             }
702         } else if (arrayObject instanceof Byte JavaDoc[]) {
703             Byte JavaDoc[] val = (Byte JavaDoc[])arrayObject;
704             result = new byte[val.length];
705             for (int j=0;j<val.length;j++) {
706                 ((byte[])result)[j] = val[j].byteValue();
707             }
708         } else if (arrayObject instanceof Short JavaDoc[]) {
709             Short JavaDoc[] val = (Short JavaDoc[])arrayObject;
710             result = new short[val.length];
711             for (int j=0;j<val.length;j++) {
712                 ((short[])result)[j] = val[j].shortValue();
713             }
714         } else if (arrayObject instanceof Float JavaDoc[]) {
715             Float JavaDoc[] val = (Float JavaDoc[])arrayObject;
716             result = new float[val.length];
717             for (int j=0;j<val.length;j++) {
718                 ((float[])result)[j] = val[j].floatValue();
719             }
720         } else if (arrayObject instanceof Double JavaDoc[]) {
721             Double JavaDoc[] val = (Double JavaDoc[])arrayObject;
722             result = new double[val.length];
723             for (int j=0;j<val.length;j++) {
724                 ((double[])result)[j] = val[j].doubleValue();
725             }
726         } else if (arrayObject instanceof Boolean JavaDoc[]) {
727             Boolean JavaDoc[] val = (Boolean JavaDoc[])arrayObject;
728             result = new boolean[val.length];
729             for (int j=0;j<val.length;j++) {
730                 ((boolean[])result)[j] = val[j].booleanValue();
731             }
732         } else if (arrayObject instanceof Character JavaDoc[]) {
733             Character JavaDoc[] val = (Character JavaDoc[])arrayObject;
734             result = new char[val.length];
735             for (int j=0;j<val.length;j++) {
736                 ((char[])result)[j] = val[j].charValue();
737             }
738         } else result=arrayObject;
739         return result;
740     }
741 }
742
Popular Tags