adapforms.runtime.state
Class StateTree

java.lang.Object
  extended by adapforms.runtime.state.StateTree

public class StateTree
extends java.lang.Object

Holds the collective state and entered values for a FormInstance.

Recursive tree structure where each form path refers to a node (StateTreeNode instance). Each node can hold a value, a list of current validation problems, a list of trigger hooks etc.

Should not be used directly by domain applications.

Author:
Henrik Gammelmark, geemark@cs.au.dk

Nested Class Summary
(package private)  class StateTree.DOMStateDocument
          DOM document representation of the state tree, used for XPath evaluation etc.
(package private) static class StateTree.EnumerationAction
          Which action should be taken when continuing enumeration with a StateTree.EnumerationFilter.
(package private) static interface StateTree.EnumerationFilter
          Filter to use when enumerating nodes,
 
Constructor Summary
StateTree(FormInstanceImpl instance)
          Create a new state tree belonging to the specified form instance.
 
Method Summary
 StateTreeNode findNode(FormPath path)
          Look up an existing node in the tree.
 StateTreeNode findOrCreateMetaNode(FormPath path)
          Look up an existing node in the tree, and create it as a meta-node, if none is found.
 StateTreeNode findOrCreateNode(FormPath path)
          Look up an existing node in the tree, and create it, if none is found.
 java.util.Map<FormPath,java.util.List<ValidationProblem>> getAllValidationProblems(FormPath parentPath, boolean ignoreWarnings)
          Retrieve a collection of all validation problems in the sub-form rooted at the specified path.
 StateTree.DOMStateDocument getDOMDocument()
          Get the DOM Document representation of this tree.
 FormData getFormData()
          Create FormData instance by copying the data values from the tree.
 FormInstanceImpl getFormInstance()
          Reference to the form instance, to which this state tree belongs.
 java.util.List<FormPath> getRelevantChildren(FormPath parentPath)
          Enumerate all children with that are relevant below the given subtree.
 StateTreeNode getRoot()
          Get the root node of the tree.
 java.lang.String prettyPrint()
          Pretty-print the tree recursively.
 void reevaluateXPaths()
          Re-evaluate all XPath expressions.
 void removeTree(FormPath path)
          Delete an entire subtree.
(package private)  void visitChildren(FormPath parentPath, boolean visitMeta, StateTree.EnumerationFilter filter)
          Recursively visit all children in the tree, starting at the given path (not visited).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StateTree

public StateTree(FormInstanceImpl instance)
Create a new state tree belonging to the specified form instance.

Method Detail

findNode

public StateTreeNode findNode(FormPath path)
Look up an existing node in the tree.

Parameters:
path - Path to node

findOrCreateNode

public StateTreeNode findOrCreateNode(FormPath path)
Look up an existing node in the tree, and create it, if none is found. If the node is currently a meta-node, it will be converted to a non-meta node.

Parameters:
path - Path to node

findOrCreateMetaNode

public StateTreeNode findOrCreateMetaNode(FormPath path)
Look up an existing node in the tree, and create it as a meta-node, if none is found.

Parameters:
path - Path to node

getFormInstance

public FormInstanceImpl getFormInstance()
Reference to the form instance, to which this state tree belongs.


getDOMDocument

public StateTree.DOMStateDocument getDOMDocument()
Get the DOM Document representation of this tree.

See Also:
FormInstance.getDOMState().

getRoot

public StateTreeNode getRoot()
Get the root node of the tree.


removeTree

public void removeTree(FormPath path)
                throws InvalidPathException
Delete an entire subtree.

Parameters:
path - Root of tree to be removed
Throws:
InvalidPathException - if the path does not exist

prettyPrint

public java.lang.String prettyPrint()
Pretty-print the tree recursively. Used for debugging purposes.


getFormData

public FormData getFormData()
Create FormData instance by copying the data values from the tree.


getRelevantChildren

public java.util.List<FormPath> getRelevantChildren(FormPath parentPath)
                                             throws InvalidPathException
Enumerate all children with that are relevant below the given subtree. When an irrelevant child is reached, recursion ends.

Throws:
InvalidPathException

getAllValidationProblems

public java.util.Map<FormPath,java.util.List<ValidationProblem>> getAllValidationProblems(FormPath parentPath,
                                                                                          boolean ignoreWarnings)
                                                                                   throws InvalidPathException
Retrieve a collection of all validation problems in the sub-form rooted at the specified path.

Parameters:
ignoreWarnings - Ignore warnings?
Returns:
Mapping from form element paths to a list of validation errors for that element.
Throws:
InvalidPathException - if the root node does not exist

reevaluateXPaths

public void reevaluateXPaths()
Re-evaluate all XPath expressions.

See Also:
XPathManager.reevaluateXPaths()

visitChildren

void visitChildren(FormPath parentPath,
                   boolean visitMeta,
                   StateTree.EnumerationFilter filter)
             throws InvalidPathException
Recursively visit all children in the tree, starting at the given path (not visited).

Parameters:
parentPath - Path to the visiting root
visitMeta - Visit meta nodes too?
filter - Filter to apply (or null)
Throws:
InvalidPathException - If the root node does not exist