com.googlecode.sarasvati
Class CustomNode

java.lang.Object
  extended by com.googlecode.sarasvati.CustomNode
All Implemented Interfaces:
Adaptable, Node
Direct Known Subclasses:
NestedProcessNode, ScriptNode, WaitNode

public abstract class CustomNode
extends Object
implements Node

CustomNode provides a superclass for user defined nodes that are portable across all engines.

Author:
Paul Lorenz

Constructor Summary
CustomNode()
           
 
Method Summary
 void backtrack(Engine engine, NodeToken token)
          Does nothing by default.
<T> T
getAdaptor(Class<T> clazz)
          Default implementation calls CustomNodeWrapper.getDefaultAdaptor(Class).
 External getExternal()
          If the node is defined in an external, returns the external and null otherwise.
 ReadEnv getExternalEnv()
          Returns a read-only environment containing all attributes defined for all associated externals.
 Graph getGraph()
          Returns the graph that this node belongs to.
 String getGuard()
          Every node may have a guard associated with it.
 Long getId()
          Returns the node's unique id.
 String getJoinParam()
          Each node may specify a parameter to be used by the join strategy.
 JoinStrategy getJoinStrategy(Arc arc)
          Returns the JoinStrategy to be used when an ArcToken arrives at this Node.
 JoinType getJoinType()
          Returns the JoinType of the node.
 String getName()
          Returns the node name.
 Node getNodeWrapper()
           
 Node getOriginatingExternalNode()
          If a node is defined in an external, this will return the node as defined in the external graph.
 String getType()
          Every node has a type.
 GuardResult guard(Engine engine, NodeToken token)
          Default implementation calls CustomNodeWrapper.defaultGuard(Engine, NodeToken).
 boolean isBacktrackable(Engine engine, NodeToken token)
          Returns true by default.
 boolean isImportedFromExternal()
          Returns true if this node was imported from an external process definition, false otherwise.
 boolean isStart()
          Returns true if this node is a start node.
 void setNodeWrapper(CustomNodeWrapper nodeWrapper)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.googlecode.sarasvati.Node
execute
 

Constructor Detail

CustomNode

public CustomNode()
Method Detail

setNodeWrapper

public void setNodeWrapper(CustomNodeWrapper nodeWrapper)

getNodeWrapper

public Node getNodeWrapper()

getGraph

public final Graph getGraph()
Description copied from interface: Node
Returns the graph that this node belongs to.

Specified by:
getGraph in interface Node
Returns:
The associated Graph

getGuard

public final String getGuard()
Description copied from interface: Node
Every node may have a guard associated with it. The guard may be blank or null, which by default, will be treated as an Accept. If it is not null or blank, the guard method may interpret it in some fashion. It may be a GuardLang statement, it could be some other script language or it could be interpreted in some other way entirely.

Specified by:
getGuard in interface Node
Returns:
The guard

getId

public final Long getId()
Description copied from interface: Node
Returns the node's unique id. The id must be unique to the Graph, but may be globally unique.

Specified by:
getId in interface Node
Returns:
The node's unique id.

getName

public final String getName()
Description copied from interface: Node
Returns the node name. Every node must have a name which is unique in it's process definition;

Specified by:
getName in interface Node
Returns:
The node name.

getType

public final String getType()
Description copied from interface: Node
Every node has a type. The default is 'node'. Nodes of different types may have different (user defined) behavior when the execute method is invoked.

Specified by:
getType in interface Node
Returns:
The type

isImportedFromExternal

public final boolean isImportedFromExternal()
Description copied from interface: Node
Returns true if this node was imported from an external process definition, false otherwise.

Specified by:
isImportedFromExternal in interface Node
Returns:
True if this node was imported from an external process definition.

getJoinType

public final JoinType getJoinType()
Description copied from interface: Node
Returns the JoinType of the node.

Specified by:
getJoinType in interface Node
Returns:
The JoinType of the node.

getJoinParam

public final String getJoinParam()
Description copied from interface: Node
Each node may specify a parameter to be used by the join strategy. For example, it can be used to tell a token set join which token set to join on, by name. For a custom join, it may indicate the join type, or provide some other information to the join.

May be null.

Specified by:
getJoinParam in interface Node
Returns:
The join parameter.

getJoinStrategy

public JoinStrategy getJoinStrategy(Arc arc)
Description copied from interface: Node
Returns the JoinStrategy to be used when an ArcToken arrives at this Node.

Specified by:
getJoinStrategy in interface Node
Parameters:
arc - The arc of the incoming arc token. Allows different join strategies for different arcs.
Returns:
The JoinStrategy to be used when an ArcToken arrives at this Node.

