org.andromda.core.common
Class ClassUtils

java.lang.Object
  extended by org.apache.commons.lang.ClassUtils
      extended by org.andromda.core.common.ClassUtils

public class ClassUtils
extends org.apache.commons.lang.ClassUtils

Contains utilities for dealing with classes.

Author:
Chad Brandon

Field Summary
static java.lang.String CLASS_EXTENSION
          The suffix for class files.
 
Fields inherited from class org.apache.commons.lang.ClassUtils
INNER_CLASS_SEPARATOR, INNER_CLASS_SEPARATOR_CHAR, PACKAGE_SEPARATOR, PACKAGE_SEPARATOR_CHAR
 
Constructor Summary
ClassUtils()
           
 
Method Summary
static java.lang.Class findClassOfType(java.net.URL[] directoryUris, java.lang.Class type)
          Searches the contents of the directoryUri and returns the first Class found that is of the given type.
static java.util.List getAllMethods(java.lang.Class clazz)
          Loads all methods from the given clazz (this includes all super class methods, public, private and protected).
static java.lang.ClassLoader getClassLoader()
          Gets the appropriate class loader instance.
static java.util.List getInterfaces(java.lang.Class clazz)
          Retrieves all interfaces for the given clazz (including clazz itself, assuming it's an interface as well).
static java.util.List getInterfaces(java.lang.String className)
          Retrieves all interfaces for the given className (including className itself, assuming it's an interface as well).
static java.lang.Class[] getInterfacesReversed(java.lang.String className)
          Gets the interfaces for the given className in reverse order.
protected static java.lang.Class getPrimitiveClass(java.lang.String name, java.lang.ClassLoader loader)
           Returns the type class name for a Java primitive.
static java.util.Collection getStaticFieldValues(java.lang.Class clazz, java.lang.Class type)
          Returns a collection of all static fields values for the given clazz and type of field.
static boolean isClassOfTypePresent(java.net.URL[] directoryUris, java.lang.Class type)
          Indicates whether or not a class of the given type is present in one of the given directoryUris.
protected static boolean isPrimitiveType(java.lang.String name)
          

Checks if a given type name is a Java primitive type.

static java.lang.Class loadClass(java.lang.String className)
          Loads and returns the class having the className.
static java.lang.Object newInstance(java.lang.Class type)
          Creates a new instance of the class given the type.
static java.lang.Object newInstance(java.lang.String className)
          Creates a new instance of the class having the given className.
 
Methods inherited from class org.apache.commons.lang.ClassUtils
convertClassesToClassNames, convertClassNamesToClasses, getAllInterfaces, getAllSuperclasses, getClass, getClass, getClass, getClass, getPackageName, getPackageName, getPackageName, getPublicMethod, getShortClassName, getShortClassName, getShortClassName, isAssignable, isAssignable, isInnerClass, primitivesToWrappers, primitiveToWrapper
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_EXTENSION

public static final java.lang.String CLASS_EXTENSION
The suffix for class files.

See Also:
Constant Field Values
Constructor Detail

ClassUtils

public ClassUtils()
Method Detail

newInstance

public static java.lang.Object newInstance(java.lang.String className)
Creates a new instance of the class having the given className.

Parameters:
className - the name of the class to instantiate.
Returns:
Object the new instance

newInstance

public static java.lang.Object newInstance(java.lang.Class type)
Creates a new instance of the class given the type.

Parameters:
type - the type from which to instantiate the new instance.
Returns:
Object the new instance

loadClass

public static java.lang.Class loadClass(java.lang.String className)
Loads and returns the class having the className. Will load but normal classes and the classes representing primatives.

Parameters:
className - the name of the class to load.
Returns:
Class the loaded class

getClassLoader

public static java.lang.ClassLoader getClassLoader()
Gets the appropriate class loader instance.

Returns:
the class loader.

getPrimitiveClass

protected static java.lang.Class getPrimitiveClass(java.lang.String name,
                                                   java.lang.ClassLoader loader)

Returns the type class name for a Java primitive.

Parameters:
name - a String with the name of the type
loader - the loader to use.
Returns:
a String with the name of the corresponding java.lang wrapper class if name is a Java primitive type; false if not

getStaticFieldValues

public static java.util.Collection getStaticFieldValues(java.lang.Class clazz,
                                                        java.lang.Class type)
                                                 throws java.lang.IllegalAccessException
Returns a collection of all static fields values for the given clazz and type of field.

Parameters:
clazz - the Class from which to retrieve the static fields
type - the type of static fields to retrieve, if null all are retrieved
Returns:
Collection the collection of static field values.
Throws:
java.lang.IllegalAccessException

getInterfaces

public static java.util.List getInterfaces(java.lang.String className)
Retrieves all interfaces for the given className (including className itself, assuming it's an interface as well).

Parameters:
className - the root interface className
Returns:
a list containing all interfaces ordered from the root down.

getInterfaces

public static java.util.List getInterfaces(java.lang.Class clazz)
Retrieves all interfaces for the given clazz (including clazz itself, assuming it's an interface as well).

Parameters:
clazz - the root interface class
Returns:
a list containing all interfaces ordered from the root down.

getInterfacesReversed

public static java.lang.Class[] getInterfacesReversed(java.lang.String className)
Gets the interfaces for the given className in reverse order.

Parameters:
className - the name of the class for which to retrieve the interfaces
Returns:
the array containing the reversed interfaces.

isPrimitiveType

protected static boolean isPrimitiveType(java.lang.String name)

Checks if a given type name is a Java primitive type.

Parameters:
name - a String with the name of the type
Returns:
true if name is a Java primitive type; false if not

findClassOfType

public static java.lang.Class findClassOfType(java.net.URL[] directoryUris,
                                              java.lang.Class type)
Searches the contents of the directoryUri and returns the first Class found that is of the given type.

Parameters:
directoryUris - the URIs to search, ie. directories or archives.
type - the type to find.
Returns:
the class or null if not found.

getAllMethods

public static java.util.List getAllMethods(java.lang.Class clazz)
Loads all methods from the given clazz (this includes all super class methods, public, private and protected).

Parameters:
clazz - the class to retrieve the methods.
Returns:
the loaded methods.

isClassOfTypePresent

public static boolean isClassOfTypePresent(java.net.URL[] directoryUris,
                                           java.lang.Class type)
Indicates whether or not a class of the given type is present in one of the given directoryUris.

Parameters:
directoryUris - the URIs to search, ie. directories or archives.
type - the type to check.
Returns:
true/false.


Copyright © 2003-2008 AndroMDA.org. All Rights Reserved.