org.dhmp.io
Class AbstractMapInput

java.lang.Object
  extended byorg.dhmp.io.AbstractMapInput
All Implemented Interfaces:
MapInput
Direct Known Subclasses:
MapInputStream, XMLMapInputStream

public abstract class AbstractMapInput
extends java.lang.Object
implements MapInput

Abstract class for reading HierarchicalMap from InputStream.

Author:
hideyuki

Constructor Summary
AbstractMapInput(java.io.InputStream in)
          Creates a new instance of MapInputStream
 
Method Summary
 void close()
          Closes associated input source and releases any system resources associated with it.
 HierarchicalMap getBaseMap()
          Returns current base map.
protected abstract  java.lang.String getKey()
           
protected abstract  int getReference()
           
protected abstract  int getType()
           
protected abstract  java.lang.Object getValue()
           
protected  void init()
           
 void init(HierarchicalMap paramMap)
          Initializes this class using the configuration passed.
 void init(java.lang.String config)
          Initializes this class using the configuration passed.
 HierarchicalMap readMap()
          Reads-in a HierarchicalMap from input source.
protected  HierarchicalMap readMap(MapStream.Path.Position pos, java.lang.Object start, java.lang.Object stop, boolean readUntil)
           
 HierarchicalMap readMap(java.lang.Object start)
          Reads-in a HierarchicalMap from input source starting at specified node.
 HierarchicalMap readMap(java.lang.Object start, java.lang.Object stop)
          Reads-in a HierarchicalMap from input source starting at specified node and finishing at stopping node.
 HierarchicalMap readMapUntil()
          Reads-in a HierarchicalMap from input source until first node is found.
 HierarchicalMap readMapUntil(java.lang.Object stop)
          Reads-in a HierarchicalMap from input source until finishing node is found.
 java.lang.Object replace(java.lang.Object obj)
          Replace the value read from input.
 void setBaseMap(HierarchicalMap baseMap)
          Set the current base map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractMapInput

public AbstractMapInput(java.io.InputStream in)
Creates a new instance of MapInputStream

Parameters:
in - InputStream from where the maps are read.
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 reading method is called.

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

init

public void init(HierarchicalMap paramMap)
Description copied from interface: MapInput
Initializes this class using the configuration passed. The configuration must be created using HierarchicalMap. The valid configuration are the same as from init(String).

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

init

protected void init()

readMap

public HierarchicalMap readMap()
                        throws MapIOException
Description copied from interface: MapInput
Reads-in a HierarchicalMap from input source.

Specified by:
readMap in interface MapInput
Returns:
HierarchicalMap read from input or null if EOF reached.
Throws:
MapIOException - if an I/O error occurs or input stream can not be parsed to HierarchicalMap.

readMap

public HierarchicalMap readMap(java.lang.Object start)
                        throws MapIOException
Description copied from interface: MapInput
Reads-in a HierarchicalMap from input source starting at specified node.

Specified by:
readMap in interface MapInput
Parameters:
start - node from where the reading starts.
Returns:
HierarchicalMap read from input or null if EOF reached.
Throws:
MapIOException - if an I/O error occurs or input stream can not be parsed to HierarchicalMap.

readMap

public HierarchicalMap readMap(java.lang.Object start,
                               java.lang.Object stop)
                        throws MapIOException
Description copied from interface: MapInput
Reads-in a HierarchicalMap from input source starting at specified node and finishing at stopping node.

Specified by:
readMap in interface MapInput
Parameters:
start - node from where the reading starts.
stop - finish reading when this node is found.
Returns:
HierarchicalMap read from input or null if EOF reached.
Throws:
MapIOException - if an I/O error occurs or input stream can not be parsed to HierarchicalMap.

readMapUntil

public HierarchicalMap readMapUntil()
                             throws MapIOException
Description copied from interface: MapInput
Reads-in a HierarchicalMap from input source until first node is found.

Specified by:
readMapUntil in interface MapInput
Returns:
HierarchicalMap read from input or null if EOF reached.
Throws:
MapIOException - if an I/O error occurs or input stream can not be parsed to HierarchicalMap.

readMapUntil

public HierarchicalMap readMapUntil(java.lang.Object stop)
                             throws MapIOException
Description copied from interface: MapInput
Reads-in a HierarchicalMap from input source until finishing node is found. Whole HierarchicalMap is read if finishing node is not found. If stop node is null stop reading at first node.

Specified by:
readMapUntil in interface MapInput
Parameters:
stop - finish reading when this node is found.
Returns:
HierarchicalMap read from input or null if EOF reached.
Throws:
MapIOException - if an I/O error occurs or input stream can not be parsed to HierarchicalMap.

readMap

protected HierarchicalMap readMap(MapStream.Path.Position pos,
                                  java.lang.Object start,
                                  java.lang.Object stop,
                                  boolean readUntil)
                           throws MapIOException
Throws:
MapIOException

close

public void close()
           throws MapIOException
Description copied from interface: MapInput
Closes associated input source and releases any system resources associated with it.

Specified by:
close in interface MapInput
Throws:
MapIOException - if an I/O error occurs.

replace

public java.lang.Object replace(java.lang.Object obj)
Replace the value read from input. This method can be overloaded to change the object actually added to the map.

Parameters:
obj - original object.
Returns:
actual object added to the map.

getBaseMap

public HierarchicalMap getBaseMap()
Description copied from interface: MapInput
Returns current base map.

Specified by:
getBaseMap in interface MapInput
Returns:
current base map.

setBaseMap

public void setBaseMap(HierarchicalMap baseMap)
Description copied from interface: MapInput
Set the current base map. The actual map returned after read methods will be created using base map's newInstance() method.

Specified by:
setBaseMap in interface MapInput
Parameters:
baseMap - HierarchicalMap used as base for creating actual structure.

getType

protected abstract int getType()
                        throws java.io.IOException
Throws:
java.io.IOException

getKey

protected abstract java.lang.String getKey()
                                    throws java.io.IOException
Throws:
java.io.IOException

getReference

protected abstract int getReference()
                             throws java.io.IOException
Throws:
java.io.IOException

getValue

protected abstract java.lang.Object getValue()
                                      throws java.io.IOException
Throws:
java.io.IOException