org.dom4j.jaxb

Class JAXBReader

public class JAXBReader extends JAXBSupport

Reads an XML document and creates a DOM4J tree from SAX parsing events. JAXBObjectHandlerobjects can be registered to automatically receive unmarshalled XML fragments. Registered {@linkorg.dom4j.ElementHandler } implementations are notified when a certain element path is encountered

Author: Wonne Keysers (Realsoftware.be)

See Also: SAXReader javax.xml.bind.JAXBContext

Constructor Summary
JAXBReader(String contextPath)
Creates a new JAXBReader for the given JAXB context path.
JAXBReader(String contextPath, ClassLoader classloader)
Creates a new JAXBReader for the given JAXB context path, using the specified java.lang.Classloader.
Method Summary
voidaddHandler(String path, ElementHandler handler)
Adds the ElementHandler to be called when the specified path is encounted.
voidaddObjectHandler(String path, JAXBObjectHandler handler)
Registers a JAXBObjectHandlerthat will be supplied with the unmarshalled representation of the xml fragment whenever the specified path is encounted.
booleanisPruneElements()
When 'true', the DOM4J document will not be kept in memory while parsing.
Documentread(File source)
Parses the specified java.io.File
Documentread(File file, Charset charset)
Parses the specified java.io.File, using the given java.nio.charset.Charset.
Documentread(InputSource source)
Parses the specified org.xml.sax.InputSource
Documentread(InputStream source)
Parses the specified java.io.InputStream
Documentread(InputStream source, String systemId)
Parses the specified java.io.InputStream
Documentread(Reader source)
Parses the specified java.io.Reader
Documentread(Reader source, String systemId)
Parses the specified java.io.Reader
Documentread(String source)
Parses the the given URL or filename.
Documentread(URL source)
Parses the the given URL.
voidremoveHandler(String path)
Removes the ElementHandler from the event based processor, for the specified path.
voidremoveObjectHandler(String path)
Removes the JAXBObjectHandlerfrom the event based processor, for the specified element path.
voidresetHandlers()
Removes all registered JAXBObjectHandlerand ElementHandler instances from the event based processor.
voidsetPruneElements(boolean pruneElements)
Set to true when DOM4J elements must immediately be pruned from the tree.

Constructor Detail

JAXBReader

public JAXBReader(String contextPath)
Creates a new JAXBReader 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 context path to be used

See Also: javax.xml.bind.JAXBContext

JAXBReader

public JAXBReader(String contextPath, ClassLoader classloader)
Creates a new JAXBReader for the given JAXB context path, using the specified java.lang.Classloader. This is the Java package where JAXB can find the generated XML classes. This package MUST contain jaxb.properties!

Parameters: contextPath to be used classloader to be used

See Also: javax.xml.bind.JAXBContext

Method Detail

addHandler

public void addHandler(String path, ElementHandler handler)
Adds the ElementHandler to be called when the specified path is encounted.

Parameters: path is the path to be handled handler is the ElementHandler to be called by the event based processor.

addObjectHandler

public void addObjectHandler(String path, JAXBObjectHandler handler)
Registers a JAXBObjectHandlerthat will be supplied with the unmarshalled representation of the xml fragment whenever the specified path is encounted.

Parameters: path the path to listen for handler the handler to be notified

isPruneElements

public boolean isPruneElements()
When 'true', the DOM4J document will not be kept in memory while parsing.

Returns: Returns the pruneElements.

read

public Document read(File source)
Parses the specified java.io.File

Parameters: source the file to parse

Returns: the resulting DOM4J document

Throws: DocumentException when an error occurs while parsing

read

public Document read(File file, Charset charset)
Parses the specified java.io.File, using the given java.nio.charset.Charset.

Parameters: file the file to parse charset the charset to be used

Returns: the resulting DOM4J document

Throws: DocumentException when an error occurs while parsing

read

public Document read(InputSource source)
Parses the specified org.xml.sax.InputSource

Parameters: source the source to parse

Returns: the resulting DOM4J document

Throws: DocumentException when an error occurs while parsing

read

public Document read(InputStream source)
Parses the specified java.io.InputStream

Parameters: source the input stream to parse

Returns: the resulting DOM4J document

Throws: DocumentException when an error occurs while parsing

read

public Document read(InputStream source, String systemId)
Parses the specified java.io.InputStream

Parameters: source the input stream to parse systemId is the URI for the input

Returns: the resulting DOM4J document

Throws: DocumentException when an error occurs while parsing

read

public Document read(Reader source)
Parses the specified java.io.Reader

Parameters: source the input reader to use

Returns: the resulting DOM4J document

Throws: DocumentException when an error occurs while parsing

read

public Document read(Reader source, String systemId)
Parses the specified java.io.Reader

Parameters: source the input reader to parse systemId is the URI for the input

Returns: the resulting DOM4J document

Throws: DocumentException when an error occurs while parsing

read

public Document read(String source)
Parses the the given URL or filename.

Parameters: source the location to parse

Returns: the resulting DOM4J document

Throws: DocumentException when an error occurs while parsing

read

public Document read(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

removeHandler

public void removeHandler(String path)
Removes the ElementHandler from the event based processor, for the specified path.

Parameters: path is the path to remove the ElementHandler for.

removeObjectHandler

public void removeObjectHandler(String path)
Removes the JAXBObjectHandlerfrom the event based processor, for the specified element path.

Parameters: path The path to remove the JAXBObjectHandlerfor

resetHandlers

public void resetHandlers()
Removes all registered JAXBObjectHandlerand ElementHandler instances from the event based processor.

setPruneElements

public void setPruneElements(boolean pruneElements)
Set to true when DOM4J elements must immediately be pruned from the tree. The Documentwill not be available afterwards!

Parameters: pruneElements

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

SourceForge