Top Description Fields Constructors Methods
javassist.tools.reflect

public Class Metaobject

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

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,

Metaobject m = ((Metalevel)reflectiveObject)._getMetaobject();
See Also
javassist.tools.reflect.ClassMetaobject, javassist.tools.reflect.Metalevel

Field Summary

Modifier and TypeField and Description
protected Metalevel
protected ClassMetaobject
protected Method[]
private static final long
serialVersionUID

default serialVersionUID

Constructor Summary

AccessConstructor and Description
public
Metaobject(Object
the object that this metaobject is associated with.
self
,
Object[]
the parameters passed to the constructor of self.
args
)

Constructs a Metaobject.

protected
Metaobject()

Constructs a Metaobject without initialization.

Method Summary

Modifier and TypeMethod and Description
public final ClassMetaobject
getClassMetaobject()

Obtains the class metaobject associated with this metaobject.

public final String
getMethodName(int identifier)

Returns the name of the method specified by identifier.

public final Object
getObject()

Obtains the object controlled by this metaobject.

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 Class<?>
getReturnType(int identifier)

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

private void
public final void
setObject(Object
the object
self
)

Changes the object controlled by this metaobject.

public Object
trapFieldRead(String name)

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

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.

public Object
trapMethodcall(int identifier, Object[] args)

Is invoked when base-level method invocation is intercepted.

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

baseobjectback to summary
protected Metalevel baseobject
classmetaobjectback to summary
protected ClassMetaobject classmetaobject
methodsback to summary
protected Method[] methods
serialVersionUIDback to summary
private static final long serialVersionUID

default serialVersionUID

Constructor Detail

Metaobjectback to summary
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:Object

the object that this metaobject is associated with.

args:Object[]

the parameters passed to the constructor of self.

Metaobjectback to summary
protected Metaobject()

Constructs a Metaobject without initialization. If calling this constructor, a subclass should be responsible for initialization.

Method Detail

getClassMetaobjectback to summary
public final ClassMetaobject getClassMetaobject()

Obtains the class metaobject associated with this metaobject.

See Also
javassist.tools.reflect.ClassMetaobject
getMethodNameback to summary
public final String getMethodName(int identifier)

Returns the name of the method specified by identifier.

getObjectback to summary
public final Object getObject()

Obtains the object controlled by this metaobject.

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.

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

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

readObjectback to summary
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
setObjectback to summary
public final void setObject(Object self)

Changes the object controlled by this metaobject.

Parameters
self:Object

the object

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

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

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

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,

abstract class A {
  abstract void initialize();
  A() {
      initialize();    // not intercepted
  }
}

class B extends A {
  void initialize() { System.out.println("initialize()"); }
  B() {
      super();
      initialize();    // intercepted
  }
}

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.

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