org.apache.myfaces.shared.util
Class ClassUtils

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

public final class ClassUtils
extends java.lang.Object

Version:
$Revision: 805066 $ $Date: 2009-08-17 12:39:52 -0500 (Mon, 17 Aug 2009) $
Author:
Manfred Geiler (latest modification by $Author: werpu $), Anton Koinov

Field Summary
static java.lang.Class BOOLEAN_ARRAY_CLASS
           
static java.lang.Class BOOLEAN_OBJECT_ARRAY_CLASS
           
static java.lang.Class BYTE_ARRAY_CLASS
           
static java.lang.Class BYTE_OBJECT_ARRAY_CLASS
           
static java.lang.Class CHAR_ARRAY_CLASS
           
static java.lang.Class CHARACTER_OBJECT_ARRAY_CLASS
           
static ClassLoaderExtension[] classLoadingExtensions
           
static java.util.Map COMMON_TYPES
           
static java.lang.Class DOUBLE_ARRAY_CLASS
           
static java.lang.Class DOUBLE_OBJECT_ARRAY_CLASS
           
static java.lang.Class FLOAT_ARRAY_CLASS
           
static java.lang.Class FLOAT_OBJECT_ARRAY_CLASS
           
static java.lang.Class INT_ARRAY_CLASS
           
static java.lang.Class INTEGER_OBJECT_ARRAY_CLASS
           
static java.lang.Class LONG_ARRAY_CLASS
           
static java.lang.Class LONG_OBJECT_ARRAY_CLASS
           
static java.lang.Class OBJECT_ARRAY_CLASS
           
static java.lang.Class SHORT_ARRAY_CLASS
           
static java.lang.Class SHORT_OBJECT_ARRAY_CLASS
           
static java.lang.Class STRING_OBJECT_ARRAY_CLASS
           
 
Method Summary
static void addClassLoadingExtension(ClassLoaderExtension extension, boolean top)
           
static java.lang.Class classForName(java.lang.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 java.lang.Object convertToType(java.lang.Object value, java.lang.Class desiredClass)
           
static java.lang.ClassLoader getContextClassLoader()
          Gets the ClassLoader associated with the current thread.
protected static java.lang.ClassLoader getCurrentLoader(java.lang.Object defaultObject)
          Gets the ClassLoader associated with the current thread.
static java.io.InputStream getResourceAsStream(java.lang.String resource)
           
static java.util.Iterator getResources(java.lang.String resource, java.lang.Object defaultObject)
           
static java.lang.Class javaTypeToClass(java.lang.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 java.lang.Object newInstance(java.lang.Class clazz)
           
static java.lang.Object newInstance(java.lang.String type)
           
static java.lang.Object newInstance(java.lang.String type, java.lang.Class expectedType)
           
static java.lang.Object newInstance(java.lang.String type, java.lang.Class[] expectedTypes)
           
static java.lang.Class simpleClassForName(java.lang.String type)
          Same as classForName(String), but throws a RuntimeException (FacesException) instead of a ClassNotFoundException.
static java.lang.Class simpleJavaTypeToClass(java.lang.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 java.lang.Class BOOLEAN_ARRAY_CLASS

BYTE_ARRAY_CLASS

public static final java.lang.Class BYTE_ARRAY_CLASS

CHAR_ARRAY_CLASS

public static final java.lang.Class CHAR_ARRAY_CLASS

SHORT_ARRAY_CLASS

public static final java.lang.Class SHORT_ARRAY_CLASS

INT_ARRAY_CLASS

public static final java.lang.Class INT_ARRAY_CLASS

LONG_ARRAY_CLASS

public static final java.lang.Class LONG_ARRAY_CLASS

FLOAT_ARRAY_CLASS

public static final java.lang.Class FLOAT_ARRAY_CLASS

DOUBLE_ARRAY_CLASS

public static final java.lang.Class DOUBLE_ARRAY_CLASS

OBJECT_ARRAY_CLASS

public static final java.lang.Class OBJECT_ARRAY_CLASS

BOOLEAN_OBJECT_ARRAY_CLASS

public static final java.lang.Class BOOLEAN_OBJECT_ARRAY_CLASS

BYTE_OBJECT_ARRAY_CLASS

public static final java.lang.Class BYTE_OBJECT_ARRAY_CLASS

CHARACTER_OBJECT_ARRAY_CLASS

public static final java.lang.Class CHARACTER_OBJECT_ARRAY_CLASS

SHORT_OBJECT_ARRAY_CLASS

public static final java.lang.Class SHORT_OBJECT_ARRAY_CLASS

INTEGER_OBJECT_ARRAY_CLASS

public static final java.lang.Class INTEGER_OBJECT_ARRAY_CLASS

LONG_OBJECT_ARRAY_CLASS

public static final java.lang.Class LONG_OBJECT_ARRAY_CLASS

FLOAT_OBJECT_ARRAY_CLASS

public static final java.lang.Class FLOAT_OBJECT_ARRAY_CLASS

DOUBLE_OBJECT_ARRAY_CLASS

public static final java.lang.Class DOUBLE_OBJECT_ARRAY_CLASS

STRING_OBJECT_ARRAY_CLASS

public static final java.lang.Class STRING_OBJECT_ARRAY_CLASS

classLoadingExtensions

public static ClassLoaderExtension[] classLoadingExtensions

COMMON_TYPES

public static final java.util.Map COMMON_TYPES
Method Detail

addClassLoadingExtension

public static void addClassLoadingExtension(ClassLoaderExtension extension,
                                            boolean top)

classForName

public static java.lang.Class classForName(java.lang.String type)
                                    throws java.lang.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:
java.lang.NullPointerException - if type is null
java.lang.ClassNotFoundException

simpleClassForName

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

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

javaTypeToClass

public static java.lang.Class javaTypeToClass(java.lang.String type)
                                       throws java.lang.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:
java.lang.NullPointerException - if type is null
java.lang.ClassNotFoundException

simpleJavaTypeToClass

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

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

getResourceAsStream

public static java.io.InputStream getResourceAsStream(java.lang.String resource)

getResources

public static java.util.Iterator getResources(java.lang.String resource,
                                              java.lang.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 java.lang.Object newInstance(java.lang.String type)
                                    throws javax.faces.FacesException
Throws:
javax.faces.FacesException

newInstance

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

newInstance

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

newInstance

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

convertToType

public static java.lang.Object convertToType(java.lang.Object value,
                                             java.lang.Class desiredClass)

getCurrentLoader

protected static java.lang.ClassLoader getCurrentLoader(java.lang.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 java.lang.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


Copyright © 2010 The Apache Software Foundation. All Rights Reserved.