|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
javax.xml.bind.util Class JAXBSource
java.lang.Object javax.xml.transform.sax.SAXSource javax.xml.bind.util.JAXBSource
- All Implemented Interfaces:
- Source
public class JAXBSource
- extends SAXSource
编组 JAXB 生成的对象的 JAXP
javax.xml.transform.Source
实现。
此实用工具类对于将 JAXB 与其他 Java/XML 技术组合很有用。
以下示例显示了如何使用 JAXB 编组将由 XSLT 转换的文档。
MyObject o = // get JAXB content tree // jaxbContext is a JAXBContext object from which 'o' is created. JAXBSource source = new JAXBSource( jaxbContext, o ); // set up XSLT transformation TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(new StreamSource("test.xsl")); // run transformation t.transform(source,new StreamResult(System.out));
SAXSource 派生于 JAXBSource 是一个实现细节。因此,通常应用程序最好不要访问 SAXSource 上定义的方法。尤其不能调用 setXMLReader 和 setInputSource 方法。通过 getXMLReader 方法获取的 XMLReader 对象只能用于解析 getInputSource 方法返回的 InputSource 对象。
同样,通过 getInputSource 方法获得的 InputSource 对象只能由 getXMLReader 返回的 XMLReader 对象来解析。
JAXP Source
implementation
that marshals a JAXB-generated object.
This utility class is useful to combine JAXB with other Java/XML technologies.
The following example shows how to use JAXB to marshal a document for transformation by XSLT.
MyObject o = // get JAXB content tree // jaxbContext is a JAXBContext object from which 'o' is created. JAXBSource source = new JAXBSource( jaxbContext, o ); // set up XSLT transformation TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(new StreamSource("test.xsl")); // run transformation t.transform(source,new StreamResult(System.out));
The fact that JAXBSource derives from SAXSource is an implementation detail. Thus in general applications are strongly discouraged from accessing methods defined on SAXSource. In particular, the setXMLReader and setInputSource methods shall never be called. The XMLReader object obtained by the getXMLReader method shall be used only for parsing the InputSource object returned by the getInputSource method.
Similarly the InputSource object obtained by the getInputSource method shall be used only for being parsed by the XMLReader object returned by the getXMLReader.
- Author:
- Kohsuke Kawaguchi ([email protected])
Field Summary |
---|
Fields inherited from class javax.xml.transform.sax.SAXSource |
---|
FEATURE |
Constructor Summary | |
---|---|
JAXBSource(JAXBContext context,
Object contentObject)
Creates a new Source for the given content object. |
|
JAXBSource(Marshaller marshaller,
Object contentObject)
Creates a new Source for the given content object. |
Method Summary |
---|
Methods inherited from class javax.xml.transform.sax.SAXSource |
---|
getInputSource, getSystemId, getXMLReader, setInputSource, setSystemId, setXMLReader, sourceToInputSource |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public
JAXBSource(JAXBContext context, Object contentObject) throws JAXBException
针对给定的内容对象创建一个新 javax.xml.transform.Source
。
context |
用于创建 contentObject 的 JAXBContext。此上下文用于创建 marshaller 的新实例,不得为 null。 |
contentObject |
JAXB 生成的类的实例,将用作 javax.xml.transform.Source (通过将它编组到 XML)。它不得为 null。 |
Throws | JAXBException: 如果创建 JAXBSource 时遇到错误,或者任何一个参数为 null。 |
JAXBSource
public JAXBSource(JAXBContext context, Object contentObject) throws JAXBException
- Creates a new
Source
for the given content object.- Parameters:
context
- JAXBContext that was used to createcontentObject
. This context is used to create a new instance of marshaller and must not be null.contentObject
- An instance of a JAXB-generated class, which will be used as aSource
(by marshalling it into XML). It must not be null.- Throws:
JAXBException
- if an error is encountered while creating the JAXBSource or if either of the parameters are null.
public
JAXBSource(Marshaller marshaller, Object contentObject) throws JAXBException
针对给定的内容对象创建一个新 javax.xml.transform.Source
。
marshaller |
用于将 contentObject 编组到 XML 的 marshaller 实例。此实例必须根据用来构建 contentObject 的 JAXBContext 创建,不得为 null。 |
contentObject |
JAXB 生成的类的实例,将用作 javax.xml.transform.Source (通过将它编组到 XML)。它不得为 null。 |
Throws | JAXBException: 如果创建 JAXBSource 时遇到错误,或者任何一个参数为 null。 |
JAXBSource
public JAXBSource(Marshaller marshaller, Object contentObject) throws JAXBException
- Creates a new
Source
for the given content object.- Parameters:
marshaller
- A marshaller instance that will be used to marshalcontentObject
into XML. This must be created from a JAXBContext that was used to buildcontentObject
and must not be null.contentObject
- An instance of a JAXB-generated class, which will be used as aSource
(by marshalling it into XML). It must not be null.- Throws:
JAXBException
- if an error is encountered while creating the JAXBSource or if either of the parameters are null.
|
|||||||||
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 : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!