com.tomgibara.pronto.config.source
Class StringConfigSource

java.lang.Object
  extended by com.tomgibara.pronto.config.source.StringConfigSource
All Implemented Interfaces:
ConfigSource

public class StringConfigSource
extends java.lang.Object
implements ConfigSource

Instances of this class convert a single string into a set of properties as follows: 1) The string is split at each semicolon. 2) Each component is split at a colon into a key and a value. 3) Each key-value pair is trimmed and added to the map This encoding should be superficially familiar to those familiar with CSS style properties. Note that there are no mechanisms for escaping colons and semicolons. Keys may not be duplicated.

Author:
Tom Gibara

Constructor Summary
StringConfigSource(java.lang.String string)
          Constructs a new set of properties from the supplied string.
 
Method Summary
 java.util.Map<java.lang.String,java.lang.String> getProperties()
          A map of the configuration properties supplied by this source.
 long lastModified()
          Because this object is immutable, this method returns zero.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StringConfigSource

public StringConfigSource(java.lang.String string)
                   throws java.lang.IllegalArgumentException
Constructs a new set of properties from the supplied string.

Parameters:
string - a string containing key value pairs, possibly empty
Throws:
java.lang.IllegalArgumentException - if the string supplied to the constructor is null, or cannot be parsed.
Method Detail

lastModified

public long lastModified()
Because this object is immutable, this method returns zero.

Specified by:
lastModified in interface ConfigSource
Returns:
0L

getProperties

public java.util.Map<java.lang.String,java.lang.String> getProperties()
Description copied from interface: ConfigSource
A map of the configuration properties supplied by this source. The map returned by this method will not be modified by the config. The implementation is free to throw an unchecked exception of its choice if the properties cannot be supplied.

Specified by:
getProperties in interface ConfigSource
Returns:
the semicolon delimited key value pairs in the string.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
the string from which the properties of this source have been extracted.


Copyright © 2006-2007 Tom Gibara. All Rights Reserved.