JAXBResult (Java EE 5)

Java EE API


javax.xml.bind.util Class JAXBResult

java.lang.Object
  extended by javax.xml.transform.sax.SAXResult
      extended by javax.xml.bind.util.JAXBResult
All Implemented Interfaces:
Result

public class JAXBResult
extends SAXResult

Extends: javax.xml.transform.sax.SAXResult

解组 JAXB 对象的 JAXP javax.xml.transform.Result 实现。

此实用工具类对于将 JAXB 与其他 Java/XML 技术组合很有用。

以下示例显示了如何使用 JAXB 解组 XSLT 转换得到的文档。

JAXBResult result = new JAXBResult(
JAXBContext.newInstance("org.acme.foo") );
       
// set up XSLT transformation
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer(new StreamSource("test.xsl"));
       
// run transformation
t.transform(new StreamSource("document.xml"),result);
 
// obtain the unmarshalled content tree
Object o = result.getResult();
    

SAXResult 派生于 JAXBResult 是一个实现细节。因此,通常应用程序最好不要访问 SAXResult 上定义的方法。

尤其不能尝试调用 setHandler、setLexicalHandler 和 setSystemId 方法。

英文文档:

JAXP Result implementation that unmarshals a JAXB object.

This utility class is useful to combine JAXB with other Java/XML technologies.

The following example shows how to use JAXB to unmarshal a document resulting from an XSLT transformation.

       JAXBResult result = new JAXBResult(
         JAXBContext.newInstance("org.acme.foo") );
       
       // set up XSLT transformation
       TransformerFactory tf = TransformerFactory.newInstance();
       Transformer t = tf.newTransformer(new StreamSource("test.xsl"));
       
       // run transformation
       t.transform(new StreamSource("document.xml"),result);
 
       // obtain the unmarshalled content tree
       Object o = result.getResult();
    

The fact that JAXBResult derives from SAXResult is an implementation detail. Thus in general applications are strongly discouraged from accessing methods defined on SAXResult.

In particular it shall never attempt to call the setHandler, setLexicalHandler, and setSystemId methods.

Author:
Kohsuke Kawaguchi ([email protected])

Field Summary
 
Fields inherited from class javax.xml.transform.sax.SAXResult
 
Fields inherited from interface javax.xml.transform.Result
 
Constructor Summary
 
Method Summary
 Object
 
Methods inherited from class javax.xml.transform.sax.SAXResult
 
Methods inherited from class java.lang.Object
 

Constructor Detail

public JAXBResult(JAXBContext context) throws JAXBException
创建一个使用指定 JAXBContext 来解组的新实例。
context 用于创建必需的 Unmarshaller 的 JAXBContext。此参数不能为 null。
ThrowsJAXBException: 如果创建 JAXBResult 时发生错误,或者上下文参数为 null。
英文文档:

JAXBResult

public JAXBResult(JAXBContext context)
           throws JAXBException
Creates a new instance that uses the specified JAXBContext to unmarshal.

Parameters:
context - The JAXBContext that will be used to create the necessary Unmarshaller. This parameter must not be null.
Throws:
JAXBException - if an error is encountered while creating the JAXBResult or if the context parameter is null.


public JAXBResult(Unmarshaller _unmarshaller) throws JAXBException
创建一个使用指定 Unmarshaller 来解组对象的新实例。

此 JAXBResult 对象将使用指定的 Unmarshaller 实例。在此对象使用某个 Unmarshaller 时,调用者负责保证该 Unmarshaller 不做其他用途。

此方法的主要目的是允许客户端配置 Unmarshaller。如果不知道操作的后果,更容易也更安全的方式是传递 JAXBContext。

_unmarshaller Unmarshaller。此参数不得为 null。
ThrowsJAXBException: 如果创建 JAXBResult 时遇到错误,或者 Unmarshaller 参数为 null。

英文文档:

JAXBResult

public JAXBResult(Unmarshaller _unmarshaller)
           throws JAXBException
Creates a new instance that uses the specified Unmarshaller to unmarshal an object.

This JAXBResult object will use the specified Unmarshaller instance. It is the caller's responsibility not to use the same Unmarshaller for other purposes while it is being used by this object.

The primary purpose of this method is to allow the client to configure Unmarshaller. Unless you know what you are doing, it's easier and safer to pass a JAXBContext.

Parameters:
_unmarshaller - the unmarshaller. This parameter must not be null.
Throws:
JAXBException - if an error is encountered while creating the JAXBResult or the Unmarshaller parameter is null.

Method Detail

public Object getResult() throws JAXBException
获取通过转换创建的已解组对象。
return 总是返回非 null 对象。
ThrowsIllegalStateException: 如果在解组对象前调用此方法。
ThrowsJAXBException: 如果出现任何解组错误。注意,允许该实现在解析错误期间抛出 SAXException。
英文文档:

getResult

public Object getResult()
                 throws JAXBException
Gets the unmarshalled object created by the transformation.

Returns:
Always return a non-null object.
Throws:
IllegalStateException - if this method is called before an object is unmarshalled.
JAXBException - if there is any unmarshalling error. Note that the implementation is allowed to throw SAXException during the parsing when it finds an error.


Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!