public class Metaobject
extends java.lang.Object
implements java.io.Serializable
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();
ClassMetaobject
,
Metalevel
,
Serialized FormConstructor and Description |
---|
Metaobject(java.lang.Object self,
java.lang.Object[] args)
Constructs a
Metaobject . |
Modifier and Type | Method and Description |
---|---|
ClassMetaobject |
getClassMetaobject()
Obtains the class metaobject associated with this metaobject.
|
java.lang.String |
getMethodName(int identifier)
Returns the name of the method specified
by
identifier . |
java.lang.Object |
getObject()
Obtains the object controlled by this metaobject.
|
java.lang.Class[] |
getParameterTypes(int identifier)
Returns an array of
Class objects representing the
formal parameter types of the method specified
by identifier . |
java.lang.Class |
getReturnType(int identifier)
Returns a
Class objects representing the
return type of the method specified by identifier . |
void |
setObject(java.lang.Object self)
Changes the object controlled by this metaobject.
|
java.lang.Object |
trapFieldRead(java.lang.String name)
Is invoked when public fields of the base-level
class are read and the runtime system intercepts it.
|
void |
trapFieldWrite(java.lang.String name,
java.lang.Object value)
Is invoked when public fields of the base-level
class are modified and the runtime system intercepts it.
|
java.lang.Object |
trapMethodcall(int identifier,
java.lang.Object[] args)
Is invoked when base-level method invocation is intercepted.
|
public Metaobject(java.lang.Object self, java.lang.Object[] args)
Metaobject
. The metaobject is
constructed before the constructor is called on the base-level
object.self
- the object that this metaobject is associated with.args
- the parameters passed to the constructor of
self
.public final ClassMetaobject getClassMetaobject()
ClassMetaobject
public final java.lang.Object getObject()
public final void setObject(java.lang.Object self)
self
- the objectpublic final java.lang.String getMethodName(int identifier)
identifier
.public final java.lang.Class[] getParameterTypes(int identifier)
Class
objects representing the
formal parameter types of the method specified
by identifier
.public final java.lang.Class getReturnType(int identifier)
Class
objects representing the
return type of the method specified by identifier
.public java.lang.Object trapFieldRead(java.lang.String name)
Every subclass of this class should redefine this method.
public void trapFieldWrite(java.lang.String name, java.lang.Object value)
Every subclass of this class should redefine this method.
public java.lang.Object trapMethodcall(int identifier, java.lang.Object[] args) throws java.lang.Throwable
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.
java.lang.Throwable
Javassist, a Java-bytecode translator toolkit.
Copyright (C) 1999- Shigeru Chiba. All Rights Reserved.