FileDocCategorySizeDatePackage
XMLSchemaLoader.javaAPI DocJava SE 5 API52256Fri Aug 26 14:55:50 BST 2005com.sun.org.apache.xerces.internal.impl.xs

XMLSchemaLoader

public class XMLSchemaLoader extends Object implements XMLGrammarLoader, XSLoader, DOMConfiguration, XMLComponent
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.

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.

author
Neil Graham, IBM
version
$Id: XMLSchemaLoader.java,v 1.26 2004/01/29 22:26:00 mrglavas Exp $

Fields Summary
protected static final String
SCHEMA_FULL_CHECKING
Feature identifier: schema full checking
protected static final String
CONTINUE_AFTER_FATAL_ERROR
Feature identifier: continue after fatal error.
protected static final String
ALLOW_JAVA_ENCODINGS
Feature identifier: allow java encodings to be recognized when parsing schema docs.
protected static final String
STANDARD_URI_CONFORMANT_FEATURE
Feature identifier: standard uri conformant feature.
protected static final String
DISALLOW_DOCTYPE
Feature: disallow doctype
protected static final String
AUGMENT_PSVI
protected static final String
PARSER_SETTINGS
private static final String[]
RECOGNIZED_FEATURES
public static final String
SYMBOL_TABLE
Property identifier: symbol table.
public static final String
ERROR_REPORTER
Property identifier: error reporter.
protected static final String
ERROR_HANDLER
Property identifier: error handler.
public static final String
ENTITY_RESOLVER
Property identifier: entity resolver.
public static final String
XMLGRAMMAR_POOL
Property identifier: grammar pool.
protected static final String
SCHEMA_LOCATION
Property identifier: schema location.
protected static final String
SCHEMA_NONS_LOCATION
Property identifier: no namespace schema location.
protected static final String
JAXP_SCHEMA_SOURCE
Property identifier: JAXP schema source.
protected static final String
SECURITY_MANAGER
protected static final String
ENTITY_MANAGER
private static final String[]
RECOGNIZED_PROPERTIES
private ParserConfigurationSettings
fLoaderConfig
private SymbolTable
fSymbolTable
private XMLErrorReporter
fErrorReporter
private XMLEntityManager
fEntityManager
private XMLEntityResolver
fUserEntityResolver
private XMLGrammarPool
fGrammarPool
private String
fExternalSchemas
private String
fExternalNoNSSchema
private Object
fJAXPSource
private boolean
fIsCheckedFully
private boolean
fJAXPProcessed
private boolean
fSettingsChanged
private XSDHandler
fSchemaHandler
private XSGrammarBucket
fGrammarBucket
private XSDeclarationPool
fDeclPool
private SubstitutionGroupHandler
fSubGroupHandler
private CMBuilder
fCMBuilder
private XSDDescription
fXSDDescription
private Hashtable
fJAXPCache
private Locale
fLocale
private DOMStringList
fRecognizedParameters
private DOMErrorHandlerWrapper
fErrorHandler
DOM L3 error handler
Constructors Summary
public XMLSchemaLoader()


    // default constructor.  Create objects we absolutely need:
      
        this( new SymbolTable(), null, new XMLEntityManager(), null, null, null);
    
public XMLSchemaLoader(SymbolTable symbolTable)

        this( symbolTable, null, new XMLEntityManager(), null, null, null);
    
