SolarMetric Kodo JDO 2.5.8 generated on January 11 2004

serp.util
Class Options

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--java.util.Hashtable
              |
              +--java.util.Properties
                    |
                    +--serp.util.TypedProperties
                          |
                          +--serp.util.Options
All Implemented Interfaces:
Cloneable, Map, Serializable

public class Options
extends TypedProperties

A specialization of the Properties map type with the added abilities to read application options from the command line and to use bean patterns to set an object's properties via command-line the stored mappings.

A typical use pattern for this class is to construct a new instance in the main method, then call setFromCmdLine(java.lang.String[]) with the given args. Next, an instanceof the class being invoked is created, and setInto(java.lang.Object) is called with that instance as a parameter. With this pattern, the user can configure any bean properties of the class, or even properties of classes reachable from the class, through the command line.

See Also:
Serialized Form

Inner classes inherited from class java.util.Map
Map.Entry
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
Options()
          Default constructor.
Options(Properties defaults)
          Construct the options instance with the given set of defaults.
 
Method Summary
 boolean getBooleanProperty(String key, String key2, boolean def)
          Specialization of getBooleanProperty(java.lang.String, java.lang.String, boolean) to allow a value to appear under either of two keys; useful for short and long versions of command-line flags.
 double getDoubleProperty(String key, String key2, double def)
          Specialization of TypedProperties.getDoubleProperty(java.lang.String) to allow a value to appear under either of two keys; useful for short and long versions of command-line flags.
 float getFloatProperty(String key, String key2, float def)
          Specialization of TypedProperties.getFloatProperty(java.lang.String) to allow a value to appear under either of two keys; useful for short and long versions of command-line flags.
 int getIntProperty(String key, String key2, int def)
          Specialization of TypedProperties.getIntProperty(java.lang.String) to allow a value to appear under either of two keys; useful for short and long versions of command-line flags.
 long getLongProperty(String key, String key2, long def)
          Specialization of TypedProperties.getLongProperty(java.lang.String) to allow a value to appear under either of two keys; useful for short and long versions of command-line flags.
 String getProperty(String key, String key2, String def)
          Specialization of Properties.getProperty(java.lang.String) to allow a value to appear under either of two keys; useful for short and long versions of command-line flags.
 boolean removeBooleanProperty(String key, String key2, boolean def)
          Specialization of TypedProperties.removeBooleanProperty(java.lang.String) to allow a value to appear under either of two keys; useful for short and long versions of command-line flags.
 double removeDoubleProperty(String key, String key2, double def)
          Specialization of TypedProperties.removeDoubleProperty(java.lang.String) to allow a value to appear under either of two keys; useful for short and long versions of command-line flags.
 float removeFloatProperty(String key, String key2, float def)
          Specialization of TypedProperties.removeFloatProperty(java.lang.String) to allow a value to appear under either of two keys; useful for short and long versions of command-line flags.
 int removeIntProperty(String key, String key2, int def)
          Specialization of TypedProperties.removeIntProperty(java.lang.String) to allow a value to appear under either of two keys; useful for short and long versions of command-line flags.
 long removeLongProperty(String key, String key2, long def)
          Specialization of TypedProperties.removeLongProperty(java.lang.String) to allow a value to appear under either of two keys; useful for short and long versions of command-line flags.
 String removeProperty(String key, String key2, String def)
          Specialization of Properties#removeProperty to allow a value to appear under either of two keys; useful for short and long versions of command-line flags.
 String[] setFromCmdLine(String[] args)
          Parses the given argument list into flag/value pairs, which are stored as properties.
 void setInto(Object obj)
          This method uses reflection to set all the properties in the given object that are named by the keys in this map.
 
Methods inherited from class serp.util.TypedProperties
getBooleanProperty, getBooleanProperty, getDoubleProperty, getDoubleProperty, getFloatProperty, getFloatProperty, getIntProperty, getIntProperty, getLongProperty, getLongProperty, removeBooleanProperty, removeBooleanProperty, removeDoubleProperty, removeDoubleProperty, removeFloatProperty, removeFloatProperty, removeIntProperty, removeIntProperty, removeLongProperty, removeLongProperty, removeProperty, removeProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty
 
Methods inherited from class java.util.Properties
, getProperty, getProperty, list, list, load, propertyNames, save, 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

Options

public Options()
Default constructor.

Options

public Options(Properties defaults)
Construct the options instance with the given set of defaults.
See Also:
Properties.Properties(Properties)
Method Detail

setFromCmdLine

