javassist.tools.reflect

Class ClassMetaobject

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,

See Also: Metaobject Metalevel

Field Summary
static booleanuseContextClassLoader
Specifies how a java.lang.Class object is loaded.
Constructor Summary
ClassMetaobject(String[] params)
Constructs a ClassMetaobject.
Method Summary
ClassgetJavaClass()
Obtains the java.lang.Class representing this class.
MethodgetMethod(int identifier)
Returns the java.lang.reflect.Method object representing the method specified by identifier.
intgetMethodIndex(String originalName, Class[] argTypes)
Returns the identifier index of the method, as identified by its original name.
StringgetMethodName(int identifier)
Returns the name of the method specified by identifier.
StringgetName()
Obtains the name of this class.
Class[]getParameterTypes(int identifier)
Returns an array of Class objects representing the formal parameter types of the method specified by identifier.
Method[]getReflectiveMethods()
Returns an array of the methods defined on the given reflective object.
ClassgetReturnType(int identifier)
Returns a Class objects representing the return type of the method specified by identifier.
static Objectinvoke(Object target, int identifier, Object[] args)
Invokes a method whose name begins with methodPrefix "_m_" and the identifier.
booleanisInstance(Object obj)
Returns true if obj is an instance of this class.
ObjectnewInstance(Object[] args)
Creates a new instance of the class.
ObjecttrapFieldRead(String name)
Is invoked when static fields of the base-level class are read and the runtime system intercepts it.
voidtrapFieldWrite(String name, Object value)
Is invoked when static fields of the base-level class are modified and the runtime system intercepts it.
ObjecttrapMethodcall(int identifier, Object[] args)
Is invoked when static methods of the base-level class are called and the runtime system intercepts it.

Field Detail

useContextClassLoader

public static boolean useContextClassLoader
Specifies how a java.lang.Class object is loaded.

If true, it is loaded by:

If false, it is loaded by Class.forName(). The default value is false.

Constructor Detail

ClassMetaobject

public ClassMetaobject(String[] params)
Constructs a ClassMetaobject.

Parameters: params params[0] is the name of the class of the reflective objects.

Method Detail

getJavaClass

public final Class getJavaClass()
Obtains the java.lang.Class representing this class.

getMethod

public final Method getMethod(int identifier)
Returns the java.lang.reflect.Method object representing the method specified by identifier.

Note that the actual method returned will be have an altered, reflective name i.e. _m_2_...

Parameters: identifier the identifier index given to trapMethodcall() etc.

See Also: (int,Object[]) (int,Object[])

getMethodIndex

public final int getMethodIndex(String originalName, Class[] argTypes)
Returns the identifier index of the method, as identified by its original name.

This method is useful, in conjuction with ClassMetaobject#getMethod(), 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 method argTypes 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: ClassMetaobject

getMethodName

public final String getMethodName(int identifier)
Returns the name of the method specified by identifier.

getName

public final String getName()
Obtains the name of this class.

getParameterTypes

public final Class[] getParameterTypes(int identifier)
Returns an array of Class objects representing the formal parameter types of the method specified by identifier.

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.

getReturnType

public final Class getReturnType(int identifier)
Returns a Class objects representing the return type of the method specified by identifier.

invoke

public static Object invoke(Object target, int identifier, Object[] args)
Invokes a method whose name begins with methodPrefix "_m_" and the identifier.

Throws: CannotInvokeException if the invocation fails.

isInstance

public final boolean isInstance(Object obj)
Returns true if obj is an instance of this class.

newInstance

public final Object newInstance(Object[] args)
Creates a new instance of the class.

Parameters: args the arguments passed to the constructor.

trapFieldRead

public Object trapFieldRead(String name)
Is invoked when static 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 when static 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.

trapMethodcall

public Object trapMethodcall(int identifier, Object[] args)
Is invoked when static 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.

Javassist, a Java-bytecode translator toolkit.
Copyright (C) 1999-2006 Shigeru Chiba. All Rights Reserved.