XMLSchemaLoader(XMLErrorReporter errorReporter, XSGrammarBucket grammarBucket, SubstitutionGroupHandler sHandler, CMBuilder builder)
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

        this(null, errorReporter, new XMLEntityManager(), 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;
    
Methods Summary
public booleancanSetParameter(java.lang.String name, java.lang.Object value)

		if(value instanceof Boolean){
//			boolean state = ((Boolean)value).booleanValue();
			if (name.equals(Constants.DOM_VALIDATE) ||
			    name.equals(SCHEMA_FULL_CHECKING) ||
			    name.equals(CONTINUE_AFTER_FATAL_ERROR) ||
			    name.equals(ALLOW_JAVA_ENCODINGS) ||
			    name.equals(STANDARD_URI_CONFORMANT_FEATURE)){
			    	return true;

			}
			return false;			
		}
		if (name.equals(Constants.DOM_ERROR_HANDLER)||
		    name.equals(SYMBOL_TABLE) ||
			name.equals(ERROR_REPORTER) ||
			name.equals(ERROR_HANDLER) ||
			name.equals(ENTITY_RESOLVER) ||
			name.equals(XMLGRAMMAR_POOL) ||
			name.equals(SCHEMA_LOCATION) ||
			name.equals(SCHEMA_NONS_LOCATION) ||
			name.equals(JAXP_SCHEMA_SOURCE)){
				return true;
		}
        return false;
    
private com.sun.org.apache.xerces.internal.xni.parser.XMLInputSourcedom2xmlInputSource(org.w3c.dom.ls.LSInput is)

		// need to wrap the LSInput with an XMLInputSource
		XMLInputSource xis = null;
		// if there is a string data, use a StringReader
		// according to DOM, we need to treat such data as "UTF-16".
		if (is.getStringData() != null) {
			xis = new XMLInputSource(is.getPublicId(), is.getSystemId(),
									 is.getBaseURI(), new StringReader(is.getStringData()),
									 "UTF-16");
		}
		// check whether there is a Reader
		// according to DOM, we need to treat such reader as "UTF-16".
		else if (is.getCharacterStream() != null) {
			xis = new XMLInputSource(is.getPublicId(), is.getSystemId(),
									 is.getBaseURI(), is.getCharacterStream(),
									 "UTF-16");
		}
		// check whether there is an InputStream
		else if (is.getByteStream() != null) {
			xis = new XMLInputSource(is.getPublicId(), is.getSystemId(),
									 is.getBaseURI(), is.getByteStream(),
									 is.getEncoding());
		}
		// otherwise, just use the public/system/base Ids
		else {
			xis = new XMLInputSource(is.getPublicId(), is.getSystemId(),
									 is.getBaseURI());
		}

		return xis;
	
public org.w3c.dom.DOMConfigurationgetConfig()

        return this;
    
public com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolvergetEntityResolver()
Returns the registered entity resolver.

        return fUserEntityResolver;
    
public com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandlergetErrorHandler()
Returns the registered error handler.

        return fErrorReporter.getErrorHandler();
    
public booleangetFeature(java.lang.String featureId)
Returns the state of a feature.

param
featureId The feature identifier.
throws
XMLConfigurationException Thrown on configuration error.

                
        return fLoaderConfig.getFeature(featureId);        
    
public java.lang.BooleangetFeatureDefault(java.lang.String featureId)

		if (featureId.equals(AUGMENT_PSVI)){
            return Boolean.TRUE;
		}
		return null;
	
public java.util.LocalegetLocale()
Return the Locale the XMLGrammarLoader is using.

        return fLocale;
    
public java.lang.ObjectgetParameter(java.lang.String name)

		if (name.equals(Constants.DOM_ERROR_HANDLER)){
			if (fErrorHandler != null){
				return fErrorHandler.getErrorHandler();
			}
		}
        try {
            boolean feature = getFeature(name);
            return (feature) ? Boolean.TRUE : Boolean.FALSE;
        } catch (Exception e) {
            Object property;
            try {
                property = getProperty(name);
                return property;
            } catch (Exception ex) {
                String msg =
                    DOMMessageFormatter.formatMessage(
                        DOMMessageFormatter.DOM_DOMAIN,
                        "FEATURE_NOT_SUPPORTED",
                        new Object[] { name });
                throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
            }
        }
    
public org.w3c.dom.DOMStringListgetParameterNames()

        if (fRecognizedParameters == null){
        	Vector v = new Vector();
			v.add("validate");
			v.add(SYMBOL_TABLE);
			v.add(ERROR_REPORTER);
			v.add(ERROR_HANDLER);
			v.add(ENTITY_RESOLVER);
			v.add(XMLGRAMMAR_POOL);
			v.add(SCHEMA_LOCATION);
			v.add(SCHEMA_NONS_LOCATION);
			v.add(JAXP_SCHEMA_SOURCE);
			v.add(SCHEMA_FULL_CHECKING);
			v.add(CONTINUE_AFTER_FATAL_ERROR);
			v.add(ALLOW_JAVA_ENCODINGS);
			v.add(STANDARD_URI_CONFORMANT_FEATURE);
        	fRecognizedParameters = new DOMStringListImpl(v);      	
        }
        return fRecognizedParameters;
    
public java.lang.ObjectgetProperty(java.lang.String propertyId)
Returns the state of a property.

param
propertyId The property identifier.
throws
XMLConfigurationException Thrown on configuration error.

        return fLoaderConfig.getProperty(propertyId);
    
public java.lang.ObjectgetPropertyDefault(java.lang.String propertyId)

        // TODO Auto-generated method stub
        return null;
    
public java.lang.String[]getRecognizedFeatures()
Returns a list of feature identifiers that are recognized by this XMLGrammarLoader. This method may return null if no features are recognized.

        return (String[])(RECOGNIZED_FEATURES.clone());
    
public java.lang.String[]getRecognizedProperties()
Returns a list of property identifiers that are recognized by this XMLGrammarLoader. This method may return null if no properties are recognized.

        return (String[])(RECOGNIZED_PROPERTIES.clone());
    
private voidinitGrammarBucket()

		if(fGrammarPool != null) {
			Grammar [] initialGrammars = fGrammarPool.retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA);
			for (int i = 0; i < initialGrammars.length; i++) {
				// put this grammar into the bucket, along with grammars
				// imported by it (directly or indirectly)
				if (!fGrammarBucket.putGrammar((SchemaGrammar)(initialGrammars[i]), true)) {
					// REVISIT: a conflict between new grammar(s) and grammars
					// in the bucket. What to do? A warning? An exception?
					fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
																 "GrammarConflict", null,
																 XMLErrorReporter.SEVERITY_WARNING);
				}
			}
		}
	
