net.ultrametrics.rcs
Class ControlInformation

java.lang.Object
  |
  +--net.ultrametrics.rcs.ControlInformation
Direct Known Subclasses:
Header, LogEntry, Modification

public abstract class ControlInformation
extends java.lang.Object

Encapsulation of a control information for an RCS object.

"control information" is a Map plus some intelligence about how to parse the information from a reader containing raw RCS data.


Field Summary
static java.lang.String _rcsId
           
protected static char DELIMITER
          control information default block delimiter.
static java.lang.String EXT_RCS
          RCS file default extension.
protected  java.util.HashMap map
          A map containing the name-value key pairs.
protected  java.io.BufferedReader reader
          A buffered reader from which the control keys and elements are parsed.
 
Constructor Summary
ControlInformation(java.io.BufferedReader reader)
          Construct a new map of control information.
 
Method Summary
protected  void clear()
          Calling clear is optional and provided as a mechanism to save memory by reducing what otherwise might be duplicate instances of objects.
 boolean containsKey(java.lang.String key)
          Determine whether or not this control information contains the specified key.
 void dump()
          Similar to toString(), but more verbose and dumps directly to stderr.
protected abstract  java.util.Collection getAllowedKeys()
          Retrieve the collection of allowed keys (from the implementor's concrete instance).
 Element getElement(java.lang.String key)
          Retrieve a control element.
protected  Element getFirstElement(java.lang.String key)
          The first element in an RCS control block is delimited differently compared to subsequent blocks.
protected abstract  boolean isKeyAllowed(java.lang.String key)
          Determine whether a key would be allowed (in the implementor's concrete instance of a control block).
protected static java.util.Collection makeKeyCollection(java.lang.String[] keyArray)
          Convenience method to convert an array of keys into a collection.
protected  boolean parse()
          Parse known keys and values in the form of map, from the reader.
protected  Element parseNextElement()
          Parse the next block of data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

map

protected java.util.HashMap map
A map containing the name-value key pairs.

reader

protected java.io.BufferedReader reader
A buffered reader from which the control keys and elements are parsed.

DELIMITER

protected static char DELIMITER
control information default block delimiter.

EXT_RCS

public static final java.lang.String EXT_RCS
RCS file default extension.

_rcsId

public static final java.lang.String _rcsId
Constructor Detail

ControlInformation

public ControlInformation(java.io.BufferedReader reader)
Construct a new map of control information.
Parameters:
reader - the buffered reader from which elements will be subsequently parsed.
Method Detail

containsKey

public boolean containsKey(java.lang.String key)
Determine whether or not this control information contains the specified key.
Parameters:
key - the control key.

getElement

public Element getElement(java.lang.String key)
Retrieve a control element.
Parameters:
key - the control key.
Returns:
the control element associated with the specified key.

isKeyAllowed

protected abstract boolean isKeyAllowed(java.lang.String key)
Determine whether a key would be allowed (in the implementor's concrete instance of a control block).
Parameters:
key - the control key.
Returns:
whether the specified key is allowed.

getAllowedKeys

protected abstract java.util.Collection getAllowedKeys()
Retrieve the collection of allowed keys (from the implementor's concrete instance).
Returns:
the collection of allowed control keys.

clear

protected void clear()
Calling clear is optional and provided as a mechanism to save memory by reducing what otherwise might be duplicate instances of objects.

After the object implementing control information is populated, he can optionally signal to the garbage collector that the map and reader is no longer in use.

This means that subsequent calls to key or element accessors will fail. Presumably the implementing class will have already retrieved that information and placed it in local storage.


getFirstElement

protected Element getFirstElement(java.lang.String key)
                           throws java.io.IOException
The first element in an RCS control block is delimited differently compared to subsequent blocks.
Parameters:
key - the control key.
Returns:
the control element associated with the specified key.

parseNextElement

protected Element parseNextElement()
                            throws java.io.IOException,
                                   ParserException
Parse the next block of data.
Returns:
a control element.

parse

protected boolean parse()
                 throws ParserException
Parse known keys and values in the form of map, from the reader.

Assumes that this class's reader is positioned at the head of the block which contains the desired elements. Executing this method 'consumes' the data, meaning the reader will be positioned after the block processed.

Returns:
whether all (or the last) elements have been parsed
Throws:
ParserException - if the data is not in RCS format.

dump

public void dump()
Similar to toString(), but more verbose and dumps directly to stderr.

makeKeyCollection

protected static java.util.Collection makeKeyCollection(java.lang.String[] keyArray)
Convenience method to convert an array of keys into a collection.