Package org.dom4j.jaxb
Class JAXBReader
java.lang.Object
org.dom4j.jaxb.JAXBSupport
org.dom4j.jaxb.JAXBReader
Reads an XML document and creates a DOM4J tree from SAX parsing events.
JAXBObjectHandler
objects can be registered to automatically receive
unmarshalled XML fragments. Registered ElementHandler
implementations are notified when a certain element path is encountered- See Also:
-
SAXReader
JAXBContext
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
private class
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionJAXBReader
(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 specifiedClassLoader
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addHandler
(String path, ElementHandler handler) Adds theElementHandler
to be called when the specified path is encounted.void
addObjectHandler
(String path, JAXBObjectHandler handler) Registers aJAXBObjectHandler
that will be supplied with the unmarshalled representation of the xml fragment whenever the specified path is encounted.private SAXReader
boolean
When 'true', the DOM4J document will not be kept in memory while parsing.Parses the specifiedFile
read
(InputStream source) Parses the specifiedInputStream
read
(InputStream source, String systemId) Parses the specifiedInputStream
Parses the specifiedReader
Parses the specifiedReader
Parses the the given URL or filename.Parses the the given URL.read
(InputSource source) Parses the specifiedInputSource
void
removeHandler
(String path) Removes theElementHandler
from the event based processor, for the specified path.void
removeObjectHandler
(String path) Removes theJAXBObjectHandler
from the event based processor, for the specified element path.void
Removes all registeredJAXBObjectHandler
andElementHandler
instances from the event based processor.void
setPruneElements
(boolean pruneElements) Set to true when DOM4J elements must immediately be pruned from the tree.Methods inherited from class org.dom4j.jaxb.JAXBSupport
marshal, unmarshal
-
Field Details
-
reader
-
pruneElements
private boolean pruneElements
-
-
Constructor Details
-
JAXBReader
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:
-
JAXBContext
-
JAXBReader
Creates a new JAXBReader for the given JAXB context path, using the specifiedClassLoader
. This is the Java package where JAXB can find the generated XML classes. This package MUST contain jaxb.properties!- Parameters:
contextPath
- to be usedclassloader
- to be used- See Also:
-
JAXBContext
-
-
Method Details
-
read
Parses the specifiedFile
- Parameters:
source
- the file to parse- Returns:
- the resulting DOM4J document
- Throws:
DocumentException
- when an error occurs while parsing
-
read
- Parameters:
file
- the file to parsecharset
- the charset to be used- Returns:
- the resulting DOM4J document
- Throws:
DocumentException
- when an error occurs while parsing
-
read
Parses the specifiedInputSource
- Parameters:
source
- the source to parse- Returns:
- the resulting DOM4J document
- Throws:
DocumentException
- when an error occurs while parsing
-
read
Parses the specifiedInputStream
- Parameters:
source
- the input stream to parse- Returns:
- the resulting DOM4J document
- Throws:
DocumentException
- when an error occurs while parsing
-
read
Parses the specifiedInputStream
- Parameters:
source
- the input stream to parsesystemId
- is the URI for the input- Returns:
- the resulting DOM4J document
- Throws:
DocumentException
- when an error occurs while parsing
-
read
Parses the specifiedReader
- Parameters:
source
- the input reader to use- Returns:
- the resulting DOM4J document
- Throws:
DocumentException
- when an error occurs while parsing
-
read
Parses the specifiedReader
- Parameters:
source
- the input reader to parsesystemId
- is the URI for the input- Returns:
- the resulting DOM4J document
- Throws:
DocumentException
- when an error occurs while parsing
-
read
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
Parses the the given URL.- Parameters:
source
- the URL to parse- Returns:
- the resulting DOM4J document
- Throws:
DocumentException
- when an error occurs while parsing
-
addObjectHandler
Registers aJAXBObjectHandler
that will be supplied with the unmarshalled representation of the xml fragment whenever the specified path is encounted.- Parameters:
path
- the path to listen forhandler
- the handler to be notified
-
removeObjectHandler
Removes theJAXBObjectHandler
from the event based processor, for the specified element path.- Parameters:
path
- The path to remove theJAXBObjectHandler
for
-
addHandler
Adds theElementHandler
to be called when the specified path is encounted.- Parameters:
path
- is the path to be handledhandler
- is theElementHandler
to be called by the event based processor.
-
removeHandler
Removes theElementHandler
from the event based processor, for the specified path.- Parameters:
path
- is the path to remove theElementHandler
for.
-
resetHandlers
public void resetHandlers()Removes all registeredJAXBObjectHandler
andElementHandler
instances from the event based processor. -
isPruneElements
public boolean isPruneElements()When 'true', the DOM4J document will not be kept in memory while parsing.- Returns:
- Returns the pruneElements.
-
setPruneElements
public void setPruneElements(boolean pruneElements) Set to true when DOM4J elements must immediately be pruned from the tree. TheDocument
will not be available afterwards!- Parameters:
pruneElements
- DOCUMENT ME!
-
getReader
-