public interface Validator
的Validator类负责在运行时控制树木的验证内容。
- 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.
的Validator类负责需求验证管理。的Unmarshaller类负责管理数据的操作过程中的编码解码时间验证。虽然没有正式的方法进行验证的Marshaller元帅操作过程中,可能会检测到错误,它将报告给ValidationEventHandler注册它。
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 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.
JAXBContext
,
Unmarshaller
,
ValidationEventHandler
,
ValidationEvent
,
ValidationEventCollector
Modifier and Type | Method and Description |
---|---|
ValidationEventHandler |
getEventHandler()
过时的。
因为jaxb2.0
|
Object |
getProperty(String name)
过时的。
因为jaxb2.0
|
void |
setEventHandler(ValidationEventHandler handler)
过时的。
因为jaxb2.0
|
void |
setProperty(String name, Object value)
过时的。
因为jaxb2.0
|
boolean |
validate(Object subrootObj)
过时的。
因为jaxb2.0
|
boolean |
validateRoot(Object rootObj)
过时的。
因为jaxb2.0
|
void setEventHandler(ValidationEventHandler handler) throws JAXBException
验证事件处理程序将被JAXB提供者如果任何验证期间遇到错误调用validate
。如果客户端应用程序在调用验证方法之前不注册验证事件处理程序,那么将由默认事件处理程序处理验证事件,该事件处理程序将在遇到第一个错误或致命错误后终止验证操作。
使用null参数调用此方法会导致验证器恢复到默认的默认事件处理程序。
handler
-验证事件处理程序
JAXBException
如果同时设置事件处理程序时出错
ValidationEventHandler getEventHandler() throws JAXBException
JAXBException
-如果在当前的事件处理程序时出错
boolean validate(Object subrootObj) throws JAXBException
客户端应用程序可以使用这个方法来验证java内容树按需运行。这种方法可以用来验证任意的子树的java内容树。全局约束检查作为此次行动的一部分进行将不是(即ID / IDREF约束)。
subrootObj
- OBJ开始验证
JAXBException
-如果在验证过程中出现的任何意外的问题
ValidationException
-如果
ValidationEventHandler
返回false其
handleEvent法或
Validator是无法验证的内容树扎根在
subrootObj
IllegalArgumentException
-如果subrootobj参数为空
boolean validateRoot(Object rootObj) throws JAXBException
客户端应用程序可以使用这个方法来验证java内容树按需运行。此方法用于验证整个java内容树。全局约束检查作为此次行动的一部分进行将是(即ID / IDREF约束)。
rootObj
开始验证的根本目标
JAXBException
-如果在验证过程中出现的任何意外的问题
ValidationException
-如果
ValidationEventHandler
返回false其
handleEvent法或
Validator是无法验证的内容树扎根在
rootObj
IllegalArgumentException
-如果rootobj参数为空
void setProperty(String name, Object value) throws PropertyException
name
-属性的名称是。此值可以使用常量字段或用户提供的字符串中的一个指定。
value
-属性要设置的值
PropertyException
-当有特定的属性或值的误差处理
IllegalArgumentException
如果Name参数为空
Object getProperty(String name) throws PropertyException
name
-属性的名称检索
PropertyException
-当有检索给定属性或值的属性名称错误
IllegalArgumentException
如果Name参数为空
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.