public String[] setFromCmdLine(String[] args)
Parses the given argument list into flag/value pairs, which are stored as properties. Flags that are present without values are given the value "true". If any flag is found for which there is already a mapping present, the existing mapping will be overwritten. Flags should be of the form:
java Foo -flag1 value1 -flag2 value2 ... arg1 arg2 ...
Parameters:
args - the command-line arguments
Returns:
all arguments in the original array beyond the flag/value pair list

setInto

public void setInto(Object obj)
This method uses reflection to set all the properties in the given object that are named by the keys in this map. For a given key 'foo', the algorithm will look for a 'setFoo' method in the given instance. For a given key 'foo.bar', the algorithm will first look for a 'getFoo' method in the given instance, then will recurse on the return value of that method, now looking for the 'bar' property. This allows the setting of nested object properties. If in the above example the 'getFoo' method is not present or returns null, the algorithm will look for a 'setFoo' method; if found it will constrct a new instance of the correct type, set it using the 'setFoo' method, then recurse on it as above. Property names can be nested in this way to an arbitrary depth. For setter methods that take multiple parameters, the value mapped to the key can use the ',' as an argument separator character. If not enough values are present for a given method after splitting the string on ',', the remaining arguments will receive default values. All arguments are converted from string form to the correct type if possible (i.e. if the type is primitive, java.lang.Clas, or has a constructor that takes a single string argument). Examples: Any keys present in the map for which there is no corresponding property in the given object will be ignored.
Throws:
RuntimeException - on parse error

getBooleanProperty

public boolean getBooleanProperty(String key,
                                  String key2,
                                  boolean def)
Specialization of getBooleanProperty(java.lang.String, java.lang.String, boolean) to allow a value to appear under either of two keys; useful for short and long versions of command-line flags.

getFloatProperty

public float getFloatProperty(String key,
                              String key2,
                              float def)
Specialization of TypedProperties.getFloatProperty(java.lang.String) to allow a value to appear under either of two keys; useful for short and long versions of command-line flags.

getDoubleProperty

public double getDoubleProperty(String key,
                                String key2,
                                double def)
Specialization of TypedProperties.getDoubleProperty(java.lang.String) to allow a value to appear under either of two keys; useful for short and long versions of command-line flags.

getLongProperty

public long getLongProperty(String key,
                            String key2,
                            long def)
Specialization of TypedProperties.getLongProperty(java.lang.String) to allow a value to appear under either of two keys; useful for short and long versions of command-line flags.

getIntProperty

public int getIntProperty(String key,
                          String key2,
                          int def)
Specialization of TypedProperties.getIntProperty(java.lang.String) to allow a value to appear under either of two keys; useful for short and long versions of command-line flags.

getProperty

public String getProperty(String key,
                          String key2,
                          String def)
Specialization of Properties.getProperty(java.lang.String) to allow a value to appear under either of two keys; useful for short and long versions of command-line flags.

removeBooleanProperty

public boolean removeBooleanProperty(String key,
                                     String key2,
                                     boolean def)
Specialization of TypedProperties.removeBooleanProperty(java.lang.String) to allow a value to appear under either of two keys; useful for short and long versions of command-line flags.

removeFloatProperty

public float removeFloatProperty(String key,
                                 String key2,
                                 float def)
Specialization of TypedProperties.removeFloatProperty(java.lang.String) to allow a value to appear under either of two keys; useful for short and long versions of command-line flags.

removeDoubleProperty

public double removeDoubleProperty(String key,
                                   String key2,
                                   double def)
Specialization of TypedProperties.removeDoubleProperty(java.lang.String) to allow a value to appear under either of two keys; useful for short and long versions of command-line flags.

removeLongProperty

public long removeLongProperty(String key,
                               String key2,
                               long def)
Specialization of TypedProperties.removeLongProperty(java.lang.String) to allow a value to appear under either of two keys; useful for short and long versions of command-line flags.

removeIntProperty

public int removeIntProperty(String key,
                             String key2,
                             int def)
Specialization of TypedProperties.removeIntProperty(java.lang.String) to allow a value to appear under either of two keys; useful for short and long versions of command-line flags.

removeProperty

public String removeProperty(String key,
                             String key2,
                             String def)
Specialization of Properties#removeProperty to allow a value to appear under either of two keys; useful for short and long versions of command-line flags.

SolarMetric Kodo JDO 2.5.8 generated on January 11 2004

Copyright 2001,2002,2003 SolarMetric, Inc. All Rights Reserved.