mrglavas 2005/05/23 16:28:36
Modified: java/src/org/apache/xerces/jaxp/validation
XMLSchemaFactory.java
Log:
- Use ErrorHandlerWrapper for SAX ErrorHandler.
- Fixing a bug in isSchemaLanguageSupported; this SchemaFactory only supports
the W3C XML Schema standard.
Revision Changes Path
1.6 +14 -47
xml-xerces/java/src/org/apache/xerces/jaxp/validation/XMLSchemaFactory.java
Index: XMLSchemaFactory.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/jaxp/validation/XMLSchemaFactory.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XMLSchemaFactory.java 22 May 2005 20:23:18 -0000 1.5
+++ XMLSchemaFactory.java 23 May 2005 23:28:36 -0000 1.6
@@ -95,36 +95,20 @@
/** The DOMEntityResolverWrapper */
private final DOMEntityResolverWrapper fDOMEntityResolverWrapper;
+ /** The ErrorHandlerWrapper */
+ private ErrorHandlerWrapper fErrorHandlerWrapper;
+
/** The SecurityManager. */
private SecurityManager fSecurityManager;
- private SAXParseException fLastException;
-
public XMLSchemaFactory() {
+ fErrorHandlerWrapper = new
ErrorHandlerWrapper(DraconianErrorHandler.getInstance());
fDOMEntityResolverWrapper = new DOMEntityResolverWrapper();
fXMLSchemaLoader.setFeature(SCHEMA_FULL_CHECKING, true);
fXMLSchemaLoader.setEntityResolver(fDOMEntityResolverWrapper);
- // intercept error report and remember the last thrown exception.
- fXMLSchemaLoader.setErrorHandler(new ErrorHandlerWrapper(new
ErrorHandler() {
- public void warning(SAXParseException exception) throws
SAXException {
- if( fErrorHandler!=null )
fErrorHandler.warning(exception);
- }
-
- public void error(SAXParseException exception) throws
SAXException {
- fLastException = exception;
- if( fErrorHandler!=null ) fErrorHandler.error(exception);
- else throw exception;
- }
-
- public void fatalError(SAXParseException exception) throws
SAXException {
- fLastException = exception;
- if( fErrorHandler!=null )
fErrorHandler.fatalError(exception);
- else throw exception;
- }
- }));
+ fXMLSchemaLoader.setErrorHandler(fErrorHandlerWrapper);
}
-
/**
* <p>Is specified schema supported by this
<code>SchemaFactory</code>?</p>
*
@@ -138,29 +122,16 @@
* or <code>schemaLanguage</code> does not specify a <a
href="#schemaLanguage">valid</a> schema language.
*/
public boolean isSchemaLanguageSupported(String schemaLanguage) {
-
if (schemaLanguage == null) {
- throw new NullPointerException(
- fXSMessageFormatter.formatMessage(Locale.getDefault(),
- "SchemaLanguageSupportedErrorWhenNull",
- new Object [] {this.getClass().getName()}));
+ throw new
NullPointerException(JAXPValidationMessageFormatter.formatMessage(Locale.getDefault(),
+ "SchemaLanguageNull", null));
}
-
if (schemaLanguage.length() == 0) {
- throw new IllegalArgumentException(
- fXSMessageFormatter.formatMessage(Locale.getDefault(),
- "SchemaLanguageSupportedErrorWhenLength",
- new Object [] {this.getClass().getName()}));
- }
-
- // understand W3C Schema and RELAX NG
- if (schemaLanguage.equals(XMLConstants.W3C_XML_SCHEMA_NS_URI)
- || schemaLanguage.equals(XMLConstants.RELAXNG_NS_URI)) {
- return true;
+ throw new
IllegalArgumentException(JAXPValidationMessageFormatter.formatMessage(Locale.getDefault(),
+ "SchemaLanguageLengthZero", null));
}
-
- // don't know how to validate anything else
- return false;
+ // only W3C XML Schema 1.0 is supported
+ return schemaLanguage.equals(XMLConstants.W3C_XML_SCHEMA_NS_URI);
}
public LSResourceResolver getResourceResolver() {
@@ -179,12 +150,12 @@
public void setErrorHandler(ErrorHandler errorHandler) {
fErrorHandler = errorHandler;
+ fErrorHandlerWrapper.setErrorHandler(errorHandler != null ?
errorHandler : DraconianErrorHandler.getInstance());
+ fXMLSchemaLoader.setErrorHandler(fErrorHandlerWrapper);
}
public Schema newSchema( Source[] schemas ) throws SAXException {
- fLastException = null;
-
// this will let the loader store parsed Grammars into the pool.
XMLGrammarPool pool = new XMLGrammarPoolImpl();
fXMLSchemaLoader.setProperty(XMLGRAMMAR_POOL, pool);
@@ -242,10 +213,6 @@
}
}
- // if any error had been reported, throw it.
- if( fLastException!=null )
- throw fLastException;
-
// make sure no further grammars are added by making it read-only.
return new XMLSchema(new ReadOnlyGrammarPool(pool));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]