Class ClassMetaobject
- java.lang.Object
-
- javassist.tools.reflect.ClassMetaobject
-
- All Implemented Interfaces:
Serializable
public class ClassMetaobject extends Object implements Serializable
A runtime class metaobject.A
ClassMetaobject
is created for every class of reflective objects. It can be used to hold values shared among the reflective objects of the same class.To obtain a class metaobject, calls
_getClass()
on a reflective object. For example,ClassMetaobject cm = ((Metalevel)reflectiveObject)._getClass();
- See Also:
Metaobject
,Metalevel
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
useContextClassLoader
Specifies how ajava.lang.Class
object is loaded.
-
Constructor Summary
Constructors Constructor Description ClassMetaobject(String[] params)
Constructs aClassMetaobject
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Class<?>
getJavaClass()
Obtains thejava.lang.Class
representing this class.Method
getMethod(int identifier)
Returns thejava.lang.reflect.Method
object representing the method specified byidentifier
.int
getMethodIndex(String originalName, Class<?>[] argTypes)
Returns the identifier index of the method, as identified by its original name.String
getMethodName(int identifier)
Returns the name of the method specified byidentifier
.String
getName()
Obtains the name of this class.Class<?>[]
getParameterTypes(int identifier)
Returns an array ofClass
objects representing the formal parameter types of the method specified byidentifier
.Method[]
getReflectiveMethods()
Returns an array of the methods defined on the given reflective object.Class<?>
getReturnType(int identifier)
Returns aClass
objects representing the return type of the method specified byidentifier
.static Object
invoke(Object target, int identifier, Object[] args)
Invokes a method whose name begins withmethodPrefix "_m_"
and the identifier.boolean
isInstance(Object obj)
Returns true ifobj
is an instance of this class.Object
newInstance(Object[] args)
Creates a new instance of the class.Object
trapFieldRead(String name)
Is invoked whenstatic
fields of the base-level class are read and the runtime system intercepts it.void
trapFieldWrite(String name, Object value)
Is invoked whenstatic
fields of the base-level class are modified and the runtime system intercepts it.Object
trapMethodcall(int identifier, Object[] args)
Is invoked whenstatic
methods of the base-level class are called and the runtime system intercepts it.
-
-
-
Constructor Detail
-
ClassMetaobject
public ClassMetaobject(String[] params)
Constructs aClassMetaobject
.- Parameters:
params
-params[0]
is the name of the class of the reflective objects.
-
-
Method Detail
-
getJavaClass
public final Class<?> getJavaClass()
Obtains thejava.lang.Class
representing this class.
-
getName
public final String getName()
Obtains the name of this class.
-
isInstance
public final boolean isInstance(Object obj)
Returns true ifobj
is an instance of this class.
-
newInstance
public final Object newInstance(Object[] args) throws CannotCreateException
Creates a new instance of the class.- Parameters:
args
- the arguments passed to the constructor.- Throws:
CannotCreateException
-
trapFieldRead
public Object trapFieldRead(String name)
Is invoked whenstatic
fields of the base-level class are read and the runtime system intercepts it. This method simply returns the value of the field.Every subclass of this class should redefine this method.
-
trapFieldWrite
public void trapFieldWrite(String name, Object value)
Is invoked whenstatic
fields of the base-level class are modified and the runtime system intercepts it. This method simply sets the field to the given value.Every subclass of this class should redefine this method.
-
invoke
public static Object invoke(Object target, int identifier, Object[] args) throws Throwable
Invokes a method whose name begins withmethodPrefix "_m_"
and the identifier.- Throws:
CannotInvokeException
- if the invocation fails.Throwable
-
trapMethodcall
public Object trapMethodcall(int identifier, Object[] args) throws Throwable
Is invoked whenstatic
methods of the base-level class are called and the runtime system intercepts it. This method simply executes the intercepted method invocation with the original parameters and returns the resulting value.Every subclass of this class should redefine this method.
- Throws:
Throwable
-
getReflectiveMethods
public final Method[] getReflectiveMethods()
Returns an array of the methods defined on the given reflective object. This method is for the internal use only.
-
getMethod
public final Method getMethod(int identifier)
Returns thejava.lang.reflect.Method
object representing the method specified byidentifier
.Note that the actual method returned will be have an altered, reflective name i.e.
_m_2_..
.- Parameters:
identifier
- the identifier index given totrapMethodcall()
etc.- See Also:
Metaobject.trapMethodcall(int,Object[])
,trapMethodcall(int,Object[])
-
getMethodName
public final String getMethodName(int identifier)
Returns the name of the method specified byidentifier
.
-
getParameterTypes
public final Class<?>[] getParameterTypes(int identifier)
Returns an array ofClass
objects representing the formal parameter types of the method specified byidentifier
.
-
getReturnType
public final Class<?> getReturnType(int identifier)
Returns aClass
objects representing the return type of the method specified byidentifier
.
-
getMethodIndex
public final int getMethodIndex(String originalName, Class<?>[] argTypes) throws NoSuchMethodException
Returns the identifier index of the method, as identified by its original name.This method is useful, in conjuction with
getMethod(int)
, to obtain a quick reference to the original method in the reflected class (i.e. not the proxy method), using the original name of the method.Written by Brett Randall and Shigeru Chiba.
- Parameters:
originalName
- The original name of the reflected methodargTypes
- array of Class specifying the method signature- Returns:
- the identifier index of the original method
- Throws:
NoSuchMethodException
- if the method does not exist- See Also:
getMethod(int)
-
-