org.jibx.binding.model
Class TreeContext

java.lang.Object
  extended by org.jibx.binding.model.TreeContext
Direct Known Subclasses:
ValidationContext

public class TreeContext
extends java.lang.Object

Handles walking the tree structure of a binding model, tracking order-dependent state information collected along the way.

Author:
Dennis M. Sosnoski

Field Summary
private  BindingElement m_bindingRoot
          Binding element model root (may be null, if not configured by caller).
private  DefinitionContext m_globalContext
          Global definition context (outside of binding).
private  IClassLocator m_locator
          Class locator set by environment code.
private  java.util.HashSet m_skipSet
          Set of elements to be skipped in walking tree.
private  ObjectStack m_treeHierarchy
          Stack of items for parent hierarchy to current node in tree.
 
Constructor Summary
private TreeContext()
          Internal null constructor.
  TreeContext(IClassLocator iloc)
          Constructor.
 
Method Summary
protected  void addSkip(java.lang.Object skip)
          Add element to set to be skipped.
 BindingElement getBindingRoot()
          Get root element of binding.
 TreeContext getChildContext()
          Get a secondary context for the same tree as this instance.
 IClass getClassInfo(java.lang.String name)
          Get class information.
 ContainerElementBase getContextObject()
          Get parent container with linked object.
 DefinitionContext getCurrentDefinitions()
          Get definition context for innermost nesting element.
 DefinitionContext getDefinitions()
          Get innermost containing definition context.
 DefinitionContext getFormatDefinitions()
          Get definition context for innermost nesting element for use by a format (or namespace).
 int getNestingDepth()
          Get depth of nesting in binding.
 ContainerElementBase getParentContainer()
          Get parent container information.
 NestingElementBase getParentElement()
          Get containing element.
 ElementBase getParentElement(int level)
          Get containing element at generation level.
 IClass getRequiredClassInfo(java.lang.String name)
          Get required class information.
 boolean isInBinding()
          Check if binding supports input.
 boolean isOutBinding()
          Check if binding supports output.
 boolean isSkipped(java.lang.Object obj)
          Check if a component is being skipped due to a fatal error.
protected  ElementBase peekElement()
          Peek current element of hierarchy.
 ElementBase popNode()
          Pop node from tree.
 void pushNode(ElementBase node)
          Push node on tree.
 void setBindingRoot(BindingElement root)
          Set root element of binding.
 void setGlobalDefinitions(DefinitionContext dctx)
          Set the global definition context.
 void tourTree(BindingElement root, ModelVisitor visitor)
          Tour complete binding model tree.
 void tourTree(ElementBase root, ModelVisitor visitor)
          Tour binding model tree.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_globalContext

private DefinitionContext m_globalContext
Global definition context (outside of binding).


m_bindingRoot

private BindingElement m_bindingRoot
Binding element model root (may be null, if not configured by caller).


m_treeHierarchy

private ObjectStack m_treeHierarchy
Stack of items for parent hierarchy to current node in tree.


m_locator

private IClassLocator m_locator
Class locator set by environment code.


m_skipSet

private java.util.HashSet m_skipSet
Set of elements to be skipped in walking tree.

Constructor Detail

TreeContext

private TreeContext()
Internal null constructor.


TreeContext

public TreeContext(IClassLocator iloc)
Constructor.

Parameters:
iloc - class locator to be used
Method Detail

getChildContext

public TreeContext getChildContext()
Get a secondary context for the same tree as this instance. The secondary context shares the same skip set, context, and binding root as the original context. This allows activites invoked during the touring of the original tree to start subtours of their own part of the tree.

Returns:
new context linked to original context

setGlobalDefinitions

public void setGlobalDefinitions(DefinitionContext dctx)
Set the global definition context. This context is external to the actual binding definition, providing defaults that can be overridden by values set within the actual binding.

Parameters:
dctx - global definition context

tourTree

public void tourTree(BindingElement root,
                     ModelVisitor visitor)
