public class Type extends Object implements InvocationHandler
You create and use a Type object like so:
Type tp = new Type("eve.security.Decryptor"); boolean wasFound = tp.exists(); boolean isAnInstance = tp.isInstance(anObject);
Modifier and Type | Field and Description |
---|---|
static Type |
nullType
This Type is always of a non-existent class.
|
Constructor and Description |
---|
Type(Class theClass) |
Type(String className)
Create a Type for the specified className - which should be specified in standard "."
|
Type(String className,
Class ifThisIsInstance)
Create a Type that represents a named class, but only if the class
ifThisIsInstance is an instance of that class.
|
Modifier and Type | Method and Description |
---|---|
void |
cacheMethod(String methodNameAndSpecs) |
boolean |
exists()
Return if the class of the Type was actually found.
|
static Class |
forName(String className)
Load a System class - i.e. one that can be loaded by the VM through
the System class loaders and not through an application ClassLoader.
|
static Class |
forName(String className,
Class requestor)
Load a class via the System class loader or
through the same ClassLoader that loaded the requestor class.
|
String |
getClassName()
Return the name of the Class this Type represents.
|
Method |
getMethod(String methodNameAndSpecs) |
Method |
getMethod(String nameAndSpecs,
boolean declaredOnly)
Get a named Method but don't throw an exception on error.
|
Class |
getReflectedClass()
Return the Class this type represents if present.
|
Object |
invoke(Object proxy,
Method method,
Object[] args) |
Object |
invoke(Object dest,
String nameAndSpecs,
Object[] parameters)
Invoke a method on the Object which must be of this Type.
|
boolean |
isInstance(Object obj)
Return if the specified Object is an instance of the Class represented by this Type.
|
static Class |
loadForName(String className)
Load a class via the System class loader or through any created eve.util.mClassLoader
Objects the application created.
|
Object |
newInstance()
Return a new Instance of the class if the class exists.
|
Object |
newInstance(String constructorSpecs,
Object[] parameters)
Return a new Instance of the class if the class exists.
|
Object |
newProxy(Object target,
Class[] interfacesToImplement)
Create a new instance of the class represented by this Type and then
create a Proxy object that implements the specified interfaces by
calling methods of the same signature in the created target.
|
Object |
newProxyInstance(Class interfaceToImplement)
Create a new instance of the class represented by this Type
using the default constructor, and then
create a Proxy object that implements the specified interface by
calling methods of the same signature in the created target.
|
Object |
newProxyInstance(Class interfaceToImplement,
String constructorSpecs,
Object[] args)
Create a new instance of the class represented by this Type and then
create a Proxy object that implements the specified interface by
calling methods of the same signature in the created target.
|
String |
toString()
Return a String representation of this object.
|
public static final Type nullType
public Type(String className)
public Type(Class theClass)
public Type(String className, Class ifThisIsInstance)
className
- the name of the target class.ifThisIsInstance
- the test class.public String toString()
Object
public Object newInstance()
public Object newInstance(String constructorSpecs, Object[] parameters)
constructorSpecs
- the method specs for the constructor to use.parameters
- parameters to send to the method.public Object invoke(Object dest, String nameAndSpecs, Object[] parameters)
dest
- the Object to invoke on, or null for static methods.nameAndSpecs
- the name and parameter specs for the method.parameters
- the list of parameters to pass to the method. This can be null
if there are no parameters.public Method getMethod(String nameAndSpecs, boolean declaredOnly)
nameAndSpecs
- declaredOnly
- public String getClassName()
public Class getReflectedClass()
public static Class forName(String className) throws ClassNotFoundException
className
- the name of the Class.ClassNotFoundException
- if the Class was not found.public static Class loadForName(String className) throws ClassNotFoundException
className
- the name of the Class.ClassNotFoundException
- if the Class was not found.public static Class forName(String className, Class requestor) throws ClassNotFoundException
className
- the name of the Class.requestor
- the requesting Class.ClassNotFoundException
- if the Class was not found.public boolean exists()
public boolean isInstance(Object obj)
obj
- the object to check.public void cacheMethod(String methodNameAndSpecs)
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
invoke
in interface InvocationHandler
Throwable
public Object newProxy(Object target, Class[] interfacesToImplement)
target
- an Object that is of the class represented by this Type.interfacesToImplement
- the Interfaces to implement.public Object newProxyInstance(Class interfaceToImplement, String constructorSpecs, Object[] args)
interfaceToImplement
- the Interface to implement.constructorSpecs
- the constructor signature.args
- arguments for the constructor.public Object newProxyInstance(Class interfaceToImplement)
interfaceToImplement
- the Interface to implement.