Package org.jibx.binding.model
Class TreeContext
java.lang.Object
org.jibx.binding.model.TreeContext
- Direct Known Subclasses:
ValidationContext
Handles walking the tree structure of a binding model, tracking
order-dependent state information collected along the way.
- Author:
- Dennis M. Sosnoski
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate BindingElementBinding element model root (may benull, if not configured by caller).private DefinitionContextGlobal definition context (outside of binding).private IClassLocatorClass locator set by environment code.private HashSetSet of elements to be skipped in walking tree.private ObjectStackStack of items for parent hierarchy to current node in tree. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateInternal null constructor.TreeContext(IClassLocator iloc) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAdd element to set to be skipped.Get root element of binding.Get a secondary context for the same tree as this instance.getClassInfo(String name) Get class information.Get parent container with linked object.Get definition context for innermost nesting element.Get innermost containing definition context.Get definition context for innermost nesting element for use by a format (or namespace).intGet depth of nesting in binding.Get parent container information.Get containing element.getParentElement(int level) Get containing element at generation level.getRequiredClassInfo(String name) Get required class information.booleanCheck if binding supports input.booleanCheck if class lookup is supported.booleanCheck if binding supports output.booleanCheck if a component is being skipped due to a fatal error.protected ElementBasePeek current element of hierarchy.popNode()Pop node from tree.voidpushNode(ElementBase node) Push node on tree.voidsetBindingRoot(BindingElement root) Set root element of binding.voidSet the global definition context.voidtourTree(BindingElement root, ModelVisitor visitor) Tour complete binding model tree.voidtourTree(ElementBase root, ModelVisitor visitor) Tour binding model tree.
-
Field Details
-
m_globalContext
Global definition context (outside of binding). -
m_bindingRoot
Binding element model root (may benull, if not configured by caller). -
m_treeHierarchy
Stack of items for parent hierarchy to current node in tree. -
m_locator
Class locator set by environment code. -
m_skipSet
Set of elements to be skipped in walking tree.
-
-
Constructor Details
-
TreeContext
private TreeContext()Internal null constructor. -
TreeContext
Constructor.- Parameters:
iloc- class locator to be used
-
-
Method Details
-
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
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
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
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
Peek current element of hierarchy.- Returns:
- current element
-
isSkipped
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
Add element to set to be skipped.- Parameters:
skip-
-
getBindingRoot
Get root element of binding.- Returns:
- root element of binding
- Throws:
IllegalStateException- if no root element known
-
setBindingRoot
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
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
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
Get parent container information. This returns the innermost containing binding component which refers to an object.- Returns:
- innermost containing element referencing bound object
-
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
Get innermost containing definition context.- Returns:
- innermost definition context containing this element
-
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
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
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
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
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
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
-