JAXBSource (Java EE 5 SDK)

Java

Java EE 5 SDK

深圳电信培训中心.徐海蛟老师.


javax.xml.bind.util Class JAXBSource

java.lang.Object
  extended by javax.xml.transform.sax.SAXSource
      extended by javax.xml.bind.util.JAXBSource
所有已实现的接口:
Source

public class JAXBSource
extends SAXSource

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.

作者:
Kohsuke Kawaguchi ([email protected])

字段摘要
 
Fields inherited from class javax.xml.transform.sax.SAXSource
FEATURE
 
构造器摘要
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.
 
方法摘要
 
类方法继承 javax.xml.transform.sax.SAXSource
getInputSource, getSystemId, getXMLReader, setInputSource, setSystemId, setXMLReader, sourceToInputSource
 
类方法继承 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造器详细信息

JAXBSource

public JAXBSource(JAXBContext context,
                  Object contentObject)
           throws JAXBException
Creates a new Source for the given content object.

参数:
context - JAXBContext that was used to create contentObject. 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 a Source (by marshalling it into XML). It must not be null.
抛出异常:
JAXBException - if an error is encountered while creating the JAXBSource or if either of the parameters are null.


JAXBSource

public JAXBSource(Marshaller marshaller,
                  Object contentObject)
           throws JAXBException
Creates a new Source for the given content object.

参数:
marshaller - A marshaller instance that will be used to marshal contentObject into XML. This must be created from a JAXBContext that was used to build contentObject and must not be null.
contentObject - An instance of a JAXB-generated class, which will be used as a Source (by marshalling it into XML). It must not be null.
抛出异常:
JAXBException - if an error is encountered while creating the JAXBSource or if either of the parameters are null.


Java EE 5 SDK

深圳电信培训中心.徐海蛟老师.


提交错误或意见

版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。深圳电信培训中心.徐海蛟老师教学参考.