isStart

public final boolean isStart()
Description copied from interface: Node
Returns true if this node is a start node. Start nodes will have a token placed in them when the process is started

Specified by:
isStart in interface Node
Returns:
True if the node is a start node.

getExternal

public final External getExternal()
Description copied from interface: Node
If the node is defined in an external, returns the external and null otherwise.

Specified by:
getExternal in interface Node
Returns:
If the node is defined in an external, returns the external and null otherwise.

getExternalEnv

public final ReadEnv getExternalEnv()
Description copied from interface: Node
Returns a read-only environment containing all attributes defined for all associated externals. See Node.getOriginatingExternalNode() for examples usage.

Specified by:
getExternalEnv in interface Node
Returns:
A read-only environment containing all attributes defined for associated externals.

getOriginatingExternalNode

public Node getOriginatingExternalNode()
Description copied from interface: Node
If a node is defined in an external, this will return the node as defined in the external graph. Otherwise it will return null. Generally, this is only useful if you wish to examine the external associated with the originating node.

Note: If the originating node is the original node, it will not have an external associated with it. Since this method exists to allow access to multiple levels of external, this method may return null instead of the original node.

For example, given the following three graphs, where graph II uses graph I and graph III uses graph II, you could look up different values defined in the externals.

  
    
  

  
    
      
        bar
        world
      
    

    
      
    
  

  
    
      
        baz
      
    

    
      
    
  

 If you get node A from graph III, you can observe the following:

   Node nodeA = ...;
   nodeA.getExternalEnv().getAttribute( "foo" ) // returns "baz"
   nodeA.getExternalEnv().getAttribute( "hello" ) // returns "world"
   nodeA.getExternal().getEnv().getAttribute( "foo" ) // returns "baz"
   nodeA.getExternal().getEnv().getAttribute( "hello" ) // returns null
   nodeA.getOriginatingExternalNode().getExternal().getEnv().getAttribute( "foo" ) // returns "bar"
   nodeA.getOriginatingExternalNode().getExternal().getEnv().getAttribute( "hello" ) // returns "world"
 

Specified by:
getOriginatingExternalNode in interface Node
Returns:
If node is an external node, returns the node as defined in the external, otherwise returns null.

backtrack

public void backtrack(Engine engine,
                      NodeToken token)
Does nothing by default. May be overridden by subclasses.

IMPORTANT NOTE: Do not call Node.backtrack(Engine,NodeToken) as that will just call your isBacktrackable method again, resulting in an recursive call, which will exit when your VM runs out of stack space.

Specified by:
backtrack in interface Node
Parameters:
engine - The engine doing the backtracking
token - The specific token being backtracked.
See Also:
Node.backtrack(Engine, NodeToken)

isBacktrackable

public boolean isBacktrackable(Engine engine,
                               NodeToken token)
Returns true by default. May be overridden by subclasses.

IMPORTANT NOTE: Do not call Node.isBacktrackable(Engine, NodeToken) as that will just call your isBacktrackable method again, resulting in an recursive call, which will exit when your VM runs out of stack space.

Specified by:
isBacktrackable in interface Node
Parameters:
engine - The engine doing the backtracking
token - The token being backtracked
Returns:
True if the node can be backtracked, false otherwise.
See Also:
Node.isBacktrackable(Engine,NodeToken)

getAdaptor

public <T> T getAdaptor(Class<T> clazz)
Default implementation calls CustomNodeWrapper.getDefaultAdaptor(Class). May be overridden by subclasses.

IMPORTANT NOTE: Do not call Adaptable.getAdaptor(Class) as that will just call your getAdapter method again, resulting in an recursive call, which will exit when your VM runs out of stack space.

Specified by:
getAdaptor in interface Adaptable
Parameters:
clazz - The type of adaptor requested
Returns:
An instance of the requested class, or null if the adaptor type is not supported
See Also:
Adaptable.getAdaptor(Class)

guard

public GuardResult guard(Engine engine,
                         NodeToken token)
Default implementation calls CustomNodeWrapper.defaultGuard(Engine, NodeToken). May be overridden by subclasses.

IMPORTANT NOTE: Do not call Node.guard(Engine, NodeToken) as that will just call your guard method again, resulting in an recursive call, which will exit when your VM runs out of stack space.

Specified by:
guard in interface Node
Parameters:
engine - The engine being used to execute the process
token - The node token which is currently entering a node
Returns:
A GuardResult
See Also:
Node.guard(Engine, NodeToken)