JAXBSource (Java Platform SE 7 ) (original) (raw)
- javax.xml.transform.sax.SAXSource
- javax.xml.bind.util.JAXBSource
All Implemented Interfaces:
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.
Field Summary
* ### Fields inherited from class javax.xml.transform.sax.[SAXSource](../../../../javax/xml/transform/sax/SAXSource.html "class in javax.xml.transform.sax") `[FEATURE](../../../../javax/xml/transform/sax/SAXSource.html#FEATURE)`
Constructor Summary
Constructors
Constructor and Description 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](../../../../javax/xml/transform/sax/SAXSource.html "class in javax.xml.transform.sax") `[getInputSource](../../../../javax/xml/transform/sax/SAXSource.html#getInputSource%28%29), [getSystemId](../../../../javax/xml/transform/sax/SAXSource.html#getSystemId%28%29), [getXMLReader](../../../../javax/xml/transform/sax/SAXSource.html#getXMLReader%28%29), [setInputSource](../../../../javax/xml/transform/sax/SAXSource.html#setInputSource%28org.xml.sax.InputSource%29), [setSystemId](../../../../javax/xml/transform/sax/SAXSource.html#setSystemId%28java.lang.String%29), [setXMLReader](../../../../javax/xml/transform/sax/SAXSource.html#setXMLReader%28org.xml.sax.XMLReader%29), [sourceToInputSource](../../../../javax/xml/transform/sax/SAXSource.html#sourceToInputSource%28javax.xml.transform.Source%29)` * ### Methods inherited from class java.lang.[Object](../../../../java/lang/Object.html "class in java.lang") `[clone](../../../../java/lang/Object.html#clone%28%29), [equals](../../../../java/lang/Object.html#equals%28java.lang.Object%29), [finalize](../../../../java/lang/Object.html#finalize%28%29), [getClass](../../../../java/lang/Object.html#getClass%28%29), [hashCode](../../../../java/lang/Object.html#hashCode%28%29), [notify](../../../../java/lang/Object.html#notify%28%29), [notifyAll](../../../../java/lang/Object.html#notifyAll%28%29), [toString](../../../../java/lang/Object.html#toString%28%29), [wait](../../../../java/lang/Object.html#wait%28%29), [wait](../../../../java/lang/Object.html#wait%28long%29), [wait](../../../../java/lang/Object.html#wait%28long,%20int%29)`
Constructor Detail
* #### JAXBSource public JAXBSource([JAXBContext](../../../../javax/xml/bind/JAXBContext.html "class in javax.xml.bind") context, [Object](../../../../java/lang/Object.html "class in java.lang") contentObject) throws [JAXBException](../../../../javax/xml/bind/JAXBException.html "class in javax.xml.bind") Creates a new [Source](../../../../javax/xml/transform/Source.html "interface in javax.xml.transform") for the given content object. Parameters: `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](../../../../javax/xml/transform/Source.html "interface in javax.xml.transform") (by marshalling it into XML). It must not be null. Throws: `[JAXBException](../../../../javax/xml/bind/JAXBException.html "class in javax.xml.bind")` \- if an error is encountered while creating the JAXBSource or if either of the parameters are null. * #### JAXBSource public JAXBSource([Marshaller](../../../../javax/xml/bind/Marshaller.html "interface in javax.xml.bind") marshaller, [Object](../../../../java/lang/Object.html "class in java.lang") contentObject) throws [JAXBException](../../../../javax/xml/bind/JAXBException.html "class in javax.xml.bind") Creates a new [Source](../../../../javax/xml/transform/Source.html "interface in javax.xml.transform") for the given content object. Parameters: `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](../../../../javax/xml/transform/Source.html "interface in javax.xml.transform") (by marshalling it into XML). It must not be null. Throws: `[JAXBException](../../../../javax/xml/bind/JAXBException.html "class in javax.xml.bind")` \- if an error is encountered while creating the JAXBSource or if either of the parameters are null.
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2020, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.