org.onemind.commons.java.pattern
Class DynamicVisitor

java.lang.Object
  extended by org.onemind.commons.java.pattern.DynamicVisitor

public abstract class DynamicVisitor
extends java.lang.Object

An abstract implementation of visitor that is extensible for handling different kind of object nodes by simple adding more methods. The subclass need to set up for handlers of node type in the constructor.

Version:
$Id: DynamicVisitor.java,v 1.2 2004/10/31 16:02:08 thlee Exp $ $Name: $
Author:
TiongHiang Lee (thlee@onemindsoft.org)

Nested Class Summary
protected  class DynamicVisitor.MethodNodeHandler
          A handler use reflection to invoke given method for visiting
static interface DynamicVisitor.NodeHandler
          The handler
 
Field Summary
private  InheritableValueMap _handlers
          contains the handlers for different kind of nodese
private static java.lang.Class OBJECT_ARRAY_CLASS
          the object array class
 
Constructor Summary
DynamicVisitor()
          Constructor
 
Method Summary
protected  void addMethodNodeHandler(java.lang.Class type, java.lang.String methodName)
          Add MethodNodeHandler using the given method name throws RuntimeException if the method cannot be found.
protected  void addNodeHandler(java.lang.Class type, DynamicVisitor.NodeHandler handler)
          Add node handler
protected abstract  void initNodeHandlers()
          Initialize the node handlers
 java.lang.Object visit(java.lang.Object obj, java.lang.Object[] args)
          The object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OBJECT_ARRAY_CLASS

private static java.lang.Class OBJECT_ARRAY_CLASS
the object array class


_handlers

private final InheritableValueMap _handlers
contains the handlers for different kind of nodese

Constructor Detail

DynamicVisitor

public DynamicVisitor()
Constructor

Method Detail

initNodeHandlers

protected abstract void initNodeHandlers()
Initialize the node handlers


addNodeHandler

protected void addNodeHandler(java.lang.Class type,
                              DynamicVisitor.NodeHandler handler)
Add node handler

Parameters:
type - the type
handler - the handler

addMethodNodeHandler

protected void addMethodNodeHandler(java.lang.Class type,
                                    java.lang.String methodName)
Add MethodNodeHandler using the given method name throws RuntimeException if the method cannot be found.

Parameters:
type - the type
methodName - the method name

visit

public java.lang.Object visit(java.lang.Object obj,
                              java.lang.Object[] args)
                       throws java.lang.Exception
The object

Parameters:
obj - the object
args - the arguments
Throws:
java.lang.Exception