com.arsdigita.bebop.parameters
Class BitSetParameter

java.lang.Object
  extended bycom.arsdigita.bebop.parameters.ParameterModel
      extended bycom.arsdigita.bebop.parameters.BitSetParameter
All Implemented Interfaces:
Lockable

public class BitSetParameter
extends ParameterModel

Encode and decode a bit set as a request parameter. The bit set is stored in a BitSet and encoded and decoded from the HTTP request appropriately. Currently two forms of encoding are supported: RAW encoding and DGap. RAW encoding stuffs the bits straight into characters. DGap is a variation on run length encoding particularly suited to bitsets. The most appropriate encoding to use depends on the distribution of bits. Since it iss not always possible to anticipate this distribution, an automatic encoding mode is provided which chooses the encoding with the shortest resulting string size.

Version:
$Id: //core-platform/dev/src/com/arsdigita/bebop/parameters/BitSetParameter.java#14 $
Author:
David Lutterkort

Field Summary
static int ENCODE_AUTO
          Flag to automatically choose the shortest encoding scheme
static int ENCODE_DGAP
          Flag for DGap encoding of bit set
static int ENCODE_RAW
          Flag for RAW encoding of bit set
static String versionId
           
 
Fields inherited from class com.arsdigita.bebop.parameters.ParameterModel
m_defaultValue, m_locked, m_name, m_parameterListeners
 
Constructor Summary
BitSetParameter(String name)
          Create a bit set parameter with the given name, defaulting to the RAW encoding scheme
BitSetParameter(String name, int encode)
          Create a bit set parameter with the given name.
 
Method Summary
 Class getValueClass()
          Return the class that all values produced by the model will have.
 String marshal(Object value)
          Turn the value, which must be a BitSet, into a string that can be read by unmarshal.
 Object transformValue(javax.servlet.http.HttpServletRequest request)
          Extract a bit set from the HTTP request.
 Object unmarshal(String value)
          Read a string in the format produced by marshal and produce the corresponding BitSet.
 
Methods inherited from class com.arsdigita.bebop.parameters.ParameterModel
addParameterListener, createParameterData, createParameterData, createParameterData, getDefaultOverridesNull, getDefaultValue, getName, isLocked, isPassIn, lock, setDefaultOverridesNull, setDefaultValue, setName, setPassIn, transformSingleValue, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

versionId

public static final String versionId
See Also:
Constant Field Values

ENCODE_RAW

public static final int ENCODE_RAW
Flag for RAW encoding of bit set

See Also:
Constant Field Values

ENCODE_DGAP

public static final int ENCODE_DGAP
Flag for DGap encoding of bit set

See Also:
Constant Field Values

ENCODE_AUTO

public static final int ENCODE_AUTO
Flag to automatically choose the shortest encoding scheme

See Also:
Constant Field Values
Constructor Detail

BitSetParameter

public BitSetParameter(String name,
                       int encode)
Create a bit set parameter with the given name.

Parameters:
name - the name of this parameter for use in URLs etc.
encode - the encoding scheme

BitSetParameter

public BitSetParameter(String name)
Create a bit set parameter with the given name, defaulting to the RAW encoding scheme

Parameters:
name - the name of this parameter for use in URLs etc.
Method Detail

transformValue

public Object transformValue(javax.servlet.http.HttpServletRequest request)
                      throws IllegalArgumentException
Extract a bit set from the HTTP request. Looks for a parameter with the name of this parameter and unmarshals it into a BitSet.

Specified by:
transformValue in class ParameterModel
Parameters:
request - the HTTP request
Returns:
the BitSet extracted from the request or null.
Throws:
IllegalArgumentException - if the parameter can not be transformed into a bit set.

unmarshal

public Object unmarshal(String value)
                 throws IllegalArgumentException
Read a string in the format produced by marshal and produce the corresponding BitSet.

Overrides:
unmarshal in class ParameterModel
Parameters:
value - A string representing the bit set.
Returns:
the BitSet corresponding to the value.
Throws:
IllegalArgumentException - if the value can not be transformed into a bit set.
See Also:
marshal(java.lang.Object)

marshal

public String marshal(Object value)
Turn the value, which must be a BitSet, into a string that can be read by unmarshal.

Overrides:
marshal in class ParameterModel
Parameters:
value - a BitSet produced by this parameter model.
Returns:
a string encoding of the bit set.
See Also:
unmarshal(java.lang.String)

getValueClass

public Class getValueClass()
Description copied from class: ParameterModel
Return the class that all values produced by the model will have. This should be the most specific common base class of all classes of which the model will ever produce values. This implementation returns Object.class

Overrides:
getValueClass in class ParameterModel
Returns:
the class that all values produced by the model will have.


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 20 2004:2337 UTC