- java.lang.Object
-
- javax.xml.transform.sax.SAXSource
-
- javax.xml.bind.util.JAXBSource
-
- All Implemented Interfaces:
- Source
public class JAXBSource extends SAXSource
JAXPSource
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.
-
-
Field Summary
-
Fields inherited from class javax.xml.transform.sax.SAXSource
FEATURE
-
-
Constructor Summary
Constructors Constructor and Description JAXBSource(JAXBContext context, Object contentObject)
Creates a newSource
for the given content object.JAXBSource(Marshaller marshaller, Object contentObject)
Creates a newSource
for the given content object.
-
Method Summary
-
Methods inherited from class javax.xml.transform.sax.SAXSource
getInputSource, getSystemId, getXMLReader, setInputSource, setSystemId, setXMLReader, sourceToInputSource
-
-
-
-
Constructor Detail
-
JAXBSource
public JAXBSource(JAXBContext context, Object contentObject) throws JAXBException
Creates a newSource
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.
-
JAXBSource
public JAXBSource(Marshaller marshaller, Object contentObject) throws JAXBException
Creates a newSource
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.
-
-
Document created the 11/06/2005, last modified the 04/03/2020
Source of the printed document:https://www.gaudry.be/en/java-api-rf-javax/xml/bind/util/JAXBSource.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.