org.apache.myfaces.util

Class ClassUtils

public class ClassUtils extends Object

Version: $Revision: 265527 $ $Date: 2005-08-31 18:32:30 +0200 (Wed, 31 Aug 2005) $

Author: Manfred Geiler (latest modification by $Author: manolito $) Anton Koinov

Field Summary
static ClassBOOLEAN_ARRAY_CLASS
static ClassBOOLEAN_OBJECT_ARRAY_CLASS
static ClassBYTE_ARRAY_CLASS
static ClassBYTE_OBJECT_ARRAY_CLASS
static ClassCHARACTER_OBJECT_ARRAY_CLASS
static ClassCHAR_ARRAY_CLASS
static MapCOMMON_TYPES
static ClassDOUBLE_ARRAY_CLASS
static ClassDOUBLE_OBJECT_ARRAY_CLASS
static ClassFLOAT_ARRAY_CLASS
static ClassFLOAT_OBJECT_ARRAY_CLASS
static ClassINTEGER_OBJECT_ARRAY_CLASS
static ClassINT_ARRAY_CLASS
static ClassLONG_ARRAY_CLASS
static ClassLONG_OBJECT_ARRAY_CLASS
static ClassOBJECT_ARRAY_CLASS
static ClassSHORT_ARRAY_CLASS
static ClassSHORT_OBJECT_ARRAY_CLASS
static ClassSTRING_OBJECT_ARRAY_CLASS
Method Summary
static ClassclassForName(String type)
Tries a Class.forName 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)
protected static ClassLoadergetCurrentLoader(Object defaultObject)
Gets the ClassLoader associated with the current thread.
static InputStreamgetResourceAsStream(String resource)
static IteratorgetResources(String resource, Object defaultObject)
static ClassjavaTypeToClass(String type)
Similar as classForName, but also supports primitive types and arrays as specified for the JavaType element in the JavaServer Faces Config DTD.
static ObjectnewInstance(String type)
static ObjectnewInstance(Class clazz)
static ClasssimpleClassForName(String type)
Same as classForName, but throws a RuntimeException (FacesException) instead of a ClassNotFoundException.
static ClasssimpleJavaTypeToClass(String type)
Same as javaTypeToClass, but throws a RuntimeException (FacesException) instead of a ClassNotFoundException.

Field Detail

BOOLEAN_ARRAY_CLASS

public static final Class BOOLEAN_ARRAY_CLASS

BOOLEAN_OBJECT_ARRAY_CLASS

public static final Class BOOLEAN_OBJECT_ARRAY_CLASS

BYTE_ARRAY_CLASS

public static final Class BYTE_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

CHAR_ARRAY_CLASS

public static final Class CHAR_ARRAY_CLASS

COMMON_TYPES

public static final Map COMMON_TYPES

DOUBLE_ARRAY_CLASS

public static final Class DOUBLE_ARRAY_CLASS

DOUBLE_OBJECT_ARRAY_CLASS

public static final Class DOUBLE_OBJECT_ARRAY_CLASS

FLOAT_ARRAY_CLASS

public static final Class FLOAT_ARRAY_CLASS

FLOAT_OBJECT_ARRAY_CLASS

public static final Class FLOAT_OBJECT_ARRAY_CLASS

INTEGER_OBJECT_ARRAY_CLASS

public static final Class INTEGER_OBJECT_ARRAY_CLASS

INT_ARRAY_CLASS

public static final Class INT_ARRAY_CLASS

LONG_ARRAY_CLASS

public static final Class LONG_ARRAY_CLASS

LONG_OBJECT_ARRAY_CLASS

public static final Class LONG_OBJECT_ARRAY_CLASS

OBJECT_ARRAY_CLASS

public static final Class OBJECT_ARRAY_CLASS

SHORT_ARRAY_CLASS

public static final Class SHORT_ARRAY_CLASS

SHORT_OBJECT_ARRAY_CLASS

public static final Class SHORT_OBJECT_ARRAY_CLASS

STRING_OBJECT_ARRAY_CLASS

public static final Class STRING_OBJECT_ARRAY_CLASS

Method Detail

classForName

public static Class classForName(String type)
Tries a Class.forName 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

convertToType

public static Object convertToType(Object value, Class desiredClass)

getCurrentLoader

protected 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

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 classpath defaultObject The default object to use to determine the class loader (if none associated with current thread.)

Returns: Iterator over URL Objects

javaTypeToClass

public static Class javaTypeToClass(String type)
Similar as classForName, 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

newInstance

public static Object newInstance(String type)

newInstance

public static Object newInstance(Class clazz)

simpleClassForName

public static Class simpleClassForName(String type)
Same as classForName, but throws a RuntimeException (FacesException) instead of a ClassNotFoundException.

Returns: the corresponding Class

Throws: NullPointerException if type is null FacesException if class not found

simpleJavaTypeToClass

public static Class simpleJavaTypeToClass(String type)
Same as javaTypeToClass, but throws a RuntimeException (FacesException) instead of a ClassNotFoundException.

Returns: the corresponding Class

Throws: NullPointerException if type is null FacesException if class not found