| Method from org.apache.xerces.impl.xs.XMLSchemaLoader Detail: |
public boolean canSetParameter(String name,
Object value) {
if(value instanceof Boolean){
if (name.equals(Constants.DOM_VALIDATE) ||
name.equals(SCHEMA_FULL_CHECKING) ||
name.equals(VALIDATE_ANNOTATIONS) ||
name.equals(CONTINUE_AFTER_FATAL_ERROR) ||
name.equals(ALLOW_JAVA_ENCODINGS) ||
name.equals(STANDARD_URI_CONFORMANT_FEATURE) ||
name.equals(GENERATE_SYNTHETIC_ANNOTATIONS) ||
name.equals(HONOUR_ALL_SCHEMALOCATIONS)) {
return true;
}
return false;
}
if (name.equals(Constants.DOM_ERROR_HANDLER) ||
name.equals(Constants.DOM_RESOURCE_RESOLVER) ||
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;
}
|
XMLInputSource dom2xmlInputSource(LSInput is) {
// need to wrap the LSInput with an XMLInputSource
XMLInputSource xis = null;
/**
* 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".
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());
}
// if there is a string data, use a StringReader
// according to DOM, we need to treat such data as "UTF-16".
else if (is.getStringData() != null && is.getStringData().length() != 0) {
xis = new XMLInputSource(is.getPublicId(), is.getSystemId(),
is.getBaseURI(), new StringReader(is.getStringData()),
"UTF-16");
}
// otherwise, just use the public/system/base Ids
else {
xis = new XMLInputSource(is.getPublicId(), is.getSystemId(),
is.getBaseURI());
}
return xis;
}
|
public DOMConfiguration getConfig() {
return this;
}
|
public XMLEntityResolver getEntityResolver() {
return fUserEntityResolver;
}
Returns the registered entity resolver. |
public XMLErrorHandler getErrorHandler() {
return fErrorReporter.getErrorHandler();
}
Returns the registered error handler. |
public boolean getFeature(String featureId) throws XMLConfigurationException {
return fLoaderConfig.getFeature(featureId);
}
Returns the state of a feature. |
public Boolean getFeatureDefault(String featureId) {
if (featureId.equals(AUGMENT_PSVI)){
return Boolean.TRUE;
}
return null;
}
|
public Locale getLocale() {
return fLocale;
}
Return the Locale the XMLGrammarLoader is using. |
public Object getParameter(String name) throws DOMException {
if (name.equals(Constants.DOM_ERROR_HANDLER)){
return (fErrorHandler != null) ? fErrorHandler.getErrorHandler() : null;
}
else if (name.equals(Constants.DOM_RESOURCE_RESOLVER)) {
return (fResourceResolver != null) ? fResourceResolver.getEntityResolver() : null;
}
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 DOMStringList getParameterNames() {
if (fRecognizedParameters == null){
Vector v = new Vector();
v.add(Constants.DOM_VALIDATE);
v.add(Constants.DOM_ERROR_HANDLER);
v.add(Constants.DOM_RESOURCE_RESOLVER);
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);
v.add(VALIDATE_ANNOTATIONS);
v.add(GENERATE_SYNTHETIC_ANNOTATIONS);
v.add(HONOUR_ALL_SCHEMALOCATIONS);
fRecognizedParameters = new DOMStringListImpl(v);
}
return fRecognizedParameters;
}
|
public Object getProperty(String propertyId) throws XMLConfigurationException {
return fLoaderConfig.getProperty(propertyId);
}
Returns the state of a property. |
public Object getPropertyDefault(String propertyId) {
// TODO Auto-generated method stub
return null;
}
|
public String[] getRecognizedFeatures() {
return (String[])(RECOGNIZED_FEATURES.clone());
}
Returns a list of feature identifiers that are recognized by
this XMLGrammarLoader. This method may return null if no features
are recognized. |
public String[] getRecognizedProperties() {
return (String[])(RECOGNIZED_PROPERTIES.clone());
}
Returns a list of property identifiers that are recognized by
this XMLGrammarLoader. This method may return null if no properties
are recognized. |
public XSModel load(LSInput is) {
try {
Grammar g = loadGrammar(dom2xmlInputSource(is));
return ((XSGrammar) g).toXSModel();
} catch (Exception e) {
reportDOMFatalError(e);
return null;
}
}
|
public void loadGrammar(XMLInputSource[] source) throws IOException, XNIException {
int numSource = source.length;
for (int i = 0; i < numSource; ++i) {
loadGrammar(source[i]);
}
}
Returns a Grammar object by parsing the contents of the
entities pointed to by sources. |
public Grammar loadGrammar(XMLInputSource source) 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.
reset(fLoaderConfig);
fSettingsChanged = false;
XSDDescription desc = new XSDDescription();
desc.fContextType = XSDDescription.CONTEXT_PREPARSE;
desc.setBaseSystemId(source.getBaseSystemId());
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;
}
Returns a Grammar object by parsing the contents of the
entity pointed to by source. |
public XSModel loadInputList(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) {
reportDOMFatalError(e);
return null;
}
}
return new XSModelImpl(gs);
}
|
SchemaGrammar loadSchema(XSDDescription desc,
XMLInputSource source,
Hashtable locationPairs) throws IOException, 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;
}
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 |
public XSModel loadURI(String uri) {
try {
Grammar g = loadGrammar(new XMLInputSource(null, uri, null));
return ((XSGrammar)g).toXSModel();
}
catch (Exception e){
reportDOMFatalError(e);
return null;
}
}
|
public XSModel loadURIList(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) {
reportDOMFatalError(e);
return null;
}
}
return new XSModelImpl(gs);
}
|
public static void processExternalHints(String sl,
String nsl,
Hashtable locations,
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);
}
}
}
|
void reportDOMFatalError(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);
}
}
|
public void reset(XMLComponentManager componentManager) throws XMLConfigurationException {
fGrammarBucket.reset();
fSubGroupHandler.reset();
if (!fSettingsChanged || !parserSettingsUpdated(componentManager)) {
// need to reprocess JAXP schema sources
fJAXPProcessed = false;
// 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);
// get the error reporter
fErrorReporter = (XMLErrorReporter)componentManager.getProperty(ERROR_REPORTER);
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;
}
// get generate-synthetic-annotations feature
try {
fSchemaHandler.setGenerateSyntheticAnnotations(componentManager.getFeature(GENERATE_SYNTHETIC_ANNOTATIONS));
}
catch (XMLConfigurationException e) {
fSchemaHandler.setGenerateSyntheticAnnotations(false);
}
fSchemaHandler.reset(componentManager);
}
|
public static XMLInputSource resolveDocument(XSDDescription desc,
Hashtable locationPairs,
XMLEntityResolver entityResolver) 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);
}
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. |
public void setEntityResolver(XMLEntityResolver entityResolver) {
fUserEntityResolver = entityResolver;
fLoaderConfig.setProperty(ENTITY_RESOLVER, entityResolver);
fEntityManager.setProperty(ENTITY_RESOLVER, entityResolver);
}
Sets the entity resolver. |
public void setErrorHandler(XMLErrorHandler errorHandler) {
fErrorReporter.setProperty(ERROR_HANDLER, errorHandler);
}
|
public void setFeature(String featureId,
boolean state) throws XMLConfigurationException {
fSettingsChanged = true;
if(featureId.equals(CONTINUE_AFTER_FATAL_ERROR)) {
fErrorReporter.setFeature(CONTINUE_AFTER_FATAL_ERROR, state);
}
else if(featureId.equals(GENERATE_SYNTHETIC_ANNOTATIONS)) {
fSchemaHandler.setGenerateSyntheticAnnotations(state);
}
fLoaderConfig.setFeature(featureId, state);
}
Sets the state of a feature. |
public void setLocale(Locale locale) {
fLocale = locale;
fErrorReporter.setLocale(locale);
}
Set the locale to use for messages. |
public void setParameter(String name,
Object value) throws DOMException {
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;
}
if (name.equals(Constants.DOM_RESOURCE_RESOLVER)) {
if (value instanceof LSResourceResolver) {
try {
fResourceResolver = new DOMEntityResolverWrapper((LSResourceResolver) value);
setEntityResolver(fResourceResolver);
}
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 void setProperty(String propertyId,
Object state) throws XMLConfigurationException {
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());
}
}
}
Sets the state of a property. |
public static boolean tokenizeSchemaLocationStr(String schemaStr,
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;
}
|