Package org.dom4j.jaxb
Class JAXBWriter
- java.lang.Object
-
- org.dom4j.jaxb.JAXBWriter
-
public class JAXBWriter extends java.lang.Object
WritesElement
objects to an XML stream.Element
instances can be created using the ObjectFactory that is generated by the JAXB compiler.- See Also:
XMLWriter
,JAXBContext
-
-
Constructor Summary
Constructors Constructor Description JAXBWriter(java.lang.String contextPath)
Creates a new JAXBWriter for the given JAXB context path.JAXBWriter(java.lang.String contextPath, java.lang.ClassLoader classloader)
Creates a new JAXBWriter for the given JAXB context path, using the specifiedClassLoader
.JAXBWriter(java.lang.String contextPath, java.lang.ClassLoader classloader, OutputFormat outputFormat)
Creates a new JAXBWriter for the given JAXB context path, using the specifiedClassLoader
.JAXBWriter(java.lang.String contextPath, OutputFormat outputFormat)
Creates a new JAXBWriter for the given JAXB context path.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
endDocument()
Stop writing the document to the output.OutputFormat
getOutputFormat()
Returns the OutputFormat that will be used when writing the XML stream.protected Element
marshal(javax.xml.bind.Element element)
Marshals the givenElement
in to its DOM4J counterpart.void
setOutput(java.io.File file)
Defines to write the resulting output to the specifiedFile
.void
setOutput(java.io.OutputStream outputStream)
Defines to write the resulting output to the specifiedOutputStream
void
setOutput(java.io.Writer writer)
Defines to write the resulting output to the specifiedWriter
.void
startDocument()
Start a document by writing the initial XML declaration to the output.protected javax.xml.bind.Element
unmarshal(Element element)
Unmarshalls the specified DOM4JElement
into aElement
void
write(javax.xml.bind.Element jaxbObject)
Writes the specifiedElement
to the document.void
writeClose(javax.xml.bind.Element jaxbObject)
Writes the closing tag of the specifiedElement
to the document.void
writeCloseElement(Element element)
Writes the closing tag of the specifiedElement
to the document.void
writeElement(Element element)
Writes the specifiedElement
to the document.void
writeOpen(javax.xml.bind.Element jaxbObject)
Writes the opening tag of the specifiedElement
to the document.void
writeOpenElement(Element element)
Writes the opening tag of the specifiedElement
to the document.
-
-
-
Constructor Detail
-
JAXBWriter
public JAXBWriter(java.lang.String contextPath)
Creates a new JAXBWriter for the given JAXB context path. This is the Java package where JAXB can find the generated XML classes. This package MUST contain jaxb.properties!- Parameters:
contextPath
- JAXB context path to be used- See Also:
JAXBContext
-
JAXBWriter
public JAXBWriter(java.lang.String contextPath, OutputFormat outputFormat)
Creates a new JAXBWriter for the given JAXB context path. The speciedOutputFormat
will be used for writing the XML stream.- Parameters:
contextPath
- JAXB context path to be usedoutputFormat
- the DOM4JOutputFormat
to be used- See Also:
JAXBContext
-
JAXBWriter
public JAXBWriter(java.lang.String contextPath, java.lang.ClassLoader classloader)
Creates a new JAXBWriter for the given JAXB context path, using the specifiedClassLoader
. (This is the Java package where JAXB can find the generated XML classes. This package MUST contain jaxb.properties!)- Parameters:
contextPath
- JAXB context path to be usedclassloader
- the classloader to be used for loading JAXB- See Also:
JAXBContext
-
JAXBWriter
public JAXBWriter(java.lang.String contextPath, java.lang.ClassLoader classloader, OutputFormat outputFormat)
Creates a new JAXBWriter for the given JAXB context path, using the specifiedClassLoader
. The speciedOutputFormat
will be used while writing the XML stream.- Parameters:
contextPath
- JAXB context path to be usedclassloader
- the class loader to be used to load JAXBoutputFormat
- the DOM4JOutputFormat
to be used- See Also:
JAXBContext
-
-
Method Detail
-
getOutputFormat
public OutputFormat getOutputFormat()
Returns the OutputFormat that will be used when writing the XML stream.- Returns:
- Returns the output format.
-
setOutput
public void setOutput(java.io.File file) throws java.io.IOException
Defines to write the resulting output to the specifiedFile
.- Parameters:
file
- file to write to- Throws:
java.io.IOException
- when the file cannot be found
-
setOutput
public void setOutput(java.io.OutputStream outputStream) throws java.io.IOException
Defines to write the resulting output to the specifiedOutputStream
- Parameters:
outputStream
- outputStream to write to.- Throws:
java.io.IOException
- DOCUMENT ME!
-
setOutput
public void setOutput(java.io.Writer writer) throws java.io.IOException
Defines to write the resulting output to the specifiedWriter
.- Parameters:
writer
- writer to write to- Throws:
java.io.IOException
- DOCUMENT ME!
-
startDocument
public void startDocument() throws java.io.IOException, org.xml.sax.SAXException
Start a document by writing the initial XML declaration to the output. This must be done prior to writing any other elements.- Throws:
java.io.IOException
- if an error occured while writing the outputorg.xml.sax.SAXException
- thrown by the underlying SAX driver
-
endDocument
public void endDocument() throws java.io.IOException, org.xml.sax.SAXException
Stop writing the document to the output. This must be done when all other elements are finished.- Throws:
java.io.IOException
- if an error occured while writing the outputorg.xml.sax.SAXException
- thrown by the underlying SAX driver
-
write
public void write(javax.xml.bind.Element jaxbObject) throws java.io.IOException, javax.xml.bind.JAXBException
Writes the specifiedElement
to the document.Element
instances can be created using the ObjectFactory that is generated by the JAXB compiler.- Parameters:
jaxbObject
- DOCUMENT ME!- Throws:
java.io.IOException
- if an error occured while writing the outputjavax.xml.bind.JAXBException
- when an error occured while marshalling the jaxbObject
-
writeClose
public void writeClose(javax.xml.bind.Element jaxbObject) throws java.io.IOException, javax.xml.bind.JAXBException
Writes the closing tag of the specifiedElement
to the document. This method can be used for writingElement
instances can be created using the ObjectFactory that is generated by the JAXB compiler.- Parameters:
jaxbObject
- the JAXB element to write- Throws:
java.io.IOException
- if an error occured while writing the outputjavax.xml.bind.JAXBException
- when an error occured while marshalling the jaxbObject
-
writeOpen
public void writeOpen(javax.xml.bind.Element jaxbObject) throws java.io.IOException, javax.xml.bind.JAXBException
Writes the opening tag of the specifiedElement
to the document.Element
instances can be created using the ObjectFactory that is generated by the JAXB compiler.- Parameters:
jaxbObject
- the JAXB element to write- Throws:
java.io.IOException
- if an error occured while writing the outputjavax.xml.bind.JAXBException
- when an error occured while marshalling the jaxbObject
-
writeElement
public void writeElement(Element element) throws java.io.IOException
Writes the specifiedElement
to the document.- Parameters:
element
- theElement
to write- Throws:
java.io.IOException
- if an error occured while writing the output
-
writeCloseElement
public void writeCloseElement(Element element) throws java.io.IOException
Writes the closing tag of the specifiedElement
to the document.- Parameters:
element
- theElement
to write- Throws:
java.io.IOException
- if an error occured while writing the output
-
writeOpenElement
public void writeOpenElement(Element element) throws java.io.IOException
Writes the opening tag of the specifiedElement
to the document.- Parameters:
element
- theElement
to write- Throws:
java.io.IOException
- if an error occured while writing the output
-
marshal
protected Element marshal(javax.xml.bind.Element element) throws javax.xml.bind.JAXBException
Marshals the givenElement
in to its DOM4J counterpart.- Parameters:
element
- JAXB Element to be marshalled- Returns:
- the marshalled DOM4J
Element
- Throws:
javax.xml.bind.JAXBException
- when an error occurs
-
unmarshal
protected javax.xml.bind.Element unmarshal(Element element) throws javax.xml.bind.JAXBException
Unmarshalls the specified DOM4JElement
into aElement
- Parameters:
element
- the DOM4J element to unmarshall- Returns:
- the unmarshalled JAXB object
- Throws:
javax.xml.bind.JAXBException
- when an error occurs
-
-