文字
分享


JavaTM 2 Platform
Standard Ed. 6

javax.xml.bind
接口 UnmarshallerHandler

所有超级接口:
ContentHandler

1

public interface <b>UnmarshallerHandler</b>

extends ContentHandler

作为 SAX ContentHandler 实现的 Unmarshaller。

应用程序可以使用此接口将其 JAXB 提供者用作 XML 管线中的一个组件。例如:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

JAXBContext context = JAXBContext.newInstance( "org.acme.foo" );

 

Unmarshaller unmarshaller = context.createUnmarshaller();

  

UnmarshallerHandler unmarshallerHandler = unmarshaller.getUnmarshallerHandler();

 

SAXParserFactory spf = SAXParserFactory.newInstance();

spf.setNamespaceAware( true );

  

XMLReader xmlReader = spf.newSAXParser().getXMLReader();

xmlReader.setContentHandler( unmarshallerHandler );

xmlReader.parse(new InputSource( new FileInputStream( XML_FILE ) ) );

 

MyObject myObject= (MyObject)unmarshallerHandler.getResult();                         

此接口是可重用的:即使用户解组某一对象时失败,她/他仍可开始新一轮的解组。

从以下版本开始:
JAXB1.0
另请参见:
Unmarshaller.getUnmarshallerHandler()

方法摘要
 Object getResult()
          获得解组的结果。
 
从接口 org.xml.sax.ContentHandler 继承的方法
characters, endDocument, endElement, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startElement, startPrefixMapping
 

方法详细信息

getResult

1

2

3

Object <b>getResult</b>()

                 throws JAXBException,

                        IllegalStateException

获得解组的结果。此方法只能在此处理程序接收 endDocument SAX 事件之后调用。

返回:
总是返回被解组的非 null 有效对象。
抛出:
IllegalStateException - 如果在此处理程序接收 endDocument 事件之前调用此方法。
JAXBException - 如果出现任何解组错误。注意,允许该实现在解析错误期间抛出 SAXException。

JavaTM 2 Platform
Standard Ed. 6

提交错误或意见
有关更多的 API 参考资料和开发人员文档,请参阅 Java 2 SDK SE 开发人员文档。该文档包含更详细的、面向开发人员的描述,以及总体概述、术语定义、使用技巧和工作代码示例。

版权所有 2004 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。

上一篇:Unmarshaller.Listener下一篇:ValidationEvent