Package org.jibx.binding.model
Class TreeContext
- java.lang.Object
-
- org.jibx.binding.model.TreeContext
-
- Direct Known Subclasses:
ValidationContext
public class TreeContext extends java.lang.ObjectHandles walking the tree structure of a binding model, tracking order-dependent state information collected along the way.- Author:
- Dennis M. Sosnoski
-
-
Field Summary
Fields Modifier and Type Field Description private BindingElementm_bindingRootBinding element model root (may benull, if not configured by caller).private DefinitionContextm_globalContextGlobal definition context (outside of binding).private IClassLocatorm_locatorClass locator set by environment code.private java.util.HashSetm_skipSetSet of elements to be skipped in walking tree.private ObjectStackm_treeHierarchyStack of items for parent hierarchy to current node in tree.
-
Constructor Summary
Constructors Modifier Constructor Description privateTreeContext()Internal null constructor.TreeContext(IClassLocator iloc)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddSkip(java.lang.Object skip)Add element to set to be skipped.BindingElementgetBindingRoot()Get root element of binding.TreeContextgetChildContext()Get a secondary context for the same tree as this instance.IClassgetClassInfo(java.lang.String name)Get class information.ContainerElementBasegetContextObject()Get parent container with linked object.DefinitionContextgetCurrentDefinitions()Get definition context for innermost nesting element.DefinitionContextgetDefinitions()Get innermost containing definition context.DefinitionContextgetFormatDefinitions()Get definition context for innermost nesting element for use by a format (or namespace).intgetNestingDepth()Get depth of nesting in binding.ContainerElementBasegetParentContainer()Get parent container information.NestingElementBasegetParentElement()Get containing element.ElementBasegetParentElement(int level)Get containing element at generation level.IClassgetRequiredClassInfo(java.lang.String name)Get required class information.booleanisInBinding()Check if binding supports input.booleanisLookupSupported()Check if class lookup is supported.booleanisOutBinding()Check if binding supports output.booleanisSkipped(java.lang.Object obj)Check if a component is being skipped due to a fatal error.protected ElementBasepeekElement()Peek current element of hierarchy.ElementBasepopNode()Pop node from tree.voidpushNode(ElementBase node)Push node on tree.voidsetBindingRoot(BindingElement root)Set root element of binding.voidsetGlobalDefinitions(DefinitionContext dctx)Set the global definition context.voidtourTree(BindingElement root, ModelVisitor visitor)Tour complete binding model tree.voidtourTree(ElementBase root, ModelVisitor visitor)Tour binding model tree.
-
-
-
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 benull, 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 treevisitor- 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 touredvisitor- 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 generation1parent, except that it checks for the case where there's no parent present.- Returns:
- binding definition component for parent element, or
nullif 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 ofNestingElementBase.- 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:
trueif input binding,falseif not
-
isOutBinding
public boolean isOutBinding()
Check if binding supports output.- Returns:
trueif output binding,falseif 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
-
isLookupSupported
public boolean isLookupSupported()
Check if class lookup is supported. If this returnsfalse, lookup methods return only place holder class information.- Returns:
trueif class lookup supported,falseif only place holder information returned
-
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
nullif 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
-
-