org.dhmp.io
Class MapReader

java.lang.Object
  extended byorg.dhmp.io.MapReader
All Implemented Interfaces:
MapInput

public class MapReader
extends java.lang.Object
implements MapInput

This class can read a piece of HierarchicalMap instead of whole HierarchicalMap and also support relative key manipulation. Each MapReader keeps a reference position from where HierarchicalMap is read.

Author:
hideyuki

Constructor Summary
MapReader(AbstractMapInput in)
          Creates a new instance of MapWriter sharing the same relative position.
MapReader(MapReader in)
          Creates a new instance of MapReader
 
Method Summary
 void close()
          Closes associated input source and releases any system resources associated with it.
 HierarchicalMap getBaseMap()
          Returns current base map.
 java.lang.String getCurrentPath()
          Gets the current path relative to the reference.
 java.lang.String getReferencePath()
          Gets the path used as reference for all reading methods.
 boolean hasSamePath()
          Returns true if the path has not changed after last reading method.
 void init(HierarchicalMap paramMap)
          Initializes this class using the configuration passed.
 void init(java.lang.String config)
          Initializes this class using the configuration passed.
 MapReader newCurrentReader()
          Returns new MapReader with reference path set to current path of this class.
 MapReader newCurrentReader(java.lang.Object start)
          Returns new MapReader with reference path set to start.
 MapReader newLatestReader()
          Returns new MapReader with reference path set to last read position.
 MapReader newReader()
          Returns new MapReader with same reference path.
 HierarchicalMap readAllMap()
           
 HierarchicalMap readMap()
          Reads-in a HierarchicalMap from input source.
 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.
 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

MapReader

public MapReader(MapReader in)
Creates a new instance of MapReader

Parameters:
in - Input stream from where the maps are read.

MapReader

public MapReader(AbstractMapInput in)
Creates a new instance of MapWriter sharing the same relative position.

Parameters:
in - AbstractMapInput with shared input.
Method Detail

init

public void init(java.lang.String config)
Description copied from interface: MapInput
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".

Configuration change is accepted until the first reading method is called. Check the specific MapInput init method for valid configurations.

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.

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.

readAllMap

public HierarchicalMap readAllMap()
                           throws MapIOException
Throws:
MapIOException

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.

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.

getReferencePath

public java.lang.String getReferencePath()
Gets the path used as reference for all reading methods.

Returns:
reference path.

getCurrentPath

public java.lang.String getCurrentPath()
Gets the current path relative to the reference.

Returns:
current path.

hasSamePath

public boolean hasSamePath()
Returns true if the path has not changed after last reading method.

Returns:
true if path has not changed.

newReader

public MapReader newReader()
Returns new MapReader with same reference path.

Returns:
newly created MapReader.

newCurrentReader

public MapReader newCurrentReader()
Returns new MapReader with reference path set to current path of this class.

Returns:
newly created MapReader.

newCurrentReader

public MapReader newCurrentReader(java.lang.Object start)
Returns new MapReader with reference path set to start.

Parameters:
start - node referred by reference path.
Returns:
newly created MapReader.

newLatestReader

public MapReader newLatestReader()
Returns new MapReader with reference path set to last read position. If readMap(start, stop) or readMapUntil(stop) is called, this method will return a MapReader with reference set to the stop node, whereas the method newCurrentReader will return a MapReader with reference set to the start or to the original reference held by MapReader.

Returns:
newly created MapReader.

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.