net.sf.morph.util
Class ClassUtils

java.lang.Object
  extended by net.sf.composite.util.ClassUtils
      extended by net.sf.morph.util.ClassUtils

public abstract class ClassUtils
extends net.sf.composite.util.ClassUtils

Class manipulation utilities. Note that some code was copied from the Spring framework. Some other code was copied from Apache Ant.

Since:
Nov 6, 2004
Author:
Matt Sgarlata, Keith Donald, Rob Harrop, Juergen Hoeller, Matt Benson

Field Summary
static java.lang.Class[] ARRAY_TYPES
          All the base array classes.
 
Constructor Summary
ClassUtils()
           
 
Method Summary
static java.lang.Class convertToClass(java.lang.Object type)
          Converts the given object to a Class object.
static java.lang.Class[] getAllClasses()
          Returns the set of classes for which any class will match.
static java.lang.Class getArrayClass(java.lang.Class componentType)
          Returns an array version of the given class (for example, converts Long to Long[]).
static java.lang.Class getClass(java.lang.Object object)
          Returns the class of the given object.
static java.lang.Class[] getImmutableTypes()
          Get the known immutable types.
static java.lang.Class[] getPrimitiveTypes()
          Get all the primitive classes.
static java.lang.Class getPrimitiveWrapper(java.lang.Class c)
          Get the wrapper type for the specified class (if any).
static java.lang.Class[] getWrapperTypes()
          Get all the primitive wrapper classes.
static boolean inheritanceContains(java.lang.Class[] typeArray, java.lang.Class type)
          Determines if type is equal to or a subtype of any of the types in typeArray.
static boolean isBeanUtilsPresent()
          Indicates whether the Apache Commons BeanUtils API is available.
static boolean isCommonsCollections3Present()
          Indicates whether Commons Collections 3.x is available on the classpath.
static boolean isImmutable(java.lang.Class destinationType)
          Determines whether the given destinationType is one of the primitive immutable types provided by the JDK (i.e.
static boolean isImmutableObject(java.lang.Object o)
          Determines whether the given object is an immutable object.
static boolean isJspApiPresent()
          Indicates whether the JSP API is available.
static boolean isServletApiPresent()
          Indicates whether the Servlet API is available.
static boolean isVelocityPresent()
          Indicates whether Velocity is available.
static java.lang.Object newInstance(java.lang.Object type)
          Returns a new instance of the class denoted by type.
 
Methods inherited from class net.sf.composite.util.ClassUtils
createArray, getContainedClass, getInterfaces, getUnqualifiedClassName, isClassPresent, isJdk14OrHigherPresent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ARRAY_TYPES

public static final java.lang.Class[] ARRAY_TYPES
All the base array classes. Multidimensional arrays are subclasses of these fundamental array types.

Constructor Detail

ClassUtils

public ClassUtils()
Method Detail

getArrayClass

public static java.lang.Class getArrayClass(java.lang.Class componentType)
Returns an array version of the given class (for example, converts Long to Long[]).


newInstance

public static java.lang.Object newInstance(java.lang.Object type)
Returns a new instance of the class denoted by type. The type may be expressed as a Class object, a String or a StringBuffer.

Parameters:
type - an object that specifies the class of the new instance
Returns:
an instance of the specified class
Throws:
ReflectionException - if a new instance of the requested class could not be created
TransformationException - if the class denoted by the given type could not be retrieved
java.lang.IllegalArgumentException - if the type parameter is null or not a Class, String or StringBuffer

convertToClass

public static java.lang.Class convertToClass(java.lang.Object type)
Converts the given object to a Class object. The conversion will only succeed if the object is a Class, String or StringBuffer.

Parameters:
type - an object that specifies the class
Returns:
the specified class
Throws:
TransformationException - if the class could not be retrieved for some reason
java.lang.IllegalArgumentException - if the type parameter is null or not a Class, String or StringBuffer

isServletApiPresent

public static boolean isServletApiPresent()
Indicates whether the Servlet API is available.

Returns:
true if the servlet API is available or
false otherwise

isJspApiPresent

public static boolean isJspApiPresent()
Indicates whether the JSP API is available.

Returns:
true if the JSP API is available or
false otherwise

isBeanUtilsPresent

public static boolean isBeanUtilsPresent()
Indicates whether the Apache Commons BeanUtils API is available.

Returns:
true if the BeanUtils API is available or
false otherwise

isVelocityPresent

public static boolean isVelocityPresent()
Indicates whether Velocity is available.

Returns:
true if Velocity is available or
false otherwise

isCommonsCollections3Present

public static boolean isCommonsCollections3Present()
Indicates whether Commons Collections 3.x is available on the classpath.

Returns:
true Commons Collections 3.x is available on the classpath
false otherwise

inheritanceContains

public static boolean inheritanceContains(java.lang.Class[] typeArray,
                                          java.lang.Class type)
Determines if type is equal to or a subtype of any of the types in typeArray.

Parameters:
type - the type to test
typeArray - the array of types
Returns:
true, if type if type is equal to or a subtype of any of the types in typeArray or
false, otherwise
Throws:
java.lang.IllegalArgumentException - if any of the types in the provided typeArray are null

getClass

public static java.lang.Class getClass(java.lang.Object object)
Returns the class of the given object.

Parameters:
object - the object
Returns:
null, if type is null or
the class of the given object, otherwise

isImmutable

public static boolean isImmutable(java.lang.Class destinationType)
Determines whether the given destinationType is one of the primitive immutable types provided by the JDK (i.e. a Number or a String). Note that JDK 1.6 adds AtomicLong and AtomicInteger, which are not immutable.

Parameters:
destinationType - the type to examine
Returns:
true if the destinationType is an immutable number or a String or
false, otherwise

isImmutableObject

public static boolean isImmutableObject(java.lang.Object o)
Determines whether the given object is an immutable object.

Parameters:
o -
Returns:

getImmutableTypes

public static java.lang.Class[] getImmutableTypes()
Get the known immutable types.

Returns:
Class[]

getPrimitiveWrapper

public static java.lang.Class getPrimitiveWrapper(java.lang.Class c)
Get the wrapper type for the specified class (if any).

Parameters:
c - a (presumably primitive) Class.
Returns:
the wrapper class for c, if c is primitive, else null.

getPrimitiveTypes

public static java.lang.Class[] getPrimitiveTypes()
Get all the primitive classes.

Returns:
Class[]

getWrapperTypes

public static java.lang.Class[] getWrapperTypes()
Get all the primitive wrapper classes.

Returns:
Class[]

getAllClasses

public static java.lang.Class[] getAllClasses()
Returns the set of classes for which any class will match.

Returns:
Class[]


Copyright © 2004-2008.