Top Description Fields Constructors Methods
javax.xml.bind.util

public Class JAXBSource

extends SAXSource
Class Inheritance
Imports
org.xml.sax.ContentHandler, .DTDHandler, .EntityResolver, .ErrorHandler, .InputSource, .SAXException, .SAXNotRecognizedException, .SAXParseException, .XMLReader, .XMLFilter, org.xml.sax.ext.LexicalHandler, org.xml.sax.helpers.XMLFilterImpl, javax.xml.bind.JAXBContext, .JAXBException, .Marshaller, javax.xml.transform.sax.SAXSource

JAXP javax.xml.transform.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])
Since
1.6

Field Summary

Modifier and TypeField and Description
private final Object
private final Marshaller
private final XMLReader
Inherited from javax.xml.transform.sax.SAXSource:
FEATURE

Constructor Summary

AccessConstructor and Description
public
JAXBSource(JAXBContext
JAXBContext that was used to create contentObject. This context is used to create a new instance of marshaller and must not be null.
context
,
Object
An instance of a JAXB-generated class, which will be used as a javax.xml.transform.Source (by marshalling it into XML). It must not be null.
contentObject
)

Creates a new javax.xml.transform.Source for the given content object.

public
JAXBSource(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.
marshaller
,
Object
An instance of a JAXB-generated class, which will be used as a javax.xml.transform.Source (by marshalling it into XML). It must not be null.
contentObject
)

Creates a new javax.xml.transform.Source for the given content object.

Method Summary

Modifier and TypeMethod and Description
private static Marshaller
assertionFailed(String message)

Hook to throw exception from the middle of a contructor chained call to this

Inherited from javax.xml.transform.sax.SAXSource:
getInputSourcegetSystemIdgetXMLReaderisEmptysetInputSourcesetSystemIdsetXMLReadersourceToInputSource

Field Detail

contentObjectback to summary
private final Object contentObject
marshallerback to summary
private final Marshaller marshaller
pseudoParserback to summary
private final XMLReader pseudoParser

Constructor Detail

JAXBSourceback to summary
public JAXBSource(JAXBContext context, Object contentObject) throws JAXBException

Creates a new javax.xml.transform.Source for the given content object.

Parameters
context:JAXBContext

JAXBContext that was used to create contentObject. This context is used to create a new instance of marshaller and must not be null.

contentObject:Object

An instance of a JAXB-generated class, which will be used as a javax.xml.transform.Source (by marshalling it into XML). It must not be null.

Exceptions
JAXBException:
if an error is encountered while creating the JAXBSource or if either of the parameters are null.
JAXBSourceback to summary
public JAXBSource(Marshaller marshaller, Object contentObject) throws JAXBException

Creates a new javax.xml.transform.Source for the given content object.

Parameters
marshaller: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:Object

An instance of a JAXB-generated class, which will be used as a javax.xml.transform.Source (by marshalling it into XML). It must not be null.

Exceptions
JAXBException:
if an error is encountered while creating the JAXBSource or if either of the parameters are null.

Method Detail

assertionFailedback to summary
private static Marshaller assertionFailed(String message) throws JAXBException

Hook to throw exception from the middle of a contructor chained call to this