一、前言
关于jsf-facelets(1.1.9)源码包中com.sun.facelets.compiler.ReflectionUtil反射工具类,通过指定类名称获取对应class类,详情参见源码说明。
二、源码说明
package com.sun.facelets.compiler;@b@@b@import java.lang.reflect.Array;@b@import java.util.Arrays;@b@@b@class ReflectionUtil@b@{@b@ protected static final String[] EMPTY_STRING = new String[0];@b@ protected static final String[] PRIMITIVE_NAMES = { "boolean", "byte", "char", "double", "float", "int", "long", "short", "void" };@b@ protected static final Class[] PRIMITIVES = { Boolean.TYPE, Byte.TYPE, Character.TYPE, Double.TYPE, Float.TYPE, Integer.TYPE, Long.TYPE, Short.TYPE, Void.TYPE };@b@@b@ public static Class forName(String name)@b@ throws ClassNotFoundException@b@ {@b@ if ((null == name) || ("".equals(name)))@b@ return null;@b@@b@ Class c = forNamePrimitive(name);@b@ if (c == null)@b@ if (name.endsWith("[]")) {@b@ String nc = name.substring(0, name.length() - 2);@b@ c = Class.forName(nc, true, Thread.currentThread().getContextClassLoader());@b@ c = Array.newInstance(c, 0).getClass();@b@ } else {@b@ c = Class.forName(name, true, Thread.currentThread().getContextClassLoader());@b@ }@b@@b@ return c;@b@ }@b@@b@ protected static Class forNamePrimitive(String name) {@b@ if (name.length() <= 8) {@b@ int p = Arrays.binarySearch(PRIMITIVE_NAMES, name);@b@ if (p >= 0)@b@ return PRIMITIVES[p];@b@ }@b@@b@ return null;@b@ }@b@}