com.arsdigita.bebop.parameters
Class ArrayParameter

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

public class ArrayParameter
extends ParameterModel

Reads an array of values and converts them to a Java object array. The values in the array can be any parameter type, for example strings, big decimals etc. The values are read from a request either as multiple repeated values with the same parameter name, i.e. from a URL like http://foo.com/page?array=one&array=two or from an encoded string that was previously produced by unmarshal.

Either way, the transformed value of the parameters is an array of the type of getElementParameter().getValueClass()[], so if the element parameter is a StringParameter, the transformed value will be of type String[], and if it is a BigDecimalParameter, it will be of type BigDecimal[].

Warning: The array parameter does currently no checking related to the size of the array, no matter what you set min and max value counts to.

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

Field Summary
protected  int maxCount
           
protected  int minCount
           
static String versionId
           
 
Fields inherited from class com.arsdigita.bebop.parameters.ParameterModel
m_defaultValue, m_locked, m_name, m_parameterListeners
 
Constructor Summary
ArrayParameter(ParameterModel element)
          Create a new array parameter.
ArrayParameter(String name)
          Creates a new array parameter.
 
Method Summary
 ParameterModel getElementParameter()
          Return the parameter model that transforms and validates individual entries in the array.
 int getMaxValueCount()
          Gets the maximum number of values for this parameter that may be submitted for the request to be valid.
 int getMinValueCount()
          Gets the minimum number of values for this parameter that may be submitted for the request to be valid.
 Class getValueClass()
          Return the class that all values produced by the model will have.
 void lock()
          Lock the model, blocking any further modifications.
 String marshal(Object value)
          Encode the value which must be an array of objects into one string.
 String marshalElement(Object value)
          Encode the given value into a string.
 void setElementParameter(ParameterModel v)
          Set the parameter model that transforms and validates individual entries in the array.
 void setMaxValueCount(int count)
          Sets the maximum number of values for this parameter that may be submitted for the request to be valid.
 void setMinValueCount(int count)
          Sets the minimum number of values for this parameter that may be submitted for the request to be valid.
 Object transformValue(javax.servlet.http.HttpServletRequest request)
          Extract an array of values from the request.
 Object unmarshal(String value)
          Decode the string representation of an array into an array of objects.
 Object unmarshalElement(String encoded)
          Decode one array element from its string representation.
protected  void validate(ParameterData data)
          Validate the array extracted from the request by running the validation listeners of this parameter, and by running thte validation for the element parameter for each entry in the array separately.
 
Methods inherited from class com.arsdigita.bebop.parameters.ParameterModel
addParameterListener, createParameterData, createParameterData, createParameterData, getDefaultOverridesNull, getDefaultValue, getName, isLocked, isPassIn, setDefaultOverridesNull, setDefaultValue, setName, setPassIn, transformSingleValue
 
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

maxCount

protected int maxCount

minCount

protected int minCount
Constructor Detail

ArrayParameter

public ArrayParameter(String name)
Creates a new array parameter. Entries in the array are of type String.

Parameters:
name - the name of the array parameter in URIs.

ArrayParameter

public ArrayParameter(ParameterModel element)
Create a new array parameter. Entries in the array are of the type produced by element. Validation listeners on the element are run for each array entry.

Parameters:
element - the parameter model for entries in the array.
Method Detail

getElementParameter

public final ParameterModel getElementParameter()
Return the parameter model that transforms and validates individual entries in the array.

Returns:
the parameter model for individual entries in the array.

setElementParameter

public final void setElementParameter(ParameterModel v)
Set the parameter model that transforms and validates individual entries in the array.

Parameters:
v - the parameter model for entries in the array.

marshalElement

public final String marshalElement(Object value)
Encode the given value into a string. The returned string can be turned back into an object that equals value by unmarshalElement(java.lang.String). Uses the marshalling of the element parameter model.

Parameters:
value - an object with the type of array elements
Returns:
the value encoded in a string
See Also:
ParameterModel.marshal(java.lang.Object), unmarshalElement(java.lang.String)

unmarshalElement

public final Object unmarshalElement(String encoded)
Decode one array element from its string representation. The string encoded must have been produced through the marshalling of the element parameter.

Parameters:
encoded - the marshalled representation of an array element
Returns:
the array element represented by encoded
See Also:
ParameterModel.unmarshal(java.lang.String), marshalElement(java.lang.Object)

transformValue

public Object transformValue(javax.servlet.http.HttpServletRequest request)
Extract an array of values from the request. Autodetects whether the request parameter contains the array in several parameters with identical name or as just one value in an encoded form produced by marshal(java.lang.Object).

Specified by:
transformValue in class ParameterModel
Parameters:
request - a HttpServletRequest value
Returns:
an Object value

marshal

public String marshal(Object value)
Encode the value which must be an array of objects into one string. The entries in the array must be of a type that can be understood by the element parameter. The unmarshal(java.lang.String) method can read this format and reconstruct the array from that string again.

Overrides:
marshal in class ParameterModel
Parameters:
value - an array of values
Returns:
the array encoded into one string

unmarshal

public Object unmarshal(String value)
Decode the string representation of an array into an array of objects. The returned value is of type Object[]. The type of the entries in the array depends on the element parameter.

Overrides:
unmarshal in class ParameterModel
Parameters:
value - the marshalled version of an array.
Returns:
the Object[] reconstructed from value.

setMinValueCount

public final void setMinValueCount(int count)
Sets the minimum number of values for this parameter that may be submitted for the request to be valid. If the parameter is required, the minimum must be at least one.


setMaxValueCount

public final void setMaxValueCount(int count)
Sets the maximum number of values for this parameter that may be submitted for the request to be valid.


getMinValueCount

public final int getMinValueCount()
Gets the minimum number of values for this parameter that may be submitted for the request to be valid.


getMaxValueCount

public final int getMaxValueCount()
Gets the maximum number of values for this parameter that may be submitted for the request to be valid.


validate

protected void validate(ParameterData data)
                 throws FormProcessException
Validate the array extracted from the request by running the validation listeners of this parameter, and by running thte validation for the element parameter for each entry in the array separately.

Overrides:
validate in class ParameterModel
Parameters:
data - the parameter data to validate.
Throws:
FormProcessException - if the data can not be validated.

lock

public void lock()
Description copied from class: ParameterModel
Lock the model, blocking any further modifications. Cached form models should always be locked to ensure that they remain unchanged across requests.

Specified by:
lock in interface Lockable
Overrides:
lock in class ParameterModel

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 21 2004:2337 UTC