Top Description Inners Fields Constructors Methods
org.dom4j.jaxb

public Class JAXBReader

extends JAXBSupport
Class Inheritance
Imports
java.io.File, .FileInputStream, .FileNotFoundException, .InputStream, .InputStreamReader, .Reader, java.net.URL, java.nio.charset.Charset, org.dom4j.Document, .DocumentException, .Element, .ElementHandler, .ElementPath, org.dom4j.io.SAXReader, org.xml.sax.InputSource

Reads an XML document and creates a DOM4J tree from SAX parsing events. JAXBObjectHandlerobjects can be registered to automatically receive unmarshalled XML fragments. Registered org.dom4j.ElementHandler implementations are notified when a certain element path is encountered
Author
Wonne Keysers (Realsoftware.be)
See Also
org.dom4j.io.SAXReader, javax.xml.bind.JAXBContext

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class

Field Summary

Modifier and TypeField and Description
private boolean
private SAXReader

Constructor Summary

AccessConstructor and Description
public
JAXBReader(String
context path to be used
contextPath
)

Creates a new JAXBReader for the given JAXB context path.

public
JAXBReader(String
to be used
contextPath
,
ClassLoader
to be used
classloader
)

Creates a new JAXBReader for the given JAXB context path, using the specified java.lang.ClassLoader.

Method Summary

Modifier and TypeMethod and Description
public void
addHandler(String
is the path to be handled
path
,
ElementHandler
is the ElementHandler to be called by the event based processor.
handler
)

Adds the ElementHandler to be called when the specified path is encounted.

public void
addObjectHandler(String
the path to listen for
path
,
JAXBObjectHandler
the handler to be notified
handler
)

Registers a JAXBObjectHandlerthat will be supplied with the unmarshalled representation of the xml fragment whenever the specified path is encounted.

private SAXReader
public boolean

Returns:

Returns the pruneElements.
isPruneElements
()

When 'true', the DOM4J document will not be kept in memory while parsing.

public Document

Returns:

the resulting DOM4J document
read
(File
the file to parse
source
)

Parses the specified java.io.File

public Document

Returns:

the resulting DOM4J document
read
(File
the file to parse
file
,
Charset
the charset to be used
charset
)

Parses the specified java.io.File, using the given java.nio.charset.Charset.

public Document

Returns:

the resulting DOM4J document
read
(InputSource
the source to parse
source
)

Parses the specified org.xml.sax.InputSource

public Document

Returns:

the resulting DOM4J document
read
(InputStream
the input stream to parse
source
)

Parses the specified java.io.InputStream

public Document

Returns:

the resulting DOM4J document
read
(InputStream
the input stream to parse
source
,
String
is the URI for the input
systemId
)

Parses the specified java.io.InputStream

public Document

Returns:

the resulting DOM4J document
read
(Reader
the input reader to use
source
)

Parses the specified java.io.Reader

public Document

Returns:

the resulting DOM4J document
read
(Reader
the input reader to parse
source
,
String
is the URI for the input
systemId
)

Parses the specified java.io.Reader

public Document

Returns:

the resulting DOM4J document
read
(String
the location to parse
source
)

Parses the the given URL or filename.

public Document

Returns:

the resulting DOM4J document
read
(URL
the URL to parse
source
)

Parses the the given URL.

public void
removeHandler(String
is the path to remove the ElementHandler for.
path
)

Removes the ElementHandler from the event based processor, for the specified path.

public void
removeObjectHandler(String
The path to remove the JAXBObjectHandlerfor
path
)

Removes the JAXBObjectHandlerfrom the event based processor, for the specified element path.

public void
resetHandlers()

Removes all registered JAXBObjectHandlerand org.dom4j.ElementHandler instances from the event based processor.

public void
setPruneElements(boolean
DOCUMENT ME!
pruneElements
)

Set to true when DOM4J elements must immediately be pruned from the tree.

Inherited from org.dom4j.jaxb.JAXBSupport:
marshalunmarshal

Field Detail

pruneElementsback to summary
private boolean pruneElements
readerback to summary
private SAXReader reader

Constructor Detail

JAXBReaderback to summary
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:String

context path to be used

See Also
javax.xml.bind.JAXBContext
JAXBReaderback to summary
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:String

to be used

classloader:ClassLoader

to be used

See Also
javax.xml.bind.JAXBContext

Method Detail

addHandlerback to summary
public void addHandler(String path, ElementHandler handler)

Adds the ElementHandler to be called when the specified path is encounted.

Parameters
path:String

is the path to be handled

handler:ElementHandler

is the ElementHandler to be called by the event based processor.

addObjectHandlerback to summary
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:String

the path to listen for

handler:JAXBObjectHandler

the handler to be notified

getReaderback to summary
private SAXReader getReader()
isPruneElementsback to summary
public boolean isPruneElements()

When 'true', the DOM4J document will not be kept in memory while parsing.

Returns:boolean

Returns the pruneElements.

readback to summary
public Document read(File source) throws DocumentException

Parses the specified java.io.File

Parameters
source:File

the file to parse

Returns:Document

the resulting DOM4J document

Exceptions
DocumentException:
when an error occurs while parsing
readback to summary
public Document read(File file, Charset charset) throws DocumentException

Parses the specified java.io.File, using the given java.nio.charset.Charset.

Parameters
file:File

the file to parse

charset:Charset

the charset to be used

Returns:Document

