net.vleu.visitomatic
Class VisitorRunner

java.lang.Object
  extended by net.vleu.visitomatic.VisitorRunner

public abstract class VisitorRunner
extends java.lang.Object

Allows to run a Visitor on a Visitable.

More specifically, when its ReflectionBasedVisitorRunner.visit(Visitor, Visitable) method is called, it will analyze the provided Visitable, extract the fields annotated by ToVisit and use them as argument to call a method annotated by VisitingMethod from the Visitor

The expected usage is that there will be a private static final instance of ReflectionBasedVisitorRunner per Visitor class, ready to be called on instances when needed.

See Also:
Visitor, Visitable

Nested Class Summary
 class VisitorRunner.VisitorRunnerException
          Represents an error that occurred during the operation of a VisitorRunner.
 class VisitorRunner.VisitorRunnerInitialisationException
          Represents an error that occurred during the static analysis of a Visitor.
 
Constructor Summary
protected VisitorRunner()
          Call getInstance(java.lang.Class, java.lang.String) to get an instance.
 
Method Summary
abstract
<R> java.util.concurrent.FutureTask<R>
futureVisit(Visitor visitor, Visitable visitable)
          Return a FutureTask that analyzes the provided Visitable, extracts the fields annotated by ToVisit and uses them as argument to call a method annotated by VisitingMethod from the Visitor
static VisitorRunner getInstance(java.lang.Class<? extends Visitor> visitorClass, java.lang.String visitName)
          Analyzes a Visitor Class and and returns a VisitorRunner ready to run on one or more Visitor of this class on one ore more Visitables.
abstract
<R> R
visit(Visitor visitor, Visitable visitable)
          Analyzes the provided Visitable, extracts the fields annotated by ToVisit and uses them as argument to call a method annotated by VisitingMethod from the Visitor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VisitorRunner

protected VisitorRunner()
Call getInstance(java.lang.Class, java.lang.String) to get an instance.

Method Detail

getInstance

public static final VisitorRunner getInstance(java.lang.Class<? extends Visitor> visitorClass,
                                              java.lang.String visitName)
                                       throws VisitorRunner.VisitorRunnerInitialisationException
Analyzes a Visitor Class and and returns a VisitorRunner ready to run on one or more Visitor of this class on one ore more Visitables.

Parameters:
visitorClass - The class of the Visitors the VisitorRunner we will run
visitName - The name of the visit, as given to VisitingMethods in the Visitor
Returns:
A VisitorRunner for Visitors and Visitables of those classes
Throws:
VisitorRunner.VisitorRunnerInitialisationException - If we failed to analyze the visitor
See Also:
Visitor, VisitingMethod

visit

public abstract <R> R visit(Visitor visitor,
                            Visitable visitable)
                 throws VisitorRunner.VisitorRunnerException
Analyzes the provided Visitable, extracts the fields annotated by ToVisit and uses them as argument to call a method annotated by VisitingMethod from the Visitor

Type Parameters:
R - The return type
Parameters:
visitor - The visitor to run
visitable - The visitable to visit
Returns:
The return value from the suitable method of the visitor
Throws:
VisitorRunner.VisitorRunnerException - An error occurs during the running of the visitor
See Also:
ToVisit, VisitingMethod

futureVisit

public abstract <R> java.util.concurrent.FutureTask<R> futureVisit(Visitor visitor,
                                                                   Visitable visitable)
Return a FutureTask that analyzes the provided Visitable, extracts the fields annotated by ToVisit and uses them as argument to call a method annotated by VisitingMethod from the Visitor

Type Parameters:
R - The return type
Parameters:
visitor - The visitor to run
visitable - The visitable to visit
Returns:
The return value from the suitable method of the visitor
See Also:
ToVisit, VisitingMethod