com.sfm.ap210.jsdai.utils
Class SdaiModelTraverser

java.lang.Object
  extended by com.sfm.ap210.jsdai.utils.SdaiModelTraverser

public class SdaiModelTraverser
extends java.lang.Object

This is a utility class used to control a generic traversal of an SDAI model instance starting from a root entity instance and finding/marking all connected instances. The class can be subclassed to customize the exact traversal conditions.


Field Summary
protected  java.util.Set<jsdai.lang.EEntity> cuts
           
 java.util.Set<jsdai.lang.EEntity> marked
           
protected  jsdai.lang.SdaiModel model
           
protected  java.util.List<jsdai.lang.EEntity> path
           
protected  java.util.Map<jsdai.lang.EEntity,java.util.List<jsdai.lang.EEntity>> paths
           
protected  jsdai.lang.EEntity root
           
 java.util.Set<jsdai.lang.EEntity> visited
           
 
Constructor Summary
SdaiModelTraverser(jsdai.lang.SdaiModel model, jsdai.lang.EEntity root)
          Create a new model traversal of the given model instance starting at the given root entity
 
Method Summary
protected  boolean checkBackward(jsdai.lang.EEntity ent)
          Extension method to allow subclasses to customize the traversal.
protected  boolean checkForward(jsdai.lang.EEntity ent)
          Extension method to allow subclasses to customize the traversal.
protected  void findCuts()
          Find/record all cut-entity instances specified by this traversal class
protected  void markAndSweep(jsdai.lang.EEntity ent)
          Mark the given entity (if applicable) and traverse all forward and backward references of the entity (if applicable)
 void printDiscoveryPaths()
          Print the path of discovery of each marked entity.
 void traverse()
          Traverse and mark all covered entities in the model
protected  void traverseBackwardRefs(jsdai.lang.EEntity ent)
          Traverse all entities directly referencing the given entity
protected  void traverseForwardRefs(jsdai.lang.EEntity ent)
          Traverse all entities directly referenced by the given entity
protected  void updateCuts(jsdai.lang.EEntity ent)
          Update cut-nodes for the given entity.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

model

protected jsdai.lang.SdaiModel model

root

protected jsdai.lang.EEntity root

cuts

protected java.util.Set<jsdai.lang.EEntity> cuts

path

protected java.util.List<jsdai.lang.EEntity> path

paths

protected java.util.Map<jsdai.lang.EEntity,java.util.List<jsdai.lang.EEntity>> paths

visited

public java.util.Set<jsdai.lang.EEntity> visited

marked

public java.util.Set<jsdai.lang.EEntity> marked
Constructor Detail

SdaiModelTraverser

public SdaiModelTraverser(jsdai.lang.SdaiModel model,
                          jsdai.lang.EEntity root)
                   throws jsdai.lang.SdaiException
Create a new model traversal of the given model instance starting at the given root entity

Parameters:
model - the model instance
root - the root entity to start the traversal
Throws:
jsdai.lang.SdaiException
Method Detail

findCuts

protected void findCuts()
                 throws jsdai.lang.SdaiException
Find/record all cut-entity instances specified by this traversal class

Throws:
jsdai.lang.SdaiException

traverse

public void traverse()
              throws jsdai.lang.SdaiException
Traverse and mark all covered entities in the model

Throws:
jsdai.lang.SdaiException

markAndSweep

protected void markAndSweep(jsdai.lang.EEntity ent)
                     throws jsdai.lang.SdaiException
Mark the given entity (if applicable) and traverse all forward and backward references of the entity (if applicable)

Parameters:
ent -
Throws:
jsdai.lang.SdaiException

traverseBackwardRefs

protected void traverseBackwardRefs(jsdai.lang.EEntity ent)
                             throws jsdai.lang.SdaiException
Traverse all entities directly referencing the given entity

Parameters:
ent -
Throws:
jsdai.lang.SdaiException

traverseForwardRefs

protected void traverseForwardRefs(jsdai.lang.EEntity ent)
                            throws jsdai.lang.SdaiException
Traverse all entities directly referenced by the given entity

Parameters:
ent -
Throws:
jsdai.lang.SdaiException

printDiscoveryPaths

public void printDiscoveryPaths()
                         throws jsdai.lang.SdaiException
Print the path of discovery of each marked entity. That is, print the traversal path from the root entity for each marked entity

Throws:
jsdai.lang.SdaiException

updateCuts

protected void updateCuts(jsdai.lang.EEntity ent)
                   throws jsdai.lang.SdaiException
Update cut-nodes for the given entity. Allows subclasses to do pre-processing of the traversal cut-nodes (or other internal data) prior to any actual traversal. This method is called for every entity in the model prior to starting the traversal

Parameters:
ent -
Throws:
jsdai.lang.SdaiException

checkForward

protected boolean checkForward(jsdai.lang.EEntity ent)
                        throws jsdai.lang.SdaiException
Extension method to allow subclasses to customize the traversal. Return true if the entity's forward references should be traversed.

Parameters:
ent -
Returns:
Throws:
jsdai.lang.SdaiException

checkBackward

protected boolean checkBackward(jsdai.lang.EEntity ent)
                         throws jsdai.lang.SdaiException
Extension method to allow subclasses to customize the traversal. Return true if the entity's backward references (other entities referencing the given entity) should be traversed.

Parameters:
ent -
Returns:
Throws:
jsdai.lang.SdaiException