org.grothoff
Class Runabout

java.lang.Object
  extended by org.grothoff.Runabout

public class Runabout
extends java.lang.Object

Runabout is a fast implementation of the Walkabout which is a variant of the Visitor Pattern that does not require an accept method and uses reflection instead.

An instance of Runabout is able to walk over an arbitrary object graph using visit methods which take arguments of the specific type of the object to visit. For each node in the object graph the Runabout invokes the most appropriate visit method.

Using the Runabout typically involves subclassimg Runabout and adding a couple of visit methods. The Runabout provides a 'visitAppropriate' method which will invoke the most appropriate visit method of the current Runabout instance. If no visit method is applicable, visitAppropriate calls visitDefault() which, if not overriden, throws an exception.

The elements of the object graph typically extend the Element class, which provides a generic way to quickly invoke the Runabout on all the fields of the Element.

Note that the Runabout uses dynamic code generation and dynamic loading in order to be quickly able to invoke the appropriate visit methods. To make the dynamic code generation fast, the code inlines parts of Java class-files in binary form (ugly!).
A per-thread Cache is used to speed-up the creation of the Runabout by caching reflection, code creation and dynamic loading operations.

Restrictions: Java semantics require:

Otherwise the visitor will die with an IllegalAccessError during execution.

Author:
Christian Grothoff

Nested Class Summary
static class Runabout.Code
          Code is the generic interface that all generated classes implement.
static class Runabout.RunaboutException
          Generic Exception for problems in the Runabout.
 
Constructor Summary
Runabout()
          Create a Runabout.
 
Method Summary
 void visitAppropriate(java.lang.Object o)
          Call the appropriate visit method.
protected  void visitDefault(java.lang.Object o)
          Override this method to provide a default behavior when no other visit matches.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Runabout

public Runabout()
Create a Runabout.

Method Detail

visitAppropriate

public void visitAppropriate(java.lang.Object o)
Call the appropriate visit method. Use this method if you are visiting a graph of objects (no primitives).

Parameters:
o - the object to visit

visitDefault

protected void visitDefault(java.lang.Object o)
Override this method to provide a default behavior when no other visit matches. The Runabout semantics are to search for a visit(X) and if there is no match, call visitDefault(). As usual with the Runabout, visit(X) looks at classes before interfaces. By default, visitDefault throws an exception.