📄 treecontext.java
字号:
case ElementBase.TEMPLATE_ELEMENT: visitor.exit((TemplateElement)root); break; case ElementBase.VALUE_ELEMENT: visitor.exit((ValueElement)root); break; default: break; } m_treeHierarchy.pop(); } /** * Get depth of nesting in binding. * * @return nesting depth */ public int getNestingDepth() { return m_treeHierarchy.size(); } /** * Peek current element of hierarchy. * * @return current element */ protected ElementBase peekElement() { return (ElementBase)m_treeHierarchy.peek(); } /** * Check if a component is being skipped due to a fatal error. * * @param obj component to be checked * @return flag for component being skipped */ public boolean isSkipped(Object obj) { return m_skipSet.contains(obj); } /** * Add element to set to be skipped. * * @param skip */ protected void addSkip(Object skip) { if (skip instanceof ElementBase) { m_skipSet.add(skip); } } /** * Get root element of binding. * * @return root element of binding * @throws IllegalStateException if no root element known */ public BindingElement getBindingRoot() { if (m_bindingRoot == null) { throw new IllegalStateException("No binding root defined"); } else { return m_bindingRoot; } } /** * 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. * * @param root root element of binding */ public void setBindingRoot(BindingElement root) { m_bindingRoot = root; } /** * Get containing element. This is equivalent to the generation * <code>1</code> parent, except that it checks for the case where there's * no parent present. * * @return binding definition component for parent element, or * <code>null</code> if no parent */ public NestingElementBase getParentElement() { if (m_treeHierarchy.size() > 1) { return (NestingElementBase)m_treeHierarchy.peek(1); } else { return null; } } /** * Get containing element at generation level. All except the zero-level * containing element are guaranteed to be instances of {@link * org.jibx.binding.model.NestingElementBase}. * * @param level generation level of parent * @return binding definition component for parent at level */ public ElementBase getParentElement(int level) { return (ElementBase)m_treeHierarchy.peek(level); } /** * Get parent container information. This returns the innermost containing * binding component which refers to an object. * * @return innermost containing element referencing bound object */ public ContainerElementBase getParentContainer() { int index = 1; while (index < m_treeHierarchy.size()) { NestingElementBase nest = (NestingElementBase)m_treeHierarchy.peek(index++); if (nest instanceof ContainerElementBase) { return (ContainerElementBase)nest; } } throw new IllegalStateException("Internal error: no container"); } /** * Get parent container with linked object. This returns the innermost * containing binding component which defines a context object. * * @return innermost containing element defining a context object */ public ContainerElementBase getContextObject() { int index = 1; while (index < m_treeHierarchy.size()) { NestingElementBase nest = (NestingElementBase)m_treeHierarchy.peek(index++); if (nest instanceof ContainerElementBase) { ContainerElementBase contain = (ContainerElementBase)nest; if (contain.hasObject()) { return contain; } } } throw new IllegalStateException("Internal error: no context object"); } /** * Check if binding supports input. * * @return <code>true</code> if input binding, <code>false</code> if not */ public boolean isInBinding() { return m_bindingRoot == null ? true : m_bindingRoot.isInBinding(); } /** * Check if binding supports output. * * @return <code>true</code> if output binding, <code>false</code> if not */ public boolean isOutBinding() { return m_bindingRoot == null ? true : m_bindingRoot.isOutBinding(); } /** * Get innermost containing definition context. * * @return innermost definition context containing this element */ public DefinitionContext getDefinitions() { int index = 1; while (index < m_treeHierarchy.size()) { NestingElementBase nest = (NestingElementBase)m_treeHierarchy.peek(index++); if (nest.getDefinitions() != null) { return nest.getDefinitions(); } } if (m_globalContext == null) { throw new IllegalStateException ("Internal error: no definition context"); } else { return m_globalContext; } } /** * Get definition context for innermost nesting element. If the context for * this element isn't already defined it's created by the call. * * @return definition context for innermost nesting element */ public DefinitionContext getCurrentDefinitions() { NestingElementBase parent = getParentElement(); DefinitionContext dctx = parent.getDefinitions(); if (dctx == null) { dctx = new DefinitionContext(getDefinitions()); parent.setDefinitions(dctx); } return dctx; } /** * Get definition context for innermost nesting element for use by a * <b>format</b> (or <b>namespace</b>). 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). * * @return definition context for innermost nesting element */ public DefinitionContext getFormatDefinitions() { NestingElementBase parent = getParentElement(); DefinitionContext dctx = parent.getDefinitions(); if (dctx == null) { // scan to find innermost nesting with context int index = 1; DefinitionContext pctx = null; while (++index < m_treeHierarchy.size()) { NestingElementBase nest = (NestingElementBase)m_treeHierarchy.peek(index); pctx = nest.getDefinitions(); if (pctx != null) { break; } } // add contexts for all ancestors to level while (index >= 2) { dctx = new DefinitionContext(pctx); NestingElementBase nest = (NestingElementBase)m_treeHierarchy.peek(--index); nest.setDefinitions(dctx); pctx = dctx; } } return dctx; } /** * Get class information. Finds a class by name using the class locator * configured by the environment code. * * @param name fully-qualified name of class to be found * @return class information, or <code>null</code> if class not found */ public IClass getClassInfo(String name) { return m_locator.getClassInfo(name); } /** * Get requiried 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. * * @param name fully-qualified name of class to be found * @return class information */ public IClass getRequiredClassInfo(String name) { IClass iclas = m_locator.getClassInfo(name); if (iclas == null) { throw new IllegalStateException("Internal error: class " + name + " cannot be found"); } else { return iclas; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -