Check out the new USENIX Web site. next up previous
Next: Specifying methods Up: Accessors Previous: Querying objects

Using JAVA reflection

To implement our accessors, we rely on structural reflection. The inherent JAVA language reflection capabilities [Sun99a] consist in a type-safe API that supports introspection about classes and objects in the current JAVA VM at runtime. We view introspection as one aspect of structural reflection, limited to the reification (in the sense of representation) of structures of types and classes at runtime. A second aspect, the modification of those structures is, like computational reflection, not addressed by the JAVA core reflection API.[*]

In short, JAVA provides meta-objects which reify classes, methods, fields, constructors, etc. We make extensive use of meta-objects for methods (java.lang.reflect.Method) to reify the Mi's of accessors. This defers to runtime the choice of which method is to be invoked, and enables also to effectively perform such a dynamic invocation.[*] We avoid using objects reifying attributes (java.lang.reflect.Field), since dealing with them means abandoning encapsulation.



public final class Invoke
  implements Accessor, java.io.Serializable
{
  /* only one method, can be null */
  public Invoke(Method M, Object[] args) {...}
  /* with nested accessor */
  public Invoke(Accessor nested, Method M, 
                Object[] args) {...}
  /* structurally conformant objects, nesting */
  public Invoke(String methodNames, 
                Object[][] args) {...}
  ...
  public Object get(Object m) 
                  throws Exception {...}
}




Figure 5: Invoke Class (Excerpt)
  



Patrick Eugster
12/10/2000