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

📄 xsdelementtraverser.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright 2001-2005 The Apache Software Foundation. *  * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *  *      http://www.apache.org/licenses/LICENSE-2.0 *  * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.sun.org.apache.xerces.internal.impl.xs.traversers;import com.sun.org.apache.xerces.internal.impl.dv.ValidatedInfo;import com.sun.org.apache.xerces.internal.impl.dv.XSSimpleType;import com.sun.org.apache.xerces.internal.impl.xs.SchemaGrammar;import com.sun.org.apache.xerces.internal.impl.xs.SchemaSymbols;import com.sun.org.apache.xerces.internal.impl.xs.XSAnnotationImpl;import com.sun.org.apache.xerces.internal.impl.xs.XSComplexTypeDecl;import com.sun.org.apache.xerces.internal.impl.xs.XSConstraints;import com.sun.org.apache.xerces.internal.impl.xs.XSElementDecl;import com.sun.org.apache.xerces.internal.impl.xs.XSParticleDecl;import com.sun.org.apache.xerces.internal.xs.XSConstants;import com.sun.org.apache.xerces.internal.xs.XSObject;import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition;import com.sun.org.apache.xerces.internal.impl.xs.util.XInt;import com.sun.org.apache.xerces.internal.util.DOMUtil;import com.sun.org.apache.xerces.internal.util.SymbolTable;import com.sun.org.apache.xerces.internal.xni.QName;import org.w3c.dom.Element;import org.w3c.dom.Attr;/** * The element declaration schema component traverser. * <element *   abstract = boolean : false *   block = (#all | List of (extension | restriction | substitution)) *   default = string *   final = (#all | List of (extension | restriction)) *   fixed = string *   form = (qualified | unqualified) *   id = ID *   maxOccurs = (nonNegativeInteger | unbounded)  : 1 *   minOccurs = nonNegativeInteger : 1 *   name = NCName *   nillable = boolean : false *   ref = QName *   substitutionGroup = QName *   type = QName *   {any attributes with non-schema namespace . . .}> *   Content: (annotation?, ((simpleType | complexType)?, (unique | key | keyref)*)) * </element> * * @xerces.internal  * * @author Sandy Gao, IBM * * @version $Id: XSDElementTraverser.java,v 1.3 2005/09/26 13:02:43 sunithareddy Exp $ */class XSDElementTraverser extends XSDAbstractTraverser {        protected final XSElementDecl  fTempElementDecl  = new XSElementDecl();        // this controls what happens when a local element is encountered.    // We may not encounter all local elements when first parsing.    boolean fDeferTraversingLocalElements;        XSDElementTraverser (XSDHandler handler,            XSAttributeChecker gAttrCheck) {        super(handler, gAttrCheck);    }        /**     * Traverse a locally declared element (or an element reference).     *     * To handle the recursive cases efficiently, we delay the traversal     * and return an empty particle node. We'll fill in this particle node     * later after we've done with all the global declarations.     * This method causes a number of data structures in the schema handler to be filled in.     *     * @param  elmDecl     * @param  schemaDoc     * @param  grammar     * @return the particle     */    XSParticleDecl traverseLocal(Element elmDecl,            XSDocumentInfo schemaDoc,            SchemaGrammar grammar,            int allContextFlags,            XSObject parent) {                XSParticleDecl particle = null;        if (fSchemaHandler.fDeclPool !=null) {            particle = fSchemaHandler.fDeclPool.getParticleDecl();        } else {            particle = new XSParticleDecl();        }        if(fDeferTraversingLocalElements) {            // The only thing we care about now is whether this element has            // minOccurs=0. This affects (if the element appears in a complex            // type) whether a type has emptiable content.            particle.fType = XSParticleDecl.PARTICLE_ELEMENT;            Attr attr = elmDecl.getAttributeNode(SchemaSymbols.ATT_MINOCCURS);            if (attr != null) {                String min = attr.getValue();                try {                    int m = Integer.parseInt(min.trim());                    if (m >= 0)                        particle.fMinOccurs = m;                }                catch (NumberFormatException ex) {                }            }            fSchemaHandler.fillInLocalElemInfo(elmDecl, schemaDoc, allContextFlags, parent, particle);        } else {            traverseLocal(particle, elmDecl, schemaDoc, grammar, allContextFlags, parent, null);            // If it's an empty particle, return null.            if (particle.fType == XSParticleDecl.PARTICLE_EMPTY)                particle = null;        }                return particle;    }        /**     * Traverse a locally declared element (or an element reference).     *     * This is the real traversal method. It's called after we've done with     * all the global declarations.     *     * @param  index     */    protected void traverseLocal(XSParticleDecl particle,            Element elmDecl,            XSDocumentInfo schemaDoc,            SchemaGrammar grammar,            int allContextFlags,            XSObject parent,            String[] localNSDecls) {                if (localNSDecls != null) {            schemaDoc.fNamespaceSupport.setEffectiveContext(localNSDecls);        }                // General Attribute Checking        Object[] attrValues = fAttrChecker.checkAttributes(elmDecl, false, schemaDoc);                QName refAtt = (QName) attrValues[XSAttributeChecker.ATTIDX_REF];        XInt  minAtt = (XInt)  attrValues[XSAttributeChecker.ATTIDX_MINOCCURS];        XInt  maxAtt = (XInt)  attrValues[XSAttributeChecker.ATTIDX_MAXOCCURS];                XSElementDecl element = null;        if (elmDecl.getAttributeNode(SchemaSymbols.ATT_REF) != null) {            if (refAtt != null) {                element = (XSElementDecl)fSchemaHandler.getGlobalDecl(schemaDoc, XSDHandler.ELEMENT_TYPE, refAtt, elmDecl);                                Element child = DOMUtil.getFirstChildElement(elmDecl);                if (child != null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {                    // REVISIT:  put this somewhere                    traverseAnnotationDecl(child, attrValues, false, schemaDoc);                    child = DOMUtil.getNextSiblingElement(child);                }                // Element Declaration Representation OK                // 2 If the item's parent is not <schema>, then all of the following must be true:                // 2.1 One of ref or name must be present, but not both.                // 2.2 If ref is present, then all of <complexType>, <simpleType>, <key>, <keyref>, <unique>, nillable, default, fixed, form, block and type must be absent, i.e. only minOccurs, maxOccurs, id are allowed in addition to ref, along with <annotation>.                if (child != null) {                    reportSchemaError("src-element.2.2", new Object[]{refAtt.rawname, DOMUtil.getLocalName(child)}, child);                }            } else {                element = null;            }        } else {            element = traverseNamedElement(elmDecl, attrValues, schemaDoc, grammar, false, parent);        }                particle.fMinOccurs = minAtt.intValue();        particle.fMaxOccurs = maxAtt.intValue();        if (element != null) {            particle.fType = XSParticleDecl.PARTICLE_ELEMENT;            particle.fValue = element;        }        else {            particle.fType = XSParticleDecl.PARTICLE_EMPTY;        }        Long defaultVals = (Long)attrValues[XSAttributeChecker.ATTIDX_FROMDEFAULT];        checkOccurrences(particle, SchemaSymbols.ELT_ELEMENT,                (Element)elmDecl.getParentNode(), allContextFlags,                defaultVals.longValue());                fAttrChecker.returnAttrArray(attrValues, schemaDoc);    }        /**     * Traverse a globally declared element.     *     * @param  elmDecl     * @param  schemaDoc     * @param  grammar     * @return the element declaration     */    XSElementDecl traverseGlobal(Element elmDecl,            XSDocumentInfo schemaDoc,            SchemaGrammar grammar) {                // General Attribute Checking'        Object[] attrValues = fAttrChecker.checkAttributes(elmDecl, true, schemaDoc);        XSElementDecl element = traverseNamedElement(elmDecl, attrValues, schemaDoc, grammar, true, null);        fAttrChecker.returnAttrArray(attrValues, schemaDoc);        return element;            }        /**     * Traverse a globally declared element.     *     * @param  elmDecl     * @param  attrValues     * @param  schemaDoc     * @param  grammar     * @param  isGlobal     * @return the element declaration     */    XSElementDecl traverseNamedElement(Element elmDecl,            Object[] attrValues,            XSDocumentInfo schemaDoc,            SchemaGrammar grammar,            boolean isGlobal,            XSObject parent) {                Boolean abstractAtt  = (Boolean) attrValues[XSAttributeChecker.ATTIDX_ABSTRACT];        XInt    blockAtt     = (XInt)    attrValues[XSAttributeChecker.ATTIDX_BLOCK];        String  defaultAtt   = (String)  attrValues[XSAttributeChecker.ATTIDX_DEFAULT];        XInt    finalAtt     = (XInt)    attrValues[XSAttributeChecker.ATTIDX_FINAL];        String  fixedAtt     = (String)  attrValues[XSAttributeChecker.ATTIDX_FIXED];        XInt    formAtt      = (XInt)    attrValues[XSAttributeChecker.ATTIDX_FORM];        String  nameAtt      = (String)  attrValues[XSAttributeChecker.ATTIDX_NAME];        Boolean nillableAtt  = (Boolean) attrValues[XSAttributeChecker.ATTIDX_NILLABLE];        QName   subGroupAtt  = (QName)   attrValues[XSAttributeChecker.ATTIDX_SUBSGROUP];        QName   typeAtt      = (QName)   attrValues[XSAttributeChecker.ATTIDX_TYPE];                // Step 1: get declaration information                XSElementDecl element = null;        if (fSchemaHandler.fDeclPool !=null) {

⌨️ 快捷键说明

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