public com.sun.org.apache.xerces.internal.xs.XSModelload(org.w3c.dom.ls.LSInput is)

        try {
            Grammar g = loadGrammar(dom2xmlInputSource(is));
            return ((XSGrammar) g).toXSModel();
        } catch (Exception e) {
            if (fErrorHandler != null) {
                DOMErrorImpl error = new DOMErrorImpl();
                error.fException = e;
                error.fMessage = e.getMessage();
                error.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
                fErrorHandler.getErrorHandler().handleError(error);
            }
            return null;
        }
    
public com.sun.org.apache.xerces.internal.xni.grammars.GrammarloadGrammar(com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource source)
Returns a Grammar object by parsing the contents of the entity pointed to by source.

param
source the location of the entity which forms the starting point of the grammar to be constructed.
throws
IOException When a problem is encountered reading the entity XNIException When a condition arises (such as a FatalError) that requires parsing of the entity be terminated.

        return loadGrammar( source.toSource() );
    
public com.sun.org.apache.xerces.internal.xni.grammars.GrammarloadGrammar(javax.xml.transform.Source source)

                    
        // REVISIT: this method should have a namespace parameter specified by 
        // user. In this case we can easily detect if a schema asked to be loaded
        // is already in the local cache.
              	
        reset(fLoaderConfig);
        fSettingsChanged = false;
        XSDDescription desc = new XSDDescription();
        desc.fContextType = XSDDescription.CONTEXT_PREPARSE;
        desc.setLiteralSystemId( source.getSystemId());
        // none of the other fields make sense for preparsing
        Hashtable locationPairs = new Hashtable();
        // Process external schema location properties.
        // We don't call tokenizeSchemaLocationStr here, because we also want
        // to check whether the values are valid URI.
        processExternalHints(fExternalSchemas, fExternalNoNSSchema,
                             locationPairs, fErrorReporter);
        SchemaGrammar grammar = loadSchema(desc, source, locationPairs);

        if(grammar != null && fGrammarPool != null) {
            fGrammarPool.cacheGrammars(XMLGrammarDescription.XML_SCHEMA, fGrammarBucket.getGrammars());
            // NOTE: we only need to verify full checking in case the schema was not provided via JAXP
            // since full checking already verified for all JAXP schemas
            if(fIsCheckedFully && fJAXPCache.get(grammar) != grammar) {
                XSConstraints.fullSchemaChecking(fGrammarBucket, fSubGroupHandler, fCMBuilder, fErrorReporter);
            }
        }
        return grammar;
    
