|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.jlf.util.Reflection
The Reflection
class is to help you with Java reflection
apis and provide common code you can take advantage of.
Constructor Summary | |
protected |
Reflection()
Protect the default constructor, so far no one should be creating an instance of this class. |
Method Summary | |
static java.lang.Object |
executeMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Class[] parameterTypes,
java.lang.Object[] arguments)
Executes a method on an object. |
static java.lang.Class |
getClassForName(java.lang.String className)
Helper method to get a class from a class name and throw a nice error if can't find the class through reflection. |
static java.lang.Object |
getInstance(java.lang.Class subclass,
java.lang.Class superclass)
Creates an instance of the class given as input, validating it against the superclass given to make sure it is the same class or a subclass of the superclass. |
static java.lang.Object |
getInstance(java.lang.Class subclass,
java.lang.Class[] parameterTypes,
java.lang.Object[] initArguments,
java.lang.Class superclass)
Creates an instance of the class given as input, validating it against the superclass given to make sure it is the same class or a subclass of the superclass, then trying to find a constructor according to the parameter types given. |
static java.lang.Object |
getInstance(java.lang.String className,
java.lang.Class superclass)
Creates an instance of the class name given as input, validating it against the superclass given to make sure it is the same class or a subclass of the superclass. |
static java.lang.Object |
getInstance(java.lang.String className,
java.lang.Class[] parameterTypes,
java.lang.Object[] initArguments,
java.lang.Class superclass)
Creates an instance of the class name given as input, validating it against the superclass given to make sure it is the same class or a subclass of the superclass, then trying to find a constructor according to the parameter types given. |
static java.lang.Object |
getInstance(java.lang.String className,
java.lang.String superclassName)
Creates an instance of the class name given as input, validating it against the superclass given to make sure it is the same class or a subclass of the superclass. |
static void |
validateClassAssignment(java.lang.Class subclass,
java.lang.Class superclass)
Helper method to validate a class assignment, making sure a subclass implements the interface of the desired superclass/interface. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
protected Reflection()
Method Detail |
public static java.lang.Class getClassForName(java.lang.String className)
public static void validateClassAssignment(java.lang.Class subclass, java.lang.Class superclass)
AppError
- if validation unsuccessfulpublic static java.lang.Object getInstance(java.lang.Class subclass, java.lang.Class superclass)
public static java.lang.Object getInstance(java.lang.String className, java.lang.Class superclass)
public static java.lang.Object getInstance(java.lang.String className, java.lang.String superclassName)
public static java.lang.Object executeMethod(java.lang.Object object, java.lang.String methodName, java.lang.Class[] parameterTypes, java.lang.Object[] arguments)
public static java.lang.Object getInstance(java.lang.Class subclass, java.lang.Class[] parameterTypes, java.lang.Object[] initArguments, java.lang.Class superclass)
subclass
- The class object you wish to have a new instance ofparameterTypes
- Class constructor parameter types to be used to
find and call the desired constructorinitArguments
- Class constructor parameters to send in when
creating the new instancesuperclass
- The superclass or interface that you expect the
subclass to extend/implement. The subclass is checked to make
sure it can conform to the protocol in the superclass/interface
given.
public static java.lang.Object getInstance(java.lang.String className, java.lang.Class[] parameterTypes, java.lang.Object[] initArguments, java.lang.Class superclass)
className
- The string name for a class you wish to have a
new instance ofparameterTypes
- Class constructor parameter types to be used to
find and call the desired constructorinitArguments
- Class constructor parameters to send in when
creating the new instancesuperclass
- The superclass or interface that you expect the
subclass to extend/implement. The subclass is checked to make
sure it can conform to the protocol in the superclass/interface
given.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |