public abstract class Validator 
 extends Object 
| java.lang.Object | |
| ↳ | javax.xml.validation.Validator | 
处理器根据 Schema检查XML文档。
验证器是一个线程不安全且不可重入的对象。 换句话说,应用程序有责任确保一个Validator对象不会在任何给定时间从多个线程中使用,并且在调用validate方法时,应用程序可能不会递归调用validate方法。
注意,虽然 validate(javax.xml.transform.Source)种 validate(javax.xml.transform.Source, javax.xml.transform.Result)方法采取 Source例如, Source实例必须是 SAXSource , DOMSource , StAXSource或者 StreamSource 。
| Protected constructors | |
|---|---|
|  Validator() 派生类的构造函数。 | |
| Public methods | |
|---|---|
|  abstract ErrorHandler |  getErrorHandler() 获取当前  | 
|  boolean |  getFeature(String name) 查找功能标志的值。 | 
|  Object |  getProperty(String name) 查找一个属性的值。 | 
|  abstract LSResourceResolver |  getResourceResolver() 获取当前  | 
|  abstract void |  reset() 将此  | 
|  abstract void |  setErrorHandler(ErrorHandler errorHandler) 将  | 
|  void |  setFeature(String name, boolean value) 设置功能标志的值。 | 
|  void |  setProperty(String name, Object object) 设置属性的值。 | 
|  abstract void |  setResourceResolver(LSResourceResolver resourceResolver) 设置  | 
|  void |  validate(Source source) 验证指定的输入。 | 
|  abstract void |  validate(Source source, Result result) 验证指定的输入并将扩充的验证结果发送到指定的输出。 | 
| Inherited methods | |
|---|---|
|  From class  java.lang.Object  | |
Validator ()
派生类的构造函数。
构造函数什么都不做。
派生类必须创建 Validator对象,其中包含 null ErrorHandler和 null LSResourceResolver 。
ErrorHandler getErrorHandler ()
获取当前 ErrorHandler设置为这个 Validator 。
| Returns | |
|---|---|
| ErrorHandler | This method returns the object that was last set through the setErrorHandler(ErrorHandler)method, or null if that method has never been called since thisValidatorhas created. | 
boolean getFeature (String name)
查找功能标志的值。
功能名称是任何完全限定的URI。 Validator可能会识别功能名称,但暂时无法返回其值。 某些功能值只能在特定上下文中使用,例如在验证之前,期间或之后。
实现者可以免费(并鼓励)使用构建在他们自己的URI上的名称来创建自己的特性。
| Parameters | |
|---|---|
| name | String: The feature name, which is a non-null fully-qualified URI. | 
| Returns | |
|---|---|
| boolean | The current value of the feature (true or false). | 
| Throws | |
|---|---|
| SAXNotRecognizedException | If the feature value can't be assigned or retrieved. | 
| SAXNotSupportedException | When the Validatorrecognizes the feature name but cannot determine its value at this time. | 
| NullPointerException | When the name parameter is null. | 
也可以看看:
Object getProperty (String name)
查找一个属性的值。
属性名称是任何完全限定的URI。 Validator可能会识别属性名称,但暂时无法返回其值。 某些属性值只能在特定的上下文中使用,例如在验证之前,期间或之后。
Validator不需要识别任何特定的属性名称。
实现者可以免费(并鼓励)使用构建在他们自己的URI上的名称来创建他们自己的属性。
| Parameters | |
|---|---|
| name | String: The property name, which is a non-null fully-qualified URI. | 
| Returns | |
|---|---|
| Object | The current value of the property. | 
| Throws | |
|---|---|
| SAXNotRecognizedException | If the property value can't be assigned or retrieved. | 
| SAXNotSupportedException | When the XMLReader recognizes the property name but cannot determine its value at this time. | 
| NullPointerException | When the name parameter is null. | 
也可以看看:
LSResourceResolver getResourceResolver ()
获取当前 LSResourceResolver设置为这个 Validator 。
| Returns | |
|---|---|
| LSResourceResolver | This method returns the object that was last set through the setResourceResolver(LSResourceResolver)method, or null if that method has never been called since thisValidatorhas created. | 
See also:
void reset ()
将此 Validator重置为其原始配置。
Validator被重置为与使用newValidator()创建时相同的状态。 reset()旨在允许重复使用现有的Validator从而节省与创建新的Validator相关的资源。
不保证重置Validator具有相同的LSResourceResolver或ErrorHandler Object ,例如equals(Object) 。 它保证有一个功能相同的LSResourceResolver和ErrorHandler 。
void setErrorHandler (ErrorHandler errorHandler)
将 ErrorHandler设置为接收 validate方法调用期间遇到的错误。
错误处理程序可用于在验证期间自定义错误处理过程。 当设置了ErrorHandler时,验证过程中发现的错误将首先发送到ErrorHandler 。
错误处理程序可以通过从处理程序中抛出SAXException立即中止进一步验证。 或者,例如,它可以向屏幕输出错误,并尝试通过从ErrorHandler正常返回来继续验证
如果任何 Throwable选自抛出 ErrorHandler ,所述的呼叫者 validate方法将被抛出相同 Throwable对象。
Validator不允许扔 SAXException没有首先将其报告给 ErrorHandler 。
当 ErrorHandler为空时,实现将表现得好像设置了以下 ErrorHandler :
class DraconianErrorHandler implementsErrorHandler{ public void fatalError(SAXParseExceptione ) throwsSAXException{ throw e; } public void error(SAXParseExceptione ) throwsSAXException{ throw e; } public void warning(SAXParseExceptione ) throwsSAXException{ // noop } }
当新的 Validator对象被创建时,最初这个字段被设置为空。
| Parameters | |
|---|---|
| errorHandler | ErrorHandler: A new error handler to be set. This parameter can be null. | 
void setFeature (String name, boolean value)
设置功能标志的值。
功能可以用来控制 Validator解析模式的方式,但 Validator识别任何特定的属性名称。
功能名称是任何完全限定的URI。 Validator可能会显示特征值,但无法更改当前值。 某些特征值只能在特定上下文中不可变或可变,例如在验证之前,期间或之后。
| Parameters | |
|---|---|
| name | String: The feature name, which is a non-null fully-qualified URI. | 
| value | boolean: The requested value of the feature (true or false). | 
| Throws | |
|---|---|
| SAXNotRecognizedException | If the feature value can't be assigned or retrieved. | 
| SAXNotSupportedException | When the Validatorrecognizes the feature name but cannot set the requested value. | 
| NullPointerException | When the name parameter is null. | 
也可以看看:
void setProperty (String name, Object object)
设置属性的值。
属性名称是任何完全限定的URI。 Validator可能会识别属性名称,但无法更改当前值。 某些属性值只能在特定上下文中不可变或可变,例如在验证之前,期间或之后。
Validators are not required to recognize setting any specific property names.
| Parameters | |
|---|---|
| name | String: The property name, which is a non-null fully-qualified URI. | 
| object | Object: The requested value for the property. | 
| Throws | |
|---|---|
| SAXNotRecognizedException | If the property value can't be assigned or retrieved. | 
| SAXNotSupportedException | When the Validatorrecognizes the property name but cannot set the requested value. | 
| NullPointerException | When the name parameter is null. | 
void setResourceResolver (LSResourceResolver resourceResolver)
设置 LSResourceResolver以在验证期间自定义资源分辨率。
Validator在 LSResourceResolver时需要定位外部资源时使用 LSResourceResolver ,但确切地说,构成“定位外部资源”的内容取决于每种模式语言。
当 LSResourceResolver为空时,实现将表现得好像设置了以下 LSResourceResolver :
class DumbLSResourceResolver implementsLSResourceResolver{ publicLSInputresolveResource( String publicId, String systemId, String baseURI) { return null; // always return null } }
如果 LSResourceResolver引发 RuntimeException (或其派生类的实例),则 Validator将中止解析,并且 validate方法的调用者将收到相同的 RuntimeException 。
当新的 Validator对象被创建时,最初这个字段被设置为空。
| Parameters | |
|---|---|
| resourceResolver | LSResourceResolver: A new resource resolver to be set. This parameter can be null. | 
void validate (Source source)
验证指定的输入。
这只是一个方便的方法:
validate(source,null);
| Parameters | |
|---|---|
| source | Source | 
| Throws | |
|---|---|
| SAXException | |
| IOException | |
void validate (Source source, Result result)
验证指定的输入并将扩充的验证结果发送到指定的输出。
这个方法放在该类型的下列限制 Source / Result接受。
Source/Result accepted:| SAXSource | DOMSource | StreamSource | ||
| null | OK | OK | OK | OK | 
| SAXResult | OK | Err | Err | Err | 
| DOMResult | Err | OK | Err | Err | 
| StreamResult | Err | Err | Err | OK | 
要将一个 Source验证为另一种类型的 Result ,请使用标识变换器(请参阅 newTransformer() )。
验证过程中发现的错误将发送到指定的 ErrorHandler 。
如果文档有效,或者文档包含一些错误,但没有一个是致命的,并且 ErrorHandler没有抛出任何异常,则该方法正常返回。
| Parameters | |
|---|---|
| source | Source: XML to be validated. Must not be null. | 
| result | Result: TheResultobject that receives (possibly augmented) XML. This parameter can be null if the caller is not interested in it. Note that when aDOMResultis used, a validator might just pass the same DOM node fromDOMSourcetoDOMResult(in which case source.getNode()==result.getNode()), it might copy the entire DOM tree, or it might alter the node given by the source. | 
| Throws | |
|---|---|
| IllegalArgumentException | If the Resulttype doesn't match theSourcetype, or if the specified source is not aSAXSource,DOMSourceorStreamSource. | 
| SAXException | If the ErrorHandlerthrows aSAXExceptionor if a fatal error is found and theErrorHandlerreturns normally. | 
| IOException | If the validator is processing a SAXSourceand the underlyingXMLReaderthrows anIOException. | 
| NullPointerException | If the source parameter is null. | 
也可以看看: