org.dhmp.io
Class AbstractMapOutput

java.lang.Object
  extended byorg.dhmp.io.AbstractMapOutput
All Implemented Interfaces:
MapOutput
Direct Known Subclasses:
MapOutputStream, XMLMapOutputStream

public abstract class AbstractMapOutput
extends java.lang.Object
implements MapOutput

Abstract class for writing HierarchicalMap to OutputStream.

Author:
hideyuki

Field Summary
static boolean AUTOCOMMIT_OFF
           
static boolean AUTOCOMMIT_ON
           
 
Constructor Summary
AbstractMapOutput(java.io.OutputStream out)
          Creates a new instance of MapOutputStream
 
Method Summary
 void close()
          Closes this output stream and releases any system resources associated with the stream.
protected  void closeElements(MapStream.Path.Position lastPos)
           
protected  void closeExclude(MapStream.Path.Position lastPos)
           
protected abstract  void elementReference(java.lang.String key, java.lang.Object value, java.lang.String reference, int index, boolean last)
           
protected abstract  void elementValue(java.lang.Object key, java.lang.Object value, boolean last)
           
protected abstract  void endDocument()
           
protected abstract  void endElement(java.lang.String key, boolean last)
           
 void flush()
          Flushes this output stream and forces any buffered output bytes to be written out.
protected  void flush(MapStream.Path.Position pos)
           
 void flushAll()
          Flushes this output stream and also ends any HierarchicalMap written so far.
 void init(HierarchicalMap paramMap)
          Initializes this class using the configuration passed.
 void init(java.lang.String config)
          Initializes this class using the configuration passed.
 java.lang.Object replace(java.lang.Object obj)
          Replace the value actually written to the output.
protected abstract  void startDocument()
           
protected abstract  void startElement(java.lang.String key)
           
 MapOutput writeMap(HierarchicalMap map)
          Writes out a HierarchicalMap to output drain.
protected  MapStream.Path.Position writeMap(MapStream.Path.Position pos, java.lang.Object key, HierarchicalMap map)
           
 MapOutput writeMap(java.lang.Object start, HierarchicalMap map)
          Writes out a HierarchicalMap to output drain relative to the start.
 MapOutput writeMap(java.lang.String path)
          Writes a HierarchicalMap where each of the elements that composes the path are represented as nested nodes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AUTOCOMMIT_ON

public static final boolean AUTOCOMMIT_ON
See Also:
Constant Field Values

AUTOCOMMIT_OFF

public static final boolean AUTOCOMMIT_OFF
See Also:
Constant Field Values
Constructor Detail

AbstractMapOutput

public AbstractMapOutput(java.io.OutputStream out)
Creates a new instance of MapOutputStream

Parameters:
out - OutputStream to where the maps are written.
Method Detail

init

public void init(java.lang.String config)
Initializes this class using the configuration passed. The configuration must be in XML format like "<Param compress=\"true\"/>" or "<Param compress='true\'>". Note that first element must be "Param".

Valid configurations are (bold for default value):

configuration change is accepted until the first writing method is called.

Specified by:
init in interface MapOutput
Parameters:
config - configuration used by this class.

init

public void init(HierarchicalMap paramMap)
Description copied from interface: MapOutput
Initializes this class using the configuration passed. The configuration must be created using HierarchicalMap. The valid parameters are the same as from init(String). Configuration change is accepted until the first writing method is called.

Specified by:
init in interface MapOutput
Parameters:
paramMap - HierarchicalMap containing the configuration.

writeMap

public MapOutput writeMap(java.lang.String path)
                   throws MapIOException
Description copied from interface: MapOutput
Writes a HierarchicalMap where each of the elements that composes the path are represented as nested nodes. writeMap("a/b/c") is similar to the following code:
map.add("a/b/c")
 writeMap(map)

Specified by:
writeMap in interface MapOutput
Parameters:
path - each element of the key is written as node.
Throws:
MapIOException - if an I/O error occurs.

writeMap

public MapOutput writeMap(HierarchicalMap map)
                   throws MapIOException
Description copied from interface: MapOutput
Writes out a HierarchicalMap to output drain.

Specified by:
writeMap in interface MapOutput
Parameters:
map - HierarchicalMap to be written to the output.
Throws:
MapIOException - if an I/O error occurs.

writeMap

public MapOutput writeMap(java.lang.Object start,
                          HierarchicalMap map)
                   throws MapIOException
Description copied from interface: MapOutput
Writes out a HierarchicalMap to output drain relative to the start. Each element that composes the path "start" is written as node.

Specified by:
writeMap in interface MapOutput
Parameters:
map - HierarchicalMap to be written to the output.
start - node from where the writing starts.
Throws:
MapIOException - if an I/O error occurs.

writeMap

protected MapStream.Path.Position writeMap(MapStream.Path.Position pos,
                                           java.lang.Object key,
                                           HierarchicalMap map)
                                    throws MapIOException
Throws:
MapIOException

closeElements

protected void closeElements(MapStream.Path.Position lastPos)
                      throws java.io.IOException
Throws:
java.io.IOException

closeExclude

protected void closeExclude(MapStream.Path.Position lastPos)
                     throws java.io.IOException
Throws:
java.io.IOException

close

public void close()
Description copied from interface: MapOutput
Closes this output stream and releases any system resources associated with the stream.

Specified by:
close in interface MapOutput

flush

public void flush()
Description copied from interface: MapOutput
Flushes this output stream and forces any buffered output bytes to be written out.

Specified by:
flush in interface MapOutput

flushAll

public void flushAll()
Description copied from interface: MapOutput
Flushes this output stream and also ends any HierarchicalMap written so far.

Specified by:
flushAll in interface MapOutput

flush

protected void flush(MapStream.Path.Position pos)

replace

public java.lang.Object replace(java.lang.Object obj)
Replace the value actually written to the output. This method can be overloaded to change the object written to the output.

Parameters:
obj - original object.
Returns:
actual object written to the output.

startElement

protected abstract void startElement(java.lang.String key)
                              throws java.io.IOException
Throws:
java.io.IOException

endElement

protected abstract void endElement(java.lang.String key,
                                   boolean last)
                            throws java.io.IOException
Throws:
java.io.IOException

elementValue

protected abstract void elementValue(java.lang.Object key,
                                     java.lang.Object value,
                                     boolean last)
                              throws java.io.IOException
Throws:
java.io.IOException

elementReference

protected abstract void elementReference(java.lang.String key,
                                         java.lang.Object value,
                                         java.lang.String reference,
                                         int index,
                                         boolean last)
                                  throws java.io.IOException
Throws:
java.io.IOException

startDocument

protected abstract void startDocument()
                               throws java.io.IOException
Throws:
java.io.IOException

endDocument

protected abstract void endDocument()
                             throws java.io.IOException
Throws:
java.io.IOException