org.enhydra.barracuda.core.forms
Class DefaultFormElement

java.lang.Object
  |
  +--org.enhydra.barracuda.core.forms.DefaultFormElement
All Implemented Interfaces:
FormElement

public class DefaultFormElement
extends java.lang.Object
implements FormElement

A FormElement defines how an element in a FormMap should be mapped to a first class java object. There are several key pieces of information required:

Once we have this information, we basically have enough data to map a String value in the data source to a first class Java object in the element.

Note that the element keeps track of the original value as well, so that if for some reason you ever need to get to it that information is available.

Also not that we provide convenience methods which automatically cast for you (Note however: this type of thing is not type safe, meaning that you can get a ClassCastException if you do a getXXXVal() when the underlying object is not of type XXX.


Field Summary
protected  boolean allowMultiples
           
protected  java.lang.Object defaultVal
           
protected  java.lang.String key
           
protected static org.apache.log4j.Logger logger
           
protected  java.lang.String name
           
protected  java.lang.Object origVal
           
protected  ParseException pe
           
protected  FormType type
           
protected  java.lang.Object val
           
protected  FormValidator validator
           
 
Constructor Summary
DefaultFormElement()
          Public noargs constructor.
DefaultFormElement(java.lang.String ikey)
          Public constructor.
DefaultFormElement(java.lang.String ikey, FormType itype)
          Public constructor.
DefaultFormElement(java.lang.String ikey, FormType itype, java.lang.Object idefaultVal)
          Public constructor.
DefaultFormElement(java.lang.String ikey, FormType itype, java.lang.Object idefaultVal, FormValidator ivalidator)
          Public constructor.
DefaultFormElement(java.lang.String ikey, FormType itype, java.lang.Object idefaultVal, FormValidator ivalidator, boolean iallowMultiples)
          Public constructor, Name defaults to Key
DefaultFormElement(java.lang.String ikey, java.lang.String iname, FormType itype, java.lang.Object idefaultVal, FormValidator ivalidator, boolean iallowMultiples)
          Public constructor
 
Method Summary
 boolean allowMultiples()
          Does this element allow multiple values
 java.lang.Boolean getBooleanVal()
          Get the value for this element as a Boolean
 java.lang.Boolean getBooleanVal(java.lang.Boolean dflt)
          Get a Boolean value from the map, defaulting accordingly if the value is null
 java.util.Date getDateVal()
          Get the value for this element as a Date
 java.util.Date getDateVal(java.util.Date dflt)
          Get a Date value from the map, defaulting accordingly if the value is null
 java.lang.Object getDefaultVal()
          Get the default value for this form element
 java.lang.Double getDoubleVal()
          Get the value for this element as a Double
 java.lang.Double getDoubleVal(java.lang.Double dflt)
          Get a Double value from the map, defaulting accordingly if the value is null
 java.lang.Float getFloatVal()
          Get the value for this element as a Float
 java.lang.Float getFloatVal(java.lang.Float dflt)
          Get a Float value from the map, defaulting accordingly if the value is null
 java.lang.Integer getIntegerVal()
          Get the value for this element as a Integer
 java.lang.Integer getIntegerVal(java.lang.Integer dflt)
          Get a Integer value from the map, defaulting accordingly if the value is null
 java.lang.String getKey()
          Get the key value for this form element
 java.lang.Long getLongVal()
          Get the value for this element as a Long
 java.lang.Long getLongVal(java.lang.Long dflt)
          Get a Long value from the map, defaulting accordingly if the value is null
 java.lang.String getName()
          Get the name of this form element
 java.lang.Object getOrigVal()
          Get the original value for this element
 ParseException getParseException()
          Get any parse exceptions associated with the element (ie. that might have occurred when the element was mapped)
 java.lang.Short getShortVal()
          Get the value for this element as a Short
 java.lang.Short getShortVal(java.lang.Short dflt)
          Get a Short value from the map, defaulting accordingly if the value is null
 java.lang.String getStringVal()
          Get the value for this element as a String
 java.lang.String getStringVal(java.lang.String dflt)
          Get the value for this element as a String, defaulting accordingly if the value is null
 FormType getType()
          Get the FormType for this for element
 java.lang.Object getVal()
          Get the value for this element
 FormValidator getValidator()
          Get the default FormValidator for this form element
 void setAllowMultiples(boolean val)
          Set whether or not this element allows multiple values
 void setDefaultVal(java.lang.Object idefaultVal)
          Set the default value for this form element
 void setKey(java.lang.String ikey)
          Set the key value for this form element
 void setName(java.lang.String iname)
          Set the name of this form element
 void setOrigVal(java.lang.Object iorigVal)
          Set the original value for this element
 void setParseException(ParseException ipe)
          Set the parse exception associated with this element
 void setType(FormType itype)
          Set the FormType for this form element
 void setVal(java.lang.Object ival)
          Set the value for this element
 void setValidator(FormValidator ivalidator)
          Set the FormValidator for this form element
 java.lang.String toString()
          Get a string representation of this element
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

protected static org.apache.log4j.Logger logger

key

protected java.lang.String key

name

protected java.lang.String name

type

protected FormType type

defaultVal

protected java.lang.Object defaultVal

pe

protected ParseException pe

validator

protected FormValidator validator

allowMultiples

protected boolean allowMultiples

origVal

protected java.lang.Object origVal

val

protected java.lang.Object val
Constructor Detail

DefaultFormElement

public DefaultFormElement()
Public noargs constructor. Form key defaults to null.


DefaultFormElement

public DefaultFormElement(java.lang.String ikey)
Public constructor. Form type defaults to FormType.STRING


DefaultFormElement

public DefaultFormElement(java.lang.String ikey,
                          FormType itype)
Public constructor. Default value defaults to Null.


DefaultFormElement

public DefaultFormElement(java.lang.String ikey,
                          FormType itype,
                          java.lang.Object idefaultVal)
Public constructor. Validator defaults to null.


DefaultFormElement

public DefaultFormElement(java.lang.String ikey,
                          FormType itype,
                          java.lang.Object idefaultVal,
                          FormValidator ivalidator)
Public constructor. AllowMultiples defaults to false.


DefaultFormElement

public DefaultFormElement(java.lang.String ikey,
                          FormType itype,
                          java.lang.Object idefaultVal,
                          FormValidator ivalidator,
                          boolean iallowMultiples)
Public constructor, Name defaults to Key


DefaultFormElement

public DefaultFormElement(java.lang.String ikey,
                          java.lang.String iname,
                          FormType itype,
                          java.lang.Object idefaultVal,
                          FormValidator ivalidator,
                          boolean iallowMultiples)
Public constructor

Method Detail

setKey

public void setKey(java.lang.String ikey)
Set the key value for this form element

Specified by:
setKey in interface FormElement
Parameters:
ikey - the key value for this form element

getKey

public java.lang.String getKey()
Get the key value for this form element

Specified by:
getKey in interface FormElement
Returns:
the key for this form element

setName

public void setName(java.lang.String iname)
Set the name of this form element

Specified by:
setName in interface FormElement
Parameters:
iname - the name of this form element

getName

public java.lang.String getName()
Get the name of this form element

Specified by:
getName in interface FormElement
Returns:
the name of this form element

setType

public void setType(FormType itype)
Set the FormType for this form element

Specified by:
setType in interface FormElement
Parameters:
itype - the FormType for this form element

getType

public FormType getType()
Get the FormType for this for element

Specified by:
getType in interface FormElement
Returns:
the FormType for this form element

setDefaultVal

public void setDefaultVal(java.lang.Object idefaultVal)
Set the default value for this form element

Specified by:
setDefaultVal in interface FormElement
Parameters:
idefaultVal - the FormType for this form element

getDefaultVal

public java.lang.Object getDefaultVal()
Get the default value for this form element

Specified by:
getDefaultVal in interface FormElement
Returns:
the default value for this form element (may be null)

setAllowMultiples

public void setAllowMultiples(boolean val)
Set whether or not this element allows multiple values

Specified by:
setAllowMultiples in interface FormElement
Parameters:
val - true if the element allows multiples

allowMultiples

public boolean allowMultiples()
Does this element allow multiple values

Specified by:
allowMultiples in interface FormElement
Returns:
true if this element allows multiple values

setValidator

public void setValidator(FormValidator ivalidator)
Set the FormValidator for this form element

Specified by:
setValidator in interface FormElement
Parameters:
ivalidator - the FormValidator for this form element

getValidator

public FormValidator getValidator()
Get the default FormValidator for this form element

Specified by:
getValidator in interface FormElement
Returns:
the validator for this form element (may be null)

setOrigVal

public void setOrigVal(java.lang.Object iorigVal)
Set the original value for this element

Specified by:
setOrigVal in interface FormElement

getOrigVal

public java.lang.Object getOrigVal()
Get the original value for this element

Specified by:
getOrigVal in interface FormElement
Returns:
the original value for this form element (may be null)

setVal

public void setVal(java.lang.Object ival)
Set the value for this element

Specified by:
setVal in interface FormElement

getVal

public java.lang.Object getVal()
Get the value for this element

Specified by:
getVal in interface FormElement
Returns:
the value for this form element (may be null)

setParseException

public void setParseException(ParseException ipe)
Set the parse exception associated with this element

Specified by:
setParseException in interface FormElement
Returns:
any parse exceptions associated with the element

getParseException

public ParseException getParseException()
Get any parse exceptions associated with the element (ie. that might have occurred when the element was mapped)

Specified by:
getParseException in interface FormElement
Returns:
any parse exceptions associated with the element

toString

public java.lang.String toString()
Get a string representation of this element

Overrides:
toString in class java.lang.Object
Returns:
the String describing this element

getStringVal

public java.lang.String getStringVal()
Get the value for this element as a String


getStringVal

public java.lang.String getStringVal(java.lang.String dflt)
Get the value for this element as a String, defaulting accordingly if the value is null


getBooleanVal

public java.lang.Boolean getBooleanVal()
Get the value for this element as a Boolean


getBooleanVal

public java.lang.Boolean getBooleanVal(java.lang.Boolean dflt)
Get a Boolean value from the map, defaulting accordingly if the value is null


getIntegerVal

public java.lang.Integer getIntegerVal()
Get the value for this element as a Integer


getIntegerVal

public java.lang.Integer getIntegerVal(java.lang.Integer dflt)
Get a Integer value from the map, defaulting accordingly if the value is null


getDateVal

public java.util.Date getDateVal()
Get the value for this element as a Date


getDateVal

public java.util.Date getDateVal(java.util.Date dflt)
Get a Date value from the map, defaulting accordingly if the value is null


getLongVal

public java.lang.Long getLongVal()
Get the value for this element as a Long


getLongVal

public java.lang.Long getLongVal(java.lang.Long dflt)
Get a Long value from the map, defaulting accordingly if the value is null


getShortVal

public java.lang.Short getShortVal()
Get the value for this element as a Short


getShortVal

public java.lang.Short getShortVal(java.lang.Short dflt)
Get a Short value from the map, defaulting accordingly if the value is null


getDoubleVal

public java.lang.Double getDoubleVal()
Get the value for this element as a Double


getDoubleVal

public java.lang.Double getDoubleVal(java.lang.Double dflt)
Get a Double value from the map, defaulting accordingly if the value is null


getFloatVal

public java.lang.Float getFloatVal()
Get the value for this element as a Float


getFloatVal

public java.lang.Float getFloatVal(java.lang.Float dflt)
Get a Float value from the map, defaulting accordingly if the value is null



Copyright © 2001 Enhydra.org