Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.cantaloop.cgimlet
Class Options  view Options download Options.java

java.lang.Object
  extended byjava.util.AbstractMap
      extended byjava.util.HashMap
          extended byorg.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:
@version@ ($Revision: 1.11 $)

Nested Class Summary
 
Nested classes inherited from class java.util.HashMap
 
Nested classes inherited from class java.util.AbstractMap
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
protected  Options m_defaults
           
 
Fields inherited from class java.util.HashMap
 
Fields inherited from class java.util.AbstractMap
 
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

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.


getDefaults

public Options getDefaults()
Get the default values.


setOption

public void setOption(java.lang.String key,
                      java.lang.String value)
Convenient method.


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.


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.


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.


containsKey

public boolean containsKey(java.lang.Object key)
Overwritten to ask the default instance of the key is not found in this instance.


containsValue

public boolean containsValue(java.lang.Object value)
Overwritten to ask the default instance of the key is not found in this instance.