Package org.teiid.core.util
Class ReflectionHelper
- java.lang.Object
-
- org.teiid.core.util.ReflectionHelper
-
public class ReflectionHelper extends Object
-
-
Constructor Summary
Constructors Constructor Description ReflectionHelper(Class<?> targetClass)
Construct a ReflectionHelper instance that cache's some information about the target class.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Object
create(String className, Object[] ctorObjs, Class<?>[] argTypes, ClassLoader classLoader)
static Object
create(String className, Collection<?> ctorObjs, ClassLoader classLoader)
Helper method to create an instance of the class using the appropriate constructor based on the ctorObjs passed.Method
findBestMethodOnTarget(String methodName, Object[] arguments)
Find the best method on the target class that matches the signature specified with the specified name and the list of arguments.Method
findBestMethodWithSignature(String methodName, Object[] argumentsClasses)
Find the best method on the target class that matches the signature specified with the specified name and the list of argument classes.Method
findBestMethodWithSignature(String methodName, List<Class<?>> argumentsClasses)
Find the best method on the target class that matches the signature specified with the specified name and the list of argument classes.
-
-
-
Constructor Detail
-
ReflectionHelper
public ReflectionHelper(Class<?> targetClass)
Construct a ReflectionHelper instance that cache's some information about the target class. The target class is the Class object upon which the methods will be found.- Parameters:
targetClass
- the target class- Throws:
IllegalArgumentException
- if the target class is null
-
-
Method Detail
-
findBestMethodOnTarget
public Method findBestMethodOnTarget(String methodName, Object[] arguments) throws NoSuchMethodException, SecurityException
Find the best method on the target class that matches the signature specified with the specified name and the list of arguments. This method first attempts to find the method with the specified arguments; if no such method is found, a NoSuchMethodException is thrown.This method is unable to find methods with signatures that include both primitive arguments and arguments that are instances of
Number
or its subclasses.- Parameters:
methodName
- the name of the method that is to be invoked.arguments
- the array of Object instances that correspond to the arguments passed to the method.- Returns:
- the Method object that references the method that satisfies the requirements, or null if no satisfactory method could be found.
- Throws:
NoSuchMethodException
- if a matching method is not found.SecurityException
- if access to the information is denied.
-
findBestMethodWithSignature
public Method findBestMethodWithSignature(String methodName, Object[] argumentsClasses) throws NoSuchMethodException, SecurityException
Find the best method on the target class that matches the signature specified with the specified name and the list of argument classes. This method first attempts to find the method with the specified argument classes; if no such method is found, a NoSuchMethodException is thrown.- Parameters:
methodName
- the name of the method that is to be invoked.argumentsClasses
- the list of Class instances that correspond to the classes for each argument passed to the method.- Returns:
- the Method object that references the method that satisfies the requirements, or null if no satisfactory method could be found.
- Throws:
NoSuchMethodException
- if a matching method is not found.SecurityException
- if access to the information is denied.
-
findBestMethodWithSignature
public Method findBestMethodWithSignature(String methodName, List<Class<?>> argumentsClasses) throws NoSuchMethodException, SecurityException
Find the best method on the target class that matches the signature specified with the specified name and the list of argument classes. This method first attempts to find the method with the specified argument classes; if no such method is found, a NoSuchMethodException is thrown.- Parameters:
methodName
- the name of the method that is to be invoked.argumentsClasses
- the list of Class instances that correspond to the classes for each argument passed to the method.- Returns:
- the Method object that references the method that satisfies the requirements, or null if no satisfactory method could be found.
- Throws:
NoSuchMethodException
- if a matching method is not found.SecurityException
- if access to the information is denied.
-
create
public static final Object create(String className, Collection<?> ctorObjs, ClassLoader classLoader) throws TeiidException
Helper method to create an instance of the class using the appropriate constructor based on the ctorObjs passed.- Parameters:
className
- is the class to instantiatectorObjs
- are the objects to pass to the constructor; optional, nullableclassLoader
- the class loader to use; may be null if the current class loader is to be used- Returns:
- Object is the instance of the class
- Throws:
TeiidException
- if an error occurs instantiating the class
-
create
public static final Object create(String className, Object[] ctorObjs, Class<?>[] argTypes, ClassLoader classLoader) throws TeiidException
- Throws:
TeiidException
-
-