org.apache.myfaces.commons.util
Class ClassUtils

java.lang.Object
  extended by org.apache.myfaces.commons.util.ClassUtils

public final class ClassUtils
extends Object

Version:
$Revision: 1031358 $ $Date: 2010-11-04 19:00:39 -0500 (Thu, 04 Nov 2010) $
Author:
Manfred Geiler (latest modification by $Author: lu4242 $), Anton Koinov

Field Summary
static Class BOOLEAN_ARRAY_CLASS
           
static Class BOOLEAN_OBJECT_ARRAY_CLASS
           
static Class BYTE_ARRAY_CLASS
           
static Class BYTE_OBJECT_ARRAY_CLASS
           
static Class CHAR_ARRAY_CLASS
           
static Class CHARACTER_OBJECT_ARRAY_CLASS
           
static Map COMMON_TYPES
           
static Class DOUBLE_ARRAY_CLASS
           
static Class DOUBLE_OBJECT_ARRAY_CLASS
           
static Class FLOAT_ARRAY_CLASS
           
static Class FLOAT_OBJECT_ARRAY_CLASS
           
static Class INT_ARRAY_CLASS
           
static Class INTEGER_OBJECT_ARRAY_CLASS
           
static Class LONG_ARRAY_CLASS
           
static Class LONG_OBJECT_ARRAY_CLASS
           
static Class OBJECT_ARRAY_CLASS
           
static Class SHORT_ARRAY_CLASS
           
static Class SHORT_OBJECT_ARRAY_CLASS
           
static Class STRING_OBJECT_ARRAY_CLASS
           
 
Method Summary
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.
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.
static Class 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 ClassLoader getContextClassLoader()
          Gets the ClassLoader associated with the current thread.
protected static ClassLoader getCurrentLoader(Object defaultObject)
          Gets the ClassLoader associated with the current thread.
static InputStream getResourceAsStream(String resource)
           
static Iterator getResources(String resource, Object defaultObject)
           
static Class javaTypeToClass(String type)
          Similar as classForName(String), but also supports primitive types and arrays as specified for the JavaType element in the JavaServer Faces Config DTD.
static Object newInstance(Class clazz)
           
static Object newInstance(String type)
           
static Object newInstance(String type, Class expectedType)
           
static Object newInstance(String type, Class[] expectedTypes)
           
static Class simpleClassForName(String type)
          Same as classForName(String), but throws a RuntimeException (FacesException) instead of a ClassNotFoundException.
static Class simpleJavaTypeToClass(String type)
          Same as javaTypeToClass(String), but throws a RuntimeException (FacesException) instead of a ClassNotFoundException.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

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 null
ClassNotFoundException

simpleClassForName

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

Returns:
the corresponding Class
Throws:
NullPointerException - if type is null
javax.faces.FacesException - if class not found

javaTypeToClass

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

simpleJavaTypeToClass

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

Returns:
the corresponding Class
Throws:
NullPointerException - if type is null
javax.faces.FacesException - 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 classpath
defaultObject - 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 javax.faces.FacesException
Throws:
javax.faces.FacesException

newInstance

public static Object newInstance(String type,
                                 Class expectedType)
                          throws javax.faces.FacesException
Throws:
javax.faces.FacesException

newInstance

public static Object newInstance(String type,
                                 Class[] expectedTypes)

newInstance

public static Object newInstance(Class clazz)
                          throws javax.faces.FacesException
Throws:
javax.faces.FacesException

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

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:
1.0.1

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:
Since:
1.0.1

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:
Since:
1.0.1


Copyright © 2007-2011 The Apache Software Foundation. All Rights Reserved.