public class JAXBReader
extends java.lang.Object
JAXBObjectHandler
objects can be registered to automatically receive
unmarshalled XML fragments. Registered ElementHandler
implementations are notified when a certain element path is encounteredSAXReader
,
JAXBContext
Constructor and Description |
---|
JAXBReader(java.lang.String contextPath)
Creates a new JAXBReader for the given JAXB context path.
|
JAXBReader(java.lang.String contextPath,
java.lang.ClassLoader classloader)
Creates a new JAXBReader for the given JAXB context path, using the
specified
ClassLoader . |
Modifier and Type | Method and Description |
---|---|
void |
addHandler(java.lang.String path,
ElementHandler handler)
Adds the
ElementHandler to be called when the specified
path is encounted. |
void |
addObjectHandler(java.lang.String path,
JAXBObjectHandler handler)
Registers a
JAXBObjectHandler that will be supplied with the
unmarshalled representation of the xml fragment whenever the specified
path is encounted. |
boolean |
isPruneElements()
When 'true', the DOM4J document will not be kept in memory while parsing.
|
protected Element |
marshal(javax.xml.bind.Element element)
Marshals the given
Element in to its DOM4J
counterpart. |
Document |
read(java.io.File source)
Parses the specified
File |
Document |
read(java.io.File file,
java.nio.charset.Charset charset)
Parses the specified
File , using the given Charset . |
Document |
read(org.xml.sax.InputSource source)
Parses the specified
InputSource |
Document |
read(java.io.InputStream source)
Parses the specified
InputStream |
Document |
read(java.io.InputStream source,
java.lang.String systemId)
Parses the specified
InputStream |
Document |
read(java.io.Reader source)
Parses the specified
Reader |
Document |
read(java.io.Reader source,
java.lang.String systemId)
Parses the specified
Reader |
Document |
read(java.lang.String source)
Parses the the given URL or filename.
|
Document |
read(java.net.URL source)
Parses the the given URL.
|
void |
removeHandler(java.lang.String path)
Removes the
ElementHandler from the event based processor,
for the specified path. |
void |
removeObjectHandler(java.lang.String path)
Removes the
JAXBObjectHandler from the event based processor, for
the specified element path. |
void |
resetHandlers()
Removes all registered
JAXBObjectHandler and ElementHandler instances from the event based processor. |
void |
setPruneElements(boolean pruneElements)
Set to true when DOM4J elements must immediately be pruned from the tree.
|
protected javax.xml.bind.Element |
unmarshal(Element element)
Unmarshalls the specified DOM4J
Element into a Element |
public JAXBReader(java.lang.String contextPath)
contextPath
- context path to be usedJAXBContext
public JAXBReader(java.lang.String contextPath, java.lang.ClassLoader classloader)
ClassLoader
. This is the Java package where
JAXB can find the generated XML classes. This package MUST contain
jaxb.properties!contextPath
- to be usedclassloader
- to be usedJAXBContext
public Document read(java.io.File source) throws DocumentException
File
source
- the file to parseDocumentException
- when an error occurs while parsingpublic Document read(java.io.File file, java.nio.charset.Charset charset) throws DocumentException
File
, using the given Charset
.file
- the file to parsecharset
- the charset to be usedDocumentException
- when an error occurs while parsingpublic Document read(org.xml.sax.InputSource source) throws DocumentException
InputSource
source
- the source to parseDocumentException
- when an error occurs while parsingpublic Document read(java.io.InputStream source) throws DocumentException
InputStream
source
- the input stream to parseDocumentException
- when an error occurs while parsingpublic Document read(java.io.InputStream source, java.lang.String systemId) throws DocumentException
InputStream
source
- the input stream to parsesystemId
- is the URI for the inputDocumentException
- when an error occurs while parsingpublic Document read(java.io.Reader source) throws DocumentException
Reader
source
- the input reader to useDocumentException
- when an error occurs while parsingpublic Document read(java.io.Reader source, java.lang.String systemId) throws DocumentException
Reader
source
- the input reader to parsesystemId
- is the URI for the inputDocumentException
- when an error occurs while parsingpublic Document read(java.lang.String source) throws DocumentException
source
- the location to parseDocumentException
- when an error occurs while parsingpublic Document read(java.net.URL source) throws DocumentException
source
- the URL to parseDocumentException
- when an error occurs while parsingpublic void addObjectHandler(java.lang.String path, JAXBObjectHandler handler)
JAXBObjectHandler
that will be supplied with the
unmarshalled representation of the xml fragment whenever the specified
path is encounted.path
- the path to listen forhandler
- the handler to be notifiedpublic void removeObjectHandler(java.lang.String path)
JAXBObjectHandler
from the event based processor, for
the specified element path.path
- The path to remove the JAXBObjectHandler
forpublic void addHandler(java.lang.String path, ElementHandler handler)
ElementHandler
to be called when the specified
path is encounted.path
- is the path to be handledhandler
- is the ElementHandler
to be called by the event
based processor.public void removeHandler(java.lang.String path)
ElementHandler
from the event based processor,
for the specified path.path
- is the path to remove the ElementHandler
for.public void resetHandlers()
JAXBObjectHandler
and ElementHandler
instances from the event based processor.public boolean isPruneElements()
public void setPruneElements(boolean pruneElements)
Document
will not be available afterwards!pruneElements
- DOCUMENT ME!protected Element marshal(javax.xml.bind.Element element) throws javax.xml.bind.JAXBException
Element
in to its DOM4J
counterpart.element
- JAXB Element to be marshalledElement
javax.xml.bind.JAXBException
- when an error occursprotected javax.xml.bind.Element unmarshal(Element element) throws javax.xml.bind.JAXBException
Element
into a Element
element
- the DOM4J element to unmarshalljavax.xml.bind.JAXBException
- when an error occurs