Top Description Fields Constructors Methods
javassist.tools.reflect

public Class ClassMetaobject

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.IOException, .ObjectInputStream, .ObjectOutputStream, .Serializable, java.lang.reflect.Constructor, .InvocationTargetException, .Method, java.util.Arrays

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
javassist.tools.reflect.Metaobject, javassist.tools.reflect.Metalevel

Field Summary

Modifier and TypeField and Description
private Constructor<?>[]
private Class<?>
pack-priv static final String
methodPrefix

The base-level methods controlled by a metaobject are renamed so that they begin with methodPrefix "_m_".

pack-priv static final int
private Method[]
private static final long
serialVersionUID

default serialVersionUID

public static boolean
useContextClassLoader

Specifies how a java.lang.Class object is loaded.

Constructor Summary

AccessConstructor and Description
public
ClassMetaobject(String[]
params[0] is the name of the class of the reflective objects.
params
)

Constructs a ClassMetaobject.

Method Summary

Modifier and TypeMethod and Description
private Class<?>
public final Class<?>
getJavaClass()

Obtains the java.lang.Class representing this class.

public final Method
getMethod(int
the identifier index given to trapMethodcall() etc.
identifier
)

Returns the java.lang.reflect.Method object representing the method specified by identifier.

public final int

Returns:

the identifier index of the original method
getMethodIndex
(String
The original name of the reflected method
originalName
,
Class<?>[]
array of Class specifying the method signature
argTypes
)

Returns the identifier index of the method, as identified by its original name.

public final String
getMethodName(int identifier)

Returns the name of the method specified by identifier.

public final String
getName()

Obtains the name of this class.

public final Class<?>[]
getParameterTypes(int identifier)

Returns an array of Class objects representing the formal parameter types of the method specified by identifier.

public final Method[]
getReflectiveMethods()

Returns an array of the methods defined on the given reflective object.

public final Class<?>
getReturnType(int identifier)

Returns a Class objects representing the return type of the method specified by identifier.

public static Object
invoke(Object target, int identifier, Object[] args)

Invokes a method whose name begins with methodPrefix "_m_" and the identifier.

public final boolean
isInstance(Object obj)

Returns true if obj is an instance of this class.

public final Object
newInstance(Object[]
the arguments passed to the constructor.
args
)

Creates a new instance of the class.

private void
public Object
trapFieldRead(String name)

Is invoked when static fields of the base-level class are read and the runtime system intercepts it.

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.

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.

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

constructorsback to summary
private Constructor<?>[] constructors
javaClassback to summary
private Class<?> javaClass
methodPrefixback to summary
pack-priv static final String methodPrefix

The base-level methods controlled by a metaobject are renamed so that they begin with methodPrefix "_m_".

methodPrefixLenback to summary
pack-priv static final int methodPrefixLen
methodsback to summary
private Method[] methods
serialVersionUIDback to summary
private static final long serialVersionUID

default serialVersionUID

useContextClassLoaderback to summary
public static boolean useContextClassLoader

Specifies how a java.lang.Class object 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 Detail

ClassMetaobjectback to summary
public ClassMetaobject(String[] params)

Constructs a ClassMetaobject.

Parameters
params:String[]

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

Method Detail

getClassObjectback to summary
private Class<?> getClassObject(String name) throws ClassNotFoundException
getJavaClassback to summary
public final Class<?> getJavaClass()

Obtains the java.lang.Class representing this class.

getMethodback to summary
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:int

the identifier index given to trapMethodcall() etc.

See Also
Metaobject#trapMethodcall(int, Object[]), trapMethodcall(int, Object[])
getMethodIndexback to summary
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 ClassMetaobject#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:String

The original name of the reflected method

argTypes:Class<?>[]

array of Class specifying the method signature

Returns:int

the identifier index of the original method

Exceptions
NoSuchMethodException:
if the method does not exist
See Also
ClassMetaobject#getMethod(int)
getMethodNameback to summary
public final String getMethodName(int identifier)

Returns the name of the method specified by identifier.

getNameback to summary
public final String getName()

Obtains the name of this class.

getParameterTypesback to summary
public final Class<?>[] getParameterTypes(int identifier)

Returns an array of Class objects representing the formal parameter types of the method specified by identifier.

getReflectiveMethodsback to summary
public final Method[] getReflectiveMethods()

Returns an array of the methods defined on the given reflective object. This method is for the internal use only.

getReturnTypeback to summary
public final Class<?> getReturnType(int identifier)

Returns a Class objects representing the return type of the method specified by identifier.

invokeback to summary
public static Object invoke(Object target, int identifier, Object[] args) throws Throwable

Invokes a method whose name begins with methodPrefix "_m_" and the identifier.

Exceptions
CannotInvokeException:
if the invocation fails.
isInstanceback to summary
public final boolean isInstance(Object obj)

Returns true if obj is an instance of this class.

newInstanceback to summary
public final Object newInstance(Object[] args) throws CannotCreateException

Creates a new instance of the class.

Parameters
args:Object[]

the arguments passed to the constructor.

readObjectback to summary
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
trapFieldReadback to summary
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.

trapFieldWriteback to summary
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.

trapMethodcallback to summary
public Object trapMethodcall(int identifier, Object[] args) throws Throwable

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.

writeObjectback to summary
private void writeObject(ObjectOutputStream out) throws IOException