Package org.apache.myfaces.util.lang
Class ClassUtils
- java.lang.Object
-
- org.apache.myfaces.util.lang.ClassUtils
-
public final class ClassUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static ClassBOOLEAN_ARRAY_CLASSstatic ClassBOOLEAN_OBJECT_ARRAY_CLASSstatic ClassBYTE_ARRAY_CLASSstatic ClassBYTE_OBJECT_ARRAY_CLASSstatic ClassCHAR_ARRAY_CLASSstatic ClassCHARACTER_OBJECT_ARRAY_CLASSstatic MapCOMMON_TYPESstatic ClassDOUBLE_ARRAY_CLASSstatic ClassDOUBLE_OBJECT_ARRAY_CLASSprotected static String[]EMPTY_STRINGstatic ClassFLOAT_ARRAY_CLASSstatic ClassFLOAT_OBJECT_ARRAY_CLASSstatic ClassINT_ARRAY_CLASSstatic ClassINTEGER_OBJECT_ARRAY_CLASSstatic ClassLONG_ARRAY_CLASSstatic ClassLONG_OBJECT_ARRAY_CLASSstatic ClassOBJECT_ARRAY_CLASSprotected static String[]PRIMITIVE_NAMESprotected static Class<?>[]PRIMITIVESstatic ClassSHORT_ARRAY_CLASSstatic ClassSHORT_OBJECT_ARRAY_CLASSstatic ClassSTRING_OBJECT_ARRAY_CLASS
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> TbuildApplicationObject(Class<T> interfaceClass, Class<? extends T> extendedInterfaceClass, Class<? extends T> extendedInterfaceWrapperClass, Collection<String> classNamesIterator, T defaultObject)Creates ApplicationObjects like NavigationHandler or StateManager and creates the right wrapping chain of the ApplicationObjects known as the decorator pattern.static <T> TbuildApplicationObject(Class<T> interfaceClass, Collection<String> classNamesIterator, T defaultObject)Creates ApplicationObjects like NavigationHandler or StateManager and creates the right wrapping chain of the ApplicationObjects known as the decorator pattern.static ClassclassForName(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. the loader of the myfaces.jar lib) if necessary.static ObjectconvertToType(Object value, Class desiredClass)static Class<?>forName(String name)protected static Class<?>forNamePrimitive(String name)static ClassLoadergetContextClassLoader()Gets the ClassLoader associated with the current thread.static ClassLoadergetCurrentLoader(Object defaultObject)Gets the ClassLoader associated with the current thread.static URLgetResource(String resource)static InputStreamgetResourceAsStream(String resource)static IteratorgetResources(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 ClassjavaTypeToClass(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)protected static StringparamString(Class<?>... types)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 ClasssimpleJavaTypeToClass(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 namesstatic <T> TwrapBackwardCompatible(Class<T> interfaceClass, Class<? extends T> extendedInterfaceClass, Class<? extends T> extendedInterfaceWrapperClass, T defaultObject, T newCurrent)Wrap an object using a backwards compatible wrapper if available
-
-
-
Field Detail
-
BOOLEAN_ARRAY_CLASS
public static final Class BOOLEAN_ARRAY_CLASS
-
BYTE_ARRAY_CLASS
public static final Class BYTE_ARRAY_CLASS
-
CHAR_ARRAY_CLASS
public static final Class CHAR_ARRAY_CLASS
-
SHORT_ARRAY_CLASS
public static final Class SHORT_ARRAY_CLASS
-
INT_ARRAY_CLASS
public static final Class INT_ARRAY_CLASS
-
LONG_ARRAY_CLASS
public static final Class LONG_ARRAY_CLASS
-
FLOAT_ARRAY_CLASS
public static final Class FLOAT_ARRAY_CLASS
-
DOUBLE_ARRAY_CLASS
public static final Class DOUBLE_ARRAY_CLASS
-
OBJECT_ARRAY_CLASS
public static final Class OBJECT_ARRAY_CLASS
-
BOOLEAN_OBJECT_ARRAY_CLASS
public static final Class BOOLEAN_OBJECT_ARRAY_CLASS
-
BYTE_OBJECT_ARRAY_CLASS
public static final Class BYTE_OBJECT_ARRAY_CLASS
-
CHARACTER_OBJECT_ARRAY_CLASS
public static final Class CHARACTER_OBJECT_ARRAY_CLASS
-
SHORT_OBJECT_ARRAY_CLASS
public static final Class SHORT_OBJECT_ARRAY_CLASS
-
INTEGER_OBJECT_ARRAY_CLASS
public static final Class INTEGER_OBJECT_ARRAY_CLASS
-
LONG_OBJECT_ARRAY_CLASS
public static final Class LONG_OBJECT_ARRAY_CLASS
-
FLOAT_OBJECT_ARRAY_CLASS
public static final Class FLOAT_OBJECT_ARRAY_CLASS
-
DOUBLE_OBJECT_ARRAY_CLASS
public static final Class DOUBLE_OBJECT_ARRAY_CLASS
-
STRING_OBJECT_ARRAY_CLASS
public static final Class STRING_OBJECT_ARRAY_CLASS
-
EMPTY_STRING
protected static final String[] EMPTY_STRING
-
PRIMITIVE_NAMES
protected static final String[] PRIMITIVE_NAMES
-
PRIMITIVES
protected static final Class<?>[] PRIMITIVES
-
COMMON_TYPES
public static final Map COMMON_TYPES
-
-
Method Detail
-
classForName
public static Class 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 nullClassNotFoundException
-
simpleClassForName
public 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 nullFacesException- if class not found
-
simpleClassForName
public 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
-
javaTypeToClass
public 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 nullClassNotFoundException
-
javaDefaultTypeToClass
public 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
-
simpleJavaTypeToClass
public 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 nullFacesException- if class not found
-
getResourceAsStream
public static InputStream getResourceAsStream(String resource)
-
getResources
public static Iterator getResources(String resource, Object defaultObject)
- Parameters:
resource- Name of resource(s) to find in classpathdefaultObject- The default object to use to determine the class loader (if none associated with current thread.)- Returns:
- Iterator over URL Objects
-
newInstance
public static Object newInstance(String type) throws FacesException
- Throws:
FacesException
-
newInstance
public static Object newInstance(String type, Class expectedType) throws FacesException
- Throws:
FacesException
-
newInstance
public static <T> T newInstance(Class<T> clazz) throws FacesException
- Throws:
FacesException
-
newInstance
public static <T> T newInstance(Class<T> clazz, Class<?>[] constructorArgClasses, Object... constructorArgs) throws NoSuchMethodException
- Throws:
NoSuchMethodException
-
getCurrentLoader
public 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
-
getContextClassLoader
public static ClassLoader getContextClassLoader()
Gets the ClassLoader associated with the current thread. Includes a check for priviledges against java2 security to ensure no security related exceptions are encountered.- Returns:
- ClassLoader
- Since:
- 3.0.6
-
buildApplicationObject
public static <T> T buildApplicationObject(Class<T> interfaceClass, Collection<String> classNamesIterator, T defaultObject)
Creates ApplicationObjects like NavigationHandler or StateManager and creates the right wrapping chain of the ApplicationObjects known as the decorator pattern.- Type Parameters:
T-- Parameters:
interfaceClass- The class from which the implementation has to inherit from.classNamesIterator- All the class names of the actual ApplicationObject implementations from the faces-config.xml.defaultObject- The default implementation for the given ApplicationObject.- Returns:
-
buildApplicationObject
public static <T> T buildApplicationObject(Class<T> interfaceClass, Class<? extends T> extendedInterfaceClass, Class<? extends T> extendedInterfaceWrapperClass, Collection<String> classNamesIterator, T defaultObject)
Creates ApplicationObjects like NavigationHandler or StateManager and creates the right wrapping chain of the ApplicationObjects known as the decorator pattern.- Type Parameters:
T-- Parameters:
interfaceClass- The class from which the implementation has to inherit from.extendedInterfaceClass- A subclass of interfaceClass which specifies a more detailed implementation.extendedInterfaceWrapperClass- A wrapper class for the case that you have an ApplicationObject which only implements the interfaceClass but not the extendedInterfaceClass.classNamesIterator- All the class names of the actual ApplicationObject implementations from the faces-config.xml.defaultObject- The default implementation for the given ApplicationObject.- Returns:
-
wrapBackwardCompatible
public static <T> T wrapBackwardCompatible(Class<T> interfaceClass, Class<? extends T> extendedInterfaceClass, Class<? extends T> extendedInterfaceWrapperClass, T defaultObject, T newCurrent)
Wrap an object using a backwards compatible wrapper if available- Parameters:
interfaceClass- The class from which the implementation has to inherit from.extendedInterfaceClass- A subclass of interfaceClass which specifies a more detailed implementation.extendedInterfaceWrapperClass- A wrapper class for the case that you have an ApplicationObject which only implements the interfaceClass but not the extendedInterfaceClass.defaultObject- The default implementation for the given ApplicationObject.newCurrent- The new current object- Returns:
-
forName
public static Class<?> forName(String name) throws ClassNotFoundException
- Throws:
ClassNotFoundException
-
toTypeArray
public static Class<?>[] toTypeArray(String[] s) throws ClassNotFoundException
Converts an array of Class names to Class types- Parameters:
s-- Returns:
- Throws:
ClassNotFoundException
-
toTypeNameArray
public static String[] toTypeNameArray(Class<?>[] c)
Converts an array of Class types to Class names- Parameters:
c-- Returns:
-
-