|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
javax.xml.bind.util Class JAXBResult
java.lang.Object javax.xml.transform.sax.SAXResult javax.xml.bind.util.JAXBResult
- All Implemented Interfaces:
- Result
public class JAXBResult
- extends 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 |
---|
FEATURE |
Fields inherited from interface javax.xml.transform.Result |
---|
PI_DISABLE_OUTPUT_ESCAPING, PI_ENABLE_OUTPUT_ESCAPING |
Constructor Summary | |
---|---|
JAXBResult(JAXBContext context)
Creates a new instance that uses the specified JAXBContext to unmarshal. |
|
JAXBResult(Unmarshaller _unmarshaller)
Creates a new instance that uses the specified Unmarshaller to unmarshal an object. |
Method Summary | |
---|---|
Object |
getResult()
Gets the unmarshalled object created by the transformation. |
Methods inherited from class javax.xml.transform.sax.SAXResult |
---|
getHandler, getLexicalHandler, getSystemId, setHandler, setLexicalHandler, setSystemId |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public
JAXBResult(JAXBContext context) throws JAXBException
创建一个使用指定 JAXBContext 来解组的新实例。
context | 用于创建必需的 Unmarshaller 的 JAXBContext。此参数不能为 null。 |
Throws | JAXBException: 如果创建 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。 |
Throws | JAXBException: 如果创建 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 对象。 |
Throws | IllegalStateException: 如果在解组对象前调用此方法。 |
Throws | JAXBException: 如果出现任何解组错误。注意,允许该实现在解析错误期间抛出 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.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Submit a bug or feature
Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!