Deprecated
since JAXB 2.0
The Validator class is responsible for controlling the validation
of content trees during runtime.
- Unmarshal-Time Validation
- This form of validation enables a client application to receive information about validation errors and warnings detected while unmarshalling XML data into a Java content tree and is completely orthogonal to the other types of validation. To enable or disable it, see the javadoc for
Unmarshaller.setValidating. All JAXB 1.0 Providers are required to support this operation.- On-Demand Validation
- This form of validation enables a client application to receive information about validation errors and warnings detected in the Java content tree. At any point, client applications can call the
Validator.validatemethod on the Java content tree (or any sub-tree of it). All JAXB 1.0 Providers are required to support this operation.- Fail-Fast Validation
- This form of validation enables a client application to receive immediate feedback about modifications to the Java content tree that violate type constraints on Java Properties as defined in the specification. JAXB Providers are not required support this type of validation. Of the JAXB Providers that do support this type of validation, some may require you to decide at schema compile time whether or not a client application will be allowed to request fail-fast validation at runtime.
The Validator class is responsible for managing On-Demand Validation.
The Unmarshaller class is responsible for managing Unmarshal-Time
Validation during the unmarshal operations. Although there is no formal
method of enabling validation during the marshal operations, the
Marshaller may detect errors, which will be reported to the
ValidationEventHandler registered on it.
Using the Default EventHandler
If the client application does not set an event handler on theirValidator,Unmarshaller, orMarshallerprior to calling the validate, unmarshal, or marshal methods, then a default event handler will receive notification of any errors or warnings encountered. The default event handler will cause the current operation to halt after encountering the first error or fatal error (but will attempt to continue after receiving warnings).
There are three ways to handle events encountered during the unmarshal, validate, and marshal operations:
- Use the default event handler
- The default event handler will be used if you do not specify one via the
setEventHandlerAPI's onValidator,Unmarshaller, orMarshaller.- Implement and register a custom event handler
- Client applications that require sophisticated event processing can implement the
ValidationEventHandlerinterface and register it with theUnmarshallerand/orValidator.- Use the
ValidationEventCollectorutility- For convenience, a specialized event handler is provided that simply collects any
ValidationEventobjects created during the unmarshal, validate, and marshal operations and returns them to the client application as ajava.util.Collection.
Validation and Well-Formedness
Validation events are handled differently depending on how the client application is configured to process them as described in the previous section. However, there are certain cases where a JAXB Provider indicates that it is no longer able to reliably detect and report errors. In these cases, the JAXB Provider will set the severity of the ValidationEvent to FATAL_ERROR to indicate that the unmarshal, validate, or marshal operations should be terminated. The default event handler and
ValidationEventCollectorutility class must terminate processing after being notified of a fatal error. Client applications that supply their ownValidationEventHandlershould also terminate processing after being notified of a fatal error. If not, unexpected behaviour may occur.
There currently are not any properties required to be supported by all JAXB Providers on Validator. However, some providers may support their own set of provider specific properties.
JAXBContext, Unmarshaller, ValidationEventHandler, ValidationEvent, javax.xml.bind.util.ValidationEventCollector
| Modifier and Type | Method and Description |
|---|---|
| public ValidationEventHandler | Returns: the current ValidationEventHandler or the default event handler if it hasn't been set
Deprecated
since JAXB2.0
Return the current event handler or the default event handler if one
hasn't been set.
|
| public Object | Returns: the value of the requested propertythe name of the property to retrieve name)
Deprecated
since JAXB2.0
Get the particular property in the underlying implementation of
Validator.
|
| public void | setEventHandler(ValidationEventHandler
the validation event handler handler)
Deprecated
since JAXB2.0
Allow an application to register a validation event handler.
|
| public void | setProperty(String
the name of the property to be set. This value can either
be specified using one of the constant fields or a user
supplied string. name, Object the value of the property to be set value)
Deprecated
since JAXB2.0
Set the particular property in the underlying implementation of
Validator.
|
| public boolean | |
| public boolean | Returns: true if the tree rooted atrootObj is valid, false
otherwisethe root obj to begin validation at rootObj)
Deprecated
since JAXB2.0
Validate the Java content tree rooted at rootObj.
|
| getEventHandler | back to summary |
|---|---|
| public ValidationEventHandler getEventHandler() throws JAXBException
Deprecated since JAXB2.0 Return the current event handler or the default event handler if one hasn't been set.
| |
| getProperty | back to summary |
|---|---|
| public Object getProperty(String name) throws PropertyException
Deprecated since JAXB2.0 Get the particular property in the underlying implementation of
| |
| setEventHandler | back to summary |
|---|---|
| public void setEventHandler(ValidationEventHandler handler) throws JAXBException
Deprecated since JAXB2.0 Allow an application to register a validation event handler.
The validation event handler will be called by the JAXB Provider if any
validation errors are encountered during calls to
Calling this method with a null parameter will cause the Validator to revert back to the default default event handler.
| |
| setProperty | back to summary |
|---|---|
| public void setProperty(String name, Object value) throws PropertyException
Deprecated since JAXB2.0 Set the particular property in the underlying implementation of
| |
| validate | back to summary |
|---|---|
| public boolean validate(Object subrootObj) throws JAXBException
Deprecated since JAXB2.0 Validate the Java content tree starting at Client applications can use this method to validate Java content trees on-demand at runtime. This method can be used to validate any arbitrary subtree of the Java content tree. Global constraint checking will not be performed as part of this operation (i.e. ID/IDREF constraints).
| |
| validateRoot | back to summary |
|---|---|
| public boolean validateRoot(Object rootObj) throws JAXBException
Deprecated since JAXB2.0 Validate the Java content tree rooted at Client applications can use this method to validate Java content trees on-demand at runtime. This method is used to validate an entire Java content tree. Global constraint checking will be performed as part of this operation (i.e. ID/IDREF constraints).
| |