public class ClassHelper
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static java.lang.Object |
buildNewObjectInstance(ClassDescriptor cld)
Builds a new instance for the class represented by the given class descriptor.
|
static java.lang.Class |
getClass(java.lang.String name)
Convenience method for
getClass(name, true) |
static java.lang.Class |
getClass(java.lang.String className,
boolean initialize)
Retrieves the class object for the given qualified class name.
|
static java.lang.ClassLoader |
getClassLoader()
Returns the class loader currently used by OJB.
|
static java.lang.reflect.Field |
getField(java.lang.Class clazz,
java.lang.String fieldName)
Determines the field via reflection look-up.
|
static java.lang.reflect.Method |
getMethod(java.lang.Class clazz,
java.lang.String methodName,
java.lang.Class[] params)
Determines the method with the specified signature via reflection look-up.
|
static java.lang.reflect.Method |
getMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Class[] params)
Determines the method with the specified signature via reflection look-up.
|
static java.lang.reflect.Method |
getMethod(java.lang.String className,
java.lang.String methodName,
java.lang.Class[] params)
Determines the method with the specified signature via reflection look-up.
|
static java.net.URL |
getResource(java.lang.String name)
Determines the url of the indicated resource using the currently set class loader.
|
static java.lang.Object |
newInstance(java.lang.Class target)
Returns a new instance of the given class, using the default or a no-arg constructor.
|
static java.lang.Object |
newInstance(java.lang.Class target,
boolean makeAccessible)
Returns a new instance of the given class, using the default or a no-arg constructor.
|
static java.lang.Object |
newInstance(java.lang.Class target,
java.lang.Class[] types,
java.lang.Object[] args)
Returns a new instance of the given class, using the constructor with the specified parameter types.
|
static java.lang.Object |
newInstance(java.lang.Class target,
java.lang.Class[] types,
java.lang.Object[] args,
boolean makeAccessible)
Returns a new instance of the given class, using the constructor with the specified parameter types.
|
static java.lang.Object |
newInstance(java.lang.Class target,
java.lang.Class type,
java.lang.Object arg)
Returns a new instance of the given class using the constructor with the specified parameter.
|
static java.lang.Object |
newInstance(java.lang.String className)
Returns a new instance of the class with the given qualified name using the default or
or a no-arg constructor.
|
static java.lang.Object |
newInstance(java.lang.String className,
java.lang.Class[] types,
java.lang.Object[] args)
Returns a new instance of the class with the given qualified name using the constructor with
the specified signature.
|
static java.lang.Object |
newInstance(java.lang.String className,
java.lang.Class type,
java.lang.Object arg)
Returns a new instance of the class with the given qualified name using the constructor with
the specified parameter.
|
static void |
setClassLoader(java.lang.ClassLoader loader)
Sets the classloader to be used by OJB.
|
public static void setClassLoader(java.lang.ClassLoader loader)
loader
- The class loader. If null
then OJB will use
the class loader of the current threadpublic static java.lang.ClassLoader getClassLoader()
Thread.currentThread().getContextClassLoader()
)
if not set differently. If class loader is not explicitly set and the loader for
the current thread context is null, the JVM default class loader will be used.setClassLoader(ClassLoader)
public static java.net.URL getResource(java.lang.String name)
name
- The resource namepublic static java.lang.Class getClass(java.lang.String className, boolean initialize) throws java.lang.ClassNotFoundException
className
- The qualified name of the classinitialize
- Whether the class shall be initializedjava.lang.ClassNotFoundException
public static java.lang.Object newInstance(java.lang.Class target) throws java.lang.InstantiationException, java.lang.IllegalAccessException
target
- The class to instantiatejava.lang.InstantiationException
java.lang.IllegalAccessException
public static java.lang.Object newInstance(java.lang.Class target, boolean makeAccessible) throws java.lang.InstantiationException, java.lang.IllegalAccessException
makeAccessible
is set to true
(and there are no other security constraints).target
- The class to instantiatemakeAccessible
- If the constructor shall be made accessible prior to using itjava.lang.InstantiationException
java.lang.IllegalAccessException
public static java.lang.Object newInstance(java.lang.Class target, java.lang.Class[] types, java.lang.Object[] args) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.IllegalArgumentException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.lang.SecurityException
target
- The class to instantiatetypes
- The parameter typesargs
- The argumentsjava.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.SecurityException
public static java.lang.Object newInstance(java.lang.Class target, java.lang.Class[] types, java.lang.Object[] args, boolean makeAccessible) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.IllegalArgumentException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.lang.SecurityException
makeAccessible
is set to
true
(and there are no other security constraints).target
- The class to instantiatetypes
- The parameter typesargs
- The argumentsmakeAccessible
- If the constructor shall be made accessible prior to using itjava.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.SecurityException
public static java.lang.reflect.Method getMethod(java.lang.Class clazz, java.lang.String methodName, java.lang.Class[] params)
clazz
- The java class to search inmethodName
- The method's nameparams
- The parameter typesnull
if no matching method was foundpublic static java.lang.reflect.Field getField(java.lang.Class clazz, java.lang.String fieldName)
clazz
- The java class to search infieldName
- The field's namenull
if no matching field was foundpublic static java.lang.Class getClass(java.lang.String name) throws java.lang.ClassNotFoundException
getClass(name, true)
name
- The qualified class namejava.lang.ClassNotFoundException
public static java.lang.Object newInstance(java.lang.String className) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.ClassNotFoundException
className
- The qualified name of the class to instantiatejava.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.ClassNotFoundException
public static java.lang.Object newInstance(java.lang.String className, java.lang.Class[] types, java.lang.Object[] args) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.IllegalArgumentException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.lang.SecurityException, java.lang.ClassNotFoundException
className
- The qualified name of the class to instantiatetypes
- The parameter typesargs
- The argumentsjava.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.SecurityException
java.lang.ClassNotFoundException
public static java.lang.Object newInstance(java.lang.Class target, java.lang.Class type, java.lang.Object arg) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.IllegalArgumentException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.lang.SecurityException
target
- The class to instantiatetype
- The types of the single parameter of the constructorarg
- The argumentjava.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.SecurityException
public static java.lang.Object newInstance(java.lang.String className, java.lang.Class type, java.lang.Object arg) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.IllegalArgumentException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.lang.SecurityException, java.lang.ClassNotFoundException
className
- The qualified name of the class to instantiatetype
- The types of the single parameter of the constructorarg
- The argumentjava.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.SecurityException
java.lang.ClassNotFoundException
public static java.lang.reflect.Method getMethod(java.lang.Object object, java.lang.String methodName, java.lang.Class[] params)
object
- The instance whose class is searched for the methodmethodName
- The method's nameparams
- The parameter typesnull
if no matching method was foundpublic static java.lang.reflect.Method getMethod(java.lang.String className, java.lang.String methodName, java.lang.Class[] params)
className
- The qualified name of the searched classmethodName
- The method's nameparams
- The parameter typesnull
if no matching method was foundpublic static java.lang.Object buildNewObjectInstance(ClassDescriptor cld)
cld
- The class descriptor(C) 2002 - 2005 Apache Software Foundation
All rights reserved. Published under the Apache License 2.0.
http://db.apache.org/ojb
Version: 1.0.4, 2005-12-30