public com.sun.org.apache.xerces.internal.xs.XSModelloadInputList(com.sun.org.apache.xerces.internal.xs.LSInputList is)

        int length = is.getLength();
        if (length == 0) {
            return null;
        }
        SchemaGrammar[] gs = new SchemaGrammar[length];
        for (int i = 0; i < length; i++) {
            try {
                gs[i] = (SchemaGrammar) loadGrammar(dom2xmlInputSource(is.item(i)));
            } catch (Exception e) {
                if (fErrorHandler != null) {
                    DOMErrorImpl error = new DOMErrorImpl();
                    error.fException = e;
                    error.fMessage = e.getMessage();
                    error.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
                    fErrorHandler.getErrorHandler().handleError(error);
                }
                return null;
            }
        }
        return new XSModelImpl(gs);
    
com.sun.org.apache.xerces.internal.impl.xs.SchemaGrammarloadSchema(com.sun.org.apache.xerces.internal.impl.xs.XSDDescription desc, javax.xml.transform.Source source, java.util.Hashtable locationPairs)
This method is called either from XMLGrammarLoader.loadGrammar or from XMLSchemaValidator. Note: in either case, the EntityManager (or EntityResolvers) are not going to be invoked to resolve the location of the schema in XSDDescription

param
desc
param
source
param
locationPairs
return
An XML Schema grammar
throws
IOException
throws
XNIException


        // this should only be done once per invocation of this object;
        // unless application alters JAXPSource in the mean time.
        if(!fJAXPProcessed) {
            processJAXPSchemaSource(locationPairs);
        }
        SchemaGrammar grammar = fSchemaHandler.parseSchema(source, desc, locationPairs);

        return grammar;
    
public com.sun.org.apache.xerces.internal.xs.XSModelloadURI(java.lang.String uri)

    	try {
			Grammar g = loadGrammar(new XMLInputSource(null, uri, null));
			return ((XSGrammar)g).toXSModel();
    	}
    	catch (Exception e){
			if (fErrorHandler != null) {
				DOMErrorImpl error = new DOMErrorImpl();
				error.fException = e;
				error.fMessage = e.getMessage();
				error.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
				fErrorHandler.getErrorHandler().handleError(error);
			}
    		return null;
    	}
    
public com.sun.org.apache.xerces.internal.xs.XSModelloadURIList(com.sun.org.apache.xerces.internal.xs.StringList uriList)

        int length = uriList.getLength();
        if (length == 0) {
            return null;
        }
        SchemaGrammar[] gs = new SchemaGrammar[length];
        for (int i = 0; i < length; i++) {
            try {
                gs[i] =
                    (SchemaGrammar) loadGrammar(new XMLInputSource(null, uriList.item(i), null));
            } catch (Exception e) {
                if (fErrorHandler != null) {
                    DOMErrorImpl error = new DOMErrorImpl();
                    error.fException = e;
                    error.fMessage = e.getMessage();
                    error.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
                    fErrorHandler.getErrorHandler().handleError(error);
                }
                return null;
            }
        }
        return new XSModelImpl(gs);
    
public static voidprocessExternalHints(java.lang.String sl, java.lang.String nsl, java.util.Hashtable locations, com.sun.org.apache.xerces.internal.impl.XMLErrorReporter er)

        if (sl != null) {
            try {
                // get the attribute decl for xsi:schemaLocation
                // because external schema location property has the same syntax
                // as xsi:schemaLocation
                XSAttributeDecl attrDecl = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_SCHEMALOCATION);
                // validation the string value to get the list of URI's
                attrDecl.fType.validate(sl, null, null);
                if (!tokenizeSchemaLocationStr(sl, locations)) {
                    // report warning (odd number of items)
                    er.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
                                   "SchemaLocation",
                                   new Object[]{sl},
                                   XMLErrorReporter.SEVERITY_WARNING);
                }
            }
            catch (InvalidDatatypeValueException ex) {
                // report warning (not list of URI's)
                er.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
                               ex.getKey(), ex.getArgs(),
                               XMLErrorReporter.SEVERITY_WARNING);
            }
        }

        if (nsl != null) {
            try {
                // similarly for no ns schema location property
                XSAttributeDecl attrDecl = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION);
                attrDecl.fType.validate(nsl, null, null);
                LocationArray la = ((LocationArray)locations.get(XMLSymbols.EMPTY_STRING));
                if(la == null) {
                    la = new LocationArray();
                    locations.put(XMLSymbols.EMPTY_STRING, la);
                }
                la.addLocation(nsl);
            }
            catch (InvalidDatatypeValueException ex) {
                // report warning (not a URI)
                er.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
                               ex.getKey(), ex.getArgs(),
                               XMLErrorReporter.SEVERITY_WARNING);
            }
        }
    
