* Note: The error handler should always
* throw an XNIException
from this method. This exception
* can either be the same exception that is passed as a parameter to
* the method or a new XNI exception object. If the registered error
* handler fails to throw an exception, the continuing operation of
* the parser is undetermined.
*
* @param domain The domain of the fatal error. The domain can be
* any string but is suggested to be a valid URI. The
* domain can be used to conveniently specify a web
* site location of the relevent specification or
* document pertaining to this fatal error.
* @param key The fatal error key. This key can be any string
* and is implementation dependent.
* @param exception Exception.
*
* @throws XNIException Thrown to signal that the parser should stop
* parsing the document.
*/
public void fatalError(String domain, String key,
XMLParseException exception) throws XNIException {
if (fErrorHandler != null) {
SAXParseException saxException = createSAXParseException(exception);
try {
fErrorHandler.fatalError(saxException);
}
catch (SAXParseException e) {
throw createXMLParseException(e);
}
catch (SAXException e) {
throw createXNIException(e);
}
}
} // fatalError(String,String,XMLParseException)
//
// Protected methods
//
/** Creates a SAXParseException from an XMLParseException. */
protected static SAXParseException createSAXParseException(XMLParseException exception) {
return new SAXParseException(exception.getMessage(),
exception.getPublicId(),
exception.getExpandedSystemId(),
exception.getLineNumber(),
exception.getColumnNumber(),
exception.getException());
} // createSAXParseException(XMLParseException):SAXParseException
/** Creates an XMLParseException from a SAXParseException. */
protected static XMLParseException createXMLParseException(SAXParseException exception) {
final String fPublicId = exception.getPublicId();
final String fExpandedSystemId = exception.getSystemId();
final int fLineNumber = exception.getLineNumber();
final int fColumnNumber = exception.getColumnNumber();
XMLLocator location = new XMLLocator() {
public void setPublicId(String id) {}
public String getPublicId() { return fPublicId; }
public void setExpandedSystemId( String id) {}
public String getExpandedSystemId() { return fExpandedSystemId; }
public void setBaseSystemId(String id) {}
public String getBaseSystemId() { return null; }
public void setLiteralSystemId(String id) {}
public String getLiteralSystemId() { return null; }
public int getColumnNumber() { return fColumnNumber; }
public void setColumnNumber(int col) {}
public int getLineNumber() { return fLineNumber; }
public void setLineNumber(int line) {}
public String getEncoding() { return null; }
};
return new XMLParseException(location, exception.getMessage(),exception);
} // createXMLParseException(SAXParseException):XMLParseException
/** Creates an XNIException from a SAXException.
NOTE: care should be taken *not* to call this with a SAXParseException; this will
lose information!!! */
protected static XNIException createXNIException(SAXException exception) {
return new XNIException(exception.getMessage(),exception);
} // createXNIException(SAXException):XMLParseException
} // class ErrorHandlerWrapper