xmlschemavalidator.java

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

JAVA
1,551
字号
/* * The Apache Software License, Version 1.1 * * * Copyright (c) 1999-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) 1999, 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.io.IOException;import java.util.Enumeration;import java.util.Hashtable;import java.util.HashMap;import java.util.Stack;import java.util.Vector;import com.sun.org.apache.xerces.internal.impl.Constants;import com.sun.org.apache.xerces.internal.impl.RevalidationHandler;import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;import com.sun.org.apache.xerces.internal.impl.dv.DatatypeException;import com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException;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.dv.xs.XSSimpleTypeDecl;import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;import com.sun.org.apache.xerces.internal.impl.validation.ValidationState;import com.sun.org.apache.xerces.internal.impl.xs.identity.Field;import com.sun.org.apache.xerces.internal.impl.xs.identity.FieldActivator;import com.sun.org.apache.xerces.internal.impl.xs.identity.IdentityConstraint;import com.sun.org.apache.xerces.internal.impl.xs.identity.KeyRef;import com.sun.org.apache.xerces.internal.impl.xs.identity.Selector;import com.sun.org.apache.xerces.internal.impl.xs.identity.UniqueOrKey;import com.sun.org.apache.xerces.internal.impl.xs.identity.ValueStore;import com.sun.org.apache.xerces.internal.impl.xs.identity.XPathMatcher;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.models.XSCMValidator;import com.sun.org.apache.xerces.internal.xs.XSConstants;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.util.AugmentationsImpl;import com.sun.org.apache.xerces.internal.util.IntStack;import com.sun.org.apache.xerces.internal.util.SymbolTable;import com.sun.org.apache.xerces.internal.util.XMLChar;import com.sun.org.apache.xerces.internal.util.XMLResourceIdentifierImpl;import com.sun.org.apache.xerces.internal.util.XMLSymbols;import com.sun.org.apache.xerces.internal.xni.Augmentations;import com.sun.org.apache.xerces.internal.xni.NamespaceContext;import com.sun.org.apache.xerces.internal.xni.QName;import com.sun.org.apache.xerces.internal.xni.XMLAttributes;import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler;import com.sun.org.apache.xerces.internal.xni.XMLLocator;import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;import com.sun.org.apache.xerces.internal.xni.XMLString;import com.sun.org.apache.xerces.internal.xni.XNIException;import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarDescription;import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;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.XMLDocumentFilter;import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource;import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver;import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;import com.sun.org.apache.xerces.internal.xs.AttributePSVI;import com.sun.org.apache.xerces.internal.xs.ElementPSVI;import com.sun.org.apache.xerces.internal.xs.XSComplexTypeDefinition;/** * The XML Schema validator. The validator implements a document * filter: receiving document events from the scanner; validating * the content and structure; augmenting the InfoSet, if applicable; * and notifying the parser of the information resulting from the * validation process. * <p> * This component requires the following features and properties from the * component manager that uses it: * <ul> *  <li>http://xml.org/sax/features/validation</li> *  <li>http://apache.org/xml/properties/internal/symbol-table</li> *  <li>http://apache.org/xml/properties/internal/error-reporter</li> *  <li>http://apache.org/xml/properties/internal/entity-resolver</li> * </ul> * * @author Sandy Gao IBM * @author Elena Litani IBM * @author Andy Clark IBM * @author Neeraj Bajaj, Sun Microsystems, inc. * @version $Id: XMLSchemaValidator.java,v 1.155 2004/03/25 04:03:23 mrglavas Exp $ */public class XMLSchemaValidatorimplements XMLComponent, XMLDocumentFilter, FieldActivator, RevalidationHandler {        //    // Constants    //    private static final boolean DEBUG = false;        // feature identifiers        /** Feature identifier: validation. */    protected static final String VALIDATION =    Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE;        /** Feature identifier: validation. */    protected static final String SCHEMA_VALIDATION =    Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE;        /** Feature identifier: schema full checking*/    protected static final String SCHEMA_FULL_CHECKING =    Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_FULL_CHECKING;        /** Feature identifier: dynamic validation. */    protected static final String DYNAMIC_VALIDATION =    Constants.XERCES_FEATURE_PREFIX + Constants.DYNAMIC_VALIDATION_FEATURE;        /** Feature identifier: expose schema normalized value */    protected static final String NORMALIZE_DATA =    Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_NORMALIZED_VALUE;        /** Feature identifier: send element default value via characters() */    protected static final String SCHEMA_ELEMENT_DEFAULT =    Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_ELEMENT_DEFAULT;        /** Feature identifier: augment PSVI */    protected static final String SCHEMA_AUGMENT_PSVI =    Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_AUGMENT_PSVI;        /** Feature identifier: whether to recognize java encoding names */    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: whether to continue parsing a schema after a fatal error is encountered */    protected static final String CONTINUE_AFTER_FATAL_ERROR =    Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE;        /** Feature identifier: ignore xsi:schemaLocation and xsi:noNamespaceSchemaLocation */    protected static final String IGNORE_SCHEMA_LOCATION_HINTS =    Constants.XERCES_FEATURE_PREFIX + Constants.IGNORE_SCHEMA_LOCATION_HINTS;        protected static final String CHANGE_IGNORABLE_CHARACTERS_INTO_IGNORABLE_WHITESPACES =    Constants.XERCES_FEATURE_PREFIX + Constants.CHANGE_IGNORABLE_CHARACTERS_INTO_IGNORABLE_WHITESPACES;        protected static final String PARSER_SETTINGS =    Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS;        // 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: 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;        protected static final String VALIDATION_MANAGER =    Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;        protected static final String ENTITY_MANAGER =    Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_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;        /** Property identifier: JAXP schema language. */    protected static final String JAXP_SCHEMA_LANGUAGE =    Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE;        // recognized features and properties        /** Recognized features. */    private static final String[] RECOGNIZED_FEATURES = {        VALIDATION,        SCHEMA_VALIDATION,        DYNAMIC_VALIDATION,        SCHEMA_FULL_CHECKING,        ALLOW_JAVA_ENCODINGS,        CONTINUE_AFTER_FATAL_ERROR,        STANDARD_URI_CONFORMANT_FEATURE,        IGNORE_SCHEMA_LOCATION_HINTS,        CHANGE_IGNORABLE_CHARACTERS_INTO_IGNORABLE_WHITESPACES };                /** Feature defaults. */        private static final Boolean[] FEATURE_DEFAULTS = { null,        // NOTE: The following defaults are nulled out on purpose.        //       If they are set, then when the XML Schema validator        //       is constructed dynamically, these values may override        //       those set by the application. This goes against the        //       whole purpose of XMLComponent#getFeatureDefault but        //       it can't be helped in this case. -Ac        null, //Boolean.FALSE,        null, //Boolean.FALSE,        null, //Boolean.FALSE,        null, //Boolean.FALSE,        null, //Boolean.FALSE,        null, //Boolean.FALSE,        null, //Boolean.FALSE,        null };                /** Recognized properties. */        private static final String[] RECOGNIZED_PROPERTIES = {            SYMBOL_TABLE,            ERROR_REPORTER,            ENTITY_RESOLVER,            VALIDATION_MANAGER,            SCHEMA_LOCATION,            SCHEMA_NONS_LOCATION,            JAXP_SCHEMA_SOURCE,            JAXP_SCHEMA_LANGUAGE,        };                /** Property defaults. */        private static final Object[] PROPERTY_DEFAULTS =        { null, null, null, null, null, null, null, null, };                // this is the number of valuestores of each kind        // we expect an element to have.  It's almost        // never > 1; so leave it at that.        protected static final int ID_CONSTRAINT_NUM = 1;                //        // Data        //                /** current PSVI element info */        protected ElementPSVImpl fCurrentPSVI = new ElementPSVImpl();                // since it is the responsibility of each component to an        // Augmentations parameter if one is null, to save ourselves from        // having to create this object continually, it is created here.        // If it is not present in calls that we're passing on, we *must*        // clear this before we introduce it into the pipeline.        protected final AugmentationsImpl fAugmentations = new AugmentationsImpl();                /**         * Map which is used to catch instance documents that try         * and match a field several times in the same scope.         */        protected final HashMap fMayMatchFieldMap = new HashMap();

⌨️ 快捷键说明

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