javax.xml.bind
Interface Validator

All Known Subinterfaces:
JMValidator
All 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.

Since:
JAXB1.0
Author:
JSR-31
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(java.lang.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(java.lang.String pName, java.lang.Object pValue)
          Sets the Validator property pName to pValue.
 boolean validate(java.lang.Object pObject)
          Validates the given JAXB object, invoking its error handler for any problems it detects.
 boolean validateRoot(java.lang.Object pObject)
          Validates the given JAXB object, but not its child elements.
 

Method Detail

setEventHandler

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.

getEventHandler

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.

validate

boolean validate(java.lang.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
ValidationException - It was detected, that the object is invalid.
java.lang.IllegalArgumentException - The parameter was null.
See Also:
validateRoot(Object)

validateRoot

boolean validateRoot(java.lang.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
ValidationException - It was detected, that the object is invalid.
java.lang.IllegalArgumentException - The parameter was null.
See Also:
validate(Object)

setProperty

void setProperty(java.lang.String pName,
                 java.lang.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.
java.lang.IllegalArgumentException - The pName parameter was null.

getProperty

java.lang.Object getProperty(java.lang.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.
java.lang.IllegalArgumentException - The parameter was null.