1 14 15 package com.sun.facelets.compiler; 16 17 import java.lang.reflect.Array ; 18 import java.util.Arrays ; 19 20 26 class ReflectionUtil { 27 28 protected static final String [] EMPTY_STRING = new String [0]; 29 30 protected static final String [] PRIMITIVE_NAMES = new String [] { "boolean", 31 "byte", "char", "double", "float", "int", "long", "short", "void" }; 32 33 protected static final Class [] PRIMITIVES = new Class [] { boolean.class, 34 byte.class, char.class, double.class, float.class, int.class, 35 long.class, short.class, Void.TYPE }; 36 37 40 private ReflectionUtil() { 41 super(); 42 } 43 44 public static Class forName(String name) throws ClassNotFoundException { 45 if (null == name || "".equals(name)) { 46 return null; 47 } 48 Class c = forNamePrimitive(name); 49 if (c == null) { 50 if (name.endsWith("[]")) { 51 String nc = name.substring(0, name.length() - 2); 52 c = Class.forName(nc, true, Thread.currentThread().getContextClassLoader()); 53 c = Array.newInstance(c, 0).getClass(); 54 } else { 55 c = Class.forName(name, true, Thread.currentThread().getContextClassLoader()); 56 } 57 } 58 return c; 59 } 60 61 protected static Class forNamePrimitive(String name) { 62 if (name.length() <= 8) { 63 int p = Arrays.binarySearch(PRIMITIVE_NAMES, name); 64 if (p >= 0) { 65 return PRIMITIVES[p]; 66 } 67 } 68 return null; 69 } 70 } 71 | Popular Tags |