OpMath

com.opmath.util.http
Class ParamTable

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--java.util.Hashtable
              |
              +--com.opmath.util.datastruct.OrderedHashtable
                    |
                    +--com.opmath.util.datastruct.LCHashtable
                          |
                          +--com.opmath.util.http.ParamTable
All Implemented Interfaces:
Cloneable, Map, ParamIndex, Serializable

public class ParamTable
extends LCHashtable
implements ParamIndex

An object which can provide parameter ((name, value) => index) functions, implemented by extending com.opmath.util.datastruct.OrderedHashtable.

ParamTable implements the ParamIndex interface using an OrderedHashtable of (String => OrderedHashtable) mappings. Instances of ParamTable can be used to keep track of servlet parameter names and values, and help in the control of servlet doGet(HttpServletRequest, HttpServletResponse) and doPost(HttpServletRequest, HttpServletResponse) methods.

The class com.opmath.util.http.HttpServlet shows a cononical use of the ParamTable class and the ParamIndex interface: subclasses of com.opmath.util.http.HttpServlet can make use of the ParamIndex methods directly, and need not be concerned with the creation or disposal of the ParamTable instance.

NOTE: com.opmath.util.http.ParamTable requires that the package com.opmath.util.dmldoc is in place in order to operate.

Copyright: (c) 2002 The Open Math Company Limited

The Terms of Distribution of this software are stipulated in the javadoc Overview for this project.

Since:
J2SE 1.3
Version:
HTTP v2.0
Author:
Bruno Beloff bruno.beloff@opmath.com
See Also:
Serialized Form

Inner classes inherited from class java.util.Map
Map.Entry
 
Field Summary
protected static int PARAM_INDEX_FAIL
          May be returned by getIndex(String, String) and getParamIndex(String, HttpServletRequest).
 
Constructor Summary
ParamTable()
          Constructs a new ParamTable instance.
 
Method Summary
 int getIndex(String paramName, String paramValue)
          Returns the int index associated with the paramName / paramValue pair, as established by registerIndex(String, String, int).
 int getParamIndex(String paramName, HttpServletRequest req)
          Returns the int index of the parameter value found in the HttpServletRequest whose name is paramName and whose value is found in the HttpServletRequest.
 int getValueCount(String paramName)
          Returns the number of parameter values registered against paramName.
 Enumeration paramIndices(String paramName)
          Returns an Enumeration of the parameter indices for the values registered against paramName.
 Enumeration paramMappings()
          Returns an Enumeration of the parameter (value => index) mappings known to the registry.
 Enumeration paramNames()
          Returns an Enumeration of the parameter names known to the registry.
 Enumeration paramValues(String paramName)
          Returns an Enumeration of the parameter values registered against paramName.
 void registerIndex(String paramName, String paramValue, int paramValueIndex)
          Associates the value of a servlet parameter with an int index.
 
Methods inherited from class com.opmath.util.datastruct.LCHashtable
normalized
 
Methods inherited from class com.opmath.util.datastruct.OrderedHashtable
containsKey, elements, get, keys, put, putAll, remove, toString
 
Methods inherited from class java.util.Hashtable
, clear, clone, contains, containsValue, entrySet, equals, hashCode, isEmpty, keySet, rehash, size, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

PARAM_INDEX_FAIL

protected static final int PARAM_INDEX_FAIL
May be returned by getIndex(String, String) and getParamIndex(String, HttpServletRequest).

See Also:
getIndex(String, String), getParamIndex(String, HttpServletRequest)
Since:
J2SE 1.3
Constructor Detail

ParamTable

public ParamTable()
Constructs a new ParamTable instance.

Since:
J2SE 1.3
Method Detail

registerIndex

public void registerIndex(String paramName,
                          String paramValue,
                          int paramValueIndex)
Associates the value of a servlet parameter with an int index. The main use of the register is to enable switch statements to work over commands handed to the servlet; to do this, the int must be declared by the servlet as static final.

If the paramName / paramValue pair are already known to the registry, then the previous index associated with the paramName / paramValue pair is lost.

NOTE 1: Although legal, it would be extremely unwise to register the value com.opmath.util.http.ParamTable.PARAM_INDEX_FAIL.

NOTE 2: Command parameter value strings are always case-insensitive.

Specified by:
registerIndex in interface ParamIndex
Parameters:
paramName - the String name of the parameter.
paramValue - the String value of the parameter.
paramValueIndex - the int value of the index.
the - int value associated with the parameter value.
Since:
J2SE 1.3

getIndex

public int getIndex(String paramName,
                    String paramValue)
Returns the int index associated with the paramName / paramValue pair, as established by registerIndex(String, String, int).

If the pair paramName / paramValue is not known to the registry, then getIndex(String, String) will return the int value com.opmath.util.http.ParamTable.PARAM_INDEX_FAIL.

NOTE: Command parameter value strings are always case-insensitive.

Specified by:
getIndex in interface ParamIndex
Parameters:
paramName - the String name of the parameter.
paramValue - the String value of the parameter.
Returns:
the associated int value of the parameter, or the int value com.opmath.util.http.ParamIndex.PARAM_INDEX_FAIL.
Since:
J2SE 1.3

getParamIndex

public int getParamIndex(String paramName,
                         HttpServletRequest req)
Returns the int index of the parameter value found in the HttpServletRequest whose name is paramName and whose value is found in the HttpServletRequest.

If paramName is not found in the HttpServletRequest, or if the value for paramName found in the HttpServletRequest is not known to the registry, then getParamIndex(String, HttpServletRequest) will return the int value com.opmath.util.http.ParamIndex.PARAM_INDEX_FAIL.

NOTE: Command parameter value strings are always case-insensitive.

Specified by:
getParamIndex in interface ParamIndex
Parameters:
paramName - the String name of the parameter.
req - the HttpServletRequest containing the parameter.
Returns:
the associated int value of the parameter, or the int value com.opmath.util.http.ParamIndex.PARAM_INDEX_FAIL.
Since:
J2SE 1.3

getValueCount

public int getValueCount(String paramName)
Returns the number of parameter values registered against paramName.

If paramName is not known to the registry, then getValueCount(String) returns the int value 0.

Specified by:
getValueCount in interface ParamIndex
Parameters:
paramName - the String name of the parameter.
Returns:
the int total number of values held against this name.
Since:
J2SE 1.3

paramNames

public Enumeration paramNames()
Returns an Enumeration of the parameter names known to the registry. Use the Enumeration methods on the returned object to fetch the keys sequentially. The enumerated objects can be cast to String.

Specified by:
paramNames in interface ParamIndex
Returns:
an Enumeration of parameter names.
Since:
J2SE 1.3

paramMappings

public Enumeration paramMappings()
Returns an Enumeration of the parameter (value => index) mappings known to the registry. Use the Enumeration methods on the returned object to fetch the keys sequentially. The enumerated objects can be cast to com.opmath.util.datastruct.OrderedHashTable.

Specified by:
paramMappings in interface ParamIndex
Returns:
an Enumeration of parameter (value => index) mappings.
Since:
J2SE 1.3

paramValues

public Enumeration paramValues(String paramName)
Returns an Enumeration of the parameter values registered against paramName. Use the Enumeration methods on the returned object to fetch the keys sequentially. The enumerated objects can be cast to String.

If paramName is not known to the registry, then paramValues() will return null.

Specified by:
paramValues in interface ParamIndex
Parameters:
paramName - the String name of the parameter.
Returns:
an Enumeration of parameter values.
Since:
J2SE 1.3

paramIndices

public Enumeration paramIndices(String paramName)
Returns an Enumeration of the parameter indices for the values registered against paramName. Use the Enumeration methods on the returned object to fetch the keys sequentially. The enumerated objects can be cast to Integer.

If paramName is not known to the registry, then paramIndices() will return null.

Specified by:
paramIndices in interface ParamIndex
Parameters:
paramName - the String name of the parameter.
Returns:
an Enumeration of parameter names.
Since:
J2SE 1.3

OpMath

Submit a bug or feature to Open Math
Copyright © 2002 Open Math Company Limited, Brighton, UK