tom.library.sl
Class AbstractStrategy

java.lang.Object
  extended by tom.library.sl.AbstractStrategy
All Implemented Interfaces:
Strategy, Visitable
Direct Known Subclasses:
AbstractStrategyBasic, AbstractStrategyCombinator

public abstract class AbstractStrategy
extends Object
implements Strategy

Partial implementation of the strategy interface that implements most of the visit methods. This class is extended by the two abstract classes AbstractStrategyBasic and AbstractStrategyCombinator that can be used to implement respectively new basic transformations (like a rewrite rule system) and new strategy combinators (like the All strategy).

It is not advised to implement directly this abstract class.


Field Summary
protected  Environment environment
          Environment of the strategy application
 
Constructor Summary
AbstractStrategy()
           
 
Method Summary
 Object getAncestor()
          Get the current ancestor
 Environment getEnvironment()
          Get a reference to the current environment.
 Position getPosition()
          Get the current position
 Object getRoot()
          Get the current root.
 Object getSubject()
          Get the current subject
 void init(Introspector introspector)
          Initialize the Strategy
static void init(Strategy s, Environment env)
          Initialize the Strategy by providing the environment and the strategy
 void setEnvironment(Environment env)
          Set up a new environment.
 void setRoot(Object any)
          Set up the current root.
 void setSubject(Object any)
          Set up the current subject
<T extends Visitable>
T
visit(Environment envt)
          Executes the strategy in the given environment (on its current subject).
 Object visit(Environment envt, Introspector i)
          Executes the strategy in the given environment (on its current subject).
<T extends Visitable>
T
visit(T any)
          Visits the subject any by providing the environment
<T> T
visit(T any, Introspector i)
          Visits the subject any by providing the introspector
<T extends Visitable>
T
visitLight(T any)
          Visits the subject any in a light way (without environment)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface tom.library.sl.Strategy
visit, visitLight
 
Methods inherited from interface tom.library.sl.Visitable
getChildAt, getChildCount, getChildren, setChildAt, setChildren
 

Field Detail

environment

protected Environment environment
Environment of the strategy application

Constructor Detail

AbstractStrategy

public AbstractStrategy()
Method Detail

visit

public <T extends Visitable> T visit(Environment envt)
                          throws VisitFailure
Executes the strategy in the given environment (on its current subject). This method can only be used inside user strategies to execute another strategy but with the current environment of the user strategy.

Specified by:
visit in interface Strategy
Parameters:
envt - the environment where execute the strategy.
Throws:
VisitFailure - if visit fails

visit

public <T extends Visitable> T visit(T any)
                          throws VisitFailure
Visits the subject any by providing the environment

Specified by:
visit in interface Strategy
Parameters:
any - the subject to visit.
Throws:
VisitFailure - if visit fails

visit

public Object visit(Environment envt,
                    Introspector i)
             throws VisitFailure
Executes the strategy in the given environment (on its current subject). This method can only be used inside user strategies to execute another strategy but with the current environment of the user strategy.

Specified by:
visit in interface Strategy
Parameters:
envt - the environment where execute the strategy.
i - the introspector
Throws:
VisitFailure - if visit fails

visitLight

public <T extends Visitable> T visitLight(T any)
                               throws VisitFailure
Visits the subject any in a light way (without environment)

Specified by:
visitLight in interface Strategy
Parameters:
any - the subject to visit
Throws:
VisitFailure - if visitLight fails

visit

public <T> T visit(T any,
                   Introspector i)
        throws VisitFailure
Visits the subject any by providing the introspector

Specified by:
visit in interface Strategy
Parameters:
any - the subject to visit.
i - the introspector
Throws:
VisitFailure - if visit fails

getEnvironment

public Environment getEnvironment()
Get a reference to the current environment.

Specified by:
getEnvironment in interface Strategy
Returns:
the current environment
Throws:
RuntimeException - if the environment is not initialized

setEnvironment

public void setEnvironment(Environment env)
Set up a new environment.

Specified by:
setEnvironment in interface Strategy
Parameters:
env - the environment to set up.

getRoot

public Object getRoot()
Get the current root.

Returns:
the current root

setRoot

public void setRoot(Object any)
Set up the current root.

Parameters:
any - the current root

getSubject

public Object getSubject()
Get the current subject

Returns:
the current subject

setSubject

public void setSubject(Object any)
Set up the current subject

Parameters:
any - the subject to set up

getPosition

public Position getPosition()
Get the current position

Returns:
the current application position

getAncestor

public Object getAncestor()
Get the current ancestor

Returns:
the current ancestor

init

public void init(Introspector introspector)
Initialize the Strategy


init

public static void init(Strategy s,
                        Environment env)
Initialize the Strategy by providing the environment and the strategy

Parameters:
s - the strategy
env - the environment