JavaTM 2 Platform
Standard Ed. 6

javax.xml.bind.util
类 JAXBResult

java.lang.Object
  继承者 javax.xml.transform.sax.SAXResult
      继承者 javax.xml.bind.util.JAXBResult
所有已实现的接口:
Result

public class JAXBResult
extends SAXResult

解组 JAXB 对象的 JAXP 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 方法。


字段摘要
 
从类 javax.xml.transform.sax.SAXResult 继承的字段
FEATURE
 
从接口 javax.xml.transform.Result 继承的字段
PI_DISABLE_OUTPUT_ESCAPING, PI_ENABLE_OUTPUT_ESCAPING
 
构造方法摘要
JAXBResult(JAXBContext context)
          创建一个使用指定 JAXBContext 来解组的新实例。
JAXBResult(Unmarshaller _unmarshaller)
          创建一个使用指定 Unmarshaller 来解组对象的新实例。
 
方法摘要
 Object getResult()
          获取通过转换创建的已解组对象。
 
从类 javax.xml.transform.sax.SAXResult 继承的方法
getHandler, getLexicalHandler, getSystemId, setHandler, setLexicalHandler, setSystemId
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

JAXBResult

public JAXBResult(JAXBContext context)
           throws JAXBException
创建一个使用指定 JAXBContext 来解组的新实例。

参数:
context - 用于创建必需的 Unmarshaller 的 JAXBContext。此参数不能为 null。
抛出:
JAXBException - 如果创建 JAXBResult 时发生错误,或者上下文参数为 null。

JAXBResult

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

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

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

参数:
_unmarshaller - Unmarshaller。此参数不得为 null。
抛出:
JAXBException - 如果创建 JAXBResult 时遇到错误,或者 Unmarshaller 参数为 null。
方法详细信息

getResult

public Object getResult()
                 throws JAXBException
获取通过转换创建的已解组对象。

返回:
总是返回非 null 对象。
抛出:
IllegalStateException - 如果在解组对象前调用此方法。
JAXBException - 如果发生解组错误。注意,允许实现在解析错误期间抛出 SAXException。

JavaTM 2 Platform
Standard Ed. 6

提交错误或意见

版权所有 2008 Sun Microsystems, Inc. 保留所有权利。请遵守GNU General Public License, version 2 only