the resulting DOM4J document

Exceptions
DocumentException:
when an error occurs while parsing
readback to summary
public Document read(InputSource source) throws DocumentException

Parses the specified org.xml.sax.InputSource

Parameters
source:InputSource

the source to parse

Returns:Document

the resulting DOM4J document

Exceptions
DocumentException:
when an error occurs while parsing
readback to summary
public Document read(InputStream source) throws DocumentException

Parses the specified java.io.InputStream

Parameters
source:InputStream

the input stream to parse

Returns:Document

the resulting DOM4J document

Exceptions
DocumentException:
when an error occurs while parsing
readback to summary
public Document read(InputStream source, String systemId) throws DocumentException

Parses the specified java.io.InputStream

Parameters
source:InputStream

the input stream to parse

systemId:String

is the URI for the input

Returns:Document

the resulting DOM4J document

Exceptions
DocumentException:
when an error occurs while parsing
readback to summary
public Document read(Reader source) throws DocumentException

Parses the specified java.io.Reader

Parameters
source:Reader

the input reader to use

Returns:Document

the resulting DOM4J document

Exceptions
DocumentException:
when an error occurs while parsing
readback to summary
public Document read(Reader source, String systemId) throws DocumentException

Parses the specified java.io.Reader

Parameters
source:Reader

the input reader to parse

systemId:String

is the URI for the input

Returns:Document

the resulting DOM4J document

Exceptions
DocumentException:
when an error occurs while parsing
readback to summary
public Document read(String source) throws DocumentException

Parses the the given URL or filename.

Parameters
source:String

the location to parse

Returns:Document

the resulting DOM4J document

Exceptions
DocumentException:
when an error occurs while parsing
readback to summary
public Document read(URL source) throws DocumentException

Parses the the given URL.

Parameters
source:URL

the URL to parse

Returns:Document

the resulting DOM4J document

Exceptions
DocumentException:
when an error occurs while parsing
removeHandlerback to summary
public void removeHandler(String path)

Removes the ElementHandler from the event based processor, for the specified path.

Parameters
path:String

is the path to remove the ElementHandler for.

removeObjectHandlerback to summary
public void removeObjectHandler(String path)

Removes the JAXBObjectHandlerfrom the event based processor, for the specified element path.

Parameters
path:String

The path to remove the JAXBObjectHandlerfor

resetHandlersback to summary
public void resetHandlers()

Removes all registered JAXBObjectHandlerand org.dom4j.ElementHandler instances from the event based processor.

setPruneElementsback to summary
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:boolean

DOCUMENT ME!

org.dom4j.jaxb back to summary

private Class JAXBReader.PruningElementHandler

extends Object
implements ElementHandler
Class Inheritance
All Implemented Interfaces
org.dom4j.ElementHandler

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
onEnd(ElementPath
is the current ElementPath to process
elementPath
)

Implements org.dom4j.ElementHandler.onEnd.

Called by an event based processor when an elements closing tag is encountered.
public void
onStart(ElementPath
is the current ElementPath to process
parm1
)

Implements org.dom4j.ElementHandler.onStart.

Called by an event based processor when an elements openning tag is encountered.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

PruningElementHandlerback to summary
public PruningElementHandler()

Method Detail

onEndback to summary
public void onEnd(ElementPath elementPath)

Implements org.dom4j.ElementHandler.onEnd.

Doc from org.dom4j.ElementHandler.onEnd.

Called by an event based processor when an elements closing tag is encountered.

Parameters
elementPath:ElementPath

is the current ElementPath to process

onStartback to summary
public void onStart(ElementPath parm1)

Implements org.dom4j.ElementHandler.onStart.

Doc from org.dom4j.ElementHandler.onStart.

Called by an event based processor when an elements openning tag is encountered.

Parameters
parm1:ElementPath

is the current ElementPath to process

org.dom4j.jaxb back to summary

private Class JAXBReader.UnmarshalElementHandler

extends Object
implements ElementHandler
Class Inheritance
All Implemented Interfaces
org.dom4j.ElementHandler

Field Summary

Modifier and TypeField and Description
private JAXBObjectHandler
private JAXBReader

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
onEnd(ElementPath
is the current ElementPath to process
elementPath
)

Implements org.dom4j.ElementHandler.onEnd.

Called by an event based processor when an elements closing tag is encountered.
public void
onStart(ElementPath
is the current ElementPath to process
elementPath
)

Implements org.dom4j.ElementHandler.onStart.

Called by an event based processor when an elements openning tag is encountered.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

handlerback to summary
private JAXBObjectHandler handler
jaxbReaderback to summary
private JAXBReader jaxbReader

Constructor Detail

UnmarshalElementHandlerback to summary
public UnmarshalElementHandler(JAXBReader documentReader, JAXBObjectHandler handler)

Method Detail

onEndback to summary
public void onEnd(ElementPath elementPath)

Implements org.dom4j.ElementHandler.onEnd.

Doc from org.dom4j.ElementHandler.onEnd.

Called by an event based processor when an elements closing tag is encountered.

Parameters
elementPath:ElementPath

is the current ElementPath to process

onStartback to summary
public void onStart(ElementPath elementPath)

Implements org.dom4j.ElementHandler.onStart.

Doc from org.dom4j.ElementHandler.onStart.

Called by an event based processor when an elements openning tag is encountered.

Parameters
elementPath:ElementPath

is the current ElementPath to process