org.dom4j.jaxb

Class JAXBModifier

public class JAXBModifier extends JAXBSupport

Reads an XML document using SAX and writes its content to the provided {@link org.dom4j.io.XMLWriter}. Modifications must be provided by {@link org.dom4j.jaxb.JAXBObjectModifier} objects, which are called prior to writing the XML fragment they are registered for.

Author: Wonne Keysers (Realsoftware.be)

See Also: SAXModifier

Constructor Summary
JAXBModifier(String contextPath)
Creates a new JAXBModifier for the given JAXB context path.
JAXBModifier(String contextPath, ClassLoader classloader)
Creates a new JAXBModifier for the given JAXB context path, using the given {@link java.lang.ClassLoader}.
JAXBModifier(String contextPath, OutputFormat outputFormat)
Creates a new JAXBModifier for the given JAXB context path.
JAXBModifier(String contextPath, ClassLoader classloader, OutputFormat outputFormat)
Creates a new JAXBModifier for the given JAXB context path, using the specified {@link java.lang.Classloader}.
Method Summary
voidaddObjectModifier(String path, JAXBObjectModifier mod)
Adds the {@link JAXBObjectModifier}to be called when the specified xml path is encounted while parsing the source.
booleanisPruneElements()
Returns true when the modified {@link org.dom4j.Document}is not kept in memory.
Documentmodify(File source)
Parses the specified {@link java.io.File}with SAX
Documentmodify(File source, Charset charset)
Parses the specified {@link java.io.File}with SAX, using the given {@link java.nio.charset.Charset}.
Documentmodify(InputSource source)
Parses the specified {@link org.xml.sax.InputSource}with SAX.
Documentmodify(InputStream source)
Parses the specified {@link java.io.InputStream}with SAX.
Documentmodify(InputStream source, String systemId)
Parses the specified {@link java.io.InputStream}with SAX.
Documentmodify(Reader r)
Parses the specified {@link java.io.Reader}with SAX.
Documentmodify(Reader source, String systemId)
Parses the specified {@link java.io.Reader}with SAX.
Documentmodify(String url)
Parses the the given URL or filename.
Documentmodify(URL source)
Parses the the given URL.
voidremoveObjectModifier(String path)
Removes the {@link JAXBObjectModifier}from the event based processor, for the specified element path.
voidresetObjectModifiers()
Removes all registered {@link JAXBObjectModifier}instances from the event based processor.
voidsetOutput(File file)
Sets the Output to write the (modified) xml document to.
voidsetOutput(OutputStream outputStream)
Sets the Output to write the (modified) xml document to.
voidsetOutput(Writer writer)
Sets the Output to write the (modified) xml document to.
voidsetPruneElements(boolean pruneElements)
Define whether the modified {@link org.dom4j.Document}must only be written to the output and pruned from the DOM4J tree.

Constructor Detail

JAXBModifier

public JAXBModifier(String contextPath)
Creates a new JAXBModifier 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: javax.xml.bind.JAXBContext

JAXBModifier

