Class Metaobject
- All Implemented Interfaces:
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();
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal ClassMetaobject
Obtains the class metaobject associated with this metaobject.final String
getMethodName
(int identifier) Returns the name of the method specified byidentifier
.final Object
Obtains the object controlled by this metaobject.final Class<?>[]
getParameterTypes
(int identifier) Returns an array ofClass
objects representing the formal parameter types of the method specified byidentifier
.final Class<?>
getReturnType
(int identifier) Returns aClass
objects representing the return type of the method specified byidentifier
.final void
Changes the object controlled by this metaobject.trapFieldRead
(String name) Is invoked when public fields of the base-level class are read and the runtime system intercepts it.void
trapFieldWrite
(String name, Object value) Is invoked when public fields of the base-level class are modified and the runtime system intercepts it.trapMethodcall
(int identifier, Object[] args) Is invoked when base-level method invocation is intercepted.
-
Constructor Details
-
Metaobject
Constructs aMetaobject
. 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 ofself
.
-
-
Method Details
-
getClassMetaobject
Obtains the class metaobject associated with this metaobject.- See Also:
-
getObject
Obtains the object controlled by this metaobject. -
setObject
Changes the object controlled by this metaobject.- Parameters:
self
- the object
-
getMethodName
Returns the name of the method specified byidentifier
. -
getParameterTypes
Returns an array ofClass
objects representing the formal parameter types of the method specified byidentifier
. -
getReturnType
Returns aClass
objects representing the return type of the method specified byidentifier
. -
trapFieldRead
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
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
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.
- Throws:
Throwable
-