Package org.dom4j.jaxb
Class JAXBReader
- java.lang.Object
 - 
- org.dom4j.jaxb.JAXBReader
 
 
- 
public class JAXBReader extends Object
Reads an XML document and creates a DOM4J tree from SAX parsing events.JAXBObjectHandlerobjects can be registered to automatically receive unmarshalled XML fragments. RegisteredElementHandlerimplementations are notified when a certain element path is encountered- See Also:
 SAXReader,JAXBContext
 
- 
- 
Constructor Summary
Constructors Constructor 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 specifiedClassLoader. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddHandler(String path, ElementHandler handler)Adds theElementHandlerto be called when the specified path is encounted.voidaddObjectHandler(String path, JAXBObjectHandler handler)Registers aJAXBObjectHandlerthat 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.protected Elementmarshal(javax.xml.bind.Element element)Marshals the givenElementin to its DOM4J counterpart.Documentread(File source)Parses the specifiedFileDocumentread(File file, Charset charset)Documentread(InputStream source)Parses the specifiedInputStreamDocumentread(InputStream source, String systemId)Parses the specifiedInputStreamDocumentread(Reader source)Parses the specifiedReaderDocumentread(Reader source, String systemId)Parses the specifiedReaderDocumentread(String source)Parses the the given URL or filename.Documentread(URL source)Parses the the given URL.Documentread(InputSource source)Parses the specifiedInputSourcevoidremoveHandler(String path)Removes theElementHandlerfrom the event based processor, for the specified path.voidremoveObjectHandler(String path)Removes theJAXBObjectHandlerfrom the event based processor, for the specified element path.voidresetHandlers()Removes all registeredJAXBObjectHandlerandElementHandlerinstances from the event based processor.voidsetPruneElements(boolean pruneElements)Set to true when DOM4J elements must immediately be pruned from the tree.protected javax.xml.bind.Elementunmarshal(Element element)Unmarshalls the specified DOM4JElementinto aElement 
 - 
 
- 
- 
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:
 JAXBContext
 
- 
JAXBReader
public JAXBReader(String contextPath, ClassLoader classloader)
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 Detail
- 
read
public Document read(File source) throws DocumentException
Parses the specifiedFile- 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) throws DocumentException
- 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
public Document read(InputSource source) throws DocumentException
Parses the specifiedInputSource- 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) throws DocumentException
Parses the specifiedInputStream- 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) throws DocumentException
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
public Document read(Reader source) throws DocumentException
Parses the specifiedReader- 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) throws DocumentException
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
public Document read(String source) throws DocumentException
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) throws DocumentException
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
public void addObjectHandler(String path, JAXBObjectHandler handler)
Registers aJAXBObjectHandlerthat 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
public void removeObjectHandler(String path)
Removes theJAXBObjectHandlerfrom the event based processor, for the specified element path.- Parameters:
 path- The path to remove theJAXBObjectHandlerfor
 
- 
addHandler
public void addHandler(String path, ElementHandler handler)
Adds theElementHandlerto be called when the specified path is encounted.- Parameters:
 path- is the path to be handledhandler- is theElementHandlerto be called by the event based processor.
 
- 
removeHandler
public void removeHandler(String path)
Removes theElementHandlerfrom the event based processor, for the specified path.- Parameters:
 path- is the path to remove theElementHandlerfor.
 
- 
resetHandlers
public void resetHandlers()
Removes all registeredJAXBObjectHandlerandElementHandlerinstances 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. TheDocumentwill not be available afterwards!- Parameters:
 pruneElements- DOCUMENT ME!
 
- 
marshal
protected Element marshal(javax.xml.bind.Element element) throws javax.xml.bind.JAXBException
Marshals the givenElementin to its DOM4J counterpart.- Parameters:
 element- JAXB Element to be marshalled- Returns:
 - the marshalled DOM4J 
Element - Throws:
 javax.xml.bind.JAXBException- when an error occurs
 
- 
unmarshal
protected javax.xml.bind.Element unmarshal(Element element) throws javax.xml.bind.JAXBException
Unmarshalls the specified DOM4JElementinto aElement- Parameters:
 element- the DOM4J element to unmarshall- Returns:
 - the unmarshalled JAXB object
 - Throws:
 javax.xml.bind.JAXBException- when an error occurs
 
 - 
 
 -