private voidprocessJAXPSchemaSource(java.util.Hashtable locationPairs)
Translate the various JAXP SchemaSource property types to XNI XMLInputSource. Valid types are: String, org.xml.sax.InputSource, InputStream, File, or Object[] of any of previous types. REVISIT: the JAXP 1.2 spec is less than clear as to whether this property should be available to imported schemas. I have assumed that it should. - NG Note: all JAXP schema files will be checked for full-schema validity if the feature was set up

        fJAXPProcessed = true;
        if (fJAXPSource == null) {
            return;
        }

        Class componentType = fJAXPSource.getClass().getComponentType();
        XMLInputSource xis = null;
        String sid = null;
        if (componentType == null) {
            // Not an array
            if(fJAXPSource instanceof InputStream ||
                    fJAXPSource instanceof InputSource) {
                SchemaGrammar g = (SchemaGrammar)fJAXPCache.get(fJAXPSource);
                if(g != null) {
                    fGrammarBucket.putGrammar(g);
                    return;
                }
            }
            fXSDDescription.reset();
            xis = xsdToXMLInputSource(fJAXPSource);
            sid = xis.getSystemId();
            fXSDDescription.fContextType = XSDDescription.CONTEXT_PREPARSE;
            if (sid != null) {
                fXSDDescription.setBaseSystemId(xis.getBaseSystemId());
                fXSDDescription.setLiteralSystemId(sid);
                fXSDDescription.setExpandedSystemId(sid);
                fXSDDescription.fLocationHints = new String[]{sid};
            }
            SchemaGrammar g = loadSchema(fXSDDescription, xis.toSource(), locationPairs);
            // it is possible that we won't be able to resolve JAXP schema-source location
            if (g != null){
                if(fJAXPSource instanceof InputStream ||
                    fJAXPSource instanceof InputSource) {
                        fJAXPCache.put(fJAXPSource, g);
                        if(fIsCheckedFully) {
                            XSConstraints.fullSchemaChecking(fGrammarBucket, fSubGroupHandler, fCMBuilder, fErrorReporter);
                        }
                }
                fGrammarBucket.putGrammar(g);
            }
            return ;
        } else if ( (componentType != Object.class) &&
                    (componentType != String.class) &&
                    (componentType != File.class) &&
                    (componentType != InputStream.class) &&
                    (componentType != InputSource.class)
                  ) {
            // Not an Object[], String[], File[], InputStream[], InputSource[]
            throw new XMLConfigurationException(
                XMLConfigurationException.NOT_SUPPORTED, "\""+JAXP_SCHEMA_SOURCE+
                "\" property cannot have an array of type {"+componentType.getName()+
                "}. Possible types of the array supported are Object, String, File, "+
                "InputStream, InputSource.");
        }

        // JAXP spec. allow []s of type String, File, InputStream,
        // InputSource also, apart from [] of type Object.
        Object[] objArr = (Object[]) fJAXPSource;
        //make local vector for storing targetn namespaces of schemasources specified in object arrays.
        Vector jaxpSchemaSourceNamespaces = new Vector() ;
        for (int i = 0; i < objArr.length; i++) {
            if(objArr[i] instanceof InputStream ||
                    objArr[i] instanceof InputSource) {
                SchemaGrammar g = (SchemaGrammar)fJAXPCache.get(objArr[i]);
                if (g != null) {
                    fGrammarBucket.putGrammar(g);
                    continue;
                }
            }
            fXSDDescription.reset();
            xis = xsdToXMLInputSource(objArr[i]);
            sid = xis.getSystemId();
            fXSDDescription.fContextType = XSDDescription.CONTEXT_PREPARSE;
            if (sid != null) {
                fXSDDescription.setBaseSystemId(xis.getBaseSystemId());
                fXSDDescription.setLiteralSystemId(sid);
                fXSDDescription.setExpandedSystemId(sid);
                fXSDDescription.fLocationHints = new String[]{sid};
            }
            String targetNamespace = null ;
            // load schema
			SchemaGrammar grammar = fSchemaHandler.parseSchema(xis.toSource(),fXSDDescription, locationPairs);

			if(fIsCheckedFully) {
				XSConstraints.fullSchemaChecking(fGrammarBucket, fSubGroupHandler, fCMBuilder, fErrorReporter);
			}                                   
            if(grammar != null){
                targetNamespace = grammar.getTargetNamespace() ;
                if(jaxpSchemaSourceNamespaces.contains(targetNamespace)){
                    //when an array of objects is passed it is illegal to have two schemas that share same namespace.
                    throw new java.lang.IllegalArgumentException(
                        " When using array of Objects as the value of SCHEMA_SOURCE property , " +
                        "no two Schemas should share the same targetNamespace. " );
                }
                else{
                    jaxpSchemaSourceNamespaces.add(targetNamespace) ;
                }
                if(objArr[i] instanceof InputStream ||
                        objArr[i] instanceof InputSource) {
                    fJAXPCache.put(objArr[i], grammar);
                }
                fGrammarBucket.putGrammar(grammar);
            }
            else{
                //REVISIT: What should be the acutal behavior if grammar can't be loaded as specified in schema source?
            }
        }
    
