org.codehaus.plexus.summit.parameters
Class BaseParameterConverter

java.lang.Object
  extended byorg.codehaus.plexus.summit.parameters.BaseParameterConverter
All Implemented Interfaces:
ParameterConverter
Direct Known Subclasses:
RequestParameters

public class BaseParameterConverter
extends java.lang.Object
implements ParameterConverter

Base implementation of a ParameterConverter which relies on an underlying Map of name/value pairs where each value is an array of strings (even if it contains a single value). For example, the Map returned by HttpRequest#getParameterMap().

Version:
$Revision: 2092 $
Author:
Ilkka Priha, Jon S. Stevens, Sean Legassick, Jason van Zyl, Pete Kazmier

Field Summary
protected  java.lang.String characterEncoding
          The character encoding to use when converting to byte arrays.
protected  java.util.Map parameters
          Map used to store the parameters that were parsed.
 
Constructor Summary
BaseParameterConverter(java.util.Map parameters)
          Constructor that takes a map of parameters and uses the default character encoding, "US-ASCII", when converting to byte arrays.
BaseParameterConverter(java.util.Map parameters, java.lang.String characterEncoding)
          Constructor that takes a map of parameters and a character encoding that is used when converting to byte arrays.
 
Method Summary
 boolean containsKey(java.lang.Object key)
          Determine whether a given key has been inserted
 java.lang.String get(java.lang.String name)
          Return a String for the given name.
 java.math.BigDecimal getBigDecimal(java.lang.String name)
          Return a BigDecimal for the given name.
 java.math.BigDecimal getBigDecimal(java.lang.String name, java.math.BigDecimal defaultValue)
          Return a BigDecimal for the given name.
 java.math.BigDecimal[] getBigDecimals(java.lang.String name)
          Return an array of BigDecimals for the given name.
 java.lang.Boolean getBool(java.lang.String name)
          Return a Boolean for the given name.
 java.lang.Boolean getBool(java.lang.String name, boolean defaultValue)
          Return a Boolean for the given name.
 boolean getBoolean(java.lang.String name)
          Return a boolean for the given name.
 boolean getBoolean(java.lang.String name, boolean defaultValue)
          Return a boolean for the given name.
 byte getByte(java.lang.String name)
          Return a byte for the given name.
 byte getByte(java.lang.String name, byte defaultValue)
          Return a byte for the given name.
 byte[] getBytes(java.lang.String name)
          Return an array of bytes for the given name.
 java.util.Date getDate(java.lang.String name)
          Returns a Date object.
 java.util.Date getDate(java.lang.String name, java.text.DateFormat df)
          Returns a Date object.
 java.util.Date getDate(java.lang.String name, java.text.DateFormat df, java.util.Date defaultValue)
          Returns a Date object.
 double getDouble(java.lang.String name)
          Return a double for the given name.
 double getDouble(java.lang.String name, double defaultValue)
          Return a double for the given name.
 float getFloat(java.lang.String name)
          Return a float for the given name.
 float getFloat(java.lang.String name, float defaultValue)
          Return a float for the given name.
 int getInt(java.lang.String name)
          Return an int for the given name.
 int getInt(java.lang.String name, int defaultValue)
          Return an int for the given name.
 java.lang.Integer getInteger(java.lang.String name)
          Return an Integer for the given name.
 java.lang.Integer getInteger(java.lang.String name, int defaultValue)
          Return an Integer for the given name.
 java.lang.Integer getInteger(java.lang.String name, java.lang.Integer def)
          Return an Integer for the given name.
 java.lang.Integer[] getIntegers(java.lang.String name)
          Return an array of Integers for the given name.
 int[] getInts(java.lang.String name)
          Return an array of ints for the given name.
 java.lang.Object[] getKeys()
          Get an array of all the parameter names.
 long getLong(java.lang.String name)
          Return a long for the given name.
 long getLong(java.lang.String name, long defaultValue)
          Return a long for the given name.
 java.lang.Long[] getLongObjects(java.lang.String name)
          Return an array of Longs for the given name.
 long[] getLongs(java.lang.String name)
          Return an array of longs for the given name.
 java.lang.Object getObject(java.lang.String name)
          Return an Object for the given name.
 java.lang.Object[] getObjects(java.lang.String name)
          Return an array of Objects for the given name.
 java.util.Map getParametersMap()
           
 java.lang.String getString(java.lang.String name)
          Return a String for the given name.
 java.lang.String getString(java.lang.String name, java.lang.String defaultValue)
          Return a String for the given name.
 java.lang.String[] getStrings(java.lang.String name)
          Return an array of Strings for the given name.
 java.lang.String[] getStrings(java.lang.String name, java.lang.String[] defaultValue)
          Return an array of Strings for the given name.
 java.util.Iterator keys()
          Get an Iterator for the parameter names.
 java.lang.String toString()
          Provides a textual representation of the parameters represented by this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

parameters

protected java.util.Map parameters
Map used to store the parameters that were parsed.


characterEncoding

protected java.lang.String characterEncoding
The character encoding to use when converting to byte arrays.

Constructor Detail

BaseParameterConverter

public BaseParameterConverter(java.util.Map parameters)
Constructor that takes a map of parameters and uses the default character encoding, "US-ASCII", when converting to byte arrays. The map of parameters must contain name/value pairs as described in the class documentation.

Parameters:
parameters - A map of name/value pairs representing parameters.
Throws:
java.lang.NullPointerException - If the parameters map is null.

BaseParameterConverter

public BaseParameterConverter(java.util.Map parameters,
                              java.lang.String characterEncoding)
Constructor that takes a map of parameters and a character encoding that is used when converting to byte arrays. The map of parameters must contain name/value pairs as described in the class documentation.

Parameters:
parameters - A map of name/value pairs representing parameters.
characterEncoding - The character encoding used to convert byte arrays. If the specified value is null, the default encoding of "US-ASCII" is used.
Throws:
java.lang.NullPointerException - If the parameters map is null.
Method Detail

getParametersMap

public java.util.Map getParametersMap()

containsKey

public boolean containsKey(java.lang.Object key)
Description copied from interface: ParameterConverter
Determine whether a given key has been inserted

Specified by:
containsKey in interface ParameterConverter
Parameters:
key - An Object with the key to search for.
Returns:
True if the object is found.

keys

public java.util.Iterator keys()
Description copied from interface: ParameterConverter
Get an Iterator for the parameter names.

Specified by:
keys in interface ParameterConverter
Returns:
An Iterator of the keys.

getKeys

public java.lang.Object[] getKeys()
Description copied from interface: ParameterConverter
Get an array of all the parameter names.

Specified by:
getKeys in interface ParameterConverter
Returns:
A object array with the keys.

getBoolean

public boolean getBoolean(java.lang.String name,
                          boolean defaultValue)
Description copied from interface: ParameterConverter
Return a boolean for the given name. If the name does not exist, return defaultValue.

Specified by:
getBoolean in interface ParameterConverter
Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A boolean.

getBoolean

public boolean getBoolean(java.lang.String name)
Description copied from interface: ParameterConverter
Return a boolean for the given name. If the name does not exist, return false.

Specified by:
getBoolean in interface ParameterConverter
Parameters:
name - A String with the name.
Returns:
A boolean.

getBool

public java.lang.Boolean getBool(java.lang.String name,
                                 boolean defaultValue)
Description copied from interface: ParameterConverter
Return a Boolean for the given name. If the name does not exist, return defaultValue.

Specified by:
getBool in interface ParameterConverter
Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A Boolean.

getBool

public java.lang.Boolean getBool(java.lang.String name)
Description copied from interface: ParameterConverter
Return a Boolean for the given name. If the name does not exist, return false.

Specified by:
getBool in interface ParameterConverter
Parameters:
name - A String with the name.
Returns:
A Boolean.

getDouble

public double getDouble(java.lang.String name,
                        double defaultValue)
Description copied from interface: ParameterConverter
Return a double for the given name. If the name does not exist, return defaultValue.

Specified by:
getDouble in interface ParameterConverter
Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A double.

getDouble

public double getDouble(java.lang.String name)
Description copied from interface: ParameterConverter
Return a double for the given name. If the name does not exist, return 0.0.

Specified by:
getDouble in interface ParameterConverter
Parameters:
name - A String with the name.
Returns:
A double.

getFloat

public float getFloat(java.lang.String name,
                      float defaultValue)
Description copied from interface: ParameterConverter
Return a float for the given name. If the name does not exist, return defaultValue.

Specified by:
getFloat in interface ParameterConverter
Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A float.

getFloat

public float getFloat(java.lang.String name)
Description copied from interface: ParameterConverter
Return a float for the given name. If the name does not exist, return 0.0.

Specified by:
getFloat in interface ParameterConverter
Parameters:
name - A String with the name.
Returns:
A float.

getBigDecimal

public java.math.BigDecimal getBigDecimal(java.lang.String name,
                                          java.math.BigDecimal defaultValue)
Description copied from interface: ParameterConverter
Return a BigDecimal for the given name. If the name does not exist, return defaultValue.

Specified by:
getBigDecimal in interface ParameterConverter
Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A BigDecimal.

getBigDecimal

public java.math.BigDecimal getBigDecimal(java.lang.String name)
Description copied from interface: ParameterConverter
Return a BigDecimal for the given name. If the name does not exist, return 0.0.

Specified by:
getBigDecimal in interface ParameterConverter
Parameters:
name - A String with the name.
Returns:
A BigDecimal.

getBigDecimals

public java.math.BigDecimal[] getBigDecimals(java.lang.String name)
Description copied from interface: ParameterConverter
Return an array of BigDecimals for the given name. If the name does not exist, return null.

Specified by:
getBigDecimals in interface ParameterConverter
Parameters:
name - A String with the name.
Returns:
A BigDecimal[].

getInt

public int getInt(java.lang.String name,
                  int defaultValue)
Description copied from interface: ParameterConverter
Return an int for the given name. If the name does not exist, return defaultValue.

Specified by:
getInt in interface ParameterConverter
Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
An int.

getInt

public int getInt(java.lang.String name)
Description copied from interface: ParameterConverter
Return an int for the given name. If the name does not exist, return 0.

Specified by:
getInt in interface ParameterConverter
Parameters:
name - A String with the name.
Returns:
An int.

getInteger

public java.lang.Integer getInteger(java.lang.String name,
                                    int defaultValue)
Description copied from interface: ParameterConverter
Return an Integer for the given name. If the name does not exist, return defaultValue.

Specified by:
getInteger in interface ParameterConverter
Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
An Integer.

getInteger

public java.lang.Integer getInteger(java.lang.String name,
                                    java.lang.Integer def)
Description copied from interface: ParameterConverter
Return an Integer for the given name. If the name does not exist, return defaultValue. You cannot pass in a null here for the default value.

Specified by:
getInteger in interface ParameterConverter
Parameters:
name - A String with the name.
def - The default value.
Returns:
An Integer.

getInteger

public java.lang.Integer getInteger(java.lang.String name)
Description copied from interface: ParameterConverter
Return an Integer for the given name. If the name does not exist, return 0.

Specified by:
getInteger in interface ParameterConverter
Parameters:
name - A String with the name.
Returns:
An Integer.

getInts

public int[] getInts(java.lang.String name)
Description copied from interface: ParameterConverter
Return an array of ints for the given name. If the name does not exist, return null.

Specified by:
getInts in interface ParameterConverter
Parameters:
name - A String with the name.
Returns:
An int[].

getIntegers

public java.lang.Integer[] getIntegers(java.lang.String name)
Description copied from interface: ParameterConverter
Return an array of Integers for the given name. If the name does not exist, return null.

Specified by:
getIntegers in interface ParameterConverter
Parameters:
name - A String with the name.
Returns:
An Integer[].

getLong

public long getLong(java.lang.String name,
                    long defaultValue)
Description copied from interface: ParameterConverter
Return a long for the given name. If the name does not exist, return defaultValue.

Specified by:
getLong in interface ParameterConverter
Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A long.

getLong

public long getLong(java.lang.String name)
Description copied from interface: ParameterConverter
Return a long for the given name. If the name does not exist, return 0.

Specified by:
getLong in interface ParameterConverter
Parameters:
name - A String with the name.
Returns:
A long.

getLongs

public long[] getLongs(java.lang.String name)
Description copied from interface: ParameterConverter
Return an array of longs for the given name. If the name does not exist, return null.

Specified by:
getLongs in interface ParameterConverter
Parameters:
name - A String with the name.
Returns:
A long[].

getLongObjects

public java.lang.Long[] getLongObjects(java.lang.String name)
Description copied from interface: ParameterConverter
Return an array of Longs for the given name. If the name does not exist, return null.

Specified by:
getLongObjects in interface ParameterConverter
Parameters:
name - A String with the name.
Returns:
A Long[].

getByte

public byte getByte(java.lang.String name,
                    byte defaultValue)
Description copied from interface: ParameterConverter
Return a byte for the given name. If the name does not exist, return defaultValue.

Specified by:
getByte in interface ParameterConverter
Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A byte.

getByte

public byte getByte(java.lang.String name)
Description copied from interface: ParameterConverter
Return a byte for the given name. If the name does not exist, return 0.

Specified by:
getByte in interface ParameterConverter
Parameters:
name - A String with the name.
Returns:
A byte.

getBytes

public byte[] getBytes(java.lang.String name)
                throws java.io.UnsupportedEncodingException
Description copied from interface: ParameterConverter
Return an array of bytes for the given name. If the name does not exist, return null. The array is returned according to the HttpRequest's character encoding.

Specified by:
getBytes in interface ParameterConverter
Parameters:
name - A String with the name.
Returns:
A byte[].
Throws:
java.io.UnsupportedEncodingException

getString

public java.lang.String getString(java.lang.String name)
Description copied from interface: ParameterConverter
Return a String for the given name. If the name does not exist, return null.

Specified by:
getString in interface ParameterConverter
Parameters:
name - A String with the name.
Returns:
A String.

get

public java.lang.String get(java.lang.String name)
Description copied from interface: ParameterConverter
Return a String for the given name. If the name does not exist, return null. It is the same as the getString() method however has been added for simplicity when working with template tools such as Velocity which allow you to do something like this:

$data.Parameters.form_variable_name

Specified by:
get in interface ParameterConverter
Parameters:
name - A String with the name.
Returns:
A String.

getString

public java.lang.String getString(java.lang.String name,
                                  java.lang.String defaultValue)
Description copied from interface: ParameterConverter
Return a String for the given name. If the name does not exist, return the defaultValue.

Specified by:
getString in interface ParameterConverter
Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A String.

getStrings

public java.lang.String[] getStrings(java.lang.String name)
Description copied from interface: ParameterConverter
Return an array of Strings for the given name. If the name does not exist, return null.

Specified by:
getStrings in interface ParameterConverter
Parameters:
name - A String with the name.
Returns:
A String[].

getStrings

public java.lang.String[] getStrings(java.lang.String name,
                                     java.lang.String[] defaultValue)
Description copied from interface: ParameterConverter
Return an array of Strings for the given name. If the name does not exist, return the defaultValue.

Specified by:
getStrings in interface ParameterConverter
Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A String[].

getObject

public java.lang.Object getObject(java.lang.String name)
Description copied from interface: ParameterConverter
Return an Object for the given name. If the name does not exist, return null.

Specified by:
getObject in interface ParameterConverter
Parameters:
name - A String with the name.
Returns:
An Object.

getObjects

public java.lang.Object[] getObjects(java.lang.String name)
Description copied from interface: ParameterConverter
Return an array of Objects for the given name. If the name does not exist, return null.

Specified by:
getObjects in interface ParameterConverter
Parameters:
name - A String with the name.
Returns:
An Object[].

getDate

public java.util.Date getDate(java.lang.String name,
                              java.text.DateFormat df,
                              java.util.Date defaultValue)
Description copied from interface: ParameterConverter
Returns a Date object. String is parsed by supplied DateFormat. If the name does not exist, return the defaultValue.

Specified by:
getDate in interface ParameterConverter
Parameters:
name - A String with the name.
df - A DateFormat.
defaultValue - The default value.
Returns:
A Date.

getDate

public java.util.Date getDate(java.lang.String name,
                              java.text.DateFormat df)
Description copied from interface: ParameterConverter
Returns a Date object. String is parsed by supplied DateFormat. If the name does not exist, return null.

Specified by:
getDate in interface ParameterConverter
Parameters:
name - A String with the name.
df - A DateFormat.
Returns:
A Date.

getDate

public java.util.Date getDate(java.lang.String name)
Description copied from interface: ParameterConverter
Returns a Date object. String is parsed by supplied DateFormat. If the name does not exist, return null.

Specified by:
getDate in interface ParameterConverter
Parameters:
name - A String with the name.
Returns:
A Date.

toString

public java.lang.String toString()
Provides a textual representation of the parameters represented by this object. Each parameter name and its corresponding value is generated.

Returns:
A textual representation of the name/value pairs.


Copyright © 2001-2007 Codehaus. All Rights Reserved.