public class XMLObjectReader extends Object
This class restores objects which have been serialized in XML
format using an XMLObjectWriter
.
When the XML document is parsed, each elements are recursively
processed and Java objects are created using the XMLFormat
of the class as identified by the XMLBinding
.
Multiple objects can be read from the same XML input. For example:
XMLObjectReader reader = XMLObjectReader.newInstance(inputStream); while (reader.hasNext()) { Message message = reader.read("Message", Message.class); } reader.close(); // The underlying stream is closed.
Constructor and Description |
---|
XMLObjectReader()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this reader and its underlying input then
reset
this reader for potential reuse. |
XMLStreamReader |
getStreamReader()
Returns the stream reader being used by this reader (it can be
used to set prefix, read prologs, etc).
|
boolean |
hasNext()
Indicates if more elements can be read.
|
static XMLObjectReader |
newInstance(InputStream in)
Returns a XML object reader having the specified
input stream as input.
|
static XMLObjectReader |
newInstance(InputStream in,
String encoding)
Returns a XML object reader (potentially recycled) having the specified
input stream/encoding as input.
|
static XMLObjectReader |
newInstance(Reader in)
Returns a XML object reader (potentially recycled) having the specified
reader as input.
|
<T> T |
read()
Returns the object corresponding to the next element/data.
|
<T> T |
read(String name)
Returns the object corresponding to the next nested element only
if it has the specified local name.
|
<T> T |
read(String name,
Class<T> cls)
Returns the object corresponding to the next nested element only
if it has the specified local name; the actual object type is identified
by the specified class parameter.
|
<T> T |
read(String localName,
String uri)
Returns the object corresponding to the next nested element only
if it has the specified local name and namespace URI.
|
<T> T |
read(String localName,
String uri,
Class<T> cls)
Returns the object corresponding to the next nested element only
if it has the specified local name and namespace URI; the
actual object type is identified by the specified class parameter.
|
void |
reset()
Resets this object reader for reuse.
|
XMLObjectReader |
setBinding(XMLBinding binding)
Sets the XML binding to use with this object reader.
|
XMLObjectReader |
setInput(InputStream in)
Sets the input stream source for this XML object reader
(encoding retrieved from XML prolog if any).
|
XMLObjectReader |
setInput(InputStream in,
String encoding)
Sets the input stream source and encoding for this XML object reader.
|
XMLObjectReader |
setInput(Reader in)
Sets the reader input source for this XML stream reader.
|
XMLObjectReader |
setReferenceResolver(XMLReferenceResolver referenceResolver)
Sets the XML reference resolver to use with this object reader
(the same resolver can be used accross multiple readers).
|
public static XMLObjectReader newInstance(InputStream in) throws XMLStreamException
in
- the input stream.XMLStreamException
public static XMLObjectReader newInstance(InputStream in, String encoding) throws XMLStreamException
in
- the input stream.encoding
- the input stream encodingXMLStreamException
public static XMLObjectReader newInstance(Reader in) throws XMLStreamException
in
- the reader source.XMLStreamException
public XMLStreamReader getStreamReader()
public XMLObjectReader setInput(InputStream in) throws XMLStreamException
in
- the source input stream.this
XMLStreamException
XMLStreamReaderImpl.setInput(InputStream)
public XMLObjectReader setInput(InputStream in, String encoding) throws XMLStreamException
in
- the input source.encoding
- the associated encoding.this
XMLStreamException
XMLStreamReaderImpl.setInput(InputStream, String)
public XMLObjectReader setInput(Reader in) throws XMLStreamException
in
- the source reader.this
XMLStreamException
XMLStreamReaderImpl.setInput(Reader)
public XMLObjectReader setBinding(XMLBinding binding)
binding
- the XML binding to use.this
public XMLObjectReader setReferenceResolver(XMLReferenceResolver referenceResolver)
referenceResolver
- the XML reference resolver.this
public boolean hasNext() throws XMLStreamException
true
if more element/data to be read;
false
otherwise.XMLStreamException
XMLFormat.InputElement.hasNext()
public <T> T read() throws XMLStreamException
null
)XMLStreamException
- if hasNext() == false
XMLFormat.InputElement.getNext()
public <T> T read(String name) throws XMLStreamException
name
- the local name of the next element.null
if the
local name does not match.XMLStreamException
XMLFormat.InputElement.get(String)
public <T> T read(String localName, String uri) throws XMLStreamException
localName
- the local name.uri
- the namespace URI.null
if the
name/uri does not match.XMLStreamException
XMLFormat.InputElement.get(String, String)
public <T> T read(String name, Class<T> cls) throws XMLStreamException
name
- the name of the element to match.cls
- the non-abstract class identifying the object to return.read(name, null, cls)
XMLStreamException
public <T> T read(String localName, String uri, Class<T> cls) throws XMLStreamException
localName
- the local name.uri
- the namespace URI.cls
- the non-abstract class identifying the object to return.null
if no match.XMLStreamException
public void close() throws XMLStreamException
reset
this reader for potential reuse.XMLStreamException
public void reset()
Copyright © 2005-2013 Javolution. All Rights Reserved.