public voidreset(com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager componentManager)

		
		fGrammarBucket.reset();
        
		fSubGroupHandler.reset();		
		
		// set full validation to false
		fIsCheckedFully = false;
        boolean parser_settings;
        try {
            parser_settings = componentManager.getFeature(PARSER_SETTINGS);     
        }
        catch (XMLConfigurationException e){
            parser_settings = true;
        }
        if (!parser_settings || !fSettingsChanged){            
            // reinitialize grammar bucket
            initGrammarBucket();
            return;           
        } 
        
        // get registered entity manager to be able to resolve JAXP schema-source property:
        // Note: in case XMLSchemaValidator has created the loader, 
        // the entity manager property is null
        fEntityManager = (XMLEntityManager)componentManager.getProperty(ENTITY_MANAGER);      
		
        boolean psvi = true;
        try {
            psvi = componentManager.getFeature(AUGMENT_PSVI);
        } catch (XMLConfigurationException e) {
            psvi = false;
        }
        
        if (!psvi) {
            fDeclPool.reset();
            fCMBuilder.setDeclPool(fDeclPool);
            fSchemaHandler.setDeclPool(fDeclPool);
        } else {
            fCMBuilder.setDeclPool(null);
            fSchemaHandler.setDeclPool(null);
        }
        		
		// get schema location properties
		try {
			fExternalSchemas = (String) componentManager.getProperty(SCHEMA_LOCATION);
			fExternalNoNSSchema =
				(String) componentManager.getProperty(SCHEMA_NONS_LOCATION);
		} catch (XMLConfigurationException e) {
			fExternalSchemas = null;
			fExternalNoNSSchema = null;
		}
		// get JAXP sources if available
		try {
			fJAXPSource = componentManager.getProperty(JAXP_SCHEMA_SOURCE);
			fJAXPProcessed = false;

		} catch (XMLConfigurationException e) {
			fJAXPSource = null;
			fJAXPProcessed = false;
		}
		
		// clear grammars, and put the one for schema namespace there
		try {
			fGrammarPool = (XMLGrammarPool) componentManager.getProperty(XMLGRAMMAR_POOL);
		} catch (XMLConfigurationException e) {
			fGrammarPool = null;
		}
		
        initGrammarBucket();
		// get continue-after-fatal-error feature
		try {
			boolean fatalError = componentManager.getFeature(CONTINUE_AFTER_FATAL_ERROR);
			fErrorReporter.setFeature(CONTINUE_AFTER_FATAL_ERROR, fatalError);
		} catch (XMLConfigurationException e) {
		}
        // set full validation to false        
        try {
            fIsCheckedFully = componentManager.getFeature(SCHEMA_FULL_CHECKING);
        }
        catch (XMLConfigurationException e){
            fIsCheckedFully = false;
        }
        		
		fSchemaHandler.reset(componentManager);		 
	
