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

Public Member Functions

 XMLObjectWriter ()
 
XMLStreamWriter getStreamWriter ()
 
XMLObjectWriter setOutput (OutputStream out) throws XMLStreamException
 
XMLObjectWriter setOutput (OutputStream out, String encoding) throws XMLStreamException
 
XMLObjectWriter setOutput (Writer out) throws XMLStreamException
 
XMLObjectWriter setBinding (XMLBinding binding)
 
XMLObjectWriter setIndentation (String indentation)
 
XMLObjectWriter setReferenceResolver (XMLReferenceResolver referenceResolver)
 
void write (Object obj) throws XMLStreamException
 
void write (Object obj, String name) throws XMLStreamException
 
void write (Object obj, String localName, String uri) throws XMLStreamException
 
void flush () throws XMLStreamException
 
void close () throws XMLStreamException
 
void reset ()
 

Static Public Member Functions

static XMLObjectWriter newInstance (OutputStream out) throws XMLStreamException
 
static XMLObjectWriter newInstance (OutputStream out, String encoding) throws XMLStreamException
 
static XMLObjectWriter newInstance (Writer out) throws XMLStreamException
 

Package Functions

public< T > void write (T obj, String name, Class< T > cls) throws XMLStreamException
 
public< T > void write (T obj, String localName, String uri, Class< T > cls) throws XMLStreamException
 

Private Attributes

final XMLFormat.OutputElement _xml = new XMLFormat.OutputElement()
 
Writer _writer
 
OutputStream _outputStream
 

Detailed Description

This class takes an object and formats it to XML; the resulting XML can be deserialized using a XMLObjectReader.

When an object is formatted, the XMLFormat of the object's class as identified by the XMLBinding is used to write its XML representation.

Multiple objects can be written to the same XML output. For example:[code] XMLObjectWriter writer = XMLObjectWriter.newInstance(outputStream); while (true)) { Message message = ... writer.write(message, "Message", Message.class); } writer.close(); // The underlying stream is closed. [/code]

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

Definition at line 40 of file XMLObjectWriter.java.

Constructor & Destructor Documentation

◆ XMLObjectWriter()

javolution.xml.XMLObjectWriter.XMLObjectWriter ( )

Default constructor.

Definition at line 60 of file XMLObjectWriter.java.

60 {}

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

Here is the caller graph for this function:

Member Function Documentation

◆ close()

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

Ends document writting, closes this writer and its underlying output then reset this Writer for potential reuse.

Definition at line 284 of file XMLObjectWriter.java.

284  {
285  try {
286  if (_outputStream != null) {
287  _xml._writer.writeEndDocument();
288  _xml._writer.close();
289  _outputStream.close();
290  reset();
291  } else if (_writer != null) {
292  _xml._writer.writeEndDocument();
293  _xml._writer.close();
294  _writer.close();
295  reset();
296  }
297 
298  } catch (IOException e) {
299  throw new XMLStreamException(e);
300  }
301  }

References javolution.xml.XMLObjectWriter._outputStream, javolution.xml.XMLObjectWriter._writer, javolution.xml.XMLObjectWriter._xml, and javolution.xml.XMLObjectWriter.reset().

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

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

◆ flush()

void javolution.xml.XMLObjectWriter.flush ( ) throws XMLStreamException

Flushes the output stream of this writer (automatically done when closing).

Definition at line 276 of file XMLObjectWriter.java.

276  {
277  _xml._writer.flush();
278  }

References javolution.xml.XMLObjectWriter._xml.

◆ getStreamWriter()

XMLStreamWriter javolution.xml.XMLObjectWriter.getStreamWriter ( )

Returns the stream writer used by this object writer (it can be used to write prolog, write namespaces, etc). The stream writer is setup to automatically repair namespaces and to automatically output empty elements when a start element is immediately followed by matching end element.

Returns
the stream writer.

Definition at line 111 of file XMLObjectWriter.java.

111  {
112  return _xml._writer;
113  }

References javolution.xml.XMLObjectWriter._xml.

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

Here is the caller graph for this function:

◆ newInstance() [1/3]

static XMLObjectWriter javolution.xml.XMLObjectWriter.newInstance ( OutputStream  out) throws XMLStreamException
static

Returns a XML object writer (potentially recycled) having the specified output stream as output.

Parameters
outthe output stream.

Definition at line 68 of file XMLObjectWriter.java.

69  {
70  XMLObjectWriter writer = new XMLObjectWriter();
71  writer.setOutput(out);
72  return writer;
73  }

References javolution.xml.XMLObjectWriter.setOutput(), and javolution.xml.XMLObjectWriter.XMLObjectWriter().

Here is the call graph for this function:

◆ newInstance() [2/3]

static XMLObjectWriter javolution.xml.XMLObjectWriter.newInstance ( OutputStream  out,
String  encoding 
) throws XMLStreamException
static

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

Parameters
outthe output stream.
encodingthe output stream encoding.

Definition at line 82 of file XMLObjectWriter.java.

83  {
84  XMLObjectWriter writer = new XMLObjectWriter();
85  writer.setOutput(out, encoding);
86  return writer;
87  }

References javolution.xml.XMLObjectWriter.setOutput(), and javolution.xml.XMLObjectWriter.XMLObjectWriter().

Here is the call graph for this function:

◆ newInstance() [3/3]

static XMLObjectWriter javolution.xml.XMLObjectWriter.newInstance ( Writer  out) throws XMLStreamException
static

Returns a XML object writer (potentially recycled) having the specified writer as output.

Parameters
outthe writer output.

Definition at line 95 of file XMLObjectWriter.java.

96  {
97  XMLObjectWriter writer = new XMLObjectWriter();
98  writer.setOutput(out);
99  return writer;
100  }

References javolution.xml.XMLObjectWriter.setOutput(), and javolution.xml.XMLObjectWriter.XMLObjectWriter().

Here is the call graph for this function:

◆ reset()

void javolution.xml.XMLObjectWriter.reset ( )

Resets this object writer for reuse.

Definition at line 306 of file XMLObjectWriter.java.

306  {
307  _xml.reset();
308  _outputStream = null;
309  _writer = null;
310  }

References javolution.xml.XMLObjectWriter._outputStream, javolution.xml.XMLObjectWriter._writer, and javolution.xml.XMLObjectWriter._xml.

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

Here is the caller graph for this function:

◆ setBinding()

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

Sets the XML binding to use with this object writer.

Parameters
bindingthe XML binding to use.
Returns
this

Definition at line 172 of file XMLObjectWriter.java.

172  {
173  _xml.setBinding(binding);
174  return this;
175  }

References javolution.xml.XMLObjectWriter._xml.

◆ setIndentation()

XMLObjectWriter javolution.xml.XMLObjectWriter.setIndentation ( String  indentation)

Sets the indentation to be used by this writer (no indentation by default).

Parameters
indentationthe indentation string.
Returns
this

Definition at line 184 of file XMLObjectWriter.java.

184  {
185  _xml._writer.setIndentation(indentation);
186  return this;
187  }

References javolution.xml.XMLObjectWriter._xml.

◆ setOutput() [1/3]

XMLObjectWriter javolution.xml.XMLObjectWriter.setOutput ( OutputStream  out) throws XMLStreamException

Sets the output stream for this XML object writer.

Parameters
outthe output stream destination.
Returns
this
See also
XMLStreamWriterImpl::setOutput(OutputStream)

Definition at line 122 of file XMLObjectWriter.java.

123  {
124  if ((_outputStream != null) || (_writer != null))
125  throw new IllegalStateException("Writer not closed or reset");
126  _xml._writer.setOutput(out);
127  _outputStream = out;
128  _xml._writer.writeStartDocument();
129  return this;
130  }

References javolution.xml.XMLObjectWriter._outputStream, javolution.xml.XMLObjectWriter._writer, and javolution.xml.XMLObjectWriter._xml.

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

Here is the caller graph for this function:

◆ setOutput() [2/3]

XMLObjectWriter javolution.xml.XMLObjectWriter.setOutput ( OutputStream  out,
String  encoding 
) throws XMLStreamException

Sets the output stream and encoding for this XML object writer.

Parameters
outthe output stream destination.
encodingthe stream encoding.
Returns
this
See also
XMLStreamWriterImpl::setOutput(OutputStream, String)

Definition at line 140 of file XMLObjectWriter.java.

141  {
142  if ((_outputStream != null) || (_writer != null))
143  throw new IllegalStateException("Writer not closed or reset");
144  _xml._writer.setOutput(out, encoding);
145  _outputStream = out;
146  _xml._writer.writeStartDocument();
147  return this;
148  }

References javolution.xml.XMLObjectWriter._outputStream, javolution.xml.XMLObjectWriter._writer, and javolution.xml.XMLObjectWriter._xml.

◆ setOutput() [3/3]

XMLObjectWriter javolution.xml.XMLObjectWriter.setOutput ( Writer  out) throws XMLStreamException

Sets the output writer for this XML object writer.

Parameters
outthe writer destination.
Returns
this
See also
XMLStreamWriterImpl::setOutput(Writer)

Definition at line 157 of file XMLObjectWriter.java.

157  {
158  if ((_outputStream != null) || (_writer != null))
159  throw new IllegalStateException("Writer not closed or reset");
160  _xml._writer.setOutput(out);
161  _writer = out;
162  _xml._writer.writeStartDocument();
163  return this;
164  }

References javolution.xml.XMLObjectWriter._outputStream, javolution.xml.XMLObjectWriter._writer, and javolution.xml.XMLObjectWriter._xml.

◆ setReferenceResolver()

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

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

Parameters
referenceResolverthe XML reference resolver.
Returns
this

Definition at line 196 of file XMLObjectWriter.java.

197  {
198  _xml.setReferenceResolver(referenceResolver);
199  return this;
200  }

References javolution.xml.XMLObjectWriter._xml.

◆ write() [1/5]

void javolution.xml.XMLObjectWriter.write ( Object  obj) throws XMLStreamException

Writes the specified object as an anonymous nested element of unknown type. This result in the actual type of the object being identified by the element name.

Parameters
objthe object written as nested element or null.
See also
XMLFormat.OutputElement::add(Object)

Definition at line 210 of file XMLObjectWriter.java.

210  {
211  _xml.add(obj);
212  }

References javolution.xml.XMLObjectWriter._xml.

◆ write() [2/5]

void javolution.xml.XMLObjectWriter.write ( Object  obj,
String  localName,
String  uri 
) throws XMLStreamException

Writes the specified object as a fully qualified nested element of unknown type (null objects are ignored). The nested XML element may contain a class attribute identifying the object type.

Parameters
objthe object added as nested element or null.
localNamethe local name of the nested element.
urithe namespace URI of the nested element.
See also
XMLFormat.OutputElement::add(Object, String, String)

Definition at line 238 of file XMLObjectWriter.java.

239  {
240  _xml.add(obj, localName, uri);
241  }

References javolution.xml.XMLObjectWriter._xml.

◆ write() [3/5]

void javolution.xml.XMLObjectWriter.write ( Object  obj,
String  name 
) throws XMLStreamException

Writes the specified object as a named nested element of unknown type (null objects are ignored). The nested XML element may contain a class attribute identifying the object type.

Parameters
objthe object added as nested element or null.
namethe name of the nested element.
See also
XMLFormat.OutputElement::add(Object, String)

Definition at line 223 of file XMLObjectWriter.java.

223  {
224  _xml.add(obj, name);
225  }

References javolution.xml.XMLObjectWriter._xml.

◆ write() [4/5]

public<T> void javolution.xml.XMLObjectWriter.write ( obj,
String  localName,
String  uri,
Class< T >  cls 
) throws XMLStreamException
package

Writes the specified object as a fully qualified nested element of actual type known (null objects are ignored).

Parameters
objthe object added as nested element or null.
localNamethe local name of the nested element.
urithe namespace URI of the nested element.
clsthe class identifying the XML format to use.
See also
XMLFormat.OutputElement::add(Object, String, String, Class)

Definition at line 267 of file XMLObjectWriter.java.

268  {
269  _xml.add(obj, localName, uri, cls);
270  }

References javolution.xml.XMLObjectWriter._xml.

◆ write() [5/5]

public<T> void javolution.xml.XMLObjectWriter.write ( obj,
String  name,
Class< T >  cls 
) throws XMLStreamException
package

Writes the specified object as a named nested element of actual type known (null objects are ignored).

Parameters
objthe object added as nested element or null.
namethe name of the nested element.
clsthe non-abstract class identifying the XML format to use.
See also
XMLFormat.OutputElement::add(Object, String, Class)

Definition at line 252 of file XMLObjectWriter.java.

253  {
254  _xml.add(obj, name, cls);
255  }

References javolution.xml.XMLObjectWriter._xml.

Member Data Documentation

◆ _outputStream

OutputStream javolution.xml.XMLObjectWriter._outputStream
private

◆ _writer

Writer javolution.xml.XMLObjectWriter._writer
private

◆ _xml


The documentation for this class was generated from the following file:
javolution.xml.XMLObjectWriter.reset
void reset()
Definition: XMLObjectWriter.java:306
javolution.xml.XMLObjectWriter._outputStream
OutputStream _outputStream
Definition: XMLObjectWriter.java:55
javolution.xml.XMLObjectWriter.XMLObjectWriter
XMLObjectWriter()
Definition: XMLObjectWriter.java:60
javolution.xml.XMLObjectWriter._xml
final XMLFormat.OutputElement _xml
Definition: XMLObjectWriter.java:45
javolution.xml.XMLObjectWriter._writer
Writer _writer
Definition: XMLObjectWriter.java:50