edu.sdsc.inca.util
Class ConfigProperties

java.lang.Object
  extended byjava.util.Dictionary
      extended byjava.util.Hashtable
          extended byjava.util.Properties
              extended byedu.sdsc.inca.util.ConfigProperties
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable

public class ConfigProperties
extends java.util.Properties

This is an extension of the standard Properties class that can generate elements by command-line parsing and by stripping prefixes from the elements of Properties objects--both useful in generating configuration values.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
ConfigProperties()
           
 
Method Summary
 void loadFromFile(java.lang.String path, java.lang.String prefix)
          Reads properties from a file, retaining only those properties that have a name starting with the given prefix.
 void loadFromResource(java.lang.String res, java.lang.String prefix)
          Reads properties from a resource, retaining only those properties that have a name starting with the given prefix.
 void loadFromStream(java.io.InputStream stream, java.lang.String prefix)
          Reads properties from an input stream, retaining only those properties that have a name starting with the given prefix.
static java.lang.String mergeValidOptions(java.lang.String valid1, java.lang.String valid2, boolean sort)
          Merges two strings of the form accepted by setPropertiesFromArgs.
 void putAllTrimmed(java.util.Properties p, java.lang.String prefix)
          Like putAll, but only copies those elements that have a name starting with the given prefix.
 void setPropertiesFromArgs(java.lang.String valid, java.lang.String[] args)
          Parses command-line arguments, storing each option/value pair as a property.
 
Methods inherited from class java.util.Properties
getProperty, getProperty, list, list, load, propertyNames, save, setProperty, store
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConfigProperties

public ConfigProperties()
Method Detail

loadFromFile

public void loadFromFile(java.lang.String path,
                         java.lang.String prefix)
                  throws java.io.IOException
Reads properties from a file, retaining only those properties that have a name starting with the given prefix. Trims the prefix from the property names.

Parameters:
path - Path to file to open and load.
prefix - Property name prefix to test and trim.
Throws:
java.io.IOException

loadFromResource

public void loadFromResource(java.lang.String res,
                             java.lang.String prefix)
                      throws java.io.IOException
Reads properties from a resource, retaining only those properties that have a name starting with the given prefix. Trims the prefix from the property names.

Parameters:
res - Resource to open and load.
prefix - Property name prefix to test and trim.
Throws:
java.io.IOException

loadFromStream

public void loadFromStream(java.io.InputStream stream,
                           java.lang.String prefix)
                    throws java.io.IOException
Reads properties from an input stream, retaining only those properties that have a name starting with the given prefix. Trims the prefix from the property names.

Parameters:
stream - Resource to open and load.
prefix - Property name prefix to test and trim.
Throws:
java.io.IOException

putAllTrimmed

public void putAllTrimmed(java.util.Properties p,
                          java.lang.String prefix)
Like putAll, but only copies those elements that have a name starting with the given prefix. Trims the prefix from the property names.

Parameters:
p - Properties to copy.
prefix - Property name prefix to test and trim.

setPropertiesFromArgs

public void setPropertiesFromArgs(java.lang.String valid,
                                  java.lang.String[] args)
                           throws ConfigurationException
Parses command-line arguments, storing each option/value pair as a property. Options that take no value are given the value "".

Parameters:
valid - A newline-delimited list of descriptions about valid options. The tokens in each option description list the option name (or names, separated by "|") and option type ("null" for options that take no value). Any text after the option type is ignored, making it easy to reuse the valid option description for user help.
args - Command-line arguments from main().
Throws:
ConfigurationException

mergeValidOptions

public static java.lang.String mergeValidOptions(java.lang.String valid1,
                                                 java.lang.String valid2,
                                                 boolean sort)
Merges two strings of the form accepted by setPropertiesFromArgs. Removes any duplicates and sorts and formats the result.

Parameters:
valid1 - the first set of options
valid2 - the second set of options
Returns:
the combined options