Cantaloop CGimlet - API Documentation, Version: 0.2.0, Date: 2002-05-13 21:30 CEST

org.cantaloop.cgimlet
Class Options

java.lang.Object
  |
  +--java.util.AbstractMap
        |
        +--java.util.HashMap
              |
              +--org.cantaloop.cgimlet.Options
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable

public class Options
extends java.util.HashMap

Allows a handler the store options. Options can be grouped hierarchically by providing default values. Example:

 <foo>
   <option name="input-dir" value="${input}/src"/>
   <option name="output-dir" value="${output}/build"/>
   <bar>
     <option name="input-dir" value="${input}/src/foo"/>
   </bar>
 <foo>
 
This options can be read as following:
 Element foo = root.element("foo");
 Element bar = foo.element("bar");
 OptionReaderConfigurator config = new OptionReaderConfigurator(MY_NAMESPACE);
 OptionReader fooReader = new OptionReader(config, foo, fooOpt);
 OptionReader barReader = new OptionReader(config, bar, barOpt);
 fooReader.read();
 barReader.read();
 

Version:
0.2.0 ($Revision: 1.11 $)
Author:
David Leuschner, Stefan Heimann
See Also:
Serialized Form

Inner classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
protected  Options m_defaults
           
 
Constructor Summary
Options()
          Creates a new Options instance without default values.
Options(Options def)
          Creates a new Options instance with the default values found in def
 
Method Summary
 boolean containsKey(java.lang.Object key)
          Overwritten to ask the default instance of the key is not found in this instance.
 boolean containsValue(java.lang.Object value)
          Overwritten to ask the default instance of the key is not found in this instance.
 java.lang.Object get(java.lang.Object key)
          Overwritten to ask the default instance if the key is not found in this instance.
 Options getDefaults()
          Get the default values.
 java.lang.String getOption(java.lang.String key)
          Get the option with key key.
 java.lang.String getOption(java.lang.String key, java.lang.String defaultVal)
          Get the option with key key.
 void setDefaults(Options def)
          Set the default values that should be used.
 void setOption(java.lang.String key, java.lang.String value)
          Convenient method.
 
Methods inherited from class java.util.HashMap
clear, clone, entrySet, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

m_defaults

protected Options m_defaults
Constructor Detail

Options

public Options()
Creates a new Options instance without default values.

Options

public Options(Options def)
Creates a new Options instance with the default values found in def
Parameters:
def - an Options value
Method Detail

setDefaults

public void setDefaults(Options def)
Set the default values that should be used. If you set this value to null, no default values will be used.
Parameters:
def - an Options value

getDefaults

public Options getDefaults()
Get the default values.
Returns:
an Options value

setOption

public void setOption(java.lang.String key,
                      java.lang.String value)
Convenient method.
Parameters:
key - a String value
value - a String value
Returns:
an String value

getOption

public java.lang.String getOption(java.lang.String key)
Get the option with key key. If you have used the put() of HashMap directly, this method can throw a ClassCastException if the value is not of type java.lang.String.
Parameters:
key - a String value
Returns:
an String value

getOption

public java.lang.String getOption(java.lang.String key,
                                  java.lang.String defaultVal)
Get the option with key key. If the key is not found or the value stored under this key is null, the default value defaultVal is returned.
Parameters:
key - a String value
defaultVal - a String value
Returns:
a String value
See Also:
getOption(String)

get

public java.lang.Object get(java.lang.Object key)
Overwritten to ask the default instance if the key is not found in this instance.
Overrides:
get in class java.util.HashMap
Parameters:
key - an Object value

containsKey

public boolean containsKey(java.lang.Object key)
Overwritten to ask the default instance of the key is not found in this instance.
Overrides:
containsKey in class java.util.HashMap
Parameters:
key - an Object value

containsValue

public boolean containsValue(java.lang.Object value)
Overwritten to ask the default instance of the key is not found in this instance.
Overrides:
containsValue in class java.util.HashMap
Parameters:
key - an Object value

Copyright 2001, 2002 Stefan Heimann, David Leuschner. All rights reserved.