FileDocCategorySizeDatePackage
ErrorHandlerWrapper.javaAPI DocJava SE 5 API11227Fri Aug 26 14:55:56 BST 2005com.sun.org.apache.xerces.internal.util

ErrorHandlerWrapper

public class ErrorHandlerWrapper extends Object implements XMLErrorHandler
This class wraps a SAX error handler in an XNI error handler.
see
ErrorHandler
author
Andy Clark, IBM
version
$Id: ErrorHandlerWrapper.java,v 1.10 2003/12/17 08:28:29 neeraj Exp $

Fields Summary
protected ErrorHandler
fErrorHandler
The SAX error handler.
Constructors Summary
public ErrorHandlerWrapper()
Default constructor.

public ErrorHandlerWrapper(ErrorHandler errorHandler)
Wraps the specified SAX error handler.

        setErrorHandler(errorHandler);
    
Methods Summary
protected static org.xml.sax.SAXParseExceptioncreateSAXParseException(com.sun.org.apache.xerces.internal.xni.parser.XMLParseException exception)
Creates a SAXParseException from an XMLParseException.

        return new SAXParseException(exception.getMessage(),
                                     exception.getPublicId(),
                                     exception.getExpandedSystemId(),
                                     exception.getLineNumber(),
                                     exception.getColumnNumber(),
                                     exception.getException());
    
protected static com.sun.org.apache.xerces.internal.xni.parser.XMLParseExceptioncreateXMLParseException(org.xml.sax.SAXParseException exception)
Creates an XMLParseException from a SAXParseException.

        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);
    
protected static com.sun.org.apache.xerces.internal.xni.XNIExceptioncreateXNIException(org.xml.sax.SAXException exception)
Creates an XNIException from a SAXException. NOTE: care should be taken *not* to call this with a SAXParseException; this will lose information!!!

        return new XNIException(exception.getMessage(),exception);
    
public voiderror(java.lang.String domain, java.lang.String key, com.sun.org.apache.xerces.internal.xni.parser.XMLParseException exception)
Reports an error. Errors are non-fatal and usually signify that the document is invalid with respect to its grammar(s).

param
domain The domain of the 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 error.
param
key The 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.

        
        if (fErrorHandler != null) {
        	SAXParseException saxException = createSAXParseException(exception);
        	
        	try {
        		fErrorHandler.error(saxException);
        	}
        	catch (SAXParseException e) {
        		throw createXMLParseException(e);
        	}
        	catch (SAXException e) {
        		throw createXNIException(e);
        	}
        }

    
public voidfatalError(java.lang.String domain, java.lang.String key, com.sun.org.apache.xerces.internal.xni.parser.XMLParseException exception)
Report a fatal error. Fatal errors usually occur when the document is not well-formed and signifies that the parser cannot continue normal operation.

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.

                           	
        if (fErrorHandler != null) {
        	SAXParseException saxException = createSAXParseException(exception);
        	
        	try {
        		fErrorHandler.fatalError(saxException);
        	}
        	catch (SAXParseException e) {
        		throw createXMLParseException(e);
        	}
        	catch (SAXException e) {
        		throw createXNIException(e);
        	}
        }

    
public org.xml.sax.ErrorHandlergetErrorHandler()
Returns the SAX error handler.

        return fErrorHandler;
    
public voidsetErrorHandler(org.xml.sax.ErrorHandler errorHandler)
Sets the SAX error handler.

        fErrorHandler = errorHandler;
    
public voidwarning(java.lang.String domain, java.lang.String key, com.sun.org.apache.xerces.internal.xni.parser.XMLParseException exception)
Reports a warning. Warnings are non-fatal and can be safely ignored by most applications.

param
domain The domain of the warning. 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 warning.
param
key The warning 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.


        if (fErrorHandler != null) {
        	SAXParseException saxException = createSAXParseException(exception);
        	
        	try {
        		fErrorHandler.warning(saxException);
        	}
        	catch (SAXParseException e) {
        		throw createXMLParseException(e);
        	}
        	catch (SAXException e) {
        		throw createXNIException(e);
        	}
        }