public JAXBModifier(String contextPath, ClassLoader classloader)
Creates a new JAXBModifier for the given JAXB context path, using the given {@link java.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 used classloader the classloader to use

See Also: javax.xml.bind.JAXBContext

JAXBModifier

public JAXBModifier(String contextPath, OutputFormat outputFormat)
Creates a new JAXBModifier for the given JAXB context path. The specified {@link org.dom4j.io.OutputFormat}will be used while writing the XML stream.

Parameters: contextPath JAXB context path to be used outputFormat the DOM4J {@link org.dom4j.io.OutputFormat}to be used

See Also: javax.xml.bind.JAXBContext

JAXBModifier

public JAXBModifier(String contextPath, ClassLoader classloader, OutputFormat outputFormat)
Creates a new JAXBModifier for the given JAXB context path, using the specified {@link java.lang.Classloader}. The specified {@link org.dom4j.io.OutputFormat} will be used while writing the XML stream.

Parameters: contextPath JAXB context path to be used classloader the class loader to be used to load JAXB outputFormat the DOM4J {@link org.dom4j.io.OutputFormat}to be used

See Also: javax.xml.bind.JAXBContext

Method Detail

addObjectModifier

public void addObjectModifier(String path, JAXBObjectModifier mod)
Adds the {@link JAXBObjectModifier}to be called when the specified xml path is encounted while parsing the source.

Parameters: path the element path to listen for mod the modifier to register

isPruneElements

public boolean isPruneElements()
Returns true when the modified {@link org.dom4j.Document}is not kept in memory.

Returns: Returns true if elements are pruned.

modify

public Document modify(File source)
Parses the specified {@link java.io.File}with SAX

Parameters: source the file to parse

Returns: the resulting DOM4J document

Throws: DocumentException when an error occurs while parsing IOException when an error occurs while writing to the {@link org.dom4j.io.XMLWriter}

modify

public Document modify(File source, Charset charset)
Parses the specified {@link java.io.File}with SAX, using the given {@link java.nio.charset.Charset}.

Parameters: source the file to parse charset the character set to use

Returns: the resulting DOM4J document

Throws: DocumentException when an error occurs while parsing IOException when an error occurs while writing to the {@link org.dom4j.io.XMLWriter}

modify

public Document modify(InputSource source)
Parses the specified {@link org.xml.sax.InputSource}with SAX.

Parameters: source the input source to parse

Returns: the resulting DOM4J document

Throws: DocumentException when an error occurs while parsing IOException when an error occurs while writing to the {@link org.dom4j.io.XMLWriter}

modify

public Document modify(InputStream source)
Parses the specified {@link java.io.InputStream}with SAX.

Parameters: source the inputstream to parse

Returns: the resulting DOM4J document

Throws: DocumentException when an error occurs while parsing IOException when an error occurs while writing to the {@link org.dom4j.io.XMLWriter}

modify

public Document modify(InputStream source, String systemId)
Parses the specified {@link java.io.InputStream}with SAX.

Parameters: source the inputstream to parse systemId the URI of the given inputstream

Returns: the resulting DOM4J document

Throws: DocumentException when an error occurs while parsing IOException when an error occurs while writing to the {@link org.dom4j.io.XMLWriter}

modify

public Document modify(Reader r)
Parses the specified {@link java.io.Reader}with SAX.

Parameters: r the reader to use for parsing

Returns: the resulting DOM4J document

Throws: DocumentException when an error occurs while parsing IOException when an error occurs while writing to the {@link org.dom4j.io.XMLWriter}

modify

public Document modify(Reader source, String systemId)
Parses the specified {@link java.io.Reader}with SAX.

Parameters: source the reader to parse systemId the URI of the given reader

Returns: the resulting DOM4J document

Throws: DocumentException when an error occurs while parsing IOException when an error occurs while writing to the {@link org.dom4j.io.XMLWriter}

modify

public Document modify(String url)
Parses the the given URL or filename.

Parameters: url the URL or filename to parse

Returns: the resulting DOM4J document

Throws: DocumentException when an error occurs while parsing IOException when an error occurs while writing to the {@link org.dom4j.io.XMLWriter}

modify

public Document modify(URL source)
Parses the the given URL.

Parameters: source the URL to parse

Returns: the resulting DOM4J document

Throws: DocumentException when an error occurs while parsing IOException when an error occurs while writing to the {@link org.dom4j.io.XMLWriter}

removeObjectModifier

public void removeObjectModifier(String path)
Removes the {@link JAXBObjectModifier}from the event based processor, for the specified element path.

Parameters: path the xml path to remove the modifier for

resetObjectModifiers

public void resetObjectModifiers()
Removes all registered {@link JAXBObjectModifier}instances from the event based processor.

setOutput

public void setOutput(File file)
Sets the Output to write the (modified) xml document to.

Parameters: file the {@link java.io.File}to write to

Throws: IOException when the file cannot be found or when the outputformat

setOutput

public void setOutput(OutputStream outputStream)
Sets the Output to write the (modified) xml document to.

Parameters: outputStream the {@link java.io.OutputStream}to write to

Throws: IOException when an error occurs

setOutput

public void setOutput(Writer writer)
Sets the Output to write the (modified) xml document to.

Parameters: writer the {@link java.io.Writer}to write to

Throws: IOException when an error occurs

setPruneElements

public void setPruneElements(boolean pruneElements)
Define whether the modified {@link org.dom4j.Document}must only be written to the output and pruned from the DOM4J tree.

Parameters: pruneElements When true, elements will not be kept in memory

Copyright B) 2005 MetaStuff Ltd. All Rights Reserved. Hosted by

SourceForge