biz.hammurapi.util
Class DispatchingVisitor

java.lang.Object
  extended by biz.hammurapi.util.DispatchingVisitor
All Implemented Interfaces:
Command, PoliteVisitor, Visitor, VisitorStackSource

public class DispatchingVisitor
extends java.lang.Object
implements PoliteVisitor, VisitorStackSource, Command

Dispatching visitor navigates through Visitables hierarchy and invokes visit(Type) method of targets with compatible Type.

Version:
$Revision: 1.9 $
Author:
Pavel Vlasov

Nested Class Summary
static interface DispatchingVisitor.Filter
          If target implements this insterface then it is used to filter invocations to other targets.
static interface DispatchingVisitor.Listener
           
static interface DispatchingVisitor.SelfListener
          Targets which want to listen to invocations of self should implement this interface.
static interface DispatchingVisitor.Stats
           
 
Constructor Summary
DispatchingVisitor(java.util.Collection targets, VisitorExceptionSink exceptionSink)
           
DispatchingVisitor(java.util.Collection targets, VisitorExceptionSink exceptionSink, DispatchingVisitor.Listener listener)
           
DispatchingVisitor(java.lang.Object target, VisitorExceptionSink exceptionSink)
           
DispatchingVisitor(java.lang.Object target, VisitorExceptionSink exceptionSink, DispatchingVisitor.Listener listener)
           
 
Method Summary
 void execute(java.lang.Object executionContext)
          Passes executionContext for visiting.
 java.util.Collection getClassesOfInterest()
           
 DispatchingVisitor.Stats getStats()
           
 java.util.Collection getTargets()
           
 DispatchingVisitor.Stats getThreadStats()
           
 VisitorStack getVisitorStack()
           
 void leave(java.lang.Object target)
          Shall be invoked by Visitable at the end of navigation, when all children has already been visited.
protected  void processReturnValue(java.lang.Object target, java.lang.reflect.Method method, java.lang.Object argument, java.lang.Object returnValue)
          Passes return values back to visitor.
 void remove(java.lang.Object target)
          Removes object from targets collection.
 int size()
           
 boolean visit(java.lang.Object target)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DispatchingVisitor

public DispatchingVisitor(java.util.Collection targets,
                          VisitorExceptionSink exceptionSink,
                          DispatchingVisitor.Listener listener)
Parameters:
targets -
exceptionSink -

DispatchingVisitor

public DispatchingVisitor(java.util.Collection targets,
                          VisitorExceptionSink exceptionSink)

DispatchingVisitor

public DispatchingVisitor(java.lang.Object target,
                          VisitorExceptionSink exceptionSink)
Parameters:
target -
exceptionSink -

DispatchingVisitor

public DispatchingVisitor(java.lang.Object target,
                          VisitorExceptionSink exceptionSink,
                          DispatchingVisitor.Listener listener)
Method Detail

getVisitorStack

public VisitorStack getVisitorStack()
Specified by:
getVisitorStack in interface VisitorStackSource

visit

public boolean visit(java.lang.Object target)
Specified by:
visit in interface Visitor
Returns:
false if Visitor is not interested in further descending through Visitable structure

getTargets

public java.util.Collection getTargets()

processReturnValue

protected void processReturnValue(java.lang.Object target,
                                  java.lang.reflect.Method method,
                                  java.lang.Object argument,
                                  java.lang.Object returnValue)
Passes return values back to visitor. Arrays and collections are iterated and individual elements are passed to the visitor. Override this method to process return values in a different way.

Parameters:
target - - Object which method was invoked
method - - Method which was invoked
argument - - Method argument
returnValue - - Return value

size

public int size()
Returns:
total number of handlers

getClassesOfInterest

public java.util.Collection getClassesOfInterest()

getStats

public DispatchingVisitor.Stats getStats()
Returns:
Returns visitor statistics.

getThreadStats

public DispatchingVisitor.Stats getThreadStats()

leave

public void leave(java.lang.Object target)
Description copied from interface: PoliteVisitor
Shall be invoked by Visitable at the end of navigation, when all children has already been visited.

Specified by:
leave in interface PoliteVisitor

remove

public void remove(java.lang.Object target)
Removes object from targets collection.

Parameters:
target -

execute

public void execute(java.lang.Object executionContext)
Passes executionContext for visiting. Subclasses can override this method and queue object for execution and invoke accept/visit in a different thread.

Specified by:
execute in interface Command


Copyright © 2003 Hammurapi Group. All Rights Reserved.