Class ClassMetaobject
- All Implemented Interfaces:
Serializable
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic booleanSpecifies how ajava.lang.Classobject is loaded. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal Class<?>Obtains thejava.lang.Classrepresenting this class.final MethodgetMethod(int identifier) Returns thejava.lang.reflect.Methodobject representing the method specified byidentifier.final intgetMethodIndex(String originalName, Class<?>[] argTypes) Returns the identifier index of the method, as identified by its original name.final StringgetMethodName(int identifier) Returns the name of the method specified byidentifier.final StringgetName()Obtains the name of this class.final Class<?>[]getParameterTypes(int identifier) Returns an array ofClassobjects representing the formal parameter types of the method specified byidentifier.final Method[]Returns an array of the methods defined on the given reflective object.final Class<?>getReturnType(int identifier) Returns aClassobjects representing the return type of the method specified byidentifier.static ObjectInvokes a method whose name begins withmethodPrefix "_m_"and the identifier.final booleanisInstance(Object obj) Returns true ifobjis an instance of this class.final ObjectnewInstance(Object[] args) Creates a new instance of the class.trapFieldRead(String name) Is invoked whenstaticfields of the base-level class are read and the runtime system intercepts it.voidtrapFieldWrite(String name, Object value) Is invoked whenstaticfields of the base-level class are modified and the runtime system intercepts it.trapMethodcall(int identifier, Object[] args) Is invoked whenstaticmethods of the base-level class are called and the runtime system intercepts it.
-
Field Details
-
useContextClassLoader
public static boolean useContextClassLoaderSpecifies how ajava.lang.Classobject is loaded.If true, it is loaded by:
Thread.currentThread().getContextClassLoader().loadClass()
If false, it is loaded by
Class.forName(). The default value is false.
-
-
Constructor Details
-
ClassMetaobject
Constructs aClassMetaobject.- Parameters:
params-params[0]is the name of the class of the reflective objects.
-
-
Method Details
-
getJavaClass
Obtains thejava.lang.Classrepresenting this class. -
getName
Obtains the name of this class. -
isInstance
Returns true ifobjis an instance of this class. -
newInstance
Creates a new instance of the class.- Parameters:
args- the arguments passed to the constructor.- Throws:
CannotCreateException
-
trapFieldRead
Is invoked whenstaticfields 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
Is invoked whenstaticfields 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
Invokes a method whose name begins withmethodPrefix "_m_"and the identifier.- Throws:
CannotInvokeException- if the invocation fails.Throwable
-
trapMethodcall
Is invoked whenstaticmethods 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
Returns an array of the methods defined on the given reflective object. This method is for the internal use only. -
getMethod
Returns thejava.lang.reflect.Methodobject 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:
-
getMethodName
Returns the name of the method specified byidentifier. -
getParameterTypes
Returns an array ofClassobjects representing the formal parameter types of the method specified byidentifier. -
getReturnType
Returns aClassobjects 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:
-