public static com.sun.org.apache.xerces.internal.xni.parser.XMLInputSourceresolveDocument(com.sun.org.apache.xerces.internal.impl.xs.XSDDescription desc, java.util.Hashtable locationPairs, com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver entityResolver)
This method tries to resolve location of the given schema. The loader stores the namespace/location pairs in a hashtable (use "" as the namespace of absent namespace). When resolving an entity, loader first tries to find in the hashtable whether there is a value for that namespace, if so, pass that location value to the user-defined entity resolver.

param
desc
param
locationPairs
param
entityResolver
return
throws
IOException

        String loc = null;
        // we consider the schema location properties for import
        if (desc.getContextType() == XSDDescription.CONTEXT_IMPORT ||
            desc.fromInstance()) {
            // use empty string as the key for absent namespace
            String namespace = desc.getTargetNamespace();
            String ns = namespace == null ? XMLSymbols.EMPTY_STRING : namespace;
            // get the location hint for that namespace
            LocationArray tempLA = (LocationArray)locationPairs.get(ns);
            if(tempLA != null)
                loc = tempLA.getFirstLocation();
        }

        // if it's not import, or if the target namespace is not set
        // in the schema location properties, use location hint
        if (loc == null) {
            String[] hints = desc.getLocationHints();
            if (hints != null && hints.length > 0)
                loc = hints[0];
        }

        String expandedLoc = XMLEntityManager.expandSystemId(loc, desc.getBaseSystemId(), false);
        desc.setLiteralSystemId(loc);
        desc.setExpandedSystemId(expandedLoc);
        return entityResolver.resolveEntity(desc);
    
private static com.sun.org.apache.xerces.internal.xni.parser.XMLInputSourcesaxToXMLInputSource(org.xml.sax.InputSource sis)

        String publicId = sis.getPublicId();
        String systemId = sis.getSystemId();

        Reader charStream = sis.getCharacterStream();
        if (charStream != null) {
            return new XMLInputSource(publicId, systemId, null, charStream,
                                      null);
        }

        InputStream byteStream = sis.getByteStream();
        if (byteStream != null) {
            return new XMLInputSource(publicId, systemId, null, byteStream,
                                      sis.getEncoding());
        }

        return new XMLInputSource(publicId, systemId, null);
    
public voidsetEntityResolver(com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver entityResolver)
Sets the entity resolver.

param
entityResolver The new entity resolver.

        fUserEntityResolver = entityResolver;
        fLoaderConfig.setProperty(ENTITY_RESOLVER, entityResolver);
        fEntityManager.setProperty(ENTITY_RESOLVER, entityResolver);
    
public voidsetErrorHandler(com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler errorHandler)
Sets the error handler.

param
errorHandler The error handler.

        fErrorReporter.setProperty(ERROR_HANDLER, errorHandler);
    
public voidsetFeature(java.lang.String featureId, boolean state)
Sets the state of a feature.

param
featureId The feature identifier.
param
state The state of the feature.
throws
XMLConfigurationException Thrown when a feature is not recognized or cannot be set.

        fSettingsChanged = true; 
        if(featureId.equals(CONTINUE_AFTER_FATAL_ERROR)) {
            fErrorReporter.setFeature(CONTINUE_AFTER_FATAL_ERROR, state);
        } 
        fLoaderConfig.setFeature(featureId, state);
    
public voidsetLocale(java.util.Locale locale)
Set the locale to use for messages.

param
locale The locale object to use for localization of messages.
exception
XNIException Thrown if the parser does not support the specified locale.

        fLocale = locale;
        fErrorReporter.setLocale(locale);
    
public voidsetParameter(java.lang.String name, java.lang.Object value)

        if (value instanceof Boolean) {
            boolean state = ((Boolean) value).booleanValue();
            if (name.equals("validate") && state) {
                return;
            }
            try {
                setFeature(name, state);
            } catch (Exception e) {
                String msg =
                    DOMMessageFormatter.formatMessage(
                        DOMMessageFormatter.DOM_DOMAIN,
                        "FEATURE_NOT_SUPPORTED",
                        new Object[] { name });
                throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
            }
            return;
        }
        if (name.equals(Constants.DOM_ERROR_HANDLER)) {
            if (value instanceof DOMErrorHandler) {
                try {
                    fErrorHandler = new DOMErrorHandlerWrapper((DOMErrorHandler) value);
                    setErrorHandler(fErrorHandler);
                } catch (XMLConfigurationException e) {
                }
            } else {
                // REVISIT: type mismatch
                String msg =
                    DOMMessageFormatter.formatMessage(
                        DOMMessageFormatter.DOM_DOMAIN,
                        "FEATURE_NOT_SUPPORTED",
                        new Object[] { name });
                throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
            }
            return;

        }

        try {
            setProperty(name, value);
        } catch (Exception ex) {

            String msg =
                DOMMessageFormatter.formatMessage(
                    DOMMessageFormatter.DOM_DOMAIN,
                    "FEATURE_NOT_SUPPORTED",
                    new Object[] { name });
            throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);

        }

    
