Class ClassUtils
- java.lang.Object
- 
- org.apache.myfaces.core.api.shared.lang.ClassUtils
 
- 
 public class ClassUtils extends Object 
- 
- 
Field Summary
 - 
Constructor SummaryConstructors Constructor Description ClassUtils()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Class<T>classForName(String type)Tries a Class.loadClass with the context class loader of the current thread first and automatically falls back to the ClassUtils class loader (i.e.static ObjectconvertToType(Object value, Class<?> desiredClass)static ObjectconvertToTypeNoLogging(FacesContext facesContext, Object value, Class<?> desiredClass)static Class<?>forName(String name)static Class<?>forNamePrimitive(String name)static ClassLoadergetContextClassLoader()Gets the ClassLoader associated with the current thread.static ClassLoadergetCurrentLoader(Class<?> clazz)static ClassLoadergetCurrentLoader(Object defaultObject)Gets the ClassLoader associated with the current thread.static URLgetResource(String resource)static InputStreamgetResourceAsStream(String resource)static Collection<URL>getResources(String resource, Object defaultObject)static ClassjavaDefaultTypeToClass(String type)This method is similar to shared ClassUtils.javaTypeToClass, but the default package for the type is java.langstatic Class<?>javaTypeToClass(String type)Similar asclassForName(String), but also supports primitive types and arrays as specified for the JavaType element in the JavaServer Faces Config DTD.static <T> TnewInstance(Class<T> clazz)static <T> TnewInstance(Class<T> clazz, Class<?>[] constructorArgClasses, Object... constructorArgs)static ObjectnewInstance(String type)static ObjectnewInstance(String type, Class<?> expectedType)static ObjectnewInstance(String type, Class<?>[] expectedTypes)static ClasssimpleClassForName(String type)Same asclassForName(String), but throws a RuntimeException (FacesException) instead of a ClassNotFoundException.static ClasssimpleClassForName(String type, boolean logException)Same as {linksimpleClassForName(String), but will only log the exception and rethrow a RunTimeException if logException is true.static Class<?>simpleJavaTypeToClass(String type)Same asjavaTypeToClass(String), but throws a RuntimeException (FacesException) instead of a ClassNotFoundException.static Class<?>[]toTypeArray(String[] s)Converts an array of Class names to Class typesstatic String[]toTypeNameArray(Class<?>[] c)Converts an array of Class types to Class names
 
- 
- 
- 
Field Detail- 
BOOLEAN_ARRAY_CLASSpublic static final Class<boolean[]> BOOLEAN_ARRAY_CLASS 
 - 
BYTE_ARRAY_CLASSpublic static final Class<byte[]> BYTE_ARRAY_CLASS 
 - 
CHAR_ARRAY_CLASSpublic static final Class<char[]> CHAR_ARRAY_CLASS 
 - 
SHORT_ARRAY_CLASSpublic static final Class<short[]> SHORT_ARRAY_CLASS 
 - 
INT_ARRAY_CLASSpublic static final Class<int[]> INT_ARRAY_CLASS 
 - 
LONG_ARRAY_CLASSpublic static final Class<long[]> LONG_ARRAY_CLASS 
 - 
FLOAT_ARRAY_CLASSpublic static final Class<float[]> FLOAT_ARRAY_CLASS 
 - 
DOUBLE_ARRAY_CLASSpublic static final Class<double[]> DOUBLE_ARRAY_CLASS 
 - 
EMPTY_STRINGprotected static final String[] EMPTY_STRING 
 - 
PRIMITIVE_NAMESprotected static final String[] PRIMITIVE_NAMES 
 - 
PRIMITIVESprotected static final Class<?>[] PRIMITIVES 
 
- 
 - 
Method Detail- 
classForNamepublic static <T> Class<T> classForName(String type) throws ClassNotFoundException Tries a Class.loadClass with the context class loader of the current thread first and automatically falls back to the ClassUtils class loader (i.e. the loader of the myfaces.jar lib) if necessary.- Parameters:
- type- fully qualified name of a non-primitive non-array class
- Returns:
- the corresponding Class
- Throws:
- NullPointerException- if type is null
- ClassNotFoundException
 
 - 
simpleClassForNamepublic static Class simpleClassForName(String type) Same asclassForName(String), but throws a RuntimeException (FacesException) instead of a ClassNotFoundException.- Returns:
- the corresponding Class
- Throws:
- NullPointerException- if type is null
- FacesException- if class not found
 
 - 
simpleClassForNamepublic static Class simpleClassForName(String type, boolean logException) Same as {linksimpleClassForName(String), but will only log the exception and rethrow a RunTimeException if logException is true.- Parameters:
- type-
- logException- - true to log/throw FacesException, false to avoid logging/throwing FacesException
- Returns:
- the corresponding Class
- Throws:
- FacesException- if class not found and logException is true
 
 - 
javaTypeToClasspublic static Class<?> javaTypeToClass(String type) throws ClassNotFoundException Similar asclassForName(String), but also supports primitive types and arrays as specified for the JavaType element in the JavaServer Faces Config DTD.- Parameters:
- type- fully qualified class name or name of a primitive type, both optionally followed by "[]" to indicate an array type
- Returns:
- the corresponding Class
- Throws:
- NullPointerException- if type is null
- ClassNotFoundException
 
 - 
simpleJavaTypeToClasspublic static Class<?> simpleJavaTypeToClass(String type) Same asjavaTypeToClass(String), but throws a RuntimeException (FacesException) instead of a ClassNotFoundException.- Returns:
- the corresponding Class
- Throws:
- NullPointerException- if type is null
- FacesException- if class not found
 
 - 
javaDefaultTypeToClasspublic static Class javaDefaultTypeToClass(String type) throws ClassNotFoundException This method is similar to shared ClassUtils.javaTypeToClass, but the default package for the type is java.lang- Parameters:
- type-
- Returns:
- Throws:
- ClassNotFoundException
 
 - 
getResourceAsStreampublic static InputStream getResourceAsStream(String resource) 
 - 
getResourcespublic static Collection<URL> getResources(String resource, Object defaultObject) - Parameters:
- resource- Name of resource(s) to find in classpath
- defaultObject- The default object to use to determine the class loader (if none associated with current thread.)
- Returns:
- Iterator over URL Objects
 
 - 
newInstancepublic static Object newInstance(String type) throws FacesException - Throws:
- FacesException
 
 - 
newInstancepublic static Object newInstance(String type, Class<?> expectedType) throws FacesException - Throws:
- FacesException
 
 - 
newInstancepublic static <T> T newInstance(Class<T> clazz) throws FacesException - Throws:
- FacesException
 
 - 
newInstancepublic static <T> T newInstance(Class<T> clazz, Class<?>[] constructorArgClasses, Object... constructorArgs) throws NoSuchMethodException - Throws:
- NoSuchMethodException
 
 - 
convertToTypeNoLoggingpublic static Object convertToTypeNoLogging(FacesContext facesContext, Object value, Class<?> desiredClass) throws Exception - Throws:
- Exception
 
 - 
getCurrentLoaderpublic static ClassLoader getCurrentLoader(Object defaultObject) Gets the ClassLoader associated with the current thread. Returns the class loader associated with the specified default object if no context loader is associated with the current thread.- Parameters:
- defaultObject- The default object to use to determine the class loader (if none associated with current thread.)
- Returns:
- ClassLoader
 
 - 
getCurrentLoaderpublic static ClassLoader getCurrentLoader(Class<?> clazz) 
 - 
getContextClassLoaderpublic static ClassLoader getContextClassLoader() Gets the ClassLoader associated with the current thread. Returns the class loader associated with the specified default object if no context loader is associated with the current thread.- Returns:
- ClassLoader
 
 - 
toTypeArraypublic static Class<?>[] toTypeArray(String[] s) throws ClassNotFoundException Converts an array of Class names to Class types- Parameters:
- s-
- Returns:
- Throws:
- ClassNotFoundException
 
 - 
toTypeNameArraypublic static String[] toTypeNameArray(Class<?>[] c) Converts an array of Class types to Class names- Parameters:
- c-
- Returns:
 
 - 
forNamepublic static Class<?> forName(String name) throws ClassNotFoundException - Throws:
- ClassNotFoundException
 
 
- 
 
-