Class TreeContext

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

public class TreeContext extends Object
Handles walking the tree structure of a binding model, tracking order-dependent state information collected along the way.
Author:
Dennis M. Sosnoski
  • Field Details

    • 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 HashSet m_skipSet
      Set of elements to be skipped in walking tree.
  • Constructor Details

    • TreeContext

      private TreeContext()
      Internal null constructor.
    • TreeContext

      public TreeContext(IClassLocator iloc)
      Constructor.
      Parameters:
      iloc - class locator to be used
  • Method Details

    • 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(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(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:
      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
    • isLookupSupported

      public boolean isLookupSupported()
      Check if class lookup is supported. If this returns false, lookup methods return only place holder class information.
      Returns:
      true if class lookup supported, false if only place holder information returned
    • getClassInfo

      public IClass getClassInfo(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(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