Tour complete binding model tree. This tours the entire binding model, starting from the root binding element. Using this method automatically sets the root binding element for access by processing performed during the tour. It must be used for the binding element in order to handle included binding definitions properly.

Parameters:
root - binding element root of tree
visitor - target visitor for element notifications

tourTree

public void tourTree(ElementBase root,
                     ModelVisitor visitor)
Tour binding model tree. This recursively traverses the binding model tree rooted in the supplied element, notifying the visitor of each element visited during the traversal. Elements with fatal errors are skipped in processing, along with all child elements. The method may itself be called recursively.

Parameters:
root - node of tree to be toured
visitor - target visitor for element notifications

getNestingDepth

public int getNestingDepth()
Get depth of nesting in binding.

Returns:
nesting depth

peekElement

protected ElementBase peekElement()
Peek current element of hierarchy.

Returns:
current element

isSkipped

public boolean isSkipped(java.lang.Object obj)
Check if a component is being skipped due to a fatal error.

Parameters:
obj - component to be checked
Returns:
flag for component being skipped

addSkip

protected void addSkip(java.lang.Object skip)
Add element to set to be skipped.

Parameters:
skip -

getBindingRoot

public BindingElement getBindingRoot()
Get root element of binding.

Returns:
root element of binding
Throws:
java.lang.IllegalStateException - if no root element known

setBindingRoot

public void setBindingRoot(BindingElement root)
Set root element of binding. This should be called by the user if an element other than the binding element is going to be used as the root for a tour.

Parameters:
root - root element of binding

getParentElement

public NestingElementBase getParentElement()
Get containing element. This is equivalent to the generation 1 parent, except that it checks for the case where there's no parent present.

Returns:
binding definition component for parent element, or null if no parent

getParentElement

public ElementBase getParentElement(int level)
Get containing element at generation level. All except the zero-level containing element are guaranteed to be instances of NestingElementBase.

Parameters:
level - generation level of parent
Returns:
binding definition component for parent at level

getParentContainer

public ContainerElementBase getParentContainer()
Get parent container information. This returns the innermost containing binding component which refers to an object.

Returns:
innermost containing element referencing bound object

getContextObject

public ContainerElementBase getContextObject()
Get parent container with linked object. This returns the innermost containing binding component which defines a context object.

Returns:
innermost containing element defining a context object

isInBinding

public boolean isInBinding()
Check if binding supports input.

Returns:
true if input binding, false if not

isOutBinding

public boolean isOutBinding()
Check if binding supports output.

Returns:
true if output binding, false if not

getDefinitions

public DefinitionContext getDefinitions()
Get innermost containing definition context.

Returns:
innermost definition context containing this element

getCurrentDefinitions

public DefinitionContext getCurrentDefinitions()
Get definition context for innermost nesting element. If the context for this element isn't already defined it's created by the call.

Returns:
definition context for innermost nesting element

getFormatDefinitions

public DefinitionContext getFormatDefinitions()
Get definition context for innermost nesting element for use by a format (or namespace). If the context for this element isn't already defined it's created by the call, along with the contexts for any containing elements. This is ugly, but necessary to keep the tree structure of contexts from getting split when other items are added by the registration pass (since the formats are registered in the prevalidation pass).

Returns:
definition context for innermost nesting element

getClassInfo

public IClass getClassInfo(java.lang.String name)
Get class information. Finds a class by name using the class locator configured by the environment code.

Parameters:
name - fully-qualified name of class to be found
Returns:
class information, or null if class not found

getRequiredClassInfo

public IClass getRequiredClassInfo(java.lang.String name)
Get required class information. Finds a class by name using the class locator configured by the environment code. If the class cannot be found a runtime exception is thrown.

Parameters:
name - fully-qualified name of class to be found
Returns:
class information

pushNode

public void pushNode(ElementBase node)
Push node on tree. This is provided for use during validation, when the context may be changed by recursive checks outside the normal tree traversal.

Parameters:
node -

popNode

public ElementBase popNode()
Pop node from tree. This is provided for use during validation, when the context may be changed by recursive checks outside the normal tree traversal.

Returns:
node


Project Web Site