schemagrammar.java

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

JAVA
984
字号
/* * The Apache Software License, Version 1.1 * * * Copyright (c) 2001-2004 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;import java.util.Vector;import com.sun.org.apache.xerces.internal.impl.dv.SchemaDVFactory;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.identity.IdentityConstraint;import com.sun.org.apache.xerces.internal.xs.StringList;import com.sun.org.apache.xerces.internal.xs.XSAnnotation;import com.sun.org.apache.xerces.internal.xs.XSAttributeDeclaration;import com.sun.org.apache.xerces.internal.xs.XSAttributeGroupDefinition;import com.sun.org.apache.xerces.internal.xs.XSConstants;import com.sun.org.apache.xerces.internal.xs.XSElementDeclaration;import com.sun.org.apache.xerces.internal.xs.XSModel;import com.sun.org.apache.xerces.internal.xs.XSModelGroupDefinition;import com.sun.org.apache.xerces.internal.xs.XSNamedMap;import com.sun.org.apache.xerces.internal.xs.XSNamespaceItem;import com.sun.org.apache.xerces.internal.xs.XSNotationDeclaration;import com.sun.org.apache.xerces.internal.xs.XSObjectList;import com.sun.org.apache.xerces.internal.xs.XSParticle;import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition;import com.sun.org.apache.xerces.internal.xs.XSWildcard;import com.sun.org.apache.xerces.internal.impl.xs.util.SimpleLocator;import com.sun.org.apache.xerces.internal.impl.xs.util.StringListImpl;import com.sun.org.apache.xerces.internal.impl.xs.util.XSNamedMap4Types;import com.sun.org.apache.xerces.internal.impl.xs.util.XSNamedMapImpl;import com.sun.org.apache.xerces.internal.impl.xs.util.XSObjectListImpl;import com.sun.org.apache.xerces.internal.impl.Constants;import com.sun.org.apache.xerces.internal.parsers.DOMParser;import com.sun.org.apache.xerces.internal.parsers.SAXParser;import com.sun.org.apache.xerces.internal.parsers.IntegratedParserConfiguration;import com.sun.org.apache.xerces.internal.util.SymbolHash;import com.sun.org.apache.xerces.internal.util.SymbolTable;import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarDescription;import com.sun.org.apache.xerces.internal.xni.grammars.XSGrammar;/** * This class is to hold all schema component declaration that are declared * within one namespace. * * The Grammar class this class extends contains what little * commonality there is between XML Schema and DTD grammars.  It's * useful to distinguish grammar objects from other kinds of object * when they exist in pools or caches. * * @author Sandy Gao, IBM * @author Elena Litani, IBM * * @version $Id: SchemaGrammar.java,v 1.35 2004/02/03 17:11:09 sandygao Exp $ */public class SchemaGrammar implements XSGrammar, XSNamespaceItem {    // the target namespace of grammar    String fTargetNamespace;    // global decls: map from decl name to decl object    SymbolHash fGlobalAttrDecls;    SymbolHash fGlobalAttrGrpDecls;    SymbolHash fGlobalElemDecls;    SymbolHash fGlobalGroupDecls;    SymbolHash fGlobalNotationDecls;    SymbolHash fGlobalIDConstraintDecls;    SymbolHash fGlobalTypeDecls;    // the XMLGrammarDescription member    XSDDescription fGrammarDescription = null;    // annotations associated with the "root" schema of this targetNamespace    XSAnnotationImpl [] fAnnotations = null;    // number of annotations declared    int fNumAnnotations;    // symbol table for constructing parsers (annotation support)    private SymbolTable fSymbolTable = null;    // parsers for annotation support    private SAXParser fSAXParser = null;    private DOMParser fDOMParser = null;    //    // Constructors    //    // needed to make BuiltinSchemaGrammar work.    private SchemaGrammar() {}    /**     * Default constructor.     *     * @param targetNamespace     * @param grammarDesc the XMLGrammarDescription corresponding to this objec     * 		at the least a systemId should always be known.     * @param symbolTable   needed for annotation support     */    public SchemaGrammar(String targetNamespace, XSDDescription grammarDesc,                SymbolTable symbolTable) {        fTargetNamespace = targetNamespace;        fGrammarDescription = grammarDesc;        fSymbolTable = symbolTable;        // REVISIT: do we know the numbers of the following global decls        // when creating this grammar? If so, we can pass the numbers in,        // and use that number to initialize the following hashtables.        fGlobalAttrDecls  = new SymbolHash();        fGlobalAttrGrpDecls = new SymbolHash();        fGlobalElemDecls = new SymbolHash();        fGlobalGroupDecls = new SymbolHash();        fGlobalNotationDecls = new SymbolHash();        fGlobalIDConstraintDecls = new SymbolHash();        // if we are parsing S4S, put built-in types in first        // they might get overwritten by the types from S4S, but that's        // considered what the application wants to do.        if (fTargetNamespace == SchemaSymbols.URI_SCHEMAFORSCHEMA)            fGlobalTypeDecls = SG_SchemaNS.fGlobalTypeDecls.makeClone();        else            fGlobalTypeDecls = new SymbolHash();    } // <init>(String, XSDDescription)    // number of built-in XSTypes we need to create for base and full    // datatype set    private static final int BASICSET_COUNT = 29;    private static final int FULLSET_COUNT  = 46;    private static final int GRAMMAR_XS  = 1;    private static final int GRAMMAR_XSI = 2;    // this class makes sure the static, built-in schema grammars    // are immutable.    public static class BuiltinSchemaGrammar extends SchemaGrammar {        /**         * Special constructor to create the grammars for the schema namespaces         *         * @param grammar         */        public BuiltinSchemaGrammar(int grammar) {            SchemaDVFactory schemaFactory = SchemaDVFactory.getInstance();                if (grammar == GRAMMAR_XS) {                // target namespace                fTargetNamespace = SchemaSymbols.URI_SCHEMAFORSCHEMA;                        // grammar description                fGrammarDescription = new XSDDescription();                fGrammarDescription.fContextType = XSDDescription.CONTEXT_PREPARSE;                fGrammarDescription.setNamespace(SchemaSymbols.URI_SCHEMAFORSCHEMA);                        // no global decls other than types                fGlobalAttrDecls  = new SymbolHash(1);                fGlobalAttrGrpDecls = new SymbolHash(1);                fGlobalElemDecls = new SymbolHash(1);                fGlobalGroupDecls = new SymbolHash(1);                fGlobalNotationDecls = new SymbolHash(1);                fGlobalIDConstraintDecls = new SymbolHash(1);                        // get all built-in types                fGlobalTypeDecls = schemaFactory.getBuiltInTypes();                // add anyType                fGlobalTypeDecls.put(fAnyType.getName(), fAnyType);            }            else if (grammar == GRAMMAR_XSI) {                // target namespace                fTargetNamespace = SchemaSymbols.URI_XSI;                // grammar description                fGrammarDescription = new XSDDescription();                fGrammarDescription.fContextType = XSDDescription.CONTEXT_PREPARSE;                fGrammarDescription.setNamespace(SchemaSymbols.URI_XSI);                        // no global decls other than attributes                fGlobalAttrGrpDecls = new SymbolHash(1);                fGlobalElemDecls = new SymbolHash(1);                fGlobalGroupDecls = new SymbolHash(1);                fGlobalNotationDecls = new SymbolHash(1);                fGlobalIDConstraintDecls = new SymbolHash(1);                fGlobalTypeDecls = new SymbolHash(1);                    // 4 attributes, so initialize the size as 4*2 = 8                fGlobalAttrDecls  = new SymbolHash(8);                String name = null;                String tns = null;                XSSimpleType type = null;                short scope = XSConstants.SCOPE_GLOBAL;                                // xsi:type                name = SchemaSymbols.XSI_TYPE;                tns = SchemaSymbols.URI_XSI;                type = schemaFactory.getBuiltInType(SchemaSymbols.ATTVAL_QNAME);                fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name, tns, type, scope));                                // xsi:nil                name = SchemaSymbols.XSI_NIL;                tns = SchemaSymbols.URI_XSI;                type = schemaFactory.getBuiltInType(SchemaSymbols.ATTVAL_BOOLEAN);                fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name, tns, type, scope));                                XSSimpleType anyURI = schemaFactory.getBuiltInType(SchemaSymbols.ATTVAL_ANYURI);                    // xsi:schemaLocation                name = SchemaSymbols.XSI_SCHEMALOCATION;                tns = SchemaSymbols.URI_XSI;                type = schemaFactory.createTypeList(null, SchemaSymbols.URI_XSI, (short)0, anyURI, null);                fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name, tns, type, scope));                                // xsi:noNamespaceSchemaLocation                name = SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION;                tns = SchemaSymbols.URI_XSI;                type = anyURI;                fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name, tns, type, scope));            }        } // <init>(int)        // return the XMLGrammarDescription corresponding to this        // object        public XMLGrammarDescription getGrammarDescription() {            return fGrammarDescription.makeClone();        } // getGrammarDescription():  XMLGrammarDescription        // override these methods solely so that these        // objects cannot be modified once they're created.        public void setImportedGrammars(Vector importedGrammars) {            // ignore        }        public void addGlobalAttributeDecl(XSAttributeDecl decl) {            // ignore        }        public void addGlobalAttributeGroupDecl(XSAttributeGroupDecl decl) {            // ignore        }        public void addGlobalElementDecl(XSElementDecl decl) {            // ignore        }        public void addGlobalGroupDecl(XSGroupDecl decl) {            // ignore        }        public void addGlobalNotationDecl(XSNotationDecl decl) {            // ignore        }        public void addGlobalTypeDecl(XSTypeDefinition decl) {            // ignore        }        public void addComplexTypeDecl(XSComplexTypeDecl decl, SimpleLocator locator) {            // ignore        }        public void addRedefinedGroupDecl(XSGroupDecl derived, XSGroupDecl base, SimpleLocator locator) {            // ignore        }        public synchronized void addDocument(Object document, String location) {            // ignore        }        // annotation support        synchronized DOMParser getDOMParser() {            return null;        }        synchronized SAXParser getSAXParser() {            return null;        }    }    // Grammar methods    // return the XMLGrammarDescription corresponding to this    // object    public XMLGrammarDescription getGrammarDescription() {        return fGrammarDescription;    } // getGrammarDescription():  XMLGrammarDescription    // DTDGrammar methods    public boolean isNamespaceAware () {

⌨️ 快捷键说明

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