⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 treecontext.java

📁 对xml很好的java处理引擎,编译中绑定xml
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*Copyright (c) 2004-2006, Dennis M. SosnoskiAll rights reserved.Redistribution and use in source and binary forms, with or without modification,are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this   list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice,   this list of conditions and the following disclaimer in the documentation   and/or other materials provided with the distribution. * Neither the name of JiBX nor the names of its contributors may be used   to endorse or promote products derived from this software without specific   prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ANDANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AREDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FORANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ONANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THISSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/package org.jibx.binding.model;import java.util.ArrayList;import java.util.HashSet;import org.jibx.binding.util.ObjectStack;/** * Handles walking the tree structure of a binding model, tracking * order-dependent state information collected along the way. * * @author Dennis M. Sosnoski */public class TreeContext{    /** Global definition context (outside of binding). */    private DefinitionContext m_globalContext;        /** Binding element model root (may be <code>null</code>, if not configured     by caller). */    private BindingElement m_bindingRoot;        /** Stack of items for parent hierarchy to current node in tree. */    private ObjectStack m_treeHierarchy;        /** Class locator set by environment code. */    private IClassLocator m_locator;        /** Set of elements to be skipped in walking tree. */    private HashSet m_skipSet;        /**     * Internal null constructor.     */    private TreeContext() {}        /**     * Constructor.     *      * @param iloc class locator to be used     */    public TreeContext(IClassLocator iloc) {        m_treeHierarchy = new ObjectStack();        m_locator = iloc;        m_skipSet = new HashSet();    }        /**     * 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.     *     * @return new context linked to original context     */    public TreeContext getChildContext() {        TreeContext child = new TreeContext();        child.m_bindingRoot = m_bindingRoot;        child.m_globalContext = m_globalContext;        child.m_locator = m_locator;        child.m_skipSet = m_skipSet;        child.m_treeHierarchy = new ObjectStack(m_treeHierarchy);        return child;    }        /**     * 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.     *      * @param dctx global definition context     */    public void setGlobalDefinitions(DefinitionContext dctx) {        m_globalContext = dctx;    }        /**     * 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 <b>must</b> be used for the binding element in order to     * handle included binding definitions properly.     *      * @param root binding element root of tree     * @param visitor target visitor for element notifications     */    public void tourTree(BindingElement root, ModelVisitor visitor) {                // set up binding root reference for access during processing        BindingElement hold = m_bindingRoot;        m_bindingRoot = root;                // run the actual tour        tourTree((ElementBase)root, visitor);                // restore prior binding root reference        m_bindingRoot = hold;    }        /**     * 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.     *      * @param root node of tree to be toured     * @param visitor target visitor for element notifications     */    public void tourTree(ElementBase root, ModelVisitor visitor) {                // check for fatal error on element        if (m_skipSet.contains(root)) {            return;        }                // visit the actual root of tree        boolean expand = false;        m_treeHierarchy.push(root);        switch (root.type()) {                        case ElementBase.BINDING_ELEMENT:                expand = visitor.visit((BindingElement)root);                break;                            case ElementBase.COLLECTION_ELEMENT:                expand = visitor.visit((CollectionElement)root);                break;                            case ElementBase.FORMAT_ELEMENT:                visitor.visit((FormatElement)root);                break;                            case ElementBase.INCLUDE_ELEMENT:                expand = visitor.visit((IncludeElement)root);                break;                            case ElementBase.INPUT_ELEMENT:                expand = visitor.visit((InputElement)root);                break;                            case ElementBase.MAPPING_ELEMENT:                expand = visitor.visit((MappingElement)root);                break;                            case ElementBase.NAMESPACE_ELEMENT:                visitor.visit((NamespaceElement)root);                break;                            case ElementBase.OUTPUT_ELEMENT:                expand = visitor.visit((OutputElement)root);                break;                            case ElementBase.SPLIT_ELEMENT:                expand = visitor.visit((SplitElement)root);                break;                            case ElementBase.STRUCTURE_ELEMENT:                expand = visitor.visit((StructureElement)root);                break;                            case ElementBase.TEMPLATE_ELEMENT:                expand = visitor.visit((TemplateElement)root);                break;                            case ElementBase.VALUE_ELEMENT:                visitor.visit((ValueElement)root);                break;                        default:                throw new IllegalStateException                    ("Internal error: unknown element type");                        }                // check for expansion needed        if (expand && !m_skipSet.contains(root)) {            if (root instanceof IncludeElement) {                                // include just delegates to the included binding element                BindingElement binding = ((IncludeElement)root).getBinding();                if (binding != null) {                    m_treeHierarchy.pop();                    tourTree((ElementBase)binding, visitor);                    m_treeHierarchy.push(root);                }                            } else if (root instanceof NestingElementBase) {                                // process each container child as root of own tree                ArrayList childs = null;                if (root instanceof MappingElement) {                    childs = ((MappingElement)root).topChildren();                    for (int i = 0; i < childs.size(); i++) {                        tourTree((ElementBase)childs.get(i), visitor);                    }                }                if (root instanceof BindingElement) {                    childs = ((BindingElement)root).topChildren();                } else {                    childs = ((NestingElementBase)root).children();                }                for (int i = 0; i < childs.size(); i++) {                    tourTree((ElementBase)childs.get(i), visitor);                }            }        }                // exit the actual root of tree        switch (root.type()) {                        case ElementBase.BINDING_ELEMENT:                visitor.exit((BindingElement)root);                break;                            case ElementBase.COLLECTION_ELEMENT:                visitor.exit((CollectionElement)root);                break;                            case ElementBase.INCLUDE_ELEMENT:                visitor.exit((IncludeElement)root);                break;                            case ElementBase.INPUT_ELEMENT:                visitor.exit((InputElement)root);                break;                            case ElementBase.MAPPING_ELEMENT:                visitor.exit((MappingElement)root);                break;                            case ElementBase.OUTPUT_ELEMENT:                visitor.exit((OutputElement)root);                break;                            case ElementBase.SPLIT_ELEMENT:                visitor.exit((SplitElement)root);                break;                            case ElementBase.STRUCTURE_ELEMENT:                visitor.exit((StructureElement)root);                break;                

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -