- java.lang.Object
-
- javax.xml.bind.helpers.AbstractUnmarshallerImpl
-
- All Implemented Interfaces:
-
Unmarshaller
public abstract class AbstractUnmarshallerImpl extends Object implements Unmarshaller
部分默认Unmarshaller实现。该类为
Unmarshaller接口提供了部分默认实现。JAXB Provider必须实现五种方法(getUnmarshallerHandler,unmarshal(Node),unmarshal(XMLReader,InputSource),unmarshal(XMLStreamReader)和unmarshal(XMLEventReader)。
- 从以下版本开始:
- 1.6,JAXB 1.0
- 另请参见:
-
Unmarshaller
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface javax.xml.bind.Unmarshaller
Unmarshaller.Listener
-
-
Field Summary
Fields Modifier and Type Field 描述 protected booleanvalidating解密者是否验证
-
构造方法摘要
构造方法 Constructor 描述 AbstractUnmarshallerImpl()
-
方法摘要
所有方法 接口方法 抽象方法 具体的方法 Modifier and Type 方法 描述 protected UnmarshalExceptioncreateUnmarshalException(SAXException e)从SAXException创建一个UnmarshalException。<A extends XmlAdapter>
AgetAdapter(Class<A> type)获取与指定类型相关联的适配器。AttachmentUnmarshallergetAttachmentUnmarshaller()ValidationEventHandlergetEventHandler()返回当前事件处理程序或默认事件处理程序(如果尚未设置)。Unmarshaller.ListenergetListener()ObjectgetProperty(String name)getProperty方法的默认实现总是抛出PropertyException,因为没有必需的属性。SchemagetSchema()protected XMLReadergetXMLReader()获取配置的XMLReader。booleanisValidating()指示Unmarshaller是否配置为在解组操作期间进行验证。<A extends XmlAdapter>
voidsetAdapter(Class<A> type, A adapter)将配置的XmlAdapter实例与此解组器相关联。voidsetAdapter(XmlAdapter adapter)将配置的XmlAdapter实例与此解组器相关联。voidsetAttachmentUnmarshaller(AttachmentUnmarshaller au)将解析cid,content-id URI的上下文关联到作为附件传递的二进制数据。voidsetEventHandler(ValidationEventHandler handler)允许应用程序注册验证事件处理程序。voidsetListener(Unmarshaller.Listener listener)注册unmarshal事件回调Unmarshaller.Listener与这Unmarshaller。voidsetProperty(String name, Object value)setProperty方法的默认实现总是抛出PropertyException,因为没有必需的属性。voidsetSchema(Schema schema)指定应用于验证后续解组操作的JAXP 1.3Schema对象。voidsetValidating(boolean validating)指定Unmarshaller是否在解组操作期间进行验证。Objectunmarshal(File f)从指定的文件解组XML数据并返回生成的内容树。Objectunmarshal(InputStream is)从指定的InputStream中解组XML数据,并返回生成的内容树。Objectunmarshal(Reader reader)从指定的Reader中解组XML数据并返回生成的内容树。Objectunmarshal(URL url)从指定的URL解组XML数据并返回生成的内容树。Objectunmarshal(XMLEventReader reader)从指定的解析器解组XML数据并返回生成的内容树。<T> JAXBElement<T>unmarshal(XMLEventReader reader, Class<T> expectedType)将根元素解组到JAXB映射declaredType并返回结果内容树。Objectunmarshal(XMLStreamReader reader)从指定的解析器解组XML数据并返回生成的内容树。<T> JAXBElement<T>unmarshal(XMLStreamReader reader, Class<T> expectedType)将根元素解组到JAXB映射declaredType并返回生成的内容树。Objectunmarshal(Source source)从指定的XML Source中解组XML数据并返回生成的内容树。<T> JAXBElement<T>unmarshal(Source source, Class<T> expectedType)通过declaredType从指定的XML源解组XML数据,并返回生成的内容树。<T> JAXBElement<T>unmarshal(Node node, Class<T> expectedType)通过JAXB映射declaredType解组XML数据并返回结果内容树。Objectunmarshal(InputSource source)从指定的SAX InputSource解组XML数据并返回结果内容树。protected abstract Objectunmarshal(XMLReader reader, InputSource source)使用指定的XMLReader和InputSource解组合对象。-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface javax.xml.bind.Unmarshaller
getUnmarshallerHandler, unmarshal
-
-
-
-
方法详细信息
-
getXMLReader
protected XMLReader getXMLReader() throws JAXBException
-
unmarshal
public Object unmarshal(Source source) throws JAXBException
描述从接口Unmarshaller复制从指定的XML Source中解组XML数据并返回生成的内容树。实施Unmarshal Global Root Element 。
客户端应用程序可以选择不使用JAXB提供程序提供的默认解析器机制。 任何SAX 2.0兼容解析器可以替代JAXB提供程序的默认机制。 为此,客户端应用程序必须正确配置包含由SAX 2.0解析器提供程序实现的
SAXSource的XMLReader。 如果XMLReader有org.xml.sax.ErrorHandler上注册,它将被JAXB商进行更换,以便验证错误可以通过报告ValidationEventHandler机制JAXB的。 如果SAXSource不包含XMLReader,则将使用JAXB提供程序的默认解析器机制。此解析器替换机制也可用于替换JAXB提供者的解组时间验证引擎。 客户端应用程序必须正确配置其SAX 2.0兼容解析器才能执行验证(如上面的示例所示)。 解析器在解组操作期间遇到的任何
SAXParserExceptions将由JAXB提供商处理,并转换为JAXBValidationEvent对象,这些对象将通过ValidationEventHandler注册的Unmarshaller向客户端报告。 注意:指定替代验证SAX 2.0解析器进行解组合并不一定取代JAXB提供程序用于执行按需验证的验证引擎。客户端应用程序指定在
unmarshal(SAXSource)期间使用的替代解析器机制的唯一方法是通过unmarshal(SAXSource)API。 所有其他形式的解组方法(文件,URL,节点等)将使用JAXB提供程序的默认解析器和验证器机制。- Specified by:
-
unmarshal接口Unmarshaller - 参数
-
source-sourceXML数据的XML源(提供者只需要支持SAXSource,DOMSource和StreamSource) - 结果
- 新创建的java内容树的根对象
- 异常
-
JAXBException- 如果在解组时出现意外的错误 -
UnmarshalException- 如果ValidationEventHandler从其handleEvent方法返回false,或者Unmarshaller无法执行XML到Java绑定。 参见Unmarshalling XML Data - 另请参见:
-
Unmarshaller.unmarshal(javax.xml.transform.Source, Class)
-
unmarshal
protected abstract Object unmarshal(XMLReader reader, InputSource source) throws JAXBException
使用指定的XMLReader和InputSource解组合对象。 被调用者应该调用XMLReader的setErrorHandler方法,以便将错误传递给客户端指定的ValidationEventHandler。
-
unmarshal
public final Object unmarshal(InputSource source) throws JAXBException
描述从接口Unmarshaller复制从指定的SAX InputSource解组XML数据并返回结果内容树。- Specified by:
-
unmarshal在接口Unmarshaller - 参数
-
source-sourceXML数据的输入源 - 结果
- 新创建的java内容树的根对象
- 异常
-
JAXBException- 解组时是否发生意外错误 -
UnmarshalException- 如果ValidationEventHandler从其handleEvent方法返回false,或者Unmarshaller无法执行XML到Java绑定。 见Unmarshalling XML Data
-
unmarshal
public final Object unmarshal(URL url) throws JAXBException
说明从接口Unmarshaller复制从指定的URL解组XML数据并返回生成的内容树。- Specified by:
-
unmarshal在接口Unmarshaller - 参数
-
url-urlXML数据的URL - 结果
- 新创建的java内容树的根对象
- 异常
-
JAXBException- 解组时是否发生意外错误 -
UnmarshalException- 如果ValidationEventHandler从其handleEvent方法返回false,或者Unmarshaller无法执行XML到Java绑定。 见Unmarshalling XML Data
-
unmarshal
public final Object unmarshal(File f) throws JAXBException
描述从接口Unmarshaller复制从指定的文件解组XML数据并返回生成的内容树。- Specified by:
-
unmarshal在接口Unmarshaller - 参数
-
f-fXML数据的文件 - 结果
- 新创建的java内容树的根对象
- 异常
-
JAXBException- 解组时是否发生意外错误 -
UnmarshalException- 如果ValidationEventHandler从其handleEvent方法返回false,或者Unmarshaller无法执行XML到Java绑定。 见Unmarshalling XML Data
-
unmarshal
public final Object unmarshal(InputStream is) throws JAXBException
描述从接口Unmarshaller复制从指定的InputStream中解组XML数据,并返回生成的内容树。 使用这种形式的unmarshal API时,验证事件位置信息可能不完整。- Specified by:
-
unmarshal在接口Unmarshaller - 参数
-
is-isXML数据的InputStream - 结果
- 新创建的java内容树的根对象
- 异常
-
JAXBException- 解组时发生意外错误 -
UnmarshalException- 如果ValidationEventHandler从其handleEvent方法返回false,或者Unmarshaller无法执行XML到Java绑定。 见Unmarshalling XML Data
-
unmarshal
public final Object unmarshal(Reader reader) throws JAXBException
描述从接口Unmarshaller复制从指定的Reader中解组XML数据并返回生成的内容树。 使用此形式的解密API时,验证事件位置信息可能不完整,因为Reader不提供系统ID。- Specified by:
-
unmarshal在接口Unmarshaller - 参数
-
reader-readerXML数据的读者 - 结果
- 新创建的java内容树的根对象
- 异常
-
JAXBException- 解组时是否发生意外错误 -
UnmarshalException- 如果ValidationEventHandler从其handleEvent方法返回false,或者Unmarshaller无法执行XML到Java绑定。 见Unmarshalling XML Data
-
isValidating
public boolean isValidating() throws JAXBException指示Unmarshaller是否配置为在解组操作期间进行验证。注意:我将此方法命名为isValidating()以保持与JAXP保持一致,而不是将其命名为getValidating()。
- Specified by:
-
isValidating在接口Unmarshaller - 结果
- 如果Unmarshaller配置为在解组操作期间进行验证,则为true,否则为false
- 异常
-
JAXBException- 如果在检索验证标志时发生错误
-
setEventHandler
public void setEventHandler(ValidationEventHandler handler) throws JAXBException
允许应用程序注册验证事件处理程序。如果在任何
unmarshal方法的调用期间遇到任何验证错误,则JAXB提供程序将调用验证事件处理程序。 如果客户端应用程序在调用解组方法之前未注册验证事件处理程序,则所有验证事件将被默认忽略,并可能导致意外行为。- Specified by:
-
setEventHandler在接口Unmarshaller - 参数
-
handler- 验证事件处理程序 - 异常
-
JAXBException- 如果在设置事件处理程序时遇到错误
-
setValidating
public void setValidating(boolean validating) throws JAXBException指定Unmarshaller是否在解组操作期间进行验证。 默认情况下,Unmarshaller未验证。该方法只能在调用其中一个解组方法之前或之后调用。
- Specified by:
-
setValidating在接口Unmarshaller - 参数
-
validating- 如果Unmarshaller在validating过程中验证,validatingtrue,否则为false - 异常
-
JAXBException- 如果在JAXBException时启用或禁用验证时发生错误
-
getEventHandler
public ValidationEventHandler getEventHandler() throws JAXBException
返回当前事件处理程序或默认事件处理程序(如果尚未设置)。- Specified by:
-
getEventHandler在接口Unmarshaller - 结果
- 当前的ValidationEventHandler或默认事件处理程序(如果尚未设置)
- 异常
-
JAXBException- 如果在获取当前事件处理程序时遇到错误
-
createUnmarshalException
protected UnmarshalException createUnmarshalException(SAXException e)
从SAXException创建一个UnmarshalException。 这是为派生类提供的实用方法。当提供者实现的ContentHandler想要抛出JAXBException时,需要通过SAXException来包装异常。 如果unmarshaller实现通过JAXBException盲包裹SAXException,这样的异常将是由另一个JAXBException包装的SAXException包装的JAXBException。 这很傻
此方法检查嵌套异常SAXException并减少这些过度的包装。
- 结果
- 生成的UnmarshalException
-
setProperty
public void setProperty(String name, Object value) throws PropertyException
setProperty方法的默认实现总是抛出PropertyException,因为没有必需的属性。 如果提供程序需要处理其他属性,则它应该在派生类中重写此方法。- Specified by:
-
setProperty在接口Unmarshaller - 参数
-
name- 要设置的属性的名称。 可以使用常数字段或用户提供的字符串指定此值。 -
value- 要设置的属性的值 - 异常
-
PropertyException- 处理给定属性或值时出错
-
getProperty
public Object getProperty(String name) throws PropertyException
getProperty方法的默认实现总是抛出PropertyException,因为没有必需的属性。 如果提供程序需要处理其他属性,则它应该在派生类中重写此方法。- Specified by:
-
getProperty在接口Unmarshaller - 参数
-
name- 要检索的属性的名称 - 结果
- 请求的属性的值
- 异常
-
PropertyException- 检索给定属性或值属性名称时出现错误
-
unmarshal
public Object unmarshal(XMLEventReader reader) throws JAXBException
说明从接口Unmarshaller复制从指定的解析器解组XML数据并返回生成的内容树。这个方法是一个Unmarshal Global Root method 。
该方法假定解析器处于START_DOCUMENT或START_ELEMENT事件。 解组将从此开始事件到相应的结束事件。 如果此方法成功返回,则
reader将在结束事件之后指向令牌。- Specified by:
-
unmarshal在接口Unmarshaller - 参数
-
reader- 要读取的解析器。 - 结果
- 新创建的java内容树的根对象。
- 异常
-
JAXBException- 解组时如果发生意外错误 -
UnmarshalException- 如果ValidationEventHandler从其handleEvent方法返回false,或者Unmarshaller无法执行XML到Java绑定。 见Unmarshalling XML Data - 另请参见:
-
Unmarshaller.unmarshal(javax.xml.stream.XMLEventReader, Class)
-
unmarshal
public Object unmarshal(XMLStreamReader reader) throws JAXBException
描述从接口Unmarshaller复制从指定的解析器解组XML数据并返回生成的内容树。实施Unmarshal Global Root Element 。
该方法假定解析器处于START_DOCUMENT或START_ELEMENT事件。 解组将从此开始事件到相应的结束事件。 如果此方法成功返回,则
reader将在结束事件之后指向该令牌。- Specified by:
-
unmarshal在接口Unmarshaller - 参数
-
reader- 要读取的解析器。 - 结果
- 新创建的java内容树的根对象。
- 异常
-
JAXBException- 如果在解组时出现意外的错误 -
UnmarshalException- 如果ValidationEventHandler从其handleEvent方法返回false,或者Unmarshaller无法执行XML到Java绑定。 见Unmarshalling XML Data - 另请参见:
-
Unmarshaller.unmarshal(javax.xml.stream.XMLStreamReader, Class)
-
unmarshal
public <T> JAXBElement<T> unmarshal(Node node, Class<T> expectedType) throws JAXBException
描述从接口Unmarshaller复制通过JAXB映射declaredType解组XML数据,并返回结果内容树。- Specified by:
-
unmarshal在接口Unmarshaller - 参数
-
node-nodeXML数据的文档/元素。 呼叫者至少必须支持Document和Element。 -
expectedType- 适当的JAXB映射类来保存node的XML数据。 - 结果
-
JAXB Element表示
node - 异常
-
JAXBException- 解组时是否发生意外错误 -
UnmarshalException- 如果ValidationEventHandler从其handleEvent方法返回false,或者Unmarshaller无法执行XML到Java绑定。 见Unmarshalling XML Data
-
unmarshal
public <T> JAXBElement<T> unmarshal(Source source, Class<T> expectedType) throws JAXBException
描述从接口Unmarshaller复制从指定的XML源declaredTypeXML数据declaredType并返回结果内容树。- Specified by:
-
unmarshal在接口Unmarshaller - 参数
-
source-sourceXML数据的XML源(提供者只需要支持SAXSource,DOMSource和StreamSource) -
expectedType- 适当的JAXB映射类保存source的xml根元素 - 结果
- Java内容根植于 JAXB Element
- 异常
-
JAXBException- 解组时是否发生意外错误 -
UnmarshalException- 如果ValidationEventHandler从其handleEvent方法返回false,或者Unmarshaller无法执行XML到Java绑定。 见Unmarshalling XML Data
-
unmarshal
public <T> JAXBElement<T> unmarshal(XMLStreamReader reader, Class<T> expectedType) throws JAXBException
描述从接口Unmarshaller复制将根元素解组到JAXB映射declaredType并返回生成的内容树。该方法实现unmarshal by declaredType 。
该方法假定解析器处于START_DOCUMENT或START_ELEMENT事件。 解组将从此开始事件到相应的结束事件。 如果此方法成功返回,则
reader将在结束事件之后指向该令牌。- Specified by:
-
unmarshal在接口Unmarshaller - 参数
-
reader- 要读取的解析器。 -
expectedType- 适当的JAXB映射类来保存reader的START_ELEMENT XML数据。 - 结果
- 内容树根据 JAXB Element representation
- 异常
-
JAXBException- 解组时是否发生意外错误 -
UnmarshalException- 如果ValidationEventHandler从其handleEvent方法返回false,或者Unmarshaller无法执行XML到Java绑定。 见Unmarshalling XML Data
-
unmarshal
public <T> JAXBElement<T> unmarshal(XMLEventReader reader, Class<T> expectedType) throws JAXBException
说明从接口Unmarshaller复制将根元素解组到JAXB映射declaredType并返回生成的内容树。该方法实现unmarshal by declaredType 。
该方法假定解析器处于START_DOCUMENT或START_ELEMENT事件。 解组将从此开始事件到相应的结束事件。 如果此方法成功返回,则
reader将在结束事件之后指向该令牌。- Specified by:
-
unmarshal在接口Unmarshaller - 参数
-
reader- 要读取的解析器。 -
expectedType- 适当的JAXB映射类保存reader的START_ELEMENT XML数据。 - 结果
- 内容树根据 JAXB Element representation
- 异常
-
JAXBException- 如果在解组时出现意外错误 -
UnmarshalException- 如果ValidationEventHandler从其handleEvent方法返回false,或者Unmarshaller无法执行XML到Java绑定。 见Unmarshalling XML Data
-
setSchema
public void setSchema(Schema schema)
描述从接口Unmarshaller复制指定应用于验证后续解组操作的JAXP 1.3Schema对象。 将null传递给此方法将禁用验证。此方法将替换已弃用的
setValidating(boolean)API。最初此属性设置为
null。- Specified by:
-
setSchema在接口Unmarshaller - 参数
-
schema- 用于验证解组操作的模式对象或null以禁用验证
-
getSchema
public Schema getSchema()
描述从接口Unmarshaller复制获取用于执行解密时间验证的JAXP 1.3Schema对象。 如果在unmarshaller上没有设置Schema,则该方法将返回null,表示将不执行解密时间验证。此方法提供了一种用于不推荐的替换功能
Unmarshaller.isValidating()API以及访问架构对象。 要确定Unmarshaller是否启用了验证,只需将null的返回类型测试:boolean isValidating = u.getSchema()!=null;- Specified by:
-
getSchema在接口Unmarshaller - 结果
- 用于执行解密时间验证的Schema对象,如果不存在则使用null
-
setAdapter
public void setAdapter(XmlAdapter adapter)
描述从接口Unmarshaller复制将配置的XmlAdapter实例与此解组器相关联。这是调用
setAdapter(adapter.getClass(),adapter);的方便方法。- Specified by:
-
setAdapter在接口Unmarshaller - 另请参见:
-
Unmarshaller.setAdapter(Class,XmlAdapter)
-
setAdapter
public <A extends XmlAdapter> void setAdapter(Class<A> type, A adapter)
描述从接口Unmarshaller复制将配置的XmlAdapter实例与此解组器相关联。每个unmarshaller内部维护一个
Map<Class,XmlAdapter>,它使用用于解组类,它们的字段/方法的注解为XmlJavaTypeAdapter。该方法允许应用程序使用配置的
XmlAdapter实例。 当未给出适配器的实例时,解组器将通过调用其默认构造函数来创建一个。- Specified by:
-
setAdapter在接口Unmarshaller - 参数
-
type- 适配器的类型。 当XmlJavaTypeAdapter.value()引用此类型时,将使用指定的实例。 -
adapter- 要使用的适配器的实例。 如果为空,它将取消注册此类型的当前适配器集。
-
getAdapter
public <A extends XmlAdapter> A getAdapter(Class<A> type)
说明从接口Unmarshaller复制获取与指定类型相关联的适配器。 这是Unmarshaller.setAdapter(javax.xml.bind.annotation.adapters.XmlAdapter)方法的反向操作。- Specified by:
-
getAdapter在接口Unmarshaller
-
setAttachmentUnmarshaller
public void setAttachmentUnmarshaller(AttachmentUnmarshaller au)
描述从接口Unmarshaller复制将解析cid,content-id URI的上下文关联到作为附件传递的二进制数据。
即使在解组器执行XOP处理时,也必须支持通过
Unmarshaller.setSchema(Schema)启用解密时间验证。- Specified by:
-
setAttachmentUnmarshaller在接口Unmarshaller
-
getAttachmentUnmarshaller
public AttachmentUnmarshaller getAttachmentUnmarshaller()
- Specified by:
-
getAttachmentUnmarshaller在接口Unmarshaller
-
setListener
public void setListener(Unmarshaller.Listener listener)
描述从接口Unmarshaller复制注册unmarshal事件回调
Unmarshaller.Listener与这Unmarshaller。每个Unmarshaller只有一个监听器。 设置侦听器将替换以前设置的侦听器。 可以通过将侦听器设置为
null来注销当前侦听器。- Specified by:
-
setListener在接口Unmarshaller - 参数
-
listener- 为此Unmarshaller提供了解组件事件回调
-
getListener
public Unmarshaller.Listener getListener()
描述从接口Unmarshaller复制- Specified by:
-
getListener在接口Unmarshaller - 结果
-
注册了
Unmarshaller.Listener或null如果没有监听器已经注册到这个Unmarshaller。
-
-