Package org.onemind.commons.java.pattern
Class DynamicVisitor
- java.lang.Object
-
- 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
Nested Classes Modifier and Type Class Description protected class
DynamicVisitor.MethodNodeHandler
A handler use reflection to invoke given method for visitingstatic interface
DynamicVisitor.NodeHandler
The handler
-
Field Summary
Fields Modifier and Type Field Description private InheritableValueMap
_handlers
contains the handlers for different kind of nodeseprivate static java.lang.Class
OBJECT_ARRAY_CLASS
the object array class
-
Constructor Summary
Constructors Constructor Description DynamicVisitor()
Constructor
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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 handlerprotected abstract void
initNodeHandlers()
Initialize the node handlersjava.lang.Object
visit(java.lang.Object obj, java.lang.Object[] args)
The object
-
-
-
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
-
-
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 typehandler
- 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 typemethodName
- 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 objectargs
- the arguments- Throws:
java.lang.Exception
-
-