javassist.tools.reflect

Class Metaobject

public class Metaobject extends Object implements Serializable

A runtime metaobject.

A Metaobject is created for every object at the base level. A different reflective object is associated with a different metaobject.

The metaobject intercepts method calls on the reflective object at the base-level. To change the behavior of the method calls, a subclass of Metaobject should be defined.

To obtain a metaobject, calls _getMetaobject() on a reflective object. For example,

See Also: ClassMetaobject Metalevel

Constructor Summary
Metaobject(Object self, Object[] args)
Constructs a Metaobject.
Method Summary
ClassMetaobjectgetClassMetaobject()
Obtains the class metaobject associated with this metaobject.
StringgetMethodName(int identifier)
Returns the name of the method specified by identifier.
ObjectgetObject()
Obtains the object controlled by this metaobject.
Class[]getParameterTypes(int identifier)
Returns an array of Class objects representing the formal parameter types of the method specified by identifier.
ClassgetReturnType(int identifier)
Returns a Class objects representing the return type of the method specified by identifier.
voidsetObject(Object self)
Changes the object controlled by this metaobject.
ObjecttrapFieldRead(String name)
Is invoked when public fields of the base-level class are read and the runtime system intercepts it.
voidtrapFieldWrite(String name, Object value)
Is invoked when public fields of the base-level class are modified and the runtime system intercepts it.
ObjecttrapMethodcall(int identifier, Object[] args)
Is invoked when base-level method invocation is intercepted.

Constructor Detail

Metaobject

public Metaobject(Object self, Object[] args)
Constructs a Metaobject. The metaobject is constructed before the constructor is called on the base-level object.

Parameters: self the object that this metaobject is associated with. args the parameters passed to the constructor of self.

Method Detail

getClassMetaobject

public final ClassMetaobject getClassMetaobject()
Obtains the class metaobject associated with this metaobject.

See Also: ClassMetaobject

getMethodName

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

getObject

public final Object getObject()
Obtains the object controlled by this metaobject.

getParameterTypes

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

getReturnType

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

setObject

public final void setObject(Object self)
Changes the object controlled by this metaobject.

Parameters: self the object

trapFieldRead

public Object trapFieldRead(String name)
Is invoked when public 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 public 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 base-level method invocation is intercepted. 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.

Note: this method is not invoked if the base-level method is invoked by a constructor in the super class. For example,

if an instance of B is created, the invocation of initialize() in B is intercepted only once. The first invocation by the constructor in A is not intercepted. This is because the link between a base-level object and a metaobject is not created until the execution of a constructor of the super class finishes.

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