Package org.dom4j.jaxb
Class JAXBWriter
java.lang.Object
org.dom4j.jaxb.JAXBWriter
Writes
Element
objects to an XML stream. Element
instances can be created using the ObjectFactory that
is generated by the JAXB compiler.- Author:
- Wonne Keysers (Realsoftware.be)
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionJAXBWriter
(String contextPath) Creates a new JAXBWriter for the given JAXB context path.JAXBWriter
(String contextPath, ClassLoader classloader) Creates a new JAXBWriter for the given JAXB context path, using the specifiedjava.lang.Classloader
.JAXBWriter
(String contextPath, ClassLoader classloader, OutputFormat outputFormat) Creates a new JAXBWriter for the given JAXB context path, using the specifiedjava.lang.Classloader
.JAXBWriter
(String contextPath, OutputFormat outputFormat) Creates a new JAXBWriter for the given JAXB context path. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Stop writing the document to the output.Returns the OutputFormat that will be used when writing the XML stream.protected Element
Marshals the givenElement
in to its DOM4J counterpart.void
Defines to write the resulting output to the specifiedFile
.void
setOutput
(OutputStream outputStream) Defines to write the resulting output to the specifiedOutputStream
void
Defines to write the resulting output to the specifiedWriter
.void
Start a document by writing the initial XML declaration to the output.protected Element
void
Writes the specifiedElement
to the document.void
writeClose
(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
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 Details
-
JAXBWriter
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:
-
JAXBWriter
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:
-
JAXBWriter
Creates a new JAXBWriter for the given JAXB context path, using the specifiedjava.lang.Classloader
. (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:
-
JAXBWriter
Creates a new JAXBWriter for the given JAXB context path, using the specifiedjava.lang.Classloader
. 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:
-
-
Method Details
-
getOutputFormat
Returns the OutputFormat that will be used when writing the XML stream.- Returns:
- Returns the output format.
-
setOutput
Defines to write the resulting output to the specifiedFile
.- Parameters:
file
- file to write to- Throws:
IOException
- when the file cannot be found
-
setOutput
Defines to write the resulting output to the specifiedOutputStream
- Parameters:
outputStream
- outputStream to write to.- Throws:
IOException
- DOCUMENT ME!
-
setOutput
Defines to write the resulting output to the specifiedWriter
.- Parameters:
writer
- writer to write to- Throws:
IOException
-
startDocument
Start a document by writing the initial XML declaration to the output. This must be done prior to writing any other elements.- Throws:
IOException
- if an error occured while writing the outputSAXException
- thrown by the underlying SAX driver
-
endDocument
Stop writing the document to the output. This must be done when all other elements are finished.- Throws:
IOException
- if an error occured while writing the outputSAXException
- thrown by the underlying SAX driver
-
write
Writes the specifiedElement
to the document.Element
instances can be created using the ObjectFactory that is generated by the JAXB compiler.- Parameters:
jaxbObject
-- Throws:
IOException
- if an error occured while writing the outputJAXBException
- when an error occured while marshalling the jaxbObject
-
writeClose
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:
IOException
- if an error occured while writing the outputJAXBException
- when an error occured while marshalling the jaxbObject
-
writeOpen
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:
IOException
- if an error occured while writing the outputJAXBException
- when an error occured while marshalling the jaxbObject
-
writeElement
Writes the specifiedElement
to the document.- Parameters:
element
- theElement
to write- Throws:
IOException
- if an error occured while writing the output
-
writeCloseElement
Writes the closing tag of the specifiedElement
to the document.- Parameters:
element
- theElement
to write- Throws:
IOException
- if an error occured while writing the output
-
writeOpenElement
Writes the opening tag of the specifiedElement
to the document.- Parameters:
element
- theElement
to write- Throws:
IOException
- if an error occured while writing the output
-
marshal
Marshals the givenElement
in to its DOM4J counterpart.- Parameters:
element
- JAXB Element to be marshalled- Returns:
- the marshalled DOM4J
Element
- Throws:
JAXBException
- when an error occurs
-
unmarshal
- Parameters:
element
- the DOM4J element to unmarshall- Returns:
- the unmarshalled JAXB object
- Throws:
JAXBException
- when an error occurs
-