public voidsetProperty(java.lang.String propertyId, java.lang.Object state)
Sets the state of a property.

param
propertyId The property identifier.
param
state The state of the property.
throws
XMLConfigurationException Thrown when a property is not recognized or cannot be set.

                   
        fSettingsChanged = true;            
        fLoaderConfig.setProperty(propertyId, state);    
        if(propertyId.equals( JAXP_SCHEMA_SOURCE)) {
            fJAXPSource = state;
            fJAXPProcessed = false;
        }  
        else if(propertyId.equals( XMLGRAMMAR_POOL)) {
             fGrammarPool = (XMLGrammarPool)state;
        } 
        else if (propertyId.equals(SCHEMA_LOCATION)){
            fExternalSchemas = (String)state;
        }
        else if (propertyId.equals(SCHEMA_NONS_LOCATION)){
            fExternalNoNSSchema = (String) state;
        }
        else if (propertyId.equals(ENTITY_RESOLVER)){
            fEntityManager.setProperty(ENTITY_RESOLVER, state);
        }
        else if (propertyId.equals(ERROR_REPORTER)){
            fErrorReporter = (XMLErrorReporter)state;
            if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) {
            	fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, new XSMessageFormatter());
            }
        }
    
public static booleantokenizeSchemaLocationStr(java.lang.String schemaStr, java.util.Hashtable locations)

        if (schemaStr!= null) {
            StringTokenizer t = new StringTokenizer(schemaStr, " \n\t\r");
            String namespace, location;
            while (t.hasMoreTokens()) {
                namespace = t.nextToken ();
                if (!t.hasMoreTokens()) {
                    return false; // error!
                }
                location = t.nextToken();
                LocationArray la = ((LocationArray)locations.get(namespace));
                if(la == null) {
                    la = new LocationArray();
                    locations.put(namespace, la);
                }
                la.addLocation(location);
            }
        }
        return true;
    
private com.sun.org.apache.xerces.internal.xni.parser.XMLInputSourcexsdToXMLInputSource(java.lang.Object val)

        if (val instanceof String) {
            // String value is treated as a URI that is passed through the
            // EntityResolver
            String loc = (String) val;          
                fXSDDescription.reset();
                fXSDDescription.setValues(null, loc, null, null);
                XMLInputSource xis = null;
                try {
                    xis = fEntityManager.resolveEntity(fXSDDescription);
                } catch (IOException ex) {
                    fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
                        "schema_reference.4",
                                      new Object[] { loc }, XMLErrorReporter.SEVERITY_ERROR);
                }
                if (xis == null) {
                    // REVISIT: can this happen?
                    // Treat value as a URI and pass in as systemId
                    return new XMLInputSource(null, loc, null);
                }
                return xis;
        } else if (val instanceof InputSource) {
            return saxToXMLInputSource((InputSource) val);
        } else if (val instanceof InputStream) {
            return new XMLInputSource(null, null, null,
                                      (InputStream) val, null);
        } else if (val instanceof File) {
            File file = (File) val;
            InputStream is = null;
            try {
                is = new BufferedInputStream(new FileInputStream(file));
            } catch (FileNotFoundException ex) {
                fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
                "schema_reference.4", new Object[] { file.toString() },
                XMLErrorReporter.SEVERITY_ERROR);
            }
            return new XMLInputSource(null, null, null, is, null);
        }
        throw new XMLConfigurationException(
            XMLConfigurationException.NOT_SUPPORTED, "\""+JAXP_SCHEMA_SOURCE+
            "\" property cannot have a value of type {"+val.getClass().getName()+
            "}. Possible types of the value supported are String, File, InputStream, "+
            "InputSource OR an array of these types.");