com.cgiams.esl.common.xml
Class XMLErrorHandler

java.lang.Object
  extended byorg.xml.sax.helpers.DefaultHandler
      extended bycom.cgiams.esl.common.xml.XMLErrorHandler
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, javax.xml.bind.ValidationEventHandler

public class XMLErrorHandler
extends org.xml.sax.helpers.DefaultHandler
implements org.xml.sax.ErrorHandler, javax.xml.bind.ValidationEventHandler

This is an Error Handler class for capturing any parse errors that might occur during XML schema validation. This class implements the ErrorHandler interface and can be used by either the DOM or SAX parse objects.

Any Warnings or Errors that occur during parsing are collected until the entire XML document is parsed. All warning and/or error messages can be retrieved using the getWarningMessages() and getErrorMessages() methods, respectively. Only the last SAXParseException that may have occurred is available by calling the getLastException() method.

If a single Fatal Error is encountered during parsing, the SAXParseException that was responsible is immediately rethrown to the caller. The actual exception can be retrieved from a call to getLastException() while the message text is available from the getErrorMessages() method.

Modification History
Programmer Date Description
Scott Bowers April 2005 Initial version.


Constructor Summary
XMLErrorHandler()
           
 
Method Summary
 void error(org.xml.sax.SAXParseException ao_exception)
          API called by the DocumentBuilder if an error occurs during parsing of the XML document.
 void fatalError(org.xml.sax.SAXParseException ao_exception)
          API called by the DocumentBuilder if a fatal error occurs during parsing of the XML document.
 java.lang.String getAllMessages()
          Return a String of all Error and Warning messages.
 java.lang.String getErrorMessages()
          Returns a formatted string of all Error Messages.
 org.xml.sax.SAXParseException getLastException()
          Retrieve the last parsing exception that occured during validation.
 java.lang.String getWarningMessages()
          Returns a formatted string of all Warning Messages.
 boolean handleEvent(javax.xml.bind.ValidationEvent event)
          Receive notification of a validation warning or error.
 boolean hasErrors()
          Determines whethere any error occured during parsing.
 boolean hasWarnings()
          Determines whethere any error occured during parsing.
 boolean isClean()
          Determines whether there are no errors or warnings of any kind.
 void warning(org.xml.sax.SAXParseException ao_exception)
          API called by the DocumentBuilder if a warning occurs during parsing of the XML document.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
characters, endDocument, endElement, endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startElement, startPrefixMapping, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLErrorHandler

public XMLErrorHandler()
Method Detail

handleEvent

public boolean handleEvent(javax.xml.bind.ValidationEvent event)
Receive notification of a validation warning or error. The ValidationEvent will have a ValidationEventLocator embedded in it that indicates where the error or warning occurred. If an unchecked runtime exception is thrown from this method, the JAXB provider will treat it as if the method returned false and interrupt the current unmarshal, validate, or marshal operation.

Specified by:
handleEvent in interface javax.xml.bind.ValidationEventHandler
Parameters:
event - The encapsulated validation event information. It is a provider error if this parameter is null.
Returns:
True if the JAXB Provider should attempt to continue the current unmarshal, validate, or marshal operation after handling this warning/error, False if the provider should terminate the current operation with the appropriate UnmarshalException, ValidationException, or MarshalException.

hasErrors

public boolean hasErrors()
Determines whethere any error occured during parsing.

Returns:
True if an error occurred, or False otherwise.

hasWarnings

public boolean hasWarnings()
Determines whethere any error occured during parsing.

Returns:
True if an error occurred, or False otherwise.

isClean

public boolean isClean()
Determines whether there are no errors or warnings of any kind.

Returns:
True if no errors and no warnings, otherwise false.

getErrorMessages

public java.lang.String getErrorMessages()
Returns a formatted string of all Error Messages.

Returns:
The formatted string of all Error Messages, or empty string if no errors occurred.

getWarningMessages

public java.lang.String getWarningMessages()
Returns a formatted string of all Warning Messages.

Returns:
The formatted string of all Warning Messages, or empty string if no errors occurred.

getAllMessages

public java.lang.String getAllMessages()
Return a String of all Error and Warning messages.

Returns:
A formatted String of all Error and Warning messages.

getLastException

public org.xml.sax.SAXParseException getLastException()
Retrieve the last parsing exception that occured during validation.

Returns:
The last parsing exception (SAXParseException) that occurred during validation, or null if none occurred.

error

public void error(org.xml.sax.SAXParseException ao_exception)
           throws org.xml.sax.SAXException
API called by the DocumentBuilder if an error occurs during parsing of the XML document.

Specified by:
error in interface org.xml.sax.ErrorHandler
Parameters:
ao_exception - The SAXParseException that occured.
Throws:
java.lang.IllegalArgumentException - If incoming exception is null.
org.xml.sax.SAXException - If any exception occurs.

fatalError

public void fatalError(org.xml.sax.SAXParseException ao_exception)
                throws org.xml.sax.SAXException
API called by the DocumentBuilder if a fatal error occurs during parsing of the XML document. In this case, any exception is immediately re-thrown.

Specified by:
fatalError in interface org.xml.sax.ErrorHandler
Parameters:
ao_exception - The SAXParseException that occured.
Throws:
java.lang.IllegalArgumentException - If incoming exception is null.
org.xml.sax.SAXException - If any exception occurs.

warning

public void warning(org.xml.sax.SAXParseException ao_exception)
             throws org.xml.sax.SAXException
API called by the DocumentBuilder if a warning occurs during parsing of the XML document.

Specified by:
warning in interface org.xml.sax.ErrorHandler
Parameters:
ao_exception - The SAXParseException that occured.
Throws:
java.lang.IllegalArgumentException - If incoming exception is null.
org.xml.sax.SAXException - If any exception occurs.