/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2000-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This class implements xni.grammars.XMLGrammarLoader.
* It also serves as implementation of xs.XSLoader interface and DOMConfiguration interface.
*
* This class is designed to interact either with a proxy for a user application
* which wants to preparse schemas, or with our own Schema validator.
* It is hoped that none of these "external" classes will therefore need to communicate directly
* with XSDHandler in future.
* <p>This class only knows how to make XSDHandler do its thing.
* The caller must ensure that all its properties (schemaLocation, JAXPSchemaSource
* etc.) have been properly set.
*
* @xerces.internal
*
* @author Neil Graham, IBM
* @version $Id: XMLSchemaLoader.java,v 1.10 2010-11-01 04:39:55 joehw Exp $
*/
// XML Component API
// Feature identifiers:
/** Feature identifier: schema full checking*/
/** Feature identifier: continue after fatal error. */
/** Feature identifier: allow java encodings to be recognized when parsing schema docs. */
/** Feature identifier: standard uri conformant feature. */
/** Feature identifier: validate annotations. */
/** Feature: disallow doctype*/
/** Feature: generate synthetic annotations */
/** Feature identifier: honour all schemaLocations */
/** Feature identifier: namespace growth */
/** Feature identifier: tolerate duplicates */
/** Property identifier: Schema DV Factory */
// recognized features:
};
// property identifiers
/** Property identifier: symbol table. */
/** Property identifier: error reporter. */
/** Property identifier: error handler. */
/** Property identifier: entity resolver. */
/** Property identifier: grammar pool. */
/** Property identifier: schema location. */
/** Property identifier: no namespace schema location. */
/** Property identifier: JAXP schema source. */
/** Property identifier: locale. */
/** Property identifier: access to external dtd */
/** Property identifier: access to external schema */
// recognized properties
};
// Data
// features and properties
// JAXP property: schema source
// is Schema Full Checking enabled
private boolean fIsCheckedFully = false;
// boolean that tells whether we've tested the JAXP property.
private boolean fJAXPProcessed = false;
// if features/properties has not been changed, the value of this attribute is "false"
private boolean fSettingsChanged = true;
// xml schema parsing
// XSLoader attributes
/** DOM L3 error handler */
/** DOM L3 resource resolver */
// default constructor. Create objects we absolutely need:
public XMLSchemaLoader() {
}
}
/**
* 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
*/
}
// store properties and features in configuration
if (symbolTable != null){
}
if(errorReporter == null) {
errorReporter = new XMLErrorReporter ();
}
// make sure error reporter knows about schemas...
}
// entity manager is null if XMLSchemaValidator creates the loader
if (fEntityManager != null){
}
// by default augment PSVI (i.e. don't use declaration pool)
if(grammarBucket == null ) {
grammarBucket = new XSGrammarBucket();
}
}
}
}
fJAXPCache = new HashMap();
fSettingsChanged = true;
}
/**
* Returns a list of feature identifiers that are recognized by
* this XMLGrammarLoader. This method may return null if no features
* are recognized.
*/
} // getRecognizedFeatures(): String[]
/**
* Returns the state of a feature.
*
* @param featureId The feature identifier.
*
* @throws XMLConfigurationException Thrown on configuration error.
*/
throws XMLConfigurationException {
} // getFeature (String): boolean
/**
* 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.
*/
boolean state) throws XMLConfigurationException {
fSettingsChanged = true;
}
}
} // setFeature(String, boolean)
/**
* Returns a list of property identifiers that are recognized by
* this XMLGrammarLoader. This method may return null if no properties
* are recognized.
*/
} // getRecognizedProperties(): String[]
/**
* Returns the state of a property.
*
* @param propertyId The property identifier.
*
* @throws XMLConfigurationException Thrown on configuration error.
*/
throws XMLConfigurationException {
} // getProperty(String): Object
/**
* 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;
fJAXPSource = state;
fJAXPProcessed = false;
}
}
}
}
}
}
}
}
}
}
} // setProperty(String, Object)
/**
* 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.
*/
} // setLocale(Locale)
/** Return the Locale the XMLGrammarLoader is using. */
return fLocale;
} // getLocale(): Locale
/**
* Sets the error handler.
*
* @param errorHandler The error handler.
*/
} // setErrorHandler(XMLErrorHandler)
/** Returns the registered error handler. */
return fErrorReporter.getErrorHandler();
} // getErrorHandler(): XMLErrorHandler
/**
* Sets the entity resolver.
*
* @param entityResolver The new entity resolver.
*/
} // setEntityResolver(XMLEntityResolver)
/** Returns the registered entity resolver. */
return fUserEntityResolver;
} // getEntityResolver(): XMLEntityResolver
/**
* Returns a Grammar object by parsing the contents of the
* entities pointed to by sources.
*
* @param source[] the locations of the entity which forms
* the staring point of the grammars to be constructed
* @throws IOException when a problem is encounted reading the entity
* @throws XNIException when a condition arises (such as a FatalError) that requires parsing
* of the entity be terminated
*/
throws IOException, XNIException {
for (int i = 0; i < numSource; ++i) {
loadGrammar(source[i]);
}
}
/**
* 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.
*/
throws IOException, XNIException {
// 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.
fSettingsChanged = false;
// none of the other fields make sense for preparsing
// Process external schema location properties.
// We don't call tokenizeSchemaLocationStr here, because we also want
// to check whether the values are valid URI.
// 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
}
}
return grammar;
} // loadGrammar(XMLInputSource): Grammar
/**
* 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) {
}
if (desc.isExternal()) {
String accessError = SecuritySupport.checkAccess(desc.getExpandedSystemId(), faccessExternalSchema, Constants.ACCESS_EXTERNAL_ALL);
if (accessError != null) {
"schema_reference.access",
new Object[] { SecuritySupport.sanitizePath(desc.getExpandedSystemId()), accessError }, XMLErrorReporter.SEVERITY_ERROR));
}
}
return grammar;
} // loadSchema(XSDDescription, XMLInputSource): SchemaGrammar
/** This method tries to resolve location of the given schema.
* 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
*/
// we consider the schema location properties for import
desc.fromInstance()) {
// use empty string as the key for absent namespace
// get the location hint for that namespace
}
// if it's not import, or if the target namespace is not set
// in the schema location properties, use location hint
}
}
// add external schema locations to the location pairs
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
// report warning (odd number of items)
"SchemaLocation",
}
}
catch (InvalidDatatypeValueException ex) {
// report warning (not list of URI's)
}
}
try {
// similarly for no ns schema location property
XSAttributeDecl attrDecl = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION);
la = new LocationArray();
}
}
catch (InvalidDatatypeValueException ex) {
// report warning (not a URI)
}
}
}
// this method takes a SchemaLocation string.
// If an error is encountered, false is returned;
// otherwise, true is returned. In either case, locations
// is augmented to include as many tokens as possible.
// @param schemaStr The schemaLocation string to tokenize
// @param locations HashMap mapping namespaces to LocationArray objects holding lists of locaitons
// @return true if no problems; false if string could not be tokenized
while (t.hasMoreTokens()) {
if (!t.hasMoreTokens()) {
return false; // error!
}
la = new LocationArray();
}
}
}
return true;
} // tokenizeSchemaLocation(String, HashMap): boolean
/**
* 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;
}
if (componentType == null) {
// Not an array
if(fJAXPSource instanceof InputStream ||
fJAXPSource instanceof InputSource) {
if(g != null) {
return;
}
}
}
// 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) {
if(fIsCheckedFully) {
}
}
}
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(
"}. 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.
//make local vector for storing targetn namespaces of schemasources specified in object arrays.
if(objArr[i] instanceof InputStream ||
objArr[i] instanceof InputSource) {
if (g != null) {
continue;
}
}
}
// load schema
if(fIsCheckedFully) {
}
//when an array of objects is passed it is illegal to have two schemas that share same namespace.
" When using array of Objects as the value of SCHEMA_SOURCE property , " +
"no two Schemas should share the same targetNamespace. " );
}
else{
}
if(objArr[i] instanceof InputStream ||
objArr[i] instanceof InputSource) {
}
}
else{
//REVISIT: What should be the acutal behavior if grammar can't be loaded as specified in schema source?
}
}
}//processJAXPSchemaSource
{
// String value is treated as a URI that is passed through the
// EntityResolver
try {
} catch (IOException ex) {
"schema_reference.4",
}
// REVISIT: can this happen?
// Treat value as a URI and pass in as systemId
}
return xis;
} else if (val instanceof InputSource) {
} else if (val instanceof InputStream) {
try {
} catch (FileNotFoundException ex) {
}
}
throw new XMLConfigurationException(
"}. Possible types of the value supported are String, File, InputStream, "+
"InputSource OR an array of these types.");
}
//Convert a SAX InputSource to an equivalent XNI XMLInputSource
if (charStream != null) {
null);
}
if (byteStream != null) {
sis.getEncoding());
}
}
static class LocationArray{
int length ;
}
}
}//setLocation()
}
return locations;
}//getLocationArray()
}
public int getLength(){
return length ;
}
} //locationArray
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xni.parser.XMLComponent#getFeatureDefault(java.lang.String)
*/
}
return null;
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xni.parser.XMLComponent#getPropertyDefault(java.lang.String)
*/
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xni.parser.XMLComponent#reset(com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager)
*/
if (!parser_settings || !fSettingsChanged){
// need to reprocess JAXP schema sources
fJAXPProcessed = false;
// reinitialize grammar bucket
return;
}
//pass the component manager to the factory..
// 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
// get the error reporter
// Determine schema dv factory to use
}
if (!psvi) {
}
else {
fDeclPool = new XSDeclarationPool();
}
if (dvFactory instanceof SchemaDVFactoryImpl) {
}
} else {
}
// get schema location properties
try {
} catch (XMLConfigurationException e) {
}
// get JAXP sources if available
fJAXPProcessed = false;
// clear grammars, and put the one for schema namespace there
// get continue-after-fatal-error feature
try {
if (!fatalError) {
}
} catch (XMLConfigurationException e) {
}
// set full validation to false
// get generate-synthetic-annotations feature
fSchemaHandler.setGenerateSyntheticAnnotations(componentManager.getFeature(GENERATE_SYNTHETIC_ANNOTATIONS, false));
}
private void initGrammarBucket(){
if(fGrammarPool != null) {
Grammar [] initialGrammars = fGrammarPool.retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA);
// put this grammar into the bucket, along with grammars
// imported by it (directly or indirectly)
// REVISIT: a conflict between new grammar(s) and grammars
// in the bucket. What to do? A warning? An exception?
"GrammarConflict", null,
}
}
}
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xs.XSLoader#getConfig()
*/
return this;
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xs.XSLoader#load(org.w3c.dom.ls.LSInput)
*/
try {
} catch (Exception e) {
return null;
}
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xs.XSLoader#loadInputList(com.sun.org.apache.xerces.internal.xs.DOMInputList)
*/
for (int i = 0; i < length; i++) {
try {
} catch (Exception e) {
return null;
}
}
return new XSModelImpl(gs);
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xs.XSLoader#loadURI(java.lang.String)
*/
try {
}
catch (Exception e){
return null;
}
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xs.XSLoader#loadURIList(com.sun.org.apache.xerces.internal.xs.StringList)
*/
for (int i = 0; i < length; i++) {
try {
gs[i] =
} catch (Exception e) {
return null;
}
}
return new XSModelImpl(gs);
}
if (fErrorHandler != null) {
error.fException = e;
}
}
/* (non-Javadoc)
* @see DOMConfiguration#canSetParameter(String, Object)
*/
return true;
}
return false;
}
return true;
}
return false;
}
/* (non-Javadoc)
* @see DOMConfiguration#getParameter(String)
*/
}
}
try {
} catch (Exception e) {
try {
return property;
"FEATURE_NOT_SUPPORTED",
}
}
}
/* (non-Javadoc)
* @see DOMConfiguration#getParameterNames()
*/
if (fRecognizedParameters == null){
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(NAMESPACE_GROWTH);
fRecognizedParameters = new DOMStringListImpl(v);
}
return fRecognizedParameters;
}
/* (non-Javadoc)
* @see DOMConfiguration#setParameter(String, Object)
*/
return;
}
try {
} catch (Exception e) {
"FEATURE_NOT_SUPPORTED",
}
return;
}
if (value instanceof DOMErrorHandler) {
try {
} catch (XMLConfigurationException e) {
}
} else {
// REVISIT: type mismatch
"FEATURE_NOT_SUPPORTED",
}
return;
}
if (value instanceof LSResourceResolver) {
try {
}
catch (XMLConfigurationException e) {}
} else {
// REVISIT: type mismatch
"FEATURE_NOT_SUPPORTED",
}
return;
}
try {
"FEATURE_NOT_SUPPORTED",
}
}
// need to wrap the LSInput with an XMLInputSource
/**
* An LSParser looks at inputs specified in LSInput in
* the following order: characterStream, byteStream,
* stringData, systemId, publicId. For consistency
* have the same behaviour for XSLoader.
*/
// check whether there is a Reader
// according to DOM, we need to treat such reader as "UTF-16".
"UTF-16");
}
// check whether there is an InputStream
is.getEncoding());
}
// if there is a string data, use a StringReader
// according to DOM, we need to treat such data as "UTF-16".
"UTF-16");
}
else {
is.getBaseURI());
}
return xis;
}
} // XMLGrammarLoader