BeanIO 1.2.3

org.beanio.stream.xml
Class XmlWriter

java.lang.Object
  extended by org.beanio.stream.xml.XmlWriter
All Implemented Interfaces:
RecordWriter, StatefulWriter

public class XmlWriter
extends Object
implements RecordWriter, StatefulWriter

A XmlWriter is used to write records to a XML output stream. A document object model (DOM) is used to represent a record. Group elements, as indicated by a user data key (see below), are not closed when a record is written. When write(null) is called, an open group element is closed. Finally, calling flush() will close all remaining group elements and complete the document.

A XmlWriter makes use of the DOM user data feature to pass additional information to and from the parser. The IS_GROUP_ELEMENT user data is a Boolean value added to an element to indicate the element is group. And the IS_NAMESPACE_IGNORED user data is a Boolean value set on elements where the XML namespace should be ignored when writing to the output stream.

Since:
1.1
Author:
Kevin Seim

Field Summary
static String IS_GROUP_ELEMENT
          The DOM user data key to indicate a DOM element is a group element and should be left "open" when the record is written to the output stream.
static String IS_NAMESPACE_IGNORED
          The DOM user data key to indicate whether the namespace of a DOM element should be ignored when writing to the output stream.
 
Constructor Summary
XmlWriter(Writer writer)
          Constructs a new XmlWriter.
XmlWriter(Writer writer, XmlWriterConfiguration config)
          Constructs a new XmlWriter.
 
Method Summary
 void close()
          Closes the output stream.
 void flush()
          Flushes the output stream.
 void restoreState(String namespace, Map<String,Object> state)
          Restores a Map of previously stored state information.
 void updateState(String namespace, Map<String,Object> state)
          Updates a Map with the current state of the Writer to allow for restoration at a later time.
 void write(Object record)
          Writes a record object to this output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IS_NAMESPACE_IGNORED

public static final String IS_NAMESPACE_IGNORED
The DOM user data key to indicate whether the namespace of a DOM element should be ignored when writing to the output stream. The value must be of type java.lang.Boolean.

See Also:
Constant Field Values

IS_GROUP_ELEMENT

public static final String IS_GROUP_ELEMENT
The DOM user data key to indicate a DOM element is a group element and should be left "open" when the record is written to the output stream. The value must of type java.lang.Boolean.

See Also:
Constant Field Values
Constructor Detail

XmlWriter

public XmlWriter(Writer writer)
Constructs a new XmlWriter.

Parameters:
writer - the output stream to write to

XmlWriter

public XmlWriter(Writer writer,
                 XmlWriterConfiguration config)
Constructs a new XmlWriter.

Parameters:
writer - the output stream to write to
config - the XML writer configuration
Method Detail

write

public void write(Object record)
           throws IOException
Description copied from interface: RecordWriter
Writes a record object to this output stream.

Specified by:
write in interface RecordWriter
Parameters:
record - the record object to write
Throws:
IOException - if an I/O error occurs writing the record to the stream

flush

public void flush()
           throws IOException
Description copied from interface: RecordWriter
Flushes the output stream.

Specified by:
flush in interface RecordWriter
Throws:
IOException - if an I/O error occurs flushing the stream

close

public void close()
           throws IOException
Description copied from interface: RecordWriter
Closes the output stream.

Specified by:
close in interface RecordWriter
Throws:
IOException - if an I/O error occurs closing the stream

updateState

public void updateState(String namespace,
                        Map<String,Object> state)
Description copied from interface: StatefulWriter
Updates a Map with the current state of the Writer to allow for restoration at a later time.

Specified by:
updateState in interface StatefulWriter
Parameters:
namespace - a String to prefix all state keys with
state - the Map to update with the latest state

restoreState

public void restoreState(String namespace,
                         Map<String,Object> state)
                  throws IllegalStateException
Description copied from interface: StatefulWriter
Restores a Map of previously stored state information.

Specified by:
restoreState in interface StatefulWriter
Parameters:
namespace - a String to prefix all state keys with
state - the Map containing the state to restore
Throws:
IllegalStateException - if the Map is missing any state information

BeanIO 1.2.3

Copyright © 2010-2012 Kevin Seim