xmlschemaloader.java

来自「JAVA 所有包」· Java 代码 · 共 1,324 行 · 第 1/4 页

JAVA
1,324
字号
/* * Copyright 2000-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;import java.io.BufferedInputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;import java.io.Reader;import java.io.StringReader;import java.util.Hashtable;import java.util.Locale;import java.util.StringTokenizer;import java.util.Vector;import com.sun.org.apache.xerces.internal.dom.DOMErrorImpl;import com.sun.org.apache.xerces.internal.dom.DOMMessageFormatter;import com.sun.org.apache.xerces.internal.dom.DOMStringListImpl;import com.sun.org.apache.xerces.internal.impl.Constants;import com.sun.org.apache.xerces.internal.impl.XMLEntityManager;import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;import com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException;import com.sun.org.apache.xerces.internal.impl.xs.models.CMBuilder;import com.sun.org.apache.xerces.internal.impl.xs.models.CMNodeFactory;import com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler;import com.sun.org.apache.xerces.internal.util.DOMEntityResolverWrapper;import com.sun.org.apache.xerces.internal.util.DOMErrorHandlerWrapper;import com.sun.org.apache.xerces.internal.util.DefaultErrorHandler;import com.sun.org.apache.xerces.internal.util.ParserConfigurationSettings;import com.sun.org.apache.xerces.internal.util.SymbolTable;import com.sun.org.apache.xerces.internal.util.XMLSymbols;import com.sun.org.apache.xerces.internal.xni.XNIException;import com.sun.org.apache.xerces.internal.xni.grammars.Grammar;import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarDescription;import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarLoader;import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;import com.sun.org.apache.xerces.internal.xni.grammars.XSGrammar;import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent;import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver;import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler;import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;import com.sun.org.apache.xerces.internal.xs.LSInputList;import com.sun.org.apache.xerces.internal.xs.StringList;import com.sun.org.apache.xerces.internal.xs.XSLoader;import com.sun.org.apache.xerces.internal.xs.XSModel;import org.w3c.dom.DOMConfiguration;import org.w3c.dom.DOMError;import org.w3c.dom.DOMErrorHandler;import org.w3c.dom.DOMStringList;import org.w3c.dom.DOMException;import org.w3c.dom.ls.LSInput;import org.w3c.dom.ls.LSResourceResolver;import org.xml.sax.InputSource;/** * This class implements xni.grammars.XMLGrammarLoader. * It also serves as implementation of xs.XSLoader interface and DOMConfiguration interface. *  * This class is designed to interact either with a proxy for a user application  * which wants to preparse schemas, or with our own Schema validator.   * It is hoped that none of these "external" classes will therefore need to communicate directly * with XSDHandler in future. * <p>This class only knows how to make XSDHandler do its thing. * The caller must ensure that all its properties (schemaLocation, JAXPSchemaSource * etc.) have been properly set. * * @xerces.internal  * * @author Neil Graham, IBM * @version $Id: XMLSchemaLoader.java,v 1.3 2005/09/26 13:02:34 sunithareddy Exp $ */public class XMLSchemaLoader implements XMLGrammarLoader, XMLComponent,// XML Component API XSLoader, DOMConfiguration {        // Feature identifiers:        /** Feature identifier: schema full checking*/    protected static final String SCHEMA_FULL_CHECKING =        Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_FULL_CHECKING;        /** Feature identifier: continue after fatal error. */    protected static final String CONTINUE_AFTER_FATAL_ERROR =        Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE;        /** Feature identifier: allow java encodings to be recognized when parsing schema docs. */    protected static final String ALLOW_JAVA_ENCODINGS =        Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE;        /** Feature identifier: standard uri conformant feature. */    protected static final String STANDARD_URI_CONFORMANT_FEATURE =        Constants.XERCES_FEATURE_PREFIX + Constants.STANDARD_URI_CONFORMANT_FEATURE;        /** Feature identifier: validate annotations. */    protected static final String VALIDATE_ANNOTATIONS =        Constants.XERCES_FEATURE_PREFIX + Constants.VALIDATE_ANNOTATIONS_FEATURE;            /** Feature: disallow doctype*/    protected static final String DISALLOW_DOCTYPE =         Constants.XERCES_FEATURE_PREFIX + Constants.DISALLOW_DOCTYPE_DECL_FEATURE;        /** Feature: generate synthetic annotations */    protected static final String GENERATE_SYNTHETIC_ANNOTATIONS =         Constants.XERCES_FEATURE_PREFIX + Constants.GENERATE_SYNTHETIC_ANNOTATIONS_FEATURE;        /** Feature identifier: honour all schemaLocations */    protected static final String HONOUR_ALL_SCHEMALOCATIONS =         Constants.XERCES_FEATURE_PREFIX + Constants.HONOUR_ALL_SCHEMALOCATIONS_FEATURE;        protected static final String AUGMENT_PSVI =         Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_AUGMENT_PSVI;        protected static final String PARSER_SETTINGS =         Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS;           // recognized features:    private static final String[] RECOGNIZED_FEATURES = {        SCHEMA_FULL_CHECKING,        AUGMENT_PSVI,        CONTINUE_AFTER_FATAL_ERROR,        ALLOW_JAVA_ENCODINGS,        STANDARD_URI_CONFORMANT_FEATURE,         DISALLOW_DOCTYPE,        GENERATE_SYNTHETIC_ANNOTATIONS,        VALIDATE_ANNOTATIONS,        HONOUR_ALL_SCHEMALOCATIONS    };        // property identifiers        /** Property identifier: symbol table. */    public static final String SYMBOL_TABLE =        Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY;        /** Property identifier: error reporter. */    public static final String ERROR_REPORTER =        Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;        /** Property identifier: error handler. */    protected static final String ERROR_HANDLER =        Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY;        /** Property identifier: entity resolver. */    public static final String ENTITY_RESOLVER =        Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY;        /** Property identifier: grammar pool. */    public static final String XMLGRAMMAR_POOL =        Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY;        /** Property identifier: schema location. */    protected static final String SCHEMA_LOCATION =        Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_LOCATION;        /** Property identifier: no namespace schema location. */    protected static final String SCHEMA_NONS_LOCATION =        Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_NONS_LOCATION;        /** Property identifier: JAXP schema source. */    protected static final String JAXP_SCHEMA_SOURCE =        Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE;        protected static final String SECURITY_MANAGER =        Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY;          protected static final String ENTITY_MANAGER =        Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY;           // recognized properties    private static final String [] RECOGNIZED_PROPERTIES = {        ENTITY_MANAGER,        SYMBOL_TABLE,        ERROR_REPORTER,        ERROR_HANDLER,        ENTITY_RESOLVER,        XMLGRAMMAR_POOL,        SCHEMA_LOCATION,        SCHEMA_NONS_LOCATION,        JAXP_SCHEMA_SOURCE,        SECURITY_MANAGER    };        // Data        // features and properties    private ParserConfigurationSettings fLoaderConfig = new ParserConfigurationSettings();    private SymbolTable fSymbolTable = null;    private XMLErrorReporter fErrorReporter = new XMLErrorReporter ();    private XMLEntityManager fEntityManager = null;    private XMLEntityResolver fUserEntityResolver = null;    private XMLGrammarPool fGrammarPool = null;    private String fExternalSchemas = null;    private String fExternalNoNSSchema = null;    // JAXP property: schema source     private Object fJAXPSource = null;    // is Schema Full Checking enabled    private boolean fIsCheckedFully = false;    // boolean that tells whether we've tested the JAXP property.    private boolean fJAXPProcessed = false;    // if features/properties has not been changed, the value of this attribute is "false"    private boolean fSettingsChanged = true;        // xml schema parsing    private XSDHandler fSchemaHandler;    private XSGrammarBucket fGrammarBucket;    private XSDeclarationPool fDeclPool = null;    private SubstitutionGroupHandler fSubGroupHandler;    private CMBuilder fCMBuilder;    private XSDDescription fXSDDescription = new XSDDescription();        private Hashtable fJAXPCache;    private Locale fLocale = Locale.getDefault();        // XSLoader attributes    private DOMStringList fRecognizedParameters = null;        /** DOM L3 error handler */    private DOMErrorHandlerWrapper fErrorHandler = null;        /** DOM L3 resource resolver */    private DOMEntityResolverWrapper fResourceResolver = null;        // default constructor.  Create objects we absolutely need:    public XMLSchemaLoader() {        this( new SymbolTable(), null, new XMLEntityManager(), null, null, null);    }        public XMLSchemaLoader(SymbolTable symbolTable) {        this( symbolTable, null, new XMLEntityManager(), null, null, null);    }        /**     * This constractor is used by the XMLSchemaValidator. Additional properties, i.e. XMLEntityManager,      * will be passed during reset(XMLComponentManager).     * @param errorReporter     * @param grammarBucket     * @param sHandler     * @param builder     */    XMLSchemaLoader(XMLErrorReporter errorReporter,            XSGrammarBucket grammarBucket,            SubstitutionGroupHandler sHandler, CMBuilder builder) {        this(null, errorReporter, null, grammarBucket, sHandler, builder);    }        XMLSchemaLoader(SymbolTable symbolTable,            XMLErrorReporter errorReporter,            XMLEntityManager entityResolver,            XSGrammarBucket grammarBucket,            SubstitutionGroupHandler sHandler,            CMBuilder builder) {                // store properties and features in configuration        fLoaderConfig.addRecognizedFeatures(RECOGNIZED_FEATURES);        fLoaderConfig.addRecognizedProperties(RECOGNIZED_PROPERTIES);         if (symbolTable != null){             fLoaderConfig.setProperty(SYMBOL_TABLE, symbolTable);               }                if(errorReporter == null) {            errorReporter = new XMLErrorReporter ();            errorReporter.setLocale(fLocale);            errorReporter.setProperty(ERROR_HANDLER, new DefaultErrorHandler());                    }        fErrorReporter = errorReporter;        // make sure error reporter knows about schemas...        if(fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) {            fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, new XSMessageFormatter());        }        fLoaderConfig.setProperty(ERROR_REPORTER, fErrorReporter);        fEntityManager = entityResolver;           // entity manager is null if XMLSchemaValidator creates the loader          if (fEntityManager != null){               fLoaderConfig.setProperty(ENTITY_MANAGER, fEntityManager);        }                // by default augment PSVI (i.e. don't use declaration pool)        fLoaderConfig.setFeature(AUGMENT_PSVI, true);                if(grammarBucket == null ) {            grammarBucket = new XSGrammarBucket();        }        fGrammarBucket = grammarBucket;        if(sHandler == null) {            sHandler = new SubstitutionGroupHandler(fGrammarBucket);        }        fSubGroupHandler = sHandler;                //get an instance of the CMNodeFactory */        CMNodeFactory nodeFactory = new CMNodeFactory() ;                if(builder == null) {            builder = new CMBuilder(nodeFactory);        }        fCMBuilder = builder;        fSchemaHandler = new XSDHandler(fGrammarBucket);        fDeclPool = new XSDeclarationPool();        fJAXPCache = new Hashtable();                fSettingsChanged = true;    }        /**     * Returns a list of feature identifiers that are recognized by     * this XMLGrammarLoader.  This method may return null if no features     * are recognized.     */    public String[] getRecognizedFeatures() {        return (String[])(RECOGNIZED_FEATURES.clone());    } // getRecognizedFeatures():  String[]    

⌨️ 快捷键说明

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