Javolution 6.0.0 java
javolution.xml.XMLObjectReader Class Reference
Collaboration diagram for javolution.xml.XMLObjectReader:
[legend]

Public Member Functions

 XMLObjectReader ()
 
XMLStreamReader getStreamReader ()
 
XMLObjectReader setInput (InputStream in) throws XMLStreamException
 
XMLObjectReader setInput (InputStream in, String encoding) throws XMLStreamException
 
XMLObjectReader setInput (Reader in) throws XMLStreamException
 
XMLObjectReader setBinding (XMLBinding binding)
 
XMLObjectReader setReferenceResolver (XMLReferenceResolver referenceResolver)
 
boolean hasNext () throws XMLStreamException
 
void close () throws XMLStreamException
 
void reset ()
 

Static Public Member Functions

static XMLObjectReader newInstance (InputStream in) throws XMLStreamException
 
static XMLObjectReader newInstance (InputStream in, String encoding) throws XMLStreamException
 
static XMLObjectReader newInstance (Reader in) throws XMLStreamException
 

Package Functions

public< T > T read () throws XMLStreamException
 
public< T > T read (String name) throws XMLStreamException
 
public< T > T read (String localName, String uri) throws XMLStreamException
 
public< T > T read (String name, Class< T > cls) throws XMLStreamException
 
public< T > T read (String localName, String uri, Class< T > cls) throws XMLStreamException
 

Private Attributes

final XMLFormat.InputElement _xml = new XMLFormat.InputElement()
 
Reader _reader
 
InputStream _inputStream
 

Detailed Description

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:[code] XMLObjectReader reader = XMLObjectReader.newInstance(inputStream); while (reader.hasNext()) { Message message = reader.read("Message", Message.class); } reader.close(); // The underlying stream is closed. [/code]

Author
Jean-Marie Dautelle
Version
4.0, September 4, 2006

Definition at line 39 of file XMLObjectReader.java.

Constructor & Destructor Documentation

◆ XMLObjectReader()

javolution.xml.XMLObjectReader.XMLObjectReader ( )

Default constructor.

Definition at line 99 of file XMLObjectReader.java.

99 {}

Referenced by javolution.xml.XMLObjectReader.newInstance().

Here is the caller graph for this function:

Member Function Documentation

◆ close()

void javolution.xml.XMLObjectReader.close ( ) throws XMLStreamException

Closes this reader and its underlying input then reset this reader for potential reuse.

Definition at line 269 of file XMLObjectReader.java.

269  {
270  try {
271  if (_inputStream != null) {
272  _inputStream.close();
273  reset();
274  } else if (_reader != null) {
275  _reader.close();
276  reset();
277  }
278  } catch (IOException e) {
279  throw new XMLStreamException(e);
280  }
281  }

References javolution.xml.XMLObjectReader._inputStream, javolution.xml.XMLObjectReader._reader, and javolution.xml.XMLObjectReader.reset().

Referenced by javolution.xml.ws.WebServiceClient.invoke().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getStreamReader()

XMLStreamReader javolution.xml.XMLObjectReader.getStreamReader ( )

Returns the stream reader being used by this reader (it can be used to set prefix, read prologs, etc).

Returns
the stream reader.

Definition at line 107 of file XMLObjectReader.java.

107  {
108  return _xml._reader;
109  }

References javolution.xml.XMLObjectReader._xml.

Referenced by javolution.xml.ws.WebServiceClient.invoke().

Here is the caller graph for this function:

◆ hasNext()

boolean javolution.xml.XMLObjectReader.hasNext ( ) throws XMLStreamException

Indicates if more elements can be read. This method positions the reader at the start of the next element to be read (if any).

Returns
true if more element/data to be read; false otherwise.
See also
XMLFormat.InputElement::hasNext()

Definition at line 192 of file XMLObjectReader.java.

192  {
193  return _xml.hasNext();
194  }

References javolution.xml.XMLObjectReader._xml.

◆ newInstance() [1/3]

static XMLObjectReader javolution.xml.XMLObjectReader.newInstance ( InputStream  in) throws XMLStreamException
static

Returns a XML object reader having the specified input stream as input.

Parameters
inthe input stream.

Definition at line 62 of file XMLObjectReader.java.

63  {
64  XMLObjectReader reader = new XMLObjectReader();
65  reader.setInput(in);
66  return reader;
67  }

References javolution.xml.XMLObjectReader.setInput(), and javolution.xml.XMLObjectReader.XMLObjectReader().

Here is the call graph for this function:

◆ newInstance() [2/3]

static XMLObjectReader javolution.xml.XMLObjectReader.newInstance ( InputStream  in,
String  encoding 
) throws XMLStreamException
static

Returns a XML object reader (potentially recycled) having the specified input stream/encoding as input.

Parameters
inthe input stream.
encodingthe input stream encoding

Definition at line 76 of file XMLObjectReader.java.

77  {
78  XMLObjectReader reader = new XMLObjectReader();
79  reader.setInput(in, encoding);
80  return reader;
81  }

References javolution.xml.XMLObjectReader.setInput(), and javolution.xml.XMLObjectReader.XMLObjectReader().

Here is the call graph for this function:

◆ newInstance() [3/3]

static XMLObjectReader javolution.xml.XMLObjectReader.newInstance ( Reader  in) throws XMLStreamException
static

Returns a XML object reader (potentially recycled) having the specified reader as input.

Parameters
inthe reader source.

Definition at line 89 of file XMLObjectReader.java.

90  {
91  XMLObjectReader reader = new XMLObjectReader();
92  reader.setInput(in);
93  return reader;
94  }

References javolution.xml.XMLObjectReader.setInput(), and javolution.xml.XMLObjectReader.XMLObjectReader().

Here is the call graph for this function:

◆ read() [1/5]

public<T> T javolution.xml.XMLObjectReader.read ( ) throws XMLStreamException
package

Returns the object corresponding to the next element/data.

Returns
the next nested object (can be null)
Exceptions
XMLStreamExceptionif hasNext() == false
See also
XMLFormat.InputElement::getNext()

Definition at line 204 of file XMLObjectReader.java.

204  {
205  return (T) _xml.getNext();
206  }

References javolution.xml.XMLObjectReader._xml.

◆ read() [2/5]

public<T> T javolution.xml.XMLObjectReader.read ( String  localName,
String  uri 
) throws XMLStreamException
package

Returns the object corresponding to the next nested element only if it has the specified local name and namespace URI.

Parameters
localNamethe local name.
urithe namespace URI.
Returns
the next content object or null if the name/uri does not match.
See also
XMLFormat.InputElement::get(String, String)

Definition at line 233 of file XMLObjectReader.java.

233  {
234  return (T) _xml.get(localName, uri);
235  }

References javolution.xml.XMLObjectReader._xml.

◆ read() [3/5]

public<T> T javolution.xml.XMLObjectReader.read ( String  localName,
String  uri,
Class< T >  cls 
) throws XMLStreamException
package

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.

Parameters
localNamethe local name.
urithe namespace URI.
clsthe non-abstract class identifying the object to return.
Returns
the next content object or null if no match.

Definition at line 260 of file XMLObjectReader.java.

261  {
262  return _xml.get(localName, uri, cls);
263  }

References javolution.xml.XMLObjectReader._xml.

◆ read() [4/5]

public<T> T javolution.xml.XMLObjectReader.read ( String  name) throws XMLStreamException
package

Returns the object corresponding to the next nested element only if it has the specified local name.

Parameters
namethe local name of the next element.
Returns
the next content object or null if the local name does not match.
See also
XMLFormat.InputElement::get(String)

Definition at line 218 of file XMLObjectReader.java.

218  {
219  return (T) _xml.get(name);
220  }

References javolution.xml.XMLObjectReader._xml.

◆ read() [5/5]

public<T> T javolution.xml.XMLObjectReader.read ( String  name,
Class< T >  cls 
) throws XMLStreamException
package

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.

Parameters
namethe name of the element to match.
clsthe non-abstract class identifying the object to return.
Returns
read(name, null, cls)

Definition at line 246 of file XMLObjectReader.java.

246  {
247  return _xml.get(name, cls);
248  }

References javolution.xml.XMLObjectReader._xml.

◆ reset()

void javolution.xml.XMLObjectReader.reset ( )

Resets this object reader for reuse.

Definition at line 286 of file XMLObjectReader.java.

286  {
287  _xml.reset();
288  _reader = null;
289  _inputStream = null;
290  }

References javolution.xml.XMLObjectReader._inputStream, javolution.xml.XMLObjectReader._reader, and javolution.xml.XMLObjectReader._xml.

Referenced by javolution.xml.XMLObjectReader.close(), and javolution.xml.ws.WebServiceClient.invoke().

Here is the caller graph for this function:

◆ setBinding()

XMLObjectReader javolution.xml.XMLObjectReader.setBinding ( XMLBinding  binding)

Sets the XML binding to use with this object reader.

Parameters
bindingthe XML binding to use.
Returns
this

Definition at line 165 of file XMLObjectReader.java.

165  {
166  _xml.setBinding(binding);
167  return this;
168  }

References javolution.xml.XMLObjectReader._xml.

◆ setInput() [1/3]

XMLObjectReader javolution.xml.XMLObjectReader.setInput ( InputStream  in) throws XMLStreamException

Sets the input stream source for this XML object reader (encoding retrieved from XML prolog if any).

Parameters
inthe source input stream.
Returns
this
See also
XMLStreamReaderImpl::setInput(InputStream)

Definition at line 119 of file XMLObjectReader.java.

119  {
120  if ((_inputStream != null) || (_reader != null))
121  throw new IllegalStateException("Reader not closed or reset");
122  _xml._reader.setInput(in);
123  _inputStream = in;
124  return this;
125  }

References javolution.xml.XMLObjectReader._inputStream, javolution.xml.XMLObjectReader._reader, and javolution.xml.XMLObjectReader._xml.

Referenced by javolution.xml.ws.WebServiceClient.invoke(), and javolution.xml.XMLObjectReader.newInstance().

Here is the caller graph for this function:

◆ setInput() [2/3]

XMLObjectReader javolution.xml.XMLObjectReader.setInput ( InputStream  in,
String  encoding 
) throws XMLStreamException

Sets the input stream source and encoding for this XML object reader.

Parameters
inthe input source.
encodingthe associated encoding.
Returns
this
See also
XMLStreamReaderImpl::setInput(InputStream, String)

Definition at line 135 of file XMLObjectReader.java.

136  {
137  if ((_inputStream != null) || (_reader != null))
138  throw new IllegalStateException("Reader not closed or reset");
139  _xml._reader.setInput(in, encoding);
140  _inputStream = in;
141  return this;
142  }

References javolution.xml.XMLObjectReader._inputStream, javolution.xml.XMLObjectReader._reader, and javolution.xml.XMLObjectReader._xml.

◆ setInput() [3/3]

XMLObjectReader javolution.xml.XMLObjectReader.setInput ( Reader  in) throws XMLStreamException

Sets the reader input source for this XML stream reader.

Parameters
inthe source reader.
Returns
this
See also
XMLStreamReaderImpl::setInput(Reader)

Definition at line 151 of file XMLObjectReader.java.

151  {
152  if ((_inputStream != null) || (_reader != null))
153  throw new IllegalStateException("Reader not closed or reset");
154  _xml._reader.setInput(in);
155  _reader = in;
156  return this;
157  }

References javolution.xml.XMLObjectReader._inputStream, javolution.xml.XMLObjectReader._reader, and javolution.xml.XMLObjectReader._xml.

◆ setReferenceResolver()

XMLObjectReader javolution.xml.XMLObjectReader.setReferenceResolver ( XMLReferenceResolver  referenceResolver)

Sets the XML reference resolver to use with this object reader (the same resolver can be used accross multiple readers).

Parameters
referenceResolverthe XML reference resolver.
Returns
this

Definition at line 177 of file XMLObjectReader.java.

178  {
179  _xml.setReferenceResolver(referenceResolver);
180  return this;
181  }

References javolution.xml.XMLObjectReader._xml.

Member Data Documentation

◆ _inputStream

InputStream javolution.xml.XMLObjectReader._inputStream
private

◆ _reader

Reader javolution.xml.XMLObjectReader._reader
private

◆ _xml


The documentation for this class was generated from the following file:
javolution.xml.XMLObjectReader.reset
void reset()
Definition: XMLObjectReader.java:286
javolution.xml.XMLObjectReader._inputStream
InputStream _inputStream
Definition: XMLObjectReader.java:54
javolution.xml.XMLObjectReader.XMLObjectReader
XMLObjectReader()
Definition: XMLObjectReader.java:99
javolution.xml.XMLObjectReader._reader
Reader _reader
Definition: XMLObjectReader.java:49
javolution.xml.XMLObjectReader._xml
final XMLFormat.InputElement _xml
Definition: XMLObjectReader.java:44