xsdabstracttraverser.java

来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 714 行 · 第 1/3 页

JAVA
714
字号
/* * The Apache Software License, Version 1.1 * * * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * * 2. 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. * * 3. The end-user documentation included with the redistribution, *    if any, must include the following acknowledgment: *       "This product includes software developed by the *        Apache Software Foundation (http://www.apache.org/)." *    Alternately, this acknowledgment may appear in the software itself, *    if and wherever such third-party acknowledgments normally appear. * * 4. The names "Xerces" and "Apache Software Foundation" must *    not be used to endorse or promote products derived from this *    software without prior written permission. For written *    permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", *    nor may "Apache" appear in their name, without prior written *    permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY 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 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation and was * originally based on software copyright (c) 2001, International * Business Machines, Inc., http://www.apache.org.  For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */package com.sun.org.apache.xerces.internal.impl.xs.traversers;import java.util.Vector;import com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException;import com.sun.org.apache.xerces.internal.impl.dv.XSFacets;import com.sun.org.apache.xerces.internal.impl.dv.XSSimpleType;import com.sun.org.apache.xerces.internal.impl.validation.ValidationState;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.XSAttributeGroupDecl;import com.sun.org.apache.xerces.internal.impl.xs.XSAttributeUseImpl;import com.sun.org.apache.xerces.internal.impl.xs.XSComplexTypeDecl;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.impl.xs.XSWildcardDecl;import com.sun.org.apache.xerces.internal.xs.XSObjectList;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.impl.xs.util.XSObjectListImpl;import com.sun.org.apache.xerces.internal.util.DOMUtil;import com.sun.org.apache.xerces.internal.util.NamespaceSupport;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.Node;import org.w3c.dom.Text;/** * Class <code>XSDAbstractTraverser</code> serves as the base class for all * other <code>XSD???Traverser</code>s. It holds the common data and provide * a unified way to initialize these data. * * @author Elena Litani, IBM * @author Rahul Srivastava, Sun Microsystems Inc. * @author Neeraj Bajaj, Sun Microsystems Inc. * * @version $Id: XSDAbstractTraverser.java,v 1.35 2003/11/11 20:15:00 sandygao Exp $ */abstract class XSDAbstractTraverser {    protected static final String NO_NAME      = "(no name)";    // Flags for checkOccurrences to indicate any special    // restrictions on minOccurs and maxOccurs relating to "all".    //    NOT_ALL_CONTEXT    - not processing an <all>    //    PROCESSING_ALL_EL  - processing an <element> in an <all>    //    GROUP_REF_WITH_ALL - processing <group> reference that contained <all>    //    CHILD_OF_GROUP     - processing a child of a model group definition    //    PROCESSING_ALL_GP  - processing an <all> group itself    protected static final int NOT_ALL_CONTEXT    = 0;    protected static final int PROCESSING_ALL_EL  = 1;    protected static final int GROUP_REF_WITH_ALL = 2;    protected static final int CHILD_OF_GROUP     = 4;    protected static final int PROCESSING_ALL_GP  = 8;    //Shared data    protected XSDHandler            fSchemaHandler = null;    protected SymbolTable           fSymbolTable = null;    protected XSAttributeChecker    fAttrChecker = null;    // used to validate default/fixed attribute values    ValidationState fValidationState = new ValidationState();    XSDAbstractTraverser (XSDHandler handler,                          XSAttributeChecker attrChecker) {        fSchemaHandler = handler;        fAttrChecker = attrChecker;    }    void reset(SymbolTable symbolTable) {        fSymbolTable = symbolTable;        fValidationState.setExtraChecking(false);        fValidationState.setSymbolTable(symbolTable);    }    // traverse the annotation declaration    // REVISIT: how to pass the parentAttrs? as DOM attributes?    //          as name/value pairs (string)? in parsed form?    // @return XSAnnotationImpl object    XSAnnotationImpl traverseAnnotationDecl(Element annotationDecl, Object[] parentAttrs,                                boolean isGlobal, XSDocumentInfo schemaDoc) {        // General Attribute Checking        Object[] attrValues = fAttrChecker.checkAttributes(annotationDecl, isGlobal, schemaDoc);        fAttrChecker.returnAttrArray(attrValues, schemaDoc);        String contents = null;        for (Element child = DOMUtil.getFirstChildElement(annotationDecl);            child != null;            child = DOMUtil.getNextSiblingElement(child)) {            String name = DOMUtil.getLocalName(child);            // the only valid children of "annotation" are            // "appinfo" and "documentation"            if (!((name.equals(SchemaSymbols.ELT_APPINFO)) ||                  (name.equals(SchemaSymbols.ELT_DOCUMENTATION)))) {                reportSchemaError("src-annotation", new Object[]{name}, child);            } else { // the annotation, as we currently know it, is a Text child                Node textContent = child.getFirstChild();                if(textContent != null && textContent.getNodeType() == Node.TEXT_NODE) {                    contents = ((Text)textContent).getData();                }            }            // General Attribute Checking            // There is no difference between global or local appinfo/documentation,            // so we assume it's always global.            attrValues = fAttrChecker.checkAttributes(child, true, schemaDoc);            fAttrChecker.returnAttrArray(attrValues, schemaDoc);        }        // if contents was null, must have been some kind of error;        // nothing to contribute to PSVI        if (contents == null) return null;        // find the grammar; fSchemaHandler must be known!        SchemaGrammar grammar = fSchemaHandler.getGrammar(schemaDoc.fTargetNamespace);        // fish out local attributes passed from parent        Vector annotationLocalAttrs = (Vector)parentAttrs[XSAttributeChecker.ATTIDX_NONSCHEMA];        // optimize for case where there are no local attributes        if(annotationLocalAttrs != null && !annotationLocalAttrs.isEmpty()) {            StringBuffer localStrBuffer = new StringBuffer(64);            localStrBuffer.append(" ");            // Vector should contain rawname value pairs            int i=0;            while(i<annotationLocalAttrs.size()) {                String rawname = (String)annotationLocalAttrs.elementAt(i++);                int colonIndex = rawname.indexOf(':');                String prefix, localpart;                if (colonIndex == -1) {                    prefix = "";                    localpart = rawname;                }                else {                    prefix = rawname.substring(0,colonIndex);                    localpart = rawname.substring(colonIndex+1);                }                String uri = schemaDoc.fNamespaceSupport.getURI(prefix.intern());                if (!annotationDecl.getAttributeNS(uri, localpart).equals("")) {                    i++; // skip the next value, too                    continue;                }                localStrBuffer.append(rawname)                    .append("=\"");                String value = (String)annotationLocalAttrs.elementAt(i++);                // search for pesky "s and >s within attr value:                value = processAttValue(value);                localStrBuffer.append(value)                    .append("\" ");            }            // and now splice it into place; immediately after the annotation token, for simplicity's sake            StringBuffer contentBuffer = new StringBuffer(contents.length() + localStrBuffer.length());            int annotationTokenEnd = contents.indexOf(SchemaSymbols.ELT_ANNOTATION);            // annotation must occur somewhere or we're in big trouble...            if(annotationTokenEnd == -1) return null;            annotationTokenEnd += SchemaSymbols.ELT_ANNOTATION.length();            contentBuffer.append(contents.substring(0,annotationTokenEnd));            contentBuffer.append(localStrBuffer.toString());            contentBuffer.append(contents.substring(annotationTokenEnd, contents.length()));            return new XSAnnotationImpl(contentBuffer.toString(), grammar);        } else {            return new XSAnnotationImpl(contents, grammar);        }    }    // the QName simple type used to resolve qnames    private static final XSSimpleType fQNameDV = (XSSimpleType)SchemaGrammar.SG_SchemaNS.getGlobalTypeDecl(SchemaSymbols.ATTVAL_QNAME);    // Temp data structures to be re-used in traversing facets    private StringBuffer fPattern = new StringBuffer();    private final XSFacets xsFacets = new XSFacets();    class FacetInfo {        XSFacets facetdata;        Element nodeAfterFacets;        short fPresentFacets;        short fFixedFacets;    }    FacetInfo traverseFacets(Element content,

⌨️ 快捷键说明

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