javax.xml.bind

Interface Validator

Known Subinterfaces:
JMValidator
Known Implementing Classes:
JMValidatorImpl

public interface Validator

A Validator may be used to decide, whether a JAXB object is valid or not. If it is not, the JAXB user may decide to trigger an exception or not (via the ValidationEventHandler and he may receive information on the problems location (via the event handlers ValidationEventLocator.

A Validator may be present implicitly, invoked by the Unmarshaller. See Unmarshaller.setValidating(boolean) for more information on that.

Author:
JSR-31
Since:
JAXB1.0
See Also:
ValidationEventHandler, ValidationEvent

Method Summary

ValidationEventHandler
getEventHandler()
Returns an event handler that shall be invoked for notifications on problems detected by the Validator.
java.lang.Object
getProperty(String pName)
Returns the marshallers property pName.
void
setEventHandler(ValidationEventHandler pHandler)
Registers an event handler that shall be invoked for notifications on problems detected by the Validator.
void
setProperty(String pName, Object pValue)
Sets the Validator property pName to pValue.
boolean
validate(Object pObject)
Validates the given JAXB object, invoking its error handler for any problems it detects.
boolean
validateRoot(Object pObject)
Validates the given JAXB object, but not its child elements.

Method Details

getEventHandler

public ValidationEventHandler getEventHandler()
            throws JAXBException
Returns an event handler that shall be invoked for notifications on problems detected by the Validator. If no specific event handler was set, returns the default event handler. The default event handler will trigger an exception for errors and fatal errors.
Returns:
The event handler previously set or the default handler.
Throws:
JAXBException - Getting the event handler failed.

getProperty

public java.lang.Object getProperty(String pName)
            throws PropertyException
Returns the marshallers property pName.

Note: The values type depends on the property name.

Parameters:
pName - The property name.
Returns:
The property value.
Throws:
PropertyException - Fetching the property failed.

setEventHandler

public void setEventHandler(ValidationEventHandler pHandler)
            throws JAXBException
Registers an event handler that shall be invoked for notifications on problems detected by the Validator. If this method is not invoked, there is a default event handler. The default event handler will trigger an exception for errors and fatal errors.
Parameters:
pHandler - The event handler being notified or null to restore the default event handler.
Throws:
JAXBException - Setting the event handler failed.

setProperty

public void setProperty(String pName,
                        Object pValue)
            throws PropertyException
Sets the Validator property pName to pValue.

Note: The values type depends on the property name.

Parameters:
pName - The property name.
pValue - The property value.
Throws:
PropertyException - Setting the property failed.

validate

public boolean validate(Object pObject)
            throws JAXBException
Validates the given JAXB object, invoking its error handler for any problems it detects. Detected problems may cause exceptions, for example, if the event handlers ValidationEventHandler.handleEvent(ValidationEvent) method returns false.
Parameters:
pObject - The JAXB object being validated.
Throws:
JAXBException - An unexpected problem occurred during validation

validateRoot

public boolean validateRoot(Object pObject)
            throws JAXBException
Validates the given JAXB object, but not its child elements.
Parameters:
pObject - The JAXB object being validated.
Throws:
JAXBException - An unexpected problem occurred during validation