KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > util > Classes


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.util;
23
24 import java.lang.reflect.Method JavaDoc;
25 import java.lang.reflect.Modifier JavaDoc;
26 import java.lang.reflect.Array JavaDoc;
27 import java.lang.NoSuchMethodException JavaDoc;
28 import java.net.URL JavaDoc;
29
30 import java.security.AccessController JavaDoc;
31 import java.security.CodeSource JavaDoc;
32 import java.security.PrivilegedAction JavaDoc;
33 import java.security.ProtectionDomain JavaDoc;
34 import java.util.*;
35
36 /**
37  * A collection of <code>Class</code> utilities.
38  *
39  * @version <tt>$Revision: 1958 $</tt>
40  * @author <a HREF="mailto:jason@planet57.com">Jason Dillon</a>
41  * @author Scott.Stark@jboss.org
42  */

43 public final class Classes
44 {
45    /** The string used to separator packages */
46    public static final String JavaDoc PACKAGE_SEPARATOR = ".";
47
48    /** The characther used to separator packages */
49    public static final char PACKAGE_SEPARATOR_CHAR = '.';
50
51    /** The default package name. */
52    public static final String JavaDoc DEFAULT_PACKAGE_NAME = "<default>";
53
54    /** Format a string buffer containing the Class, Interfaces, CodeSource,
55     and ClassLoader information for the given object clazz.
56
57     @param clazz the Class
58     @param results - the buffer to write the info to
59     */

60    public static void displayClassInfo(Class JavaDoc clazz, StringBuffer JavaDoc results)
61    {
62       // Print out some codebase info for the clazz
63
ClassLoader JavaDoc cl = clazz.getClassLoader();
64       results.append("\n");
65       results.append(clazz.getName());
66       results.append("(");
67       results.append(Integer.toHexString(clazz.hashCode()));
68       results.append(").ClassLoader=");
69       results.append(cl);
70       ClassLoader JavaDoc parent = cl;
71       while( parent != null )
72       {
73          results.append("\n..");
74          results.append(parent);
75          URL JavaDoc[] urls = getClassLoaderURLs(parent);
76          int length = urls != null ? urls.length : 0;
77          for(int u = 0; u < length; u ++)
78          {
79             results.append("\n....");
80             results.append(urls[u]);
81          }
82          if( parent != null )
83             parent = parent.getParent();
84       }
85       CodeSource JavaDoc clazzCS = clazz.getProtectionDomain().getCodeSource();
86       if( clazzCS != null )
87       {
88          results.append("\n++++CodeSource: ");
89          results.append(clazzCS);
90       }
91       else
92          results.append("\n++++Null CodeSource");
93
94       results.append("\nImplemented Interfaces:");
95       Class JavaDoc[] ifaces = clazz.getInterfaces();
96       for(int i = 0; i < ifaces.length; i ++)
97       {
98          Class JavaDoc iface = ifaces[i];
99          results.append("\n++");
100          results.append(iface);
101          results.append("(");
102          results.append(Integer.toHexString(iface.hashCode()));
103          results.append(")");
104          ClassLoader JavaDoc loader = ifaces[i].getClassLoader();
105          results.append("\n++++ClassLoader: ");
106          results.append(loader);
107          ProtectionDomain JavaDoc pd = ifaces[i].getProtectionDomain();
108          CodeSource JavaDoc cs = pd.getCodeSource();
109          if( cs != null )
110          {
111             results.append("\n++++CodeSource: ");
112             results.append(cs);
113          }
114          else
115             results.append("\n++++Null CodeSource");
116       }
117    }
118
119    /** Use reflection to access a URL[] getURLs or URL[] getClasspath method so
120     that non-URLClassLoader class loaders, or class loaders that override
121     getURLs to return null or empty, can provide the true classpath info.
122     */

123    public static URL JavaDoc[] getClassLoaderURLs(ClassLoader JavaDoc cl)
124    {
125       URL JavaDoc[] urls = {};
126       try
127       {
128          Class JavaDoc returnType = urls.getClass();
129          Class JavaDoc[] parameterTypes = {};
130          Class JavaDoc clClass = cl.getClass();
131          Method JavaDoc getURLs = clClass.getMethod("getURLs", parameterTypes);
132          if( returnType.isAssignableFrom(getURLs.getReturnType()) )
133          {
134             Object JavaDoc[] args = {};
135             urls = (URL JavaDoc[]) getURLs.invoke(cl, args);
136          }
137          if( urls == null || urls.length == 0 )
138          {
139             Method JavaDoc getCp = clClass.getMethod("getClasspath", parameterTypes);
140             if( returnType.isAssignableFrom(getCp.getReturnType()) )
141             {
142                Object JavaDoc[] args = {};
143                urls = (URL JavaDoc[]) getCp.invoke(cl, args);
144             }
145          }
146       }
147       catch(Exception JavaDoc ignore)
148       {
149       }
150       return urls;
151    }
152
153    /**
154     * Describe the class of an object
155     *
156     * @param object the object
157     * @return the description
158     */

159    public static String JavaDoc getDescription(Object JavaDoc object)
160    {
161       StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
162       describe(buffer, object);
163       return buffer.toString();
164    }
165
166    /**
167     * Describe the class of an object
168     *
169     * @param buffer the string buffer
170     * @param object the object
171     */

172    public static void describe(StringBuffer JavaDoc buffer, Object JavaDoc object)
173    {
174       if (object == null)
175          buffer.append("**null**");
176       else
177          describe(buffer, object.getClass());
178    }
179
180    /**
181     * Describe the class
182     *
183     * @param buffer the string buffer
184     * @param clazz the clazz
185     */

186    public static void describe(StringBuffer JavaDoc buffer, Class JavaDoc clazz)
187    {
188       if (clazz == null)
189          buffer.append("**null**");
190       else
191       {
192          buffer.append("{class=").append(clazz.getName());
193          Class JavaDoc[] intfs = clazz.getInterfaces();
194          if (intfs.length > 0)
195          {
196             buffer.append(" intfs=");
197             for (int i = 0; i < intfs.length; ++i)
198             {
199                buffer.append(intfs[i].getName());
200                if (i < intfs.length-1)
201                   buffer.append(", ");
202             }
203          }
204          buffer.append("}");
205       }
206    }
207
208    /**
209     * Get the short name of the specified class by striping off the package
210     * name.
211     *
212     * @param classname Class name.
213     * @return Short class name.
214     */

215    public static String JavaDoc stripPackageName(final String JavaDoc classname)
216    {
217       int idx = classname.lastIndexOf(PACKAGE_SEPARATOR);
218
219       if (idx != -1)
220          return classname.substring(idx + 1, classname.length());
221       return classname;
222    }
223
224    /**
225     * Get the short name of the specified class by striping off the package
226     * name.
227     *
228     * @param type Class name.
229     * @return Short class name.
230     */

231    public static String JavaDoc stripPackageName(final Class JavaDoc type)
232    {
233       return stripPackageName(type.getName());
234    }
235
236    /**
237     * Get the package name of the specified class.
238     *
239     * @param classname Class name.
240     * @return Package name or "" if the classname is in the
241     * <i>default</i> package.
242     *
243     * @throws EmptyStringException Classname is an empty string.
244     */

245    public static String JavaDoc getPackageName(final String JavaDoc classname)
246    {
247       if (classname.length() == 0)
248          throw new EmptyStringException();
249
250       int index = classname.lastIndexOf(PACKAGE_SEPARATOR);
251       if (index != -1)
252          return classname.substring(0, index);
253       return "";
254    }
255
256    /**
257     * Get the package name of the specified class.
258     *
259     * @param type Class.
260     * @return Package name.
261     */

262    public static String JavaDoc getPackageName(final Class JavaDoc type)
263    {
264       return getPackageName(type.getName());
265    }
266
267    /**
268     * Force the given class to be loaded fully.
269     *
270     * <p>This method attempts to locate a static method on the given class
271     * the attempts to invoke it with dummy arguments in the hope that
272     * the virtual machine will prepare the class for the method call and
273     * call all of the static class initializers.
274     *
275     * @param type Class to force load.
276     *
277     * @throws NullArgumentException Type is <i>null</i>.
278     */

279    public static void forceLoad(final Class JavaDoc type)
280    {
281       if (type == null)
282          throw new NullArgumentException("type");
283
284       // don't attempt to force primitives to load
285
if (type.isPrimitive()) return;
286
287       // don't attempt to force java.* classes to load
288
String JavaDoc packageName = Classes.getPackageName(type);
289       // System.out.println("package name: " + packageName);
290

291       if (packageName.startsWith("java.") ||
292          packageName.startsWith("javax."))
293       {
294          return;
295       }
296
297       // System.out.println("forcing class to load: " + type);
298

299       try
300       {
301          Method JavaDoc methods[] = type.getDeclaredMethods();
302          Method JavaDoc method = null;
303          for (int i = 0; i < methods.length; i++)
304          {
305             int modifiers = methods[i].getModifiers();
306             if (Modifier.isStatic(modifiers))
307             {
308                method = methods[i];
309                break;
310             }
311          }
312
313          if (method != null)
314          {
315             method.invoke(null, null);
316          }
317          else
318          {
319             type.newInstance();
320          }
321       }
322       catch (Exception JavaDoc ignore)
323       {
324          ThrowableHandler.add(ignore);
325       }
326    }
327
328
329    /////////////////////////////////////////////////////////////////////////
330
// Primitives //
331
/////////////////////////////////////////////////////////////////////////
332

333    /** Primitive type name -> class map. */
334    private static final Map PRIMITIVE_NAME_TYPE_MAP = new HashMap();
335
336    /** Setup the primitives map. */
337    static
338    {
339       PRIMITIVE_NAME_TYPE_MAP.put("boolean", Boolean.TYPE);
340       PRIMITIVE_NAME_TYPE_MAP.put("byte", Byte.TYPE);
341       PRIMITIVE_NAME_TYPE_MAP.put("char", Character.TYPE);
342       PRIMITIVE_NAME_TYPE_MAP.put("short", Short.TYPE);
343       PRIMITIVE_NAME_TYPE_MAP.put("int", Integer.TYPE);
344       PRIMITIVE_NAME_TYPE_MAP.put("long", Long.TYPE);
345       PRIMITIVE_NAME_TYPE_MAP.put("float", Float.TYPE);
346       PRIMITIVE_NAME_TYPE_MAP.put("double", Double.TYPE);
347    }
348
349    /**
350     * Get the primitive type for the given primitive name.
351     *
352     * <p>
353     * For example, "boolean" returns Boolean.TYPE and so on...
354     *
355     * @param name Primitive type name (boolean, int, byte, ...)
356     * @return Primitive type or null.
357     *
358     * @exception IllegalArgumentException Type is not a primitive class
359     */

360    public static Class JavaDoc getPrimitiveTypeForName(final String JavaDoc name)
361    {
362       return (Class JavaDoc) PRIMITIVE_NAME_TYPE_MAP.get(name);
363    }
364
365    /** Map of primitive types to their wrapper classes */
366    private static final Class JavaDoc[] PRIMITIVE_WRAPPER_MAP = {
367       Boolean.TYPE, Boolean JavaDoc.class,
368       Byte.TYPE, Byte JavaDoc.class,
369       Character.TYPE, Character JavaDoc.class,
370       Double.TYPE, Double JavaDoc.class,
371       Float.TYPE, Float JavaDoc.class,
372       Integer.TYPE, Integer JavaDoc.class,
373       Long.TYPE, Long JavaDoc.class,
374       Short.TYPE, Short JavaDoc.class,
375    };
376
377    /**
378     * Get the wrapper class for the given primitive type.
379     *
380     * @param type Primitive class.
381     * @return Wrapper class for primitive.
382     *
383     * @exception IllegalArgumentException Type is not a primitive class
384     */

385    public static Class JavaDoc getPrimitiveWrapper(final Class JavaDoc type)
386    {
387       if (!type.isPrimitive())
388       {
389          throw new IllegalArgumentException JavaDoc("type is not a primitive class");
390       }
391
392       for (int i = 0; i < PRIMITIVE_WRAPPER_MAP.length; i += 2)
393       {
394          if (type.equals(PRIMITIVE_WRAPPER_MAP[i]))
395             return PRIMITIVE_WRAPPER_MAP[i + 1];
396       }
397
398       // should never get here, if we do then PRIMITIVE_WRAPPER_MAP
399
// needs to be updated to include the missing mapping
400
throw new UnreachableStatementException();
401    }
402
403    /**
404     * Object a list of all interfaces starting with the argument class c through
405     * all superclasses
406     *
407     * @param allIfaces - the list to populate for
408     * @param c - the class to start scanning for interfaces
409     */

410    public static void getAllInterfaces(List allIfaces, Class JavaDoc c)
411    {
412       while( c != null )
413       {
414          Class JavaDoc[] ifaces = c.getInterfaces();
415          for(int n = 0; n < ifaces.length; n ++)
416          {
417             allIfaces.add(ifaces[n]);
418          }
419          c = c.getSuperclass();
420       }
421    }
422
423    /**
424     * Check if the given class is a primitive wrapper class.
425     *
426     * @param type Class to check.
427     * @return True if the class is a primitive wrapper.
428     */

429    public static boolean isPrimitiveWrapper(final Class JavaDoc type)
430    {
431       for (int i = 0; i < PRIMITIVE_WRAPPER_MAP.length; i += 2)
432       {
433          if (type.equals(PRIMITIVE_WRAPPER_MAP[i + 1]))
434          {
435             return true;
436          }
437       }
438
439       return false;
440    }
441
442    /**
443     * Check if the given class is a primitive class or a primitive
444     * wrapper class.
445     *
446     * @param type Class to check.
447     * @return True if the class is a primitive or primitive wrapper.
448     */

449    public static boolean isPrimitive(final Class JavaDoc type)
450    {
451       if (type.isPrimitive() || isPrimitiveWrapper(type))
452       {
453          return true;
454       }
455
456       return false;
457    }
458    /** Check type against boolean, byte, char, short, int, long, float, double.
459     * @param type The java type name
460     * @return true if this is a primative type name.
461     */

462    public static boolean isPrimitive(final String JavaDoc type)
463    {
464       return PRIMITIVE_NAME_TYPE_MAP.containsKey(type);
465    }
466
467    /**
468     * @param wrapper a primitive wrapper type
469     * @return primitive type the passed in wrapper type corresponds to
470     */

471    public static Class JavaDoc getPrimitive(Class JavaDoc wrapper)
472    {
473       Class JavaDoc primitive;
474       if(Integer JavaDoc.class == wrapper)
475       {
476          primitive = int.class;
477       }
478       else if(Long JavaDoc.class == wrapper)
479       {
480          primitive = long.class;
481       }
482       else if(Double JavaDoc.class == wrapper)
483       {
484          primitive = double.class;
485       }
486       else if(Boolean JavaDoc.class == wrapper)
487       {
488          primitive = boolean.class;
489       }
490       else if(Short JavaDoc.class == wrapper)
491       {
492          primitive = short.class;
493       }
494       else if(Float JavaDoc.class == wrapper)
495       {
496          primitive = float.class;
497       }
498       else if(Byte JavaDoc.class == wrapper)
499       {
500          primitive = byte.class;
501       }
502       else if(Character JavaDoc.class == wrapper)
503       {
504          primitive = char.class;
505       }
506       else
507       {
508          throw new IllegalArgumentException JavaDoc("The class is not a primitive wrapper type: " + wrapper);
509       }
510       return primitive;
511    }
512
513    /**
514     * Instantiate a java class object
515     *
516     * @param expected the expected class type
517     * @param property the system property defining the class
518     * @param defaultClassName the default class name
519     * @return the instantiated object
520     */

521    public static Object JavaDoc instantiate(Class JavaDoc expected, String JavaDoc property, String JavaDoc defaultClassName)
522    {
523       String JavaDoc className = getProperty(property, defaultClassName);
524       Class JavaDoc clazz = null;
525       try
526       {
527          clazz = loadClass(className);
528       }
529       catch (ClassNotFoundException JavaDoc e)
530       {
531          throw new NestedRuntimeException("Cannot load class " + className, e);
532       }
533       Object JavaDoc result = null;
534       try
535       {
536          result = clazz.newInstance();
537       }
538       catch (InstantiationException JavaDoc e)
539       {
540          throw new NestedRuntimeException("Error instantiating " + className, e);
541       }
542       catch (IllegalAccessException JavaDoc e)
543       {
544          throw new NestedRuntimeException("Error instantiating " + className, e);
545       }
546       if (expected.isAssignableFrom(clazz) == false)
547          throw new NestedRuntimeException("Class " + className + " from classloader " + clazz.getClassLoader() +
548             " is not of the expected class " + expected + " loaded from " + expected.getClassLoader());
549       return result;
550    }
551
552    /////////////////////////////////////////////////////////////////////////
553
// Class Loading //
554
/////////////////////////////////////////////////////////////////////////
555

556    /**
557     * This method acts equivalently to invoking
558     * <code>Thread.currentThread().getContextClassLoader().loadClass(className);</code> but it also
559     * supports primitive types and array classes of object types or primitive types.
560     *
561     * @param className the qualified name of the class or the name of primitive type or
562     * array in the same format as returned by the
563     * <code>java.lang.Class.getName()</code> method.
564     * @return the Class object for the requested className
565     *
566     * @throws ClassNotFoundException when the <code>classLoader</code> can not find the requested class
567     */

568    public static Class JavaDoc loadClass(String JavaDoc className) throws ClassNotFoundException JavaDoc
569    {
570       return loadClass(className, Thread.currentThread().getContextClassLoader());
571    }
572
573    /**
574     * This method acts equivalently to invoking classLoader.loadClass(className)
575     * but it also supports primitive types and array classes of object types or
576     * primitive types.
577     *
578     * @param className the qualified name of the class or the name of primitive
579     * type or array in the same format as returned by the
580     * java.lang.Class.getName() method.
581     * @param classLoader the ClassLoader used to load classes
582     * @return the Class object for the requested className
583     *
584     * @throws ClassNotFoundException when the <code>classLoader</code> can not
585     * find the requested class
586     */

587    public static Class JavaDoc loadClass(String JavaDoc className, ClassLoader JavaDoc classLoader)
588       throws ClassNotFoundException JavaDoc
589    {
590       // ClassLoader.loadClass() does not handle primitive types:
591
//
592
// B byte
593
// C char
594
// D double
595
// F float
596
// I int
597
// J long
598
// S short
599
// Z boolean
600
// V void
601
//
602
if (className.length() == 1)
603       {
604          char type = className.charAt(0);
605          if (type == 'B') return Byte.TYPE;
606          if (type == 'C') return Character.TYPE;
607          if (type == 'D') return Double.TYPE;
608          if (type == 'F') return Float.TYPE;
609          if (type == 'I') return Integer.TYPE;
610          if (type == 'J') return Long.TYPE;
611          if (type == 'S') return Short.TYPE;
612          if (type == 'Z') return Boolean.TYPE;
613          if (type == 'V') return Void.TYPE;
614          // else throw...
615
throw new ClassNotFoundException JavaDoc(className);
616       }
617
618       // Check for a primative type
619
if( isPrimitive(className) == true )
620          return (Class JavaDoc) Classes.PRIMITIVE_NAME_TYPE_MAP.get(className);
621
622       // Check for the internal vm format: Lclassname;
623
if (className.charAt(0) == 'L' && className.charAt(className.length() - 1) == ';')
624          return classLoader.loadClass(className.substring(1, className.length() - 1));
625
626       // first try - be optimistic
627
// this will succeed for all non-array classes and array classes that have already been resolved
628
//
629
try
630       {
631          return classLoader.loadClass(className);
632       }
633       catch (ClassNotFoundException JavaDoc e)
634       {
635          // if it was non-array class then throw it
636
if (className.charAt(0) != '[')
637             throw e;
638       }
639
640       // we are now resolving array class for the first time
641

642       // count opening braces
643
int arrayDimension = 0;
644       while (className.charAt(arrayDimension) == '[')
645          arrayDimension++;
646
647       // resolve component type - use recursion so that we can resolve primitive types also
648
Class JavaDoc componentType = loadClass(className.substring(arrayDimension), classLoader);
649
650       // construct array class
651
return Array.newInstance(componentType, new int[arrayDimension]).getClass();
652    }
653
654    /**
655     * Convert a list of Strings from an Interator into an array of
656     * Classes (the Strings are taken as classnames).
657     *
658     * @param it A java.util.Iterator pointing to a Collection of Strings
659     * @param cl The ClassLoader to use
660     *
661     * @return Array of Classes
662     *
663     * @throws ClassNotFoundException When a class could not be loaded from
664     * the specified ClassLoader
665     */

666    public final static Class JavaDoc[] convertToJavaClasses(Iterator it,
667                                                     ClassLoader JavaDoc cl)
668       throws ClassNotFoundException JavaDoc
669    {
670       ArrayList classes = new ArrayList();
671       while (it.hasNext())
672       {
673          classes.add(convertToJavaClass((String JavaDoc) it.next(), cl));
674       }
675       return (Class JavaDoc[]) classes.toArray(new Class JavaDoc[classes.size()]);
676    }
677
678    /**
679     * Returns attribute's getter method. If the method not found then NoSuchMethodException will be thrown.
680     * @param cls the class the attribute belongs too
681     * @param attr the attribute's name
682     * @return attribute's getter method
683     * @throws NoSuchMethodException if the getter was not found
684     */

685    public final static Method JavaDoc getAttributeGetter(Class JavaDoc cls, String JavaDoc attr) throws NoSuchMethodException JavaDoc
686    {
687       StringBuffer JavaDoc buf = new StringBuffer JavaDoc(attr.length() + 3);
688       buf.append("get");
689       if(Character.isLowerCase(attr.charAt(0)))
690       {
691          buf.append(Character.toUpperCase(attr.charAt(0)))
692             .append(attr.substring(1));
693       }
694       else
695       {
696          buf.append(attr);
697       }
698
699       try
700       {
701          return cls.getMethod(buf.toString(), null);
702       }
703       catch (NoSuchMethodException JavaDoc e)
704       {
705          buf.replace(0, 3, "is");
706          return cls.getMethod(buf.toString(), null);
707       }
708    }
709
710    /**
711     * Returns attribute's setter method. If the method not found then NoSuchMethodException will be thrown.
712     * @param cls the class the attribute belongs to
713     * @param attr the attribute's name
714     * @param type the attribute's type
715     * @return attribute's setter method
716     * @throws NoSuchMethodException if the setter was not found
717     */

718    public final static Method JavaDoc getAttributeSetter(Class JavaDoc cls, String JavaDoc attr, Class JavaDoc type) throws NoSuchMethodException JavaDoc
719    {
720       StringBuffer JavaDoc buf = new StringBuffer JavaDoc(attr.length() + 3);
721       buf.append("set");
722       if(Character.isLowerCase(attr.charAt(0)))
723       {
724          buf.append(Character.toUpperCase(attr.charAt(0)))
725             .append(attr.substring(1));
726       }
727       else
728       {
729          buf.append(attr);
730       }
731
732       return cls.getMethod(buf.toString(), new Class JavaDoc[]{type});
733    }
734
735    /**
736     * Convert a given String into the appropriate Class.
737     *
738     * @param name Name of class
739     * @param cl ClassLoader to use
740     *
741     * @return The class for the given name
742     *
743     * @throws ClassNotFoundException When the class could not be found by
744     * the specified ClassLoader
745     */

746    private final static Class JavaDoc convertToJavaClass(String JavaDoc name,
747                                                  ClassLoader JavaDoc cl)
748       throws ClassNotFoundException JavaDoc
749    {
750       int arraySize = 0;
751       while (name.endsWith("[]"))
752       {
753          name = name.substring(0, name.length() - 2);
754          arraySize++;
755       }
756
757       // Check for a primitive type
758
Class JavaDoc c = (Class JavaDoc) PRIMITIVE_NAME_TYPE_MAP.get(name);
759
760       if (c == null)
761       {
762          // No primitive, try to load it from the given ClassLoader
763
try
764          {
765             c = cl.loadClass(name);
766          }
767          catch (ClassNotFoundException JavaDoc cnfe)
768          {
769             throw new ClassNotFoundException JavaDoc("Parameter class not found: " +
770                name);
771          }
772       }
773
774       // if we have an array get the array class
775
if (arraySize > 0)
776       {
777          int[] dims = new int[arraySize];
778          for (int i = 0; i < arraySize; i++)
779          {
780             dims[i] = 1;
781          }
782          c = Array.newInstance(c, dims).getClass();
783       }
784
785       return c;
786    }
787
788    /**
789     * Get a system property
790     *
791     * @param name the property name
792     * @param defaultValue the default value
793     */

794    private static String JavaDoc getProperty(final String JavaDoc name, final String JavaDoc defaultValue)
795    {
796       return (String JavaDoc) AccessController.doPrivileged(
797       new PrivilegedAction JavaDoc()
798       {
799          public Object JavaDoc run()
800          {
801             return System.getProperty(name, defaultValue);
802          }
803
804       });
805    }
806 }
807
Popular Tags