schemagrammar.java
来自「JAVA 所有包」· Java 代码 · 共 1,202 行 · 第 1/4 页
JAVA
1,202 行
/* * Copyright 2001-2004 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;import java.util.Vector;import com.sun.org.apache.xerces.internal.impl.Constants;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.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.parsers.DOMParser;import com.sun.org.apache.xerces.internal.parsers.IntegratedParserConfiguration;import com.sun.org.apache.xerces.internal.parsers.SAXParser;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.NamespaceContext;import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarDescription;import com.sun.org.apache.xerces.internal.xni.grammars.XSGrammar;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;/** * 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. * * @xerces.internal * * @author Sandy Gao, IBM * @author Elena Litani, IBM * * @version $Id: SchemaGrammar.java,v 1.2.6.1 2005/09/09 07:30:49 sunithareddy 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. protected 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; } } /** * <p>A partial schema for schemas for validating annotations.</p> * * @xerces.internal * * @author Michael Glavassevich, IBM */ public static final class Schema4Annotations extends SchemaGrammar { /** * Special constructor to create a schema * capable of validating annotations. */ public Schema4Annotations() { // target namespace fTargetNamespace = SchemaSymbols.URI_SCHEMAFORSCHEMA; // grammar description fGrammarDescription = new XSDDescription(); fGrammarDescription.fContextType = XSDDescription.CONTEXT_PREPARSE;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?