286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Copyright 2000-2005 The Apache Software Foundation.
286N/A *
286N/A * Licensed under the Apache License, Version 2.0 (the "License");
286N/A * you may not use this file except in compliance with the License.
286N/A * You may obtain a copy of the License at
286N/A *
286N/A * http://www.apache.org/licenses/LICENSE-2.0
286N/A *
286N/A * Unless required by applicable law or agreed to in writing, software
286N/A * distributed under the License is distributed on an "AS IS" BASIS,
286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286N/A * See the License for the specific language governing permissions and
286N/A * limitations under the License.
286N/A */
286N/A
286N/Apackage com.sun.org.apache.xerces.internal.impl.xs;
286N/A
286N/Aimport java.io.BufferedInputStream;
286N/Aimport java.io.File;
286N/Aimport java.io.FileInputStream;
286N/Aimport java.io.FileNotFoundException;
286N/Aimport java.io.IOException;
286N/Aimport java.io.InputStream;
286N/Aimport java.io.Reader;
286N/Aimport java.io.StringReader;
286N/Aimport java.util.Hashtable;
286N/Aimport java.util.Locale;
286N/Aimport java.util.StringTokenizer;
286N/Aimport java.util.Vector;
286N/A
286N/Aimport com.sun.org.apache.xerces.internal.dom.DOMErrorImpl;
286N/Aimport com.sun.org.apache.xerces.internal.dom.DOMMessageFormatter;
286N/Aimport com.sun.org.apache.xerces.internal.dom.DOMStringListImpl;
286N/Aimport com.sun.org.apache.xerces.internal.impl.Constants;
286N/Aimport com.sun.org.apache.xerces.internal.impl.XMLEntityManager;
286N/Aimport com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
286N/Aimport com.sun.org.apache.xerces.internal.impl.dv.DVFactoryException;
286N/Aimport com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException;
286N/Aimport com.sun.org.apache.xerces.internal.impl.dv.SchemaDVFactory;
286N/Aimport com.sun.org.apache.xerces.internal.impl.dv.xs.SchemaDVFactoryImpl;
286N/Aimport com.sun.org.apache.xerces.internal.impl.xs.models.CMBuilder;
286N/Aimport com.sun.org.apache.xerces.internal.impl.xs.models.CMNodeFactory;
286N/Aimport com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler;
286N/Aimport com.sun.org.apache.xerces.internal.util.DOMEntityResolverWrapper;
286N/Aimport com.sun.org.apache.xerces.internal.util.DOMErrorHandlerWrapper;
286N/Aimport com.sun.org.apache.xerces.internal.util.DefaultErrorHandler;
286N/Aimport com.sun.org.apache.xerces.internal.util.ParserConfigurationSettings;
286N/Aimport com.sun.org.apache.xerces.internal.util.Status;
286N/Aimport com.sun.org.apache.xerces.internal.util.SymbolTable;
286N/Aimport com.sun.org.apache.xerces.internal.util.XMLSymbols;
559N/Aimport com.sun.org.apache.xerces.internal.utils.SecuritySupport;
286N/Aimport com.sun.org.apache.xerces.internal.xni.XNIException;
286N/Aimport com.sun.org.apache.xerces.internal.xni.grammars.Grammar;
286N/Aimport com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarDescription;
286N/Aimport com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarLoader;
286N/Aimport com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;
286N/Aimport com.sun.org.apache.xerces.internal.xni.grammars.XSGrammar;
286N/Aimport com.sun.org.apache.xerces.internal.xni.parser.XMLComponent;
286N/Aimport com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
286N/Aimport com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
286N/Aimport com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver;
286N/Aimport com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler;
286N/Aimport com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
286N/Aimport com.sun.org.apache.xerces.internal.xs.LSInputList;
286N/Aimport com.sun.org.apache.xerces.internal.xs.StringList;
286N/Aimport com.sun.org.apache.xerces.internal.xs.XSLoader;
286N/Aimport com.sun.org.apache.xerces.internal.xs.XSModel;
286N/Aimport java.util.HashMap;
286N/Aimport java.util.Map;
559N/Aimport javax.xml.XMLConstants;
286N/Aimport org.w3c.dom.DOMConfiguration;
286N/Aimport org.w3c.dom.DOMError;
286N/Aimport org.w3c.dom.DOMErrorHandler;
286N/Aimport org.w3c.dom.DOMStringList;
286N/Aimport org.w3c.dom.DOMException;
286N/Aimport org.w3c.dom.ls.LSInput;
286N/Aimport org.w3c.dom.ls.LSResourceResolver;
286N/Aimport org.xml.sax.InputSource;
286N/A
286N/A/**
286N/A * This class implements xni.grammars.XMLGrammarLoader.
286N/A * It also serves as implementation of xs.XSLoader interface and DOMConfiguration interface.
286N/A *
286N/A * This class is designed to interact either with a proxy for a user application
286N/A * which wants to preparse schemas, or with our own Schema validator.
286N/A * It is hoped that none of these "external" classes will therefore need to communicate directly
286N/A * with XSDHandler in future.
286N/A * <p>This class only knows how to make XSDHandler do its thing.
286N/A * The caller must ensure that all its properties (schemaLocation, JAXPSchemaSource
286N/A * etc.) have been properly set.
286N/A *
286N/A * @xerces.internal
286N/A *
286N/A * @author Neil Graham, IBM
286N/A * @version $Id: XMLSchemaLoader.java,v 1.10 2010-11-01 04:39:55 joehw Exp $
286N/A */
286N/A
286N/Apublic class XMLSchemaLoader implements XMLGrammarLoader, XMLComponent,
286N/A// XML Component API
286N/AXSLoader, DOMConfiguration {
286N/A
286N/A // Feature identifiers:
286N/A
286N/A /** Feature identifier: schema full checking*/
286N/A protected static final String SCHEMA_FULL_CHECKING =
286N/A Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_FULL_CHECKING;
286N/A
286N/A /** Feature identifier: continue after fatal error. */
286N/A protected static final String CONTINUE_AFTER_FATAL_ERROR =
286N/A Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE;
286N/A
286N/A /** Feature identifier: allow java encodings to be recognized when parsing schema docs. */
286N/A protected static final String ALLOW_JAVA_ENCODINGS =
286N/A Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE;
286N/A
286N/A /** Feature identifier: standard uri conformant feature. */
286N/A protected static final String STANDARD_URI_CONFORMANT_FEATURE =
286N/A Constants.XERCES_FEATURE_PREFIX + Constants.STANDARD_URI_CONFORMANT_FEATURE;
286N/A
286N/A /** Feature identifier: validate annotations. */
286N/A protected static final String VALIDATE_ANNOTATIONS =
286N/A Constants.XERCES_FEATURE_PREFIX + Constants.VALIDATE_ANNOTATIONS_FEATURE;
286N/A
286N/A /** Feature: disallow doctype*/
286N/A protected static final String DISALLOW_DOCTYPE =
286N/A Constants.XERCES_FEATURE_PREFIX + Constants.DISALLOW_DOCTYPE_DECL_FEATURE;
286N/A
286N/A /** Feature: generate synthetic annotations */
286N/A protected static final String GENERATE_SYNTHETIC_ANNOTATIONS =
286N/A Constants.XERCES_FEATURE_PREFIX + Constants.GENERATE_SYNTHETIC_ANNOTATIONS_FEATURE;
286N/A
286N/A /** Feature identifier: honour all schemaLocations */
286N/A protected static final String HONOUR_ALL_SCHEMALOCATIONS =
286N/A Constants.XERCES_FEATURE_PREFIX + Constants.HONOUR_ALL_SCHEMALOCATIONS_FEATURE;
286N/A
286N/A protected static final String AUGMENT_PSVI =
286N/A Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_AUGMENT_PSVI;
286N/A
286N/A protected static final String PARSER_SETTINGS =
286N/A Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS;
286N/A
286N/A /** Feature identifier: namespace growth */
286N/A protected static final String NAMESPACE_GROWTH =
286N/A Constants.XERCES_FEATURE_PREFIX + Constants.NAMESPACE_GROWTH_FEATURE;
286N/A
286N/A /** Feature identifier: tolerate duplicates */
286N/A protected static final String TOLERATE_DUPLICATES =
286N/A Constants.XERCES_FEATURE_PREFIX + Constants.TOLERATE_DUPLICATES_FEATURE;
286N/A
286N/A /** Property identifier: Schema DV Factory */
286N/A protected static final String SCHEMA_DV_FACTORY =
286N/A Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_DV_FACTORY_PROPERTY;
286N/A
286N/A protected static final String USE_SERVICE_MECHANISM = Constants.ORACLE_FEATURE_SERVICE_MECHANISM;
286N/A
286N/A // recognized features:
286N/A private static final String[] RECOGNIZED_FEATURES = {
286N/A SCHEMA_FULL_CHECKING,
286N/A AUGMENT_PSVI,
286N/A CONTINUE_AFTER_FATAL_ERROR,
286N/A ALLOW_JAVA_ENCODINGS,
286N/A STANDARD_URI_CONFORMANT_FEATURE,
286N/A DISALLOW_DOCTYPE,
286N/A GENERATE_SYNTHETIC_ANNOTATIONS,
286N/A VALIDATE_ANNOTATIONS,
286N/A HONOUR_ALL_SCHEMALOCATIONS,
286N/A NAMESPACE_GROWTH,
286N/A TOLERATE_DUPLICATES,
286N/A USE_SERVICE_MECHANISM
286N/A };
286N/A
286N/A // property identifiers
286N/A
286N/A /** Property identifier: symbol table. */
286N/A public static final String SYMBOL_TABLE =
286N/A Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY;
286N/A
286N/A /** Property identifier: error reporter. */
286N/A public static final String ERROR_REPORTER =
286N/A Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;
286N/A
286N/A /** Property identifier: error handler. */
286N/A protected static final String ERROR_HANDLER =
286N/A Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY;
286N/A
286N/A /** Property identifier: entity resolver. */
286N/A public static final String ENTITY_RESOLVER =
286N/A Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY;
286N/A
286N/A /** Property identifier: grammar pool. */
286N/A public static final String XMLGRAMMAR_POOL =
286N/A Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY;
286N/A
286N/A /** Property identifier: schema location. */
286N/A protected static final String SCHEMA_LOCATION =
286N/A Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_LOCATION;
286N/A
286N/A /** Property identifier: no namespace schema location. */
286N/A protected static final String SCHEMA_NONS_LOCATION =
286N/A Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_NONS_LOCATION;
286N/A
286N/A /** Property identifier: JAXP schema source. */
286N/A protected static final String JAXP_SCHEMA_SOURCE =
286N/A Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE;
286N/A
286N/A protected static final String SECURITY_MANAGER =
286N/A Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY;
286N/A
286N/A /** Property identifier: locale. */
286N/A protected static final String LOCALE =
286N/A Constants.XERCES_PROPERTY_PREFIX + Constants.LOCALE_PROPERTY;
286N/A
286N/A protected static final String ENTITY_MANAGER =
286N/A Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY;
286N/A
559N/A /** Property identifier: access to external dtd */
559N/A public static final String ACCESS_EXTERNAL_DTD = XMLConstants.ACCESS_EXTERNAL_DTD;
559N/A
559N/A /** Property identifier: access to external schema */
559N/A public static final String ACCESS_EXTERNAL_SCHEMA = XMLConstants.ACCESS_EXTERNAL_SCHEMA;
559N/A
286N/A // recognized properties
286N/A private static final String [] RECOGNIZED_PROPERTIES = {
286N/A ENTITY_MANAGER,
286N/A SYMBOL_TABLE,
286N/A ERROR_REPORTER,
286N/A ERROR_HANDLER,
286N/A ENTITY_RESOLVER,
286N/A XMLGRAMMAR_POOL,
286N/A SCHEMA_LOCATION,
286N/A SCHEMA_NONS_LOCATION,
286N/A JAXP_SCHEMA_SOURCE,
286N/A SECURITY_MANAGER,
286N/A LOCALE,
559N/A SCHEMA_DV_FACTORY,
559N/A ACCESS_EXTERNAL_DTD,
559N/A ACCESS_EXTERNAL_SCHEMA
286N/A };
286N/A
286N/A // Data
286N/A
286N/A // features and properties
286N/A private ParserConfigurationSettings fLoaderConfig = new ParserConfigurationSettings();
286N/A private SymbolTable fSymbolTable = null;
286N/A private XMLErrorReporter fErrorReporter = new XMLErrorReporter ();
286N/A private XMLEntityManager fEntityManager = null;
286N/A private XMLEntityResolver fUserEntityResolver = null;
286N/A private XMLGrammarPool fGrammarPool = null;
286N/A private String fExternalSchemas = null;
286N/A private String fExternalNoNSSchema = null;
286N/A // JAXP property: schema source
286N/A private Object fJAXPSource = null;
286N/A // is Schema Full Checking enabled
286N/A private boolean fIsCheckedFully = false;
286N/A // boolean that tells whether we've tested the JAXP property.
286N/A private boolean fJAXPProcessed = false;
286N/A // if features/properties has not been changed, the value of this attribute is "false"
286N/A private boolean fSettingsChanged = true;
286N/A
286N/A // xml schema parsing
286N/A private XSDHandler fSchemaHandler;
286N/A private XSGrammarBucket fGrammarBucket;
286N/A private XSDeclarationPool fDeclPool = null;
286N/A private SubstitutionGroupHandler fSubGroupHandler;
286N/A private final CMNodeFactory fNodeFactory = new CMNodeFactory(); //component mgr will be set later
286N/A private CMBuilder fCMBuilder;
286N/A private XSDDescription fXSDDescription = new XSDDescription();
559N/A private String faccessExternalDTD = Constants.EXTERNAL_ACCESS_DEFAULT;
559N/A private String faccessExternalSchema = Constants.EXTERNAL_ACCESS_DEFAULT;
286N/A
286N/A private Map fJAXPCache;
286N/A private Locale fLocale = Locale.getDefault();
286N/A
286N/A // XSLoader attributes
286N/A private DOMStringList fRecognizedParameters = null;
286N/A
286N/A /** DOM L3 error handler */
286N/A private DOMErrorHandlerWrapper fErrorHandler = null;
286N/A
286N/A /** DOM L3 resource resolver */
286N/A private DOMEntityResolverWrapper fResourceResolver = null;
286N/A
286N/A // default constructor. Create objects we absolutely need:
286N/A public XMLSchemaLoader() {
286N/A this( new SymbolTable(), null, new XMLEntityManager(), null, null, null);
286N/A }
286N/A
286N/A public XMLSchemaLoader(SymbolTable symbolTable) {
286N/A this( symbolTable, null, new XMLEntityManager(), null, null, null);
286N/A }
286N/A
286N/A /**
286N/A * This constractor is used by the XMLSchemaValidator. Additional properties, i.e. XMLEntityManager,
286N/A * will be passed during reset(XMLComponentManager).
286N/A * @param errorReporter
286N/A * @param grammarBucket
286N/A * @param sHandler
286N/A * @param builder
286N/A */
286N/A XMLSchemaLoader(XMLErrorReporter errorReporter,
286N/A XSGrammarBucket grammarBucket,
286N/A SubstitutionGroupHandler sHandler, CMBuilder builder) {
286N/A this(null, errorReporter, null, grammarBucket, sHandler, builder);
286N/A }
286N/A
286N/A XMLSchemaLoader(SymbolTable symbolTable,
286N/A XMLErrorReporter errorReporter,
286N/A XMLEntityManager entityResolver,
286N/A XSGrammarBucket grammarBucket,
286N/A SubstitutionGroupHandler sHandler,
286N/A CMBuilder builder) {
286N/A
286N/A // store properties and features in configuration
286N/A fLoaderConfig.addRecognizedFeatures(RECOGNIZED_FEATURES);
286N/A fLoaderConfig.addRecognizedProperties(RECOGNIZED_PROPERTIES);
286N/A if (symbolTable != null){
286N/A fLoaderConfig.setProperty(SYMBOL_TABLE, symbolTable);
286N/A }
286N/A
286N/A if(errorReporter == null) {
286N/A errorReporter = new XMLErrorReporter ();
286N/A errorReporter.setLocale(fLocale);
286N/A errorReporter.setProperty(ERROR_HANDLER, new DefaultErrorHandler());
286N/A
286N/A }
286N/A fErrorReporter = errorReporter;
286N/A // make sure error reporter knows about schemas...
286N/A if(fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) {
286N/A fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, new XSMessageFormatter());
286N/A }
286N/A fLoaderConfig.setProperty(ERROR_REPORTER, fErrorReporter);
286N/A fEntityManager = entityResolver;
286N/A // entity manager is null if XMLSchemaValidator creates the loader
286N/A if (fEntityManager != null){
286N/A fLoaderConfig.setProperty(ENTITY_MANAGER, fEntityManager);
286N/A }
286N/A
286N/A // by default augment PSVI (i.e. don't use declaration pool)
286N/A fLoaderConfig.setFeature(AUGMENT_PSVI, true);
286N/A
286N/A if(grammarBucket == null ) {
286N/A grammarBucket = new XSGrammarBucket();
286N/A }
286N/A fGrammarBucket = grammarBucket;
286N/A if(sHandler == null) {
286N/A sHandler = new SubstitutionGroupHandler(fGrammarBucket);
286N/A }
286N/A fSubGroupHandler = sHandler;
286N/A
286N/A if(builder == null) {
286N/A builder = new CMBuilder(fNodeFactory);
286N/A }
286N/A fCMBuilder = builder;
286N/A fSchemaHandler = new XSDHandler(fGrammarBucket);
286N/A if (fDeclPool != null) {
286N/A fDeclPool.reset();
286N/A }
286N/A fJAXPCache = new HashMap();
286N/A
286N/A fSettingsChanged = true;
286N/A }
286N/A
286N/A /**
286N/A * Returns a list of feature identifiers that are recognized by
286N/A * this XMLGrammarLoader. This method may return null if no features
286N/A * are recognized.
286N/A */
286N/A public String[] getRecognizedFeatures() {
286N/A return (String[])(RECOGNIZED_FEATURES.clone());
286N/A } // getRecognizedFeatures(): String[]
286N/A
286N/A /**
286N/A * Returns the state of a feature.
286N/A *
286N/A * @param featureId The feature identifier.
286N/A *
286N/A * @throws XMLConfigurationException Thrown on configuration error.
286N/A */
286N/A public boolean getFeature(String featureId)
286N/A throws XMLConfigurationException {
286N/A return fLoaderConfig.getFeature(featureId);
286N/A } // getFeature (String): boolean
286N/A
286N/A /**
286N/A * Sets the state of a feature.
286N/A *
286N/A * @param featureId The feature identifier.
286N/A * @param state The state of the feature.
286N/A *
286N/A * @throws XMLConfigurationException Thrown when a feature is not
286N/A * recognized or cannot be set.
286N/A */
286N/A public void setFeature(String featureId,
286N/A boolean state) throws XMLConfigurationException {
286N/A fSettingsChanged = true;
286N/A if(featureId.equals(CONTINUE_AFTER_FATAL_ERROR)) {
286N/A fErrorReporter.setFeature(CONTINUE_AFTER_FATAL_ERROR, state);
286N/A }
286N/A else if(featureId.equals(GENERATE_SYNTHETIC_ANNOTATIONS)) {
286N/A fSchemaHandler.setGenerateSyntheticAnnotations(state);
286N/A }
286N/A fLoaderConfig.setFeature(featureId, state);
286N/A } // setFeature(String, boolean)
286N/A
286N/A /**
286N/A * Returns a list of property identifiers that are recognized by
286N/A * this XMLGrammarLoader. This method may return null if no properties
286N/A * are recognized.
286N/A */
286N/A public String[] getRecognizedProperties() {
286N/A return (String[])(RECOGNIZED_PROPERTIES.clone());
286N/A } // getRecognizedProperties(): String[]
286N/A
286N/A /**
286N/A * Returns the state of a property.
286N/A *
286N/A * @param propertyId The property identifier.
286N/A *
286N/A * @throws XMLConfigurationException Thrown on configuration error.
286N/A */
286N/A public Object getProperty(String propertyId)
286N/A throws XMLConfigurationException {
286N/A return fLoaderConfig.getProperty(propertyId);
286N/A } // getProperty(String): Object
286N/A
286N/A /**
286N/A * Sets the state of a property.
286N/A *
286N/A * @param propertyId The property identifier.
286N/A * @param state The state of the property.
286N/A *
286N/A * @throws XMLConfigurationException Thrown when a property is not
286N/A * recognized or cannot be set.
286N/A */
286N/A public void setProperty(String propertyId,
286N/A Object state) throws XMLConfigurationException {
286N/A fSettingsChanged = true;
286N/A fLoaderConfig.setProperty(propertyId, state);
286N/A if (propertyId.equals(JAXP_SCHEMA_SOURCE)) {
286N/A fJAXPSource = state;
286N/A fJAXPProcessed = false;
286N/A }
286N/A else if (propertyId.equals(XMLGRAMMAR_POOL)) {
286N/A fGrammarPool = (XMLGrammarPool)state;
286N/A }
286N/A else if (propertyId.equals(SCHEMA_LOCATION)) {
286N/A fExternalSchemas = (String)state;
286N/A }
286N/A else if (propertyId.equals(SCHEMA_NONS_LOCATION)) {
286N/A fExternalNoNSSchema = (String) state;
286N/A }
286N/A else if (propertyId.equals(LOCALE)) {
286N/A setLocale((Locale) state);
286N/A }
286N/A else if (propertyId.equals(ENTITY_RESOLVER)) {
286N/A fEntityManager.setProperty(ENTITY_RESOLVER, state);
286N/A }
286N/A else if (propertyId.equals(ERROR_REPORTER)) {
286N/A fErrorReporter = (XMLErrorReporter)state;
286N/A if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) {
286N/A fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, new XSMessageFormatter());
286N/A }
286N/A }
559N/A else if (propertyId.equals(ACCESS_EXTERNAL_DTD)) {
559N/A faccessExternalDTD = (String) state;
559N/A }
559N/A else if (propertyId.equals(ACCESS_EXTERNAL_SCHEMA)) {
559N/A faccessExternalSchema = (String) state;
559N/A }
286N/A } // setProperty(String, Object)
286N/A
286N/A /**
286N/A * Set the locale to use for messages.
286N/A *
286N/A * @param locale The locale object to use for localization of messages.
286N/A *
286N/A * @exception XNIException Thrown if the parser does not support the
286N/A * specified locale.
286N/A */
286N/A public void setLocale(Locale locale) {
286N/A fLocale = locale;
286N/A fErrorReporter.setLocale(locale);
286N/A } // setLocale(Locale)
286N/A
286N/A /** Return the Locale the XMLGrammarLoader is using. */
286N/A public Locale getLocale() {
286N/A return fLocale;
286N/A } // getLocale(): Locale
286N/A
286N/A /**
286N/A * Sets the error handler.
286N/A *
286N/A * @param errorHandler The error handler.
286N/A */
286N/A public void setErrorHandler(XMLErrorHandler errorHandler) {
286N/A fErrorReporter.setProperty(ERROR_HANDLER, errorHandler);
286N/A } // setErrorHandler(XMLErrorHandler)
286N/A
286N/A /** Returns the registered error handler. */
286N/A public XMLErrorHandler getErrorHandler() {
286N/A return fErrorReporter.getErrorHandler();
286N/A } // getErrorHandler(): XMLErrorHandler
286N/A
286N/A /**
286N/A * Sets the entity resolver.
286N/A *
286N/A * @param entityResolver The new entity resolver.
286N/A */
286N/A public void setEntityResolver(XMLEntityResolver entityResolver) {
286N/A fUserEntityResolver = entityResolver;
286N/A fLoaderConfig.setProperty(ENTITY_RESOLVER, entityResolver);
286N/A fEntityManager.setProperty(ENTITY_RESOLVER, entityResolver);
286N/A } // setEntityResolver(XMLEntityResolver)
286N/A
286N/A /** Returns the registered entity resolver. */
286N/A public XMLEntityResolver getEntityResolver() {
286N/A return fUserEntityResolver;
286N/A } // getEntityResolver(): XMLEntityResolver
286N/A
286N/A /**
286N/A * Returns a Grammar object by parsing the contents of the
286N/A * entities pointed to by sources.
286N/A *
286N/A * @param source[] the locations of the entity which forms
286N/A * the staring point of the grammars to be constructed
286N/A * @throws IOException when a problem is encounted reading the entity
286N/A * @throws XNIException when a condition arises (such as a FatalError) that requires parsing
286N/A * of the entity be terminated
286N/A */
286N/A public void loadGrammar(XMLInputSource source[])
286N/A throws IOException, XNIException {
286N/A int numSource = source.length;
286N/A for (int i = 0; i < numSource; ++i) {
286N/A loadGrammar(source[i]);
286N/A }
286N/A }
286N/A
286N/A /**
286N/A * Returns a Grammar object by parsing the contents of the
286N/A * entity pointed to by source.
286N/A *
286N/A * @param source the location of the entity which forms
286N/A * the starting point of the grammar to be constructed.
286N/A * @throws IOException When a problem is encountered reading the entity
286N/A * XNIException When a condition arises (such as a FatalError) that requires parsing
286N/A * of the entity be terminated.
286N/A */
286N/A public Grammar loadGrammar(XMLInputSource source)
286N/A throws IOException, XNIException {
286N/A
286N/A // REVISIT: this method should have a namespace parameter specified by
286N/A // user. In this case we can easily detect if a schema asked to be loaded
286N/A // is already in the local cache.
286N/A
286N/A reset(fLoaderConfig);
286N/A fSettingsChanged = false;
286N/A XSDDescription desc = new XSDDescription();
286N/A desc.fContextType = XSDDescription.CONTEXT_PREPARSE;
286N/A desc.setBaseSystemId(source.getBaseSystemId());
286N/A desc.setLiteralSystemId( source.getSystemId());
286N/A // none of the other fields make sense for preparsing
286N/A Map locationPairs = new HashMap();
286N/A // Process external schema location properties.
286N/A // We don't call tokenizeSchemaLocationStr here, because we also want
286N/A // to check whether the values are valid URI.
286N/A processExternalHints(fExternalSchemas, fExternalNoNSSchema,
286N/A locationPairs, fErrorReporter);
286N/A SchemaGrammar grammar = loadSchema(desc, source, locationPairs);
286N/A
286N/A if(grammar != null && fGrammarPool != null) {
286N/A fGrammarPool.cacheGrammars(XMLGrammarDescription.XML_SCHEMA, fGrammarBucket.getGrammars());
286N/A // NOTE: we only need to verify full checking in case the schema was not provided via JAXP
286N/A // since full checking already verified for all JAXP schemas
286N/A if(fIsCheckedFully && fJAXPCache.get(grammar) != grammar) {
286N/A XSConstraints.fullSchemaChecking(fGrammarBucket, fSubGroupHandler, fCMBuilder, fErrorReporter);
286N/A }
286N/A }
286N/A return grammar;
286N/A } // loadGrammar(XMLInputSource): Grammar
286N/A
286N/A /**
286N/A * This method is called either from XMLGrammarLoader.loadGrammar or from XMLSchemaValidator.
286N/A * Note: in either case, the EntityManager (or EntityResolvers) are not going to be invoked
286N/A * to resolve the location of the schema in XSDDescription
286N/A * @param desc
286N/A * @param source
286N/A * @param locationPairs
286N/A * @return An XML Schema grammar
286N/A * @throws IOException
286N/A * @throws XNIException
286N/A */
286N/A SchemaGrammar loadSchema(XSDDescription desc,
286N/A XMLInputSource source,
286N/A Map locationPairs) throws IOException, XNIException {
286N/A
286N/A // this should only be done once per invocation of this object;
286N/A // unless application alters JAXPSource in the mean time.
286N/A if(!fJAXPProcessed) {
286N/A processJAXPSchemaSource(locationPairs);
286N/A }
559N/A
559N/A if (desc.isExternal()) {
559N/A String accessError = SecuritySupport.checkAccess(desc.getExpandedSystemId(), faccessExternalSchema, Constants.ACCESS_EXTERNAL_ALL);
559N/A if (accessError != null) {
559N/A throw new XNIException(fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
559N/A "schema_reference.access",
559N/A new Object[] { SecuritySupport.sanitizePath(desc.getExpandedSystemId()), accessError }, XMLErrorReporter.SEVERITY_ERROR));
559N/A }
559N/A }
286N/A SchemaGrammar grammar = fSchemaHandler.parseSchema(source, desc, locationPairs);
286N/A
286N/A return grammar;
286N/A } // loadSchema(XSDDescription, XMLInputSource): SchemaGrammar
286N/A
286N/A /** This method tries to resolve location of the given schema.
286N/A * The loader stores the namespace/location pairs in a hashtable (use "" as the
286N/A * namespace of absent namespace). When resolving an entity, loader first tries
286N/A * to find in the hashtable whether there is a value for that namespace,
286N/A * if so, pass that location value to the user-defined entity resolver.
286N/A *
286N/A * @param desc
286N/A * @param locationPairs
286N/A * @param entityResolver
286N/A * @return
286N/A * @throws IOException
286N/A */
286N/A public static XMLInputSource resolveDocument(XSDDescription desc, Map locationPairs,
286N/A XMLEntityResolver entityResolver) throws IOException {
286N/A String loc = null;
286N/A // we consider the schema location properties for import
286N/A if (desc.getContextType() == XSDDescription.CONTEXT_IMPORT ||
286N/A desc.fromInstance()) {
286N/A // use empty string as the key for absent namespace
286N/A String namespace = desc.getTargetNamespace();
286N/A String ns = namespace == null ? XMLSymbols.EMPTY_STRING : namespace;
286N/A // get the location hint for that namespace
286N/A LocationArray tempLA = (LocationArray)locationPairs.get(ns);
286N/A if(tempLA != null)
286N/A loc = tempLA.getFirstLocation();
286N/A }
286N/A
286N/A // if it's not import, or if the target namespace is not set
286N/A // in the schema location properties, use location hint
286N/A if (loc == null) {
286N/A String[] hints = desc.getLocationHints();
286N/A if (hints != null && hints.length > 0)
286N/A loc = hints[0];
286N/A }
286N/A
286N/A String expandedLoc = XMLEntityManager.expandSystemId(loc, desc.getBaseSystemId(), false);
286N/A desc.setLiteralSystemId(loc);
286N/A desc.setExpandedSystemId(expandedLoc);
286N/A return entityResolver.resolveEntity(desc);
286N/A }
286N/A
286N/A // add external schema locations to the location pairs
286N/A public static void processExternalHints(String sl, String nsl,
286N/A Map locations,
286N/A XMLErrorReporter er) {
286N/A if (sl != null) {
286N/A try {
286N/A // get the attribute decl for xsi:schemaLocation
286N/A // because external schema location property has the same syntax
286N/A // as xsi:schemaLocation
286N/A XSAttributeDecl attrDecl = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_SCHEMALOCATION);
286N/A // validation the string value to get the list of URI's
286N/A attrDecl.fType.validate(sl, null, null);
286N/A if (!tokenizeSchemaLocationStr(sl, locations)) {
286N/A // report warning (odd number of items)
286N/A er.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
286N/A "SchemaLocation",
286N/A new Object[]{sl},
286N/A XMLErrorReporter.SEVERITY_WARNING);
286N/A }
286N/A }
286N/A catch (InvalidDatatypeValueException ex) {
286N/A // report warning (not list of URI's)
286N/A er.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
286N/A ex.getKey(), ex.getArgs(),
286N/A XMLErrorReporter.SEVERITY_WARNING);
286N/A }
286N/A }
286N/A
286N/A if (nsl != null) {
286N/A try {
286N/A // similarly for no ns schema location property
286N/A XSAttributeDecl attrDecl = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION);
286N/A attrDecl.fType.validate(nsl, null, null);
286N/A LocationArray la = ((LocationArray)locations.get(XMLSymbols.EMPTY_STRING));
286N/A if(la == null) {
286N/A la = new LocationArray();
286N/A locations.put(XMLSymbols.EMPTY_STRING, la);
286N/A }
286N/A la.addLocation(nsl);
286N/A }
286N/A catch (InvalidDatatypeValueException ex) {
286N/A // report warning (not a URI)
286N/A er.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
286N/A ex.getKey(), ex.getArgs(),
286N/A XMLErrorReporter.SEVERITY_WARNING);
286N/A }
286N/A }
286N/A }
286N/A // this method takes a SchemaLocation string.
286N/A // If an error is encountered, false is returned;
286N/A // otherwise, true is returned. In either case, locations
286N/A // is augmented to include as many tokens as possible.
286N/A // @param schemaStr The schemaLocation string to tokenize
286N/A // @param locations HashMap mapping namespaces to LocationArray objects holding lists of locaitons
286N/A // @return true if no problems; false if string could not be tokenized
286N/A public static boolean tokenizeSchemaLocationStr(String schemaStr, Map locations) {
286N/A if (schemaStr!= null) {
286N/A StringTokenizer t = new StringTokenizer(schemaStr, " \n\t\r");
286N/A String namespace, location;
286N/A while (t.hasMoreTokens()) {
286N/A namespace = t.nextToken ();
286N/A if (!t.hasMoreTokens()) {
286N/A return false; // error!
286N/A }
286N/A location = t.nextToken();
286N/A LocationArray la = ((LocationArray)locations.get(namespace));
286N/A if(la == null) {
286N/A la = new LocationArray();
286N/A locations.put(namespace, la);
286N/A }
286N/A la.addLocation(location);
286N/A }
286N/A }
286N/A return true;
286N/A } // tokenizeSchemaLocation(String, HashMap): boolean
286N/A
286N/A /**
286N/A * Translate the various JAXP SchemaSource property types to XNI
286N/A * XMLInputSource. Valid types are: String, org.xml.sax.InputSource,
286N/A * InputStream, File, or Object[] of any of previous types.
286N/A * REVISIT: the JAXP 1.2 spec is less than clear as to whether this property
286N/A * should be available to imported schemas. I have assumed
286N/A * that it should. - NG
286N/A * Note: all JAXP schema files will be checked for full-schema validity if the feature was set up
286N/A *
286N/A */
286N/A private void processJAXPSchemaSource(Map locationPairs) throws IOException {
286N/A fJAXPProcessed = true;
286N/A if (fJAXPSource == null) {
286N/A return;
286N/A }
286N/A
286N/A Class componentType = fJAXPSource.getClass().getComponentType();
286N/A XMLInputSource xis = null;
286N/A String sid = null;
286N/A if (componentType == null) {
286N/A // Not an array
286N/A if(fJAXPSource instanceof InputStream ||
286N/A fJAXPSource instanceof InputSource) {
286N/A SchemaGrammar g = (SchemaGrammar)fJAXPCache.get(fJAXPSource);
286N/A if(g != null) {
286N/A fGrammarBucket.putGrammar(g);
286N/A return;
286N/A }
286N/A }
286N/A fXSDDescription.reset();
286N/A xis = xsdToXMLInputSource(fJAXPSource);
286N/A sid = xis.getSystemId();
286N/A fXSDDescription.fContextType = XSDDescription.CONTEXT_PREPARSE;
286N/A if (sid != null) {
286N/A fXSDDescription.setBaseSystemId(xis.getBaseSystemId());
286N/A fXSDDescription.setLiteralSystemId(sid);
286N/A fXSDDescription.setExpandedSystemId(sid);
286N/A fXSDDescription.fLocationHints = new String[]{sid};
286N/A }
286N/A SchemaGrammar g = loadSchema(fXSDDescription, xis, locationPairs);
286N/A // it is possible that we won't be able to resolve JAXP schema-source location
286N/A if (g != null){
286N/A if(fJAXPSource instanceof InputStream ||
286N/A fJAXPSource instanceof InputSource) {
286N/A fJAXPCache.put(fJAXPSource, g);
286N/A if(fIsCheckedFully) {
286N/A XSConstraints.fullSchemaChecking(fGrammarBucket, fSubGroupHandler, fCMBuilder, fErrorReporter);
286N/A }
286N/A }
286N/A fGrammarBucket.putGrammar(g);
286N/A }
286N/A return ;
286N/A } else if ( (componentType != Object.class) &&
286N/A (componentType != String.class) &&
286N/A (componentType != File.class) &&
286N/A (componentType != InputStream.class) &&
286N/A (componentType != InputSource.class)
286N/A ) {
286N/A // Not an Object[], String[], File[], InputStream[], InputSource[]
286N/A throw new XMLConfigurationException(
286N/A Status.NOT_SUPPORTED, "\""+JAXP_SCHEMA_SOURCE+
286N/A "\" property cannot have an array of type {"+componentType.getName()+
286N/A "}. Possible types of the array supported are Object, String, File, "+
286N/A "InputStream, InputSource.");
286N/A }
286N/A
286N/A // JAXP spec. allow []s of type String, File, InputStream,
286N/A // InputSource also, apart from [] of type Object.
286N/A Object[] objArr = (Object[]) fJAXPSource;
286N/A //make local vector for storing targetn namespaces of schemasources specified in object arrays.
286N/A Vector jaxpSchemaSourceNamespaces = new Vector() ;
286N/A for (int i = 0; i < objArr.length; i++) {
286N/A if(objArr[i] instanceof InputStream ||
286N/A objArr[i] instanceof InputSource) {
286N/A SchemaGrammar g = (SchemaGrammar)fJAXPCache.get(objArr[i]);
286N/A if (g != null) {
286N/A fGrammarBucket.putGrammar(g);
286N/A continue;
286N/A }
286N/A }
286N/A fXSDDescription.reset();
286N/A xis = xsdToXMLInputSource(objArr[i]);
286N/A sid = xis.getSystemId();
286N/A fXSDDescription.fContextType = XSDDescription.CONTEXT_PREPARSE;
286N/A if (sid != null) {
286N/A fXSDDescription.setBaseSystemId(xis.getBaseSystemId());
286N/A fXSDDescription.setLiteralSystemId(sid);
286N/A fXSDDescription.setExpandedSystemId(sid);
286N/A fXSDDescription.fLocationHints = new String[]{sid};
286N/A }
286N/A String targetNamespace = null ;
286N/A // load schema
286N/A SchemaGrammar grammar = fSchemaHandler.parseSchema(xis,fXSDDescription, locationPairs);
286N/A
286N/A if(fIsCheckedFully) {
286N/A XSConstraints.fullSchemaChecking(fGrammarBucket, fSubGroupHandler, fCMBuilder, fErrorReporter);
286N/A }
286N/A if(grammar != null){
286N/A targetNamespace = grammar.getTargetNamespace() ;
286N/A if(jaxpSchemaSourceNamespaces.contains(targetNamespace)){
286N/A //when an array of objects is passed it is illegal to have two schemas that share same namespace.
286N/A throw new java.lang.IllegalArgumentException(
286N/A " When using array of Objects as the value of SCHEMA_SOURCE property , " +
286N/A "no two Schemas should share the same targetNamespace. " );
286N/A }
286N/A else{
286N/A jaxpSchemaSourceNamespaces.add(targetNamespace) ;
286N/A }
286N/A if(objArr[i] instanceof InputStream ||
286N/A objArr[i] instanceof InputSource) {
286N/A fJAXPCache.put(objArr[i], grammar);
286N/A }
286N/A fGrammarBucket.putGrammar(grammar);
286N/A }
286N/A else{
286N/A //REVISIT: What should be the acutal behavior if grammar can't be loaded as specified in schema source?
286N/A }
286N/A }
286N/A }//processJAXPSchemaSource
286N/A
286N/A private XMLInputSource xsdToXMLInputSource(
286N/A Object val)
286N/A {
286N/A if (val instanceof String) {
286N/A // String value is treated as a URI that is passed through the
286N/A // EntityResolver
286N/A String loc = (String) val;
286N/A fXSDDescription.reset();
286N/A fXSDDescription.setValues(null, loc, null, null);
286N/A XMLInputSource xis = null;
286N/A try {
286N/A xis = fEntityManager.resolveEntity(fXSDDescription);
286N/A } catch (IOException ex) {
286N/A fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
286N/A "schema_reference.4",
286N/A new Object[] { loc }, XMLErrorReporter.SEVERITY_ERROR);
286N/A }
286N/A if (xis == null) {
286N/A // REVISIT: can this happen?
286N/A // Treat value as a URI and pass in as systemId
286N/A return new XMLInputSource(null, loc, null);
286N/A }
286N/A return xis;
286N/A } else if (val instanceof InputSource) {
286N/A return saxToXMLInputSource((InputSource) val);
286N/A } else if (val instanceof InputStream) {
286N/A return new XMLInputSource(null, null, null,
286N/A (InputStream) val, null);
286N/A } else if (val instanceof File) {
286N/A File file = (File) val;
286N/A InputStream is = null;
286N/A try {
286N/A is = new BufferedInputStream(new FileInputStream(file));
286N/A } catch (FileNotFoundException ex) {
286N/A fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
286N/A "schema_reference.4", new Object[] { file.toString() },
286N/A XMLErrorReporter.SEVERITY_ERROR);
286N/A }
286N/A return new XMLInputSource(null, null, null, is, null);
286N/A }
286N/A throw new XMLConfigurationException(
286N/A Status.NOT_SUPPORTED, "\""+JAXP_SCHEMA_SOURCE+
286N/A "\" property cannot have a value of type {"+val.getClass().getName()+
286N/A "}. Possible types of the value supported are String, File, InputStream, "+
286N/A "InputSource OR an array of these types.");
286N/A }
286N/A
286N/A
286N/A //Convert a SAX InputSource to an equivalent XNI XMLInputSource
286N/A
286N/A private static XMLInputSource saxToXMLInputSource(InputSource sis) {
286N/A String publicId = sis.getPublicId();
286N/A String systemId = sis.getSystemId();
286N/A
286N/A Reader charStream = sis.getCharacterStream();
286N/A if (charStream != null) {
286N/A return new XMLInputSource(publicId, systemId, null, charStream,
286N/A null);
286N/A }
286N/A
286N/A InputStream byteStream = sis.getByteStream();
286N/A if (byteStream != null) {
286N/A return new XMLInputSource(publicId, systemId, null, byteStream,
286N/A sis.getEncoding());
286N/A }
286N/A
286N/A return new XMLInputSource(publicId, systemId, null);
286N/A }
286N/A
286N/A static class LocationArray{
286N/A
286N/A int length ;
286N/A String [] locations = new String[2];
286N/A
286N/A public void resize(int oldLength , int newLength){
286N/A String [] temp = new String[newLength] ;
286N/A System.arraycopy(locations, 0, temp, 0, Math.min(oldLength, newLength));
286N/A locations = temp ;
286N/A length = Math.min(oldLength, newLength);
286N/A }
286N/A
286N/A public void addLocation(String location){
286N/A if(length >= locations.length ){
286N/A resize(length, Math.max(1, length*2));
286N/A }
286N/A locations[length++] = location;
286N/A }//setLocation()
286N/A
286N/A public String [] getLocationArray(){
286N/A if(length < locations.length ){
286N/A resize(locations.length, length);
286N/A }
286N/A return locations;
286N/A }//getLocationArray()
286N/A
286N/A public String getFirstLocation(){
286N/A return length > 0 ? locations[0] : null;
286N/A }
286N/A
286N/A public int getLength(){
286N/A return length ;
286N/A }
286N/A
286N/A } //locationArray
286N/A
286N/A /* (non-Javadoc)
286N/A * @see com.sun.org.apache.xerces.internal.xni.parser.XMLComponent#getFeatureDefault(java.lang.String)
286N/A */
286N/A public Boolean getFeatureDefault(String featureId) {
286N/A if (featureId.equals(AUGMENT_PSVI)){
286N/A return Boolean.TRUE;
286N/A }
286N/A return null;
286N/A }
286N/A
286N/A /* (non-Javadoc)
286N/A * @see com.sun.org.apache.xerces.internal.xni.parser.XMLComponent#getPropertyDefault(java.lang.String)
286N/A */
286N/A public Object getPropertyDefault(String propertyId) {
286N/A // TODO Auto-generated method stub
286N/A return null;
286N/A }
286N/A
286N/A /* (non-Javadoc)
286N/A * @see com.sun.org.apache.xerces.internal.xni.parser.XMLComponent#reset(com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager)
286N/A */
286N/A public void reset(XMLComponentManager componentManager) throws XMLConfigurationException {
286N/A
286N/A fGrammarBucket.reset();
286N/A
286N/A fSubGroupHandler.reset();
286N/A
286N/A boolean parser_settings = componentManager.getFeature(PARSER_SETTINGS, true);
286N/A
286N/A if (!parser_settings || !fSettingsChanged){
286N/A // need to reprocess JAXP schema sources
286N/A fJAXPProcessed = false;
286N/A // reinitialize grammar bucket
286N/A initGrammarBucket();
286N/A return;
286N/A }
286N/A
286N/A //pass the component manager to the factory..
286N/A fNodeFactory.reset(componentManager);
286N/A
286N/A // get registered entity manager to be able to resolve JAXP schema-source property:
286N/A // Note: in case XMLSchemaValidator has created the loader,
286N/A // the entity manager property is null
286N/A fEntityManager = (XMLEntityManager)componentManager.getProperty(ENTITY_MANAGER);
286N/A
286N/A // get the error reporter
286N/A fErrorReporter = (XMLErrorReporter)componentManager.getProperty(ERROR_REPORTER);
286N/A
286N/A // Determine schema dv factory to use
286N/A SchemaDVFactory dvFactory = null;
286N/A dvFactory = fSchemaHandler.getDVFactory();
286N/A if (dvFactory == null) {
286N/A dvFactory = SchemaDVFactory.getInstance();
286N/A fSchemaHandler.setDVFactory(dvFactory);
286N/A }
286N/A
286N/A boolean psvi = componentManager.getFeature(AUGMENT_PSVI, false);
286N/A
286N/A if (!psvi) {
286N/A if (fDeclPool != null) {
286N/A fDeclPool.reset();
286N/A }
286N/A else {
286N/A fDeclPool = new XSDeclarationPool();
286N/A }
286N/A fCMBuilder.setDeclPool(fDeclPool);
286N/A fSchemaHandler.setDeclPool(fDeclPool);
286N/A if (dvFactory instanceof SchemaDVFactoryImpl) {
286N/A fDeclPool.setDVFactory((SchemaDVFactoryImpl)dvFactory);
286N/A ((SchemaDVFactoryImpl)dvFactory).setDeclPool(fDeclPool);
286N/A }
286N/A } else {
286N/A fCMBuilder.setDeclPool(null);
286N/A fSchemaHandler.setDeclPool(null);
286N/A }
286N/A
286N/A // get schema location properties
286N/A try {
286N/A fExternalSchemas = (String) componentManager.getProperty(SCHEMA_LOCATION);
286N/A fExternalNoNSSchema = (String) componentManager.getProperty(SCHEMA_NONS_LOCATION);
286N/A } catch (XMLConfigurationException e) {
286N/A fExternalSchemas = null;
286N/A fExternalNoNSSchema = null;
286N/A }
286N/A
286N/A // get JAXP sources if available
286N/A fJAXPSource = componentManager.getProperty(JAXP_SCHEMA_SOURCE, null);
286N/A fJAXPProcessed = false;
286N/A
286N/A // clear grammars, and put the one for schema namespace there
286N/A fGrammarPool = (XMLGrammarPool) componentManager.getProperty(XMLGRAMMAR_POOL, null);
286N/A initGrammarBucket();
286N/A // get continue-after-fatal-error feature
286N/A try {
286N/A boolean fatalError = componentManager.getFeature(CONTINUE_AFTER_FATAL_ERROR, false);
286N/A if (!fatalError) {
286N/A fErrorReporter.setFeature(CONTINUE_AFTER_FATAL_ERROR, fatalError);
286N/A }
286N/A } catch (XMLConfigurationException e) {
286N/A }
286N/A // set full validation to false
286N/A fIsCheckedFully = componentManager.getFeature(SCHEMA_FULL_CHECKING, false);
286N/A
286N/A // get generate-synthetic-annotations feature
286N/A fSchemaHandler.setGenerateSyntheticAnnotations(componentManager.getFeature(GENERATE_SYNTHETIC_ANNOTATIONS, false));
286N/A fSchemaHandler.reset(componentManager);
559N/A
559N/A faccessExternalDTD = (String) componentManager.getProperty(ACCESS_EXTERNAL_DTD);
559N/A faccessExternalSchema = (String) componentManager.getProperty(ACCESS_EXTERNAL_SCHEMA);
286N/A }
286N/A
286N/A private void initGrammarBucket(){
286N/A if(fGrammarPool != null) {
286N/A Grammar [] initialGrammars = fGrammarPool.retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA);
286N/A for (int i = 0; i < initialGrammars.length; i++) {
286N/A // put this grammar into the bucket, along with grammars
286N/A // imported by it (directly or indirectly)
286N/A if (!fGrammarBucket.putGrammar((SchemaGrammar)(initialGrammars[i]), true)) {
286N/A // REVISIT: a conflict between new grammar(s) and grammars
286N/A // in the bucket. What to do? A warning? An exception?
286N/A fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
286N/A "GrammarConflict", null,
286N/A XMLErrorReporter.SEVERITY_WARNING);
286N/A }
286N/A }
286N/A }
286N/A }
286N/A
286N/A
286N/A /* (non-Javadoc)
286N/A * @see com.sun.org.apache.xerces.internal.xs.XSLoader#getConfig()
286N/A */
286N/A public DOMConfiguration getConfig() {
286N/A return this;
286N/A }
286N/A
286N/A /* (non-Javadoc)
286N/A * @see com.sun.org.apache.xerces.internal.xs.XSLoader#load(org.w3c.dom.ls.LSInput)
286N/A */
286N/A public XSModel load(LSInput is) {
286N/A try {
286N/A Grammar g = loadGrammar(dom2xmlInputSource(is));
286N/A return ((XSGrammar) g).toXSModel();
286N/A } catch (Exception e) {
286N/A reportDOMFatalError(e);
286N/A return null;
286N/A }
286N/A }
286N/A
286N/A /* (non-Javadoc)
286N/A * @see com.sun.org.apache.xerces.internal.xs.XSLoader#loadInputList(com.sun.org.apache.xerces.internal.xs.DOMInputList)
286N/A */
286N/A public XSModel loadInputList(LSInputList is) {
286N/A int length = is.getLength();
286N/A SchemaGrammar[] gs = new SchemaGrammar[length];
286N/A for (int i = 0; i < length; i++) {
286N/A try {
286N/A gs[i] = (SchemaGrammar) loadGrammar(dom2xmlInputSource(is.item(i)));
286N/A } catch (Exception e) {
286N/A reportDOMFatalError(e);
286N/A return null;
286N/A }
286N/A }
286N/A return new XSModelImpl(gs);
286N/A }
286N/A
286N/A /* (non-Javadoc)
286N/A * @see com.sun.org.apache.xerces.internal.xs.XSLoader#loadURI(java.lang.String)
286N/A */
286N/A public XSModel loadURI(String uri) {
286N/A try {
286N/A Grammar g = loadGrammar(new XMLInputSource(null, uri, null));
286N/A return ((XSGrammar)g).toXSModel();
286N/A }
286N/A catch (Exception e){
286N/A reportDOMFatalError(e);
286N/A return null;
286N/A }
286N/A }
286N/A
286N/A /* (non-Javadoc)
286N/A * @see com.sun.org.apache.xerces.internal.xs.XSLoader#loadURIList(com.sun.org.apache.xerces.internal.xs.StringList)
286N/A */
286N/A public XSModel loadURIList(StringList uriList) {
286N/A int length = uriList.getLength();
286N/A SchemaGrammar[] gs = new SchemaGrammar[length];
286N/A for (int i = 0; i < length; i++) {
286N/A try {
286N/A gs[i] =
286N/A (SchemaGrammar) loadGrammar(new XMLInputSource(null, uriList.item(i), null));
286N/A } catch (Exception e) {
286N/A reportDOMFatalError(e);
286N/A return null;
286N/A }
286N/A }
286N/A return new XSModelImpl(gs);
286N/A }
286N/A
286N/A void reportDOMFatalError(Exception e) {
286N/A if (fErrorHandler != null) {
286N/A DOMErrorImpl error = new DOMErrorImpl();
286N/A error.fException = e;
286N/A error.fMessage = e.getMessage();
286N/A error.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
286N/A fErrorHandler.getErrorHandler().handleError(error);
286N/A }
286N/A }
286N/A
286N/A /* (non-Javadoc)
286N/A * @see DOMConfiguration#canSetParameter(String, Object)
286N/A */
286N/A public boolean canSetParameter(String name, Object value) {
286N/A if(value instanceof Boolean){
286N/A if (name.equals(Constants.DOM_VALIDATE) ||
286N/A name.equals(SCHEMA_FULL_CHECKING) ||
286N/A name.equals(VALIDATE_ANNOTATIONS) ||
286N/A name.equals(CONTINUE_AFTER_FATAL_ERROR) ||
286N/A name.equals(ALLOW_JAVA_ENCODINGS) ||
286N/A name.equals(STANDARD_URI_CONFORMANT_FEATURE) ||
286N/A name.equals(GENERATE_SYNTHETIC_ANNOTATIONS) ||
286N/A name.equals(HONOUR_ALL_SCHEMALOCATIONS) ||
286N/A name.equals(NAMESPACE_GROWTH) ||
286N/A name.equals(TOLERATE_DUPLICATES) ||
286N/A name.equals(USE_SERVICE_MECHANISM)) {
286N/A return true;
286N/A
286N/A }
286N/A return false;
286N/A }
286N/A if (name.equals(Constants.DOM_ERROR_HANDLER) ||
286N/A name.equals(Constants.DOM_RESOURCE_RESOLVER) ||
286N/A name.equals(SYMBOL_TABLE) ||
286N/A name.equals(ERROR_REPORTER) ||
286N/A name.equals(ERROR_HANDLER) ||
286N/A name.equals(ENTITY_RESOLVER) ||
286N/A name.equals(XMLGRAMMAR_POOL) ||
286N/A name.equals(SCHEMA_LOCATION) ||
286N/A name.equals(SCHEMA_NONS_LOCATION) ||
286N/A name.equals(JAXP_SCHEMA_SOURCE) ||
286N/A name.equals(SCHEMA_DV_FACTORY)) {
286N/A return true;
286N/A }
286N/A return false;
286N/A }
286N/A
286N/A /* (non-Javadoc)
286N/A * @see DOMConfiguration#getParameter(String)
286N/A */
286N/A public Object getParameter(String name) throws DOMException {
286N/A
286N/A if (name.equals(Constants.DOM_ERROR_HANDLER)){
286N/A return (fErrorHandler != null) ? fErrorHandler.getErrorHandler() : null;
286N/A }
286N/A else if (name.equals(Constants.DOM_RESOURCE_RESOLVER)) {
286N/A return (fResourceResolver != null) ? fResourceResolver.getEntityResolver() : null;
286N/A }
286N/A
286N/A try {
286N/A boolean feature = getFeature(name);
286N/A return (feature) ? Boolean.TRUE : Boolean.FALSE;
286N/A } catch (Exception e) {
286N/A Object property;
286N/A try {
286N/A property = getProperty(name);
286N/A return property;
286N/A } catch (Exception ex) {
286N/A String msg =
286N/A DOMMessageFormatter.formatMessage(
286N/A DOMMessageFormatter.DOM_DOMAIN,
286N/A "FEATURE_NOT_SUPPORTED",
286N/A new Object[] { name });
286N/A throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
286N/A }
286N/A }
286N/A }
286N/A
286N/A /* (non-Javadoc)
286N/A * @see DOMConfiguration#getParameterNames()
286N/A */
286N/A public DOMStringList getParameterNames() {
286N/A if (fRecognizedParameters == null){
286N/A Vector v = new Vector();
286N/A v.add(Constants.DOM_VALIDATE);
286N/A v.add(Constants.DOM_ERROR_HANDLER);
286N/A v.add(Constants.DOM_RESOURCE_RESOLVER);
286N/A v.add(SYMBOL_TABLE);
286N/A v.add(ERROR_REPORTER);
286N/A v.add(ERROR_HANDLER);
286N/A v.add(ENTITY_RESOLVER);
286N/A v.add(XMLGRAMMAR_POOL);
286N/A v.add(SCHEMA_LOCATION);
286N/A v.add(SCHEMA_NONS_LOCATION);
286N/A v.add(JAXP_SCHEMA_SOURCE);
286N/A v.add(SCHEMA_FULL_CHECKING);
286N/A v.add(CONTINUE_AFTER_FATAL_ERROR);
286N/A v.add(ALLOW_JAVA_ENCODINGS);
286N/A v.add(STANDARD_URI_CONFORMANT_FEATURE);
286N/A v.add(VALIDATE_ANNOTATIONS);
286N/A v.add(GENERATE_SYNTHETIC_ANNOTATIONS);
286N/A v.add(HONOUR_ALL_SCHEMALOCATIONS);
286N/A v.add(NAMESPACE_GROWTH);
286N/A v.add(TOLERATE_DUPLICATES);
286N/A v.add(USE_SERVICE_MECHANISM);
286N/A fRecognizedParameters = new DOMStringListImpl(v);
286N/A }
286N/A return fRecognizedParameters;
286N/A }
286N/A
286N/A /* (non-Javadoc)
286N/A * @see DOMConfiguration#setParameter(String, Object)
286N/A */
286N/A public void setParameter(String name, Object value) throws DOMException {
286N/A if (value instanceof Boolean) {
286N/A boolean state = ((Boolean) value).booleanValue();
286N/A if (name.equals("validate") && state) {
286N/A return;
286N/A }
286N/A try {
286N/A setFeature(name, state);
286N/A } catch (Exception e) {
286N/A String msg =
286N/A DOMMessageFormatter.formatMessage(
286N/A DOMMessageFormatter.DOM_DOMAIN,
286N/A "FEATURE_NOT_SUPPORTED",
286N/A new Object[] { name });
286N/A throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
286N/A }
286N/A return;
286N/A }
286N/A if (name.equals(Constants.DOM_ERROR_HANDLER)) {
286N/A if (value instanceof DOMErrorHandler) {
286N/A try {
286N/A fErrorHandler = new DOMErrorHandlerWrapper((DOMErrorHandler) value);
286N/A setErrorHandler(fErrorHandler);
286N/A } catch (XMLConfigurationException e) {
286N/A }
286N/A } else {
286N/A // REVISIT: type mismatch
286N/A String msg =
286N/A DOMMessageFormatter.formatMessage(
286N/A DOMMessageFormatter.DOM_DOMAIN,
286N/A "FEATURE_NOT_SUPPORTED",
286N/A new Object[] { name });
286N/A throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
286N/A }
286N/A return;
286N/A
286N/A }
286N/A if (name.equals(Constants.DOM_RESOURCE_RESOLVER)) {
286N/A if (value instanceof LSResourceResolver) {
286N/A try {
286N/A fResourceResolver = new DOMEntityResolverWrapper((LSResourceResolver) value);
286N/A setEntityResolver(fResourceResolver);
286N/A }
286N/A catch (XMLConfigurationException e) {}
286N/A } else {
286N/A // REVISIT: type mismatch
286N/A String msg =
286N/A DOMMessageFormatter.formatMessage(
286N/A DOMMessageFormatter.DOM_DOMAIN,
286N/A "FEATURE_NOT_SUPPORTED",
286N/A new Object[] { name });
286N/A throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
286N/A }
286N/A return;
286N/A }
286N/A
286N/A try {
286N/A setProperty(name, value);
286N/A } catch (Exception ex) {
286N/A
286N/A String msg =
286N/A DOMMessageFormatter.formatMessage(
286N/A DOMMessageFormatter.DOM_DOMAIN,
286N/A "FEATURE_NOT_SUPPORTED",
286N/A new Object[] { name });
286N/A throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
286N/A
286N/A }
286N/A
286N/A }
286N/A
286N/A XMLInputSource dom2xmlInputSource(LSInput is) {
286N/A // need to wrap the LSInput with an XMLInputSource
286N/A XMLInputSource xis = null;
286N/A
286N/A /**
286N/A * An LSParser looks at inputs specified in LSInput in
286N/A * the following order: characterStream, byteStream,
286N/A * stringData, systemId, publicId. For consistency
286N/A * have the same behaviour for XSLoader.
286N/A */
286N/A
286N/A // check whether there is a Reader
286N/A // according to DOM, we need to treat such reader as "UTF-16".
286N/A if (is.getCharacterStream() != null) {
286N/A xis = new XMLInputSource(is.getPublicId(), is.getSystemId(),
286N/A is.getBaseURI(), is.getCharacterStream(),
286N/A "UTF-16");
286N/A }
286N/A // check whether there is an InputStream
286N/A else if (is.getByteStream() != null) {
286N/A xis = new XMLInputSource(is.getPublicId(), is.getSystemId(),
286N/A is.getBaseURI(), is.getByteStream(),
286N/A is.getEncoding());
286N/A }
286N/A // if there is a string data, use a StringReader
286N/A // according to DOM, we need to treat such data as "UTF-16".
286N/A else if (is.getStringData() != null && is.getStringData().length() != 0) {
286N/A xis = new XMLInputSource(is.getPublicId(), is.getSystemId(),
286N/A is.getBaseURI(), new StringReader(is.getStringData()),
286N/A "UTF-16");
286N/A }
286N/A // otherwise, just use the public/system/base Ids
286N/A else {
286N/A xis = new XMLInputSource(is.getPublicId(), is.getSystemId(),
286N/A is.getBaseURI());
286N/A }
286N/A
286N/A return xis;
286N/A }
286N/A
286N/A} // XMLGrammarLoader