public class JAXBReader extends Object
JAXBObjectHandler
objects can be registered to automatically receive
unmarshalled XML fragments. Registered
implementations are notified when a certain element path is encounteredSAXReader
,
JAXBContext
Constructor and Description |
---|
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
Classloader . |
Modifier and Type | Method and Description |
---|---|
void |
addHandler(String path,
ElementHandler handler)
Adds the
ElementHandler to be called when the specified
path is encounted. |
void |
addObjectHandler(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(Element element)
Marshals the given
Element in to its DOM4J
counterpart. |
Document |
read(File source)
Parses the specified
File |
Document |
read(File file,
Charset charset)
|
Document |
read(InputSource source)
Parses the specified
InputSource |
Document |
read(InputStream source)
Parses the specified
InputStream |
Document |
read(InputStream source,
String systemId)
Parses the specified
InputStream |
Document |
read(Reader source)
Parses the specified
Reader |
Document |
read(Reader source,
String systemId)
Parses the specified
Reader |
Document |
read(String source)
Parses the the given URL or filename.
|
Document |
read(URL source)
Parses the the given URL.
|
void |
removeHandler(String path)
Removes the
ElementHandler from the event based processor,
for the specified path. |
void |
removeObjectHandler(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 Element |
unmarshal(Element element)
|
public JAXBReader(String contextPath)
contextPath
- context path to be usedJAXBContext
public JAXBReader(String contextPath, 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(File source) throws DocumentException
File
source
- the file to parseDocumentException
- when an error occurs while parsingpublic Document read(File file, Charset charset) throws DocumentException
file
- the file to parsecharset
- the charset to be usedDocumentException
- when an error occurs while parsingpublic Document read(InputSource source) throws DocumentException
InputSource
source
- the source to parseDocumentException
- when an error occurs while parsingpublic Document read(InputStream source) throws DocumentException
InputStream
source
- the input stream to parseDocumentException
- when an error occurs while parsingpublic Document read(InputStream source, 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(Reader source) throws DocumentException
Reader
source
- the input reader to useDocumentException
- when an error occurs while parsingpublic Document read(Reader source, 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(String source) throws DocumentException
source
- the location to parseDocumentException
- when an error occurs while parsingpublic Document read(URL source) throws DocumentException
source
- the URL to parseDocumentException
- when an error occurs while parsingpublic void addObjectHandler(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(String path)
JAXBObjectHandler
from the event based processor, for
the specified element path.path
- The path to remove the JAXBObjectHandler
forpublic void addHandler(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(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
- protected Element marshal(Element element) throws JAXBException
Element
in to its DOM4J
counterpart.element
- JAXB Element to be marshalledElement
JAXBException
- when an error occursprotected Element unmarshal(Element element) throws JAXBException
element
- the DOM4J element to unmarshallJAXBException
- when an error occursCopyright © 2012 JBoss by Red Hat. All Rights Reserved.