org.yajul.util
Class ReflectionUtil

java.lang.Object
  extended by org.yajul.util.ReflectionUtil

public class ReflectionUtil
extends java.lang.Object

Reflection utilities. User: josh Date: Nov 16, 2003 Time: 4:45:36 PM


Constructor Summary
ReflectionUtil()
           
 
Method Summary
static java.lang.Object createInstance(java.lang.String className)
          Creates a new instance of the class, throwing an initialization error, if there was a problem.
static
<T> T
createInstance(java.lang.String className, java.lang.Class<T> componentType)
          Type checked version of create instance using the default class loader.
static java.lang.Object createInstance(java.lang.String className, java.lang.ClassLoader loader)
          Creates a new instance of the class using the specified loader.
static java.lang.String filenameToClassname(java.lang.String filename)
          Turns a class file name into a class name.
static java.net.URL findClassURL(java.lang.Class c)
          Returns the URL where the specified class is located in the current classpath.
static java.lang.String getClassResourceName(java.lang.Class c)
          Returns the resource name for the specified class.
static java.util.Map<java.lang.Integer,java.lang.String> getConstantNameMap(java.lang.Class c)
          Returns a map of (Integer->String) from the values of any static integer constants in the class.
static java.lang.ClassLoader getCurrentClassLoader()
           
static java.lang.String getterPropertyName(java.lang.reflect.Method method)
          Returns the name of the property IFF the method is a property getter, or null if the method is not a getter.
static boolean isPropertyGetter(java.lang.reflect.Method method)
          Returns true if the method is a property getter.
static java.lang.String setterPropertyName(java.lang.reflect.Method method)
          Returns the name of the property IFF the method is a property setter, or null if the method is not a setter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionUtil

public ReflectionUtil()
Method Detail

getConstantNameMap

public static java.util.Map<java.lang.Integer,java.lang.String> getConstantNameMap(java.lang.Class c)
Returns a map of (Integer->String) from the values of any static integer constants in the class.

Parameters:
c - The class to get the constants from.
Returns:
Map - A map of the constant integer values to their names.

isPropertyGetter

public static boolean isPropertyGetter(java.lang.reflect.Method method)
Returns true if the method is a property getter.

Parameters:
method - The method.
Returns:
true if the method is a property getter.

getterPropertyName

public static java.lang.String getterPropertyName(java.lang.reflect.Method method)
Returns the name of the property IFF the method is a property getter, or null if the method is not a getter.

Parameters:
method - The method.
Returns:
the name of the property IFF the method is a property getter, or null if the method is not a getter.

setterPropertyName

public static java.lang.String setterPropertyName(java.lang.reflect.Method method)
Returns the name of the property IFF the method is a property setter, or null if the method is not a setter.

Parameters:
method - The method.
Returns:
the name of the property IFF the method is a property setter, or null if the method is not a setter.

getCurrentClassLoader

public static java.lang.ClassLoader getCurrentClassLoader()

createInstance

public static java.lang.Object createInstance(java.lang.String className,
                                              java.lang.ClassLoader loader)
Creates a new instance of the class using the specified loader.

Parameters:
className - The class to instatiate - if null a default will be used
loader - The class loader to use when obtaining the instance
Returns:
An Object which is an instance of the class

createInstance

public static java.lang.Object createInstance(java.lang.String className)
Creates a new instance of the class, throwing an initialization error, if there was a problem.

Parameters:
className - The class name
Returns:
Object - The instance.

createInstance

public static <T> T createInstance(java.lang.String className,
                                   java.lang.Class<T> componentType)
Type checked version of create instance using the default class loader.

Parameters:
className - the class name
componentType - the type of the instance (e.g. an interface)
Returns:
an instance of the object cast to 'componentType'

getClassResourceName

public static java.lang.String getClassResourceName(java.lang.Class c)
Returns the resource name for the specified class.

Parameters:
c - The class.
Returns:
String - The resource name for the class.

findClassURL

public static java.net.URL findClassURL(java.lang.Class c)
Returns the URL where the specified class is located in the current classpath.

Parameters:
c - The class to look for.
Returns:
URL - The URL where the class was found, using the current class loader.

filenameToClassname

public static java.lang.String filenameToClassname(java.lang.String filename)
Turns a class file name into a class name.

Parameters:
filename - the file name
Returns:
the class name.


Copyright © 2008. All Rights Reserved.