-
Deprecated.since JAXB 2.0
public interface Validator
As of JAXB 2.0, this class is deprecated and optional.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.validate
method 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 their Validator, Unmarshaller, or Marshaller prior 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 setEventHandler API's on Validator, Unmarshaller, or Marshaller.
- Implement and register a custom event handler
- Client applications that require sophisticated event processing can implement the ValidationEventHandler interface and register it with the Unmarshaller and/or Validator.
- Use the
ValidationEventCollector
utility - For convenience, a specialized event handler is provided that simply collects any ValidationEvent objects created during the unmarshal, validate, and marshal operations and returns them to the client application as a java.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 ValidationEventCollector utility class must terminate processing after being notified of a fatal error. Client applications that supply their own ValidationEventHandler should 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.
- Since:
- JAXB1.0
- See Also:
JAXBContext
,Unmarshaller
,ValidationEventHandler
,ValidationEvent
,ValidationEventCollector
-
-
Method Summary
Methods Modifier and Type Method and Description ValidationEventHandler
getEventHandler()
Deprecated.since JAXB2.0Object
getProperty(String name)
Deprecated.since JAXB2.0void
setEventHandler(ValidationEventHandler handler)
Deprecated.since JAXB2.0void
setProperty(String name, Object value)
Deprecated.since JAXB2.0boolean
validate(Object subrootObj)
Deprecated.since JAXB2.0boolean
validateRoot(Object rootObj)
Deprecated.since JAXB2.0
-
-
-
Method Detail
-
setEventHandler
void setEventHandler(ValidationEventHandler handler) throws JAXBException
Deprecated. since JAXB2.0Allow 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
validate
. If the client application does not register a validation event handler before invoking the validate method, then validation events will be handled by the default event handler which will terminate the validate operation after the first error or fatal error is encountered.Calling this method with a null parameter will cause the Validator to revert back to the default default event handler.
- Parameters:
handler
- the validation event handler- Throws:
JAXBException
- if an error was encountered while setting the event handler
-
getEventHandler
ValidationEventHandler getEventHandler() throws JAXBException
Deprecated. since JAXB2.0Return the current event handler or the default event handler if one hasn't been set.- Returns:
- the current ValidationEventHandler or the default event handler if it hasn't been set
- Throws:
JAXBException
- if an error was encountered while getting the current event handler
-
validate
boolean validate(Object subrootObj) throws JAXBException
Deprecated. since JAXB2.0Validate the Java content tree starting at subrootObj.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).
- Parameters:
subrootObj
- the obj to begin validation at- Returns:
- true if the subtree rooted at subrootObj is valid, false otherwise
- Throws:
JAXBException
- if any unexpected problem occurs during validationValidationException
- If theValidationEventHandler
returns false from its handleEvent method or the Validator is unable to validate the content tree rooted at subrootObjIllegalArgumentException
- If the subrootObj parameter is null
-
validateRoot
boolean validateRoot(Object rootObj) throws JAXBException
Deprecated. since JAXB2.0Validate the Java content tree rooted at rootObj.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).
- Parameters:
rootObj
- the root obj to begin validation at- Returns:
- true if the tree rooted at rootObj is valid, false otherwise
- Throws:
JAXBException
- if any unexpected problem occurs during validationValidationException
- If theValidationEventHandler
returns false from its handleEvent method or the Validator is unable to validate the content tree rooted at rootObjIllegalArgumentException
- If the rootObj parameter is null
-
setProperty
void setProperty(String name, Object value) throws PropertyException
Deprecated. since JAXB2.0Set the particular property in the underlying implementation of Validator. This method can only be used to set one of the standard JAXB defined properties above or a provider specific property. Attempting to set an undefined property will result in a PropertyException being thrown. See Supported Properties.- Parameters:
name
- 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.value
- the value of the property to be set- Throws:
PropertyException
- when there is an error processing the given property or valueIllegalArgumentException
- If the name parameter is null
-
getProperty
Object getProperty(String name) throws PropertyException
Deprecated. since JAXB2.0Get the particular property in the underlying implementation of Validator. This method can only be used to get one of the standard JAXB defined properties above or a provider specific property. Attempting to get an undefined property will result in a PropertyException being thrown. See Supported Properties.- Parameters:
name
- the name of the property to retrieve- Returns:
- the value of the requested property
- Throws:
PropertyException
- when there is an error retrieving the given property or value property nameIllegalArgumentException
- If the name parameter is null
-
-
Deutsche Übersetzung
Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.
Vielen Dank im Voraus.
Dokument erstellt 11/06/2005, zuletzt geändert 04/03/2020
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/java-api-rf-javax/xml/bind/validator.html
Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.
Referenzen
Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.