org.apache.xerces.impl
Class XMLErrorReporter

java.lang.Object
  extended by org.apache.xerces.impl.XMLErrorReporter
All Implemented Interfaces:
XMLComponent

public class XMLErrorReporter
extends java.lang.Object
implements XMLComponent

This class is a common element of all parser configurations and is used to report errors that occur. This component can be queried by parser components from the component manager using the following property ID:

   http://apache.org/xml/properties/internal/error-reporter
 

Errors are separated into domains that categorize a class of errors. In a parser configuration, the parser would register a MessageFormatter for each domain that is capable of localizing error messages and formatting them based on information about the error. Any parser component can invent new error domains and register additional message formatters to localize messages in those domains.

This component requires the following features and properties from the component manager that uses it:

This component can use the following features and properties but they are not required:

Version:
$Id: XMLErrorReporter.java 575002 2007-09-12 16:02:04Z mrglavas $
Author:
Eric Ye, IBM, Andy Clark, IBM
See Also:
MessageFormatter

Field Summary
static short SEVERITY_ERROR
          Severity: error.
static short SEVERITY_FATAL_ERROR
          Severity: fatal error.
static short SEVERITY_WARNING
          Severity: warning.
 
Constructor Summary
XMLErrorReporter()
          Constructs an error reporter with a locator.
 
Method Summary
 XMLErrorHandler getErrorHandler()
          Get the internal XMLErrrorHandler.
 boolean getFeature(java.lang.String featureId)
           
 java.lang.Boolean getFeatureDefault(java.lang.String featureId)
          Returns the default state for a feature, or null if this component does not want to report a default value for this feature.
 java.util.Locale getLocale()
          Gets the current locale.
 MessageFormatter getMessageFormatter(java.lang.String domain)
          Returns the message formatter associated with the specified domain, or null if no message formatter is registered for that domain.
 java.lang.Object getPropertyDefault(java.lang.String propertyId)
          Returns the default state for a property, or null if this component does not want to report a default value for this property.
 java.lang.String[] getRecognizedFeatures()
          Returns a list of feature identifiers that are recognized by this component.
 java.lang.String[] getRecognizedProperties()
          Returns a list of property identifiers that are recognized by this component.
 ErrorHandler getSAXErrorHandler()
          Gets the internal XMLErrorHandler as SAX ErrorHandler.
 void putMessageFormatter(java.lang.String domain, MessageFormatter messageFormatter)
          Registers a message formatter for the specified domain.
 MessageFormatter removeMessageFormatter(java.lang.String domain)
          Removes the message formatter for the specified domain and returns the removed message formatter.
 void reportError(java.lang.String domain, java.lang.String key, java.lang.Object[] arguments, short severity)
          Reports an error.
 void reportError(java.lang.String domain, java.lang.String key, java.lang.Object[] arguments, short severity, java.lang.Exception exception)
          Reports an error.
 void reportError(XMLLocator location, java.lang.String domain, java.lang.String key, java.lang.Object[] arguments, short severity)
          Reports an error at a specific location.
 void reportError(XMLLocator location, java.lang.String domain, java.lang.String key, java.lang.Object[] arguments, short severity, java.lang.Exception exception)
          Reports an error at a specific location.
 void reset(XMLComponentManager componentManager)
          Resets the component.
 void setDocumentLocator(XMLLocator locator)
          Sets the document locator.
 void setFeature(java.lang.String featureId, boolean state)
          Sets the state of a feature.
 void setLocale(java.util.Locale locale)
          Sets the current locale.
 void setProperty(java.lang.String propertyId, java.lang.Object value)
          Sets the value of a property.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEVERITY_WARNING

public static final short SEVERITY_WARNING
Severity: warning. Warnings represent informational messages only that should not be considered serious enough to stop parsing or indicate an error in the document's validity.

See Also:
Constant Field Values

SEVERITY_ERROR

public static final short SEVERITY_ERROR
Severity: error. Common causes of errors are document structure and/or content that that does not conform to the grammar rules specified for the document. These are typically validation errors.

See Also:
Constant Field Values

SEVERITY_FATAL_ERROR

public static final short SEVERITY_FATAL_ERROR
Severity: fatal error. Fatal errors are errors in the syntax of the XML document or invalid byte sequences for a given encoding. The XML 1.0 Specification mandates that errors of this type are not recoverable.

Note: The parser does have a "continue after fatal error" feature but it should be used with extreme caution and care.

See Also:
Constant Field Values
Constructor Detail

XMLErrorReporter

public XMLErrorReporter()
Constructs an error reporter with a locator.

Method Detail

setLocale

public void setLocale(java.util.Locale locale)
Sets the current locale.

Parameters:
locale - The new locale.

getLocale

public java.util.Locale getLocale()
Gets the current locale.

Returns:
the current Locale

setDocumentLocator

public void setDocumentLocator(XMLLocator locator)
Sets the document locator.

Parameters:
locator - The locator.

putMessageFormatter

public void putMessageFormatter(java.lang.String domain,
                                MessageFormatter messageFormatter)
Registers a message formatter for the specified domain.

Note: Registering a message formatter for a domain when there is already a formatter registered will cause the previous formatter to be lost. This method replaces any previously registered message formatter for the specified domain.

Parameters:
domain -
messageFormatter -

getMessageFormatter

public MessageFormatter getMessageFormatter(java.lang.String domain)
Returns the message formatter associated with the specified domain, or null if no message formatter is registered for that domain.

Parameters:
domain - The domain of the message formatter.

removeMessageFormatter

public MessageFormatter removeMessageFormatter(java.lang.String domain)
Removes the message formatter for the specified domain and returns the removed message formatter.

Parameters:
domain - The domain of the message formatter.

reportError

public void reportError(java.lang.String domain,
                        java.lang.String key,
                        java.lang.Object[] arguments,
                        short severity)
                 throws XNIException
Reports an error. The error message passed to the error handler is formatted for the locale by the message formatter installed for the specified error domain.

Parameters:
domain - The error domain.
key - The key of the error message.
arguments - The replacement arguments for the error message, if needed.
severity - The severity of the error.
Throws:
XNIException
See Also:
SEVERITY_WARNING, SEVERITY_ERROR, SEVERITY_FATAL_ERROR

reportError

public void reportError(java.lang.String domain,
                        java.lang.String key,
                        java.lang.Object[] arguments,
                        short severity,
                        java.lang.Exception exception)
                 throws XNIException
Reports an error. The error message passed to the error handler is formatted for the locale by the message formatter installed for the specified error domain.

Parameters:
domain - The error domain.
key - The key of the error message.
arguments - The replacement arguments for the error message, if needed.
severity - The severity of the error.
exception - The exception to wrap.
Throws:
XNIException
See Also:
SEVERITY_WARNING, SEVERITY_ERROR, SEVERITY_FATAL_ERROR

reportError

public void reportError(XMLLocator location,
                        java.lang.String domain,
                        java.lang.String key,
                        java.lang.Object[] arguments,
                        short severity)
                 throws XNIException
Reports an error at a specific location.

Parameters:
location - The error location.
domain - The error domain.
key - The key of the error message.
arguments - The replacement arguments for the error message, if needed.
severity - The severity of the error.
Throws:
XNIException
See Also:
SEVERITY_WARNING, SEVERITY_ERROR, SEVERITY_FATAL_ERROR

reportError

public void reportError(XMLLocator location,
                        java.lang.String domain,
                        java.lang.String key,
                        java.lang.Object[] arguments,
                        short severity,
                        java.lang.Exception exception)
                 throws XNIException
Reports an error at a specific location.

Parameters:
location - The error location.
domain - The error domain.
key - The key of the error message.
arguments - The replacement arguments for the error message, if needed.
severity - The severity of the error.
exception - The exception to wrap.
Throws:
XNIException
See Also:
SEVERITY_WARNING, SEVERITY_ERROR, SEVERITY_FATAL_ERROR

reset

public void reset(XMLComponentManager componentManager)
           throws XNIException
Resets the component. The component can query the component manager about any features and properties that affect the operation of the component.

Specified by:
reset in interface XMLComponent
Parameters:
componentManager - The component manager.
Throws:
SAXException - Thrown by component on initialization error. For example, if a feature or property is required for the operation of the component, the component manager may throw a SAXNotRecognizedException or a SAXNotSupportedException.
XNIException - Thrown by component on initialization error.

getRecognizedFeatures

public java.lang.String[] getRecognizedFeatures()
Returns a list of feature identifiers that are recognized by this component. This method may return null if no features are recognized by this component.

Specified by:
getRecognizedFeatures in interface XMLComponent

setFeature

public void setFeature(java.lang.String featureId,
                       boolean state)
                throws XMLConfigurationException
Sets the state of a feature. This method is called by the component manager any time after reset when a feature changes state.

Note: Components should silently ignore features that do not affect the operation of the component.

Specified by:
setFeature in interface XMLComponent
Parameters:
featureId - The feature identifier.
state - The state of the feature.
Throws:
SAXNotRecognizedException - The component should not throw this exception.
SAXNotSupportedException - The component should not throw this exception.
XMLConfigurationException - Thrown for configuration error. In general, components should only throw this exception if it is really a critical error.

getFeature

public boolean getFeature(java.lang.String featureId)
                   throws XMLConfigurationException
Throws:
XMLConfigurationException

getRecognizedProperties

public java.lang.String[] getRecognizedProperties()
Returns a list of property identifiers that are recognized by this component. This method may return null if no properties are recognized by this component.

Specified by:
getRecognizedProperties in interface XMLComponent

setProperty

public void setProperty(java.lang.String propertyId,
                        java.lang.Object value)
                 throws XMLConfigurationException
Sets the value of a property. This method is called by the component manager any time after reset when a property changes value.

Note: Components should silently ignore properties that do not affect the operation of the component.

Specified by:
setProperty in interface XMLComponent
Parameters:
propertyId - The property identifier.
value - The value of the property.
Throws:
SAXNotRecognizedException - The component should not throw this exception.
SAXNotSupportedException - The component should not throw this exception.
XMLConfigurationException - Thrown for configuration error. In general, components should only throw this exception if it is really a critical error.

getFeatureDefault

public java.lang.Boolean getFeatureDefault(java.lang.String featureId)
Returns the default state for a feature, or null if this component does not want to report a default value for this feature.

Specified by:
getFeatureDefault in interface XMLComponent
Parameters:
featureId - The feature identifier.
Since:
Xerces 2.2.0

getPropertyDefault

public java.lang.Object getPropertyDefault(java.lang.String propertyId)
Returns the default state for a property, or null if this component does not want to report a default value for this property.

Specified by:
getPropertyDefault in interface XMLComponent
Parameters:
propertyId - The property identifier.
Since:
Xerces 2.2.0

getErrorHandler

public XMLErrorHandler getErrorHandler()
Get the internal XMLErrrorHandler.


getSAXErrorHandler

public ErrorHandler getSAXErrorHandler()
Gets the internal XMLErrorHandler as SAX ErrorHandler.