org.apache.turbine.services.intake.model
Class Field

java.lang.Object
  |
  +--org.apache.turbine.services.intake.model.Field
Direct Known Subclasses:
BigDecimalField, BooleanField, ComboKeyField, FileItemField, FloatField, IntegerField, NumberKeyField, StringField, StringKeyField

public abstract class Field
extends java.lang.Object

Base class for Intake generated input processing classes.

Version:
$Id: Field.java,v 1.2 2001/10/09 14:44:38 henning Exp $
Author:
Field Summary
protected  boolean alwaysRequired
           
protected  RunData data
          The object containing the request data
protected  java.lang.Object defaultValue
           
protected  java.lang.String displayName
           
private static java.lang.String EMPTY
           
protected  java.lang.reflect.Method getter
           
protected  Group group
           
protected  java.lang.String ifRequiredMessage
           
protected  boolean initialized
           
protected  boolean isMultiValued
           
protected  java.lang.String key
           
protected  java.lang.String mapToObject
           
protected  java.lang.String message
           
protected  java.lang.String name
           
protected  java.lang.Object onError
           
protected  boolean required
           
protected  Retrievable retrievable
           
protected  boolean set_flag
           
protected  java.lang.reflect.Method setter
           
private  java.lang.Object testValue
           
private  java.lang.Object[] valArray
           
protected  boolean valid_flag
           
protected  Validator validator
           
private  java.lang.Object validValue
           
private static java.lang.String VALUE_IF_ABSENT_KEY
           
 
Constructor Summary
Field(XmlField field, Group group)
          Constructs a field based on data in the xml specification and assigns it to a Group.
 
Method Summary
 void dispose()
          Disposes the object after use.
protected abstract  void doSetValue(ParameterParser pp)
          Compares request data with constraints and sets the valid flag.
 void getDefault()
          Loads the default value from the object
protected  java.lang.String getDefaultValidator()
           
 java.lang.Object getDefaultValue()
          Get the default Value
 java.lang.String getDisplayName()
          Get the display name of the field.
 java.lang.Object getInitialValue()
          Get the value used as a default.
 java.lang.String getKey()
          Get the key used to identify the field.
 java.lang.String getMessage()
          Get any error message resulting from invalid input.
 void getProperty(java.lang.Object obj)
          Loads the valid value from a bean
 java.lang.Object getTestValue()
          Get the value input by a user that will be validated.
 Validator getValidator()
           
 java.lang.Object getValue()
          Get the value of the field.
 java.lang.String getValueIfAbsent()
          Use in a hidden field assign a default value in the event the field is absent from the query parameters.
 Field init(Retrievable obj)
          Method called when this field or the group it belongs to is pulled from the pool.
 Field init(RunData data)
          Method called when this field (the group it belongs to) is pulled from the pool.
 boolean isRequired()
          Flag to determine whether the field has been declared as required.
 boolean isSet()
          Flag set to true, if the test value has been set to anything other than an empty value.
 boolean isValid()
          Flag set to true, if the test value met the constraints.
 void removeFromRequest()
          Removes references to this group and its fields from the query parameters
protected abstract  void setDefaultValue(java.lang.String prop)
          Set the default Value
 void setDisplayName(java.lang.String newDisplayName)
          Set the display name of the field.
(package private)  void setInitialValue(java.lang.Object obj)
          Set the value used as a default, in the event the field has not been set yet.
 void setMessage(java.lang.String message)
          Sets an error message.
 void setProperty(java.lang.Object obj)
          Calls a setter method on obj, if this field has been set.
 void setRequired(boolean v)
          Set whether this field is required to have a value.
 void setRequired(boolean v, java.lang.String message)
          Set the value of required.
(package private)  void setTestValue(java.lang.Object obj)
          Set the value input by a user that will be validated.
 java.lang.String toString()
          Calls toString() on the object returned by getValue(), unless null; and then it returns "", the empty String.
protected  boolean validate(ParameterParser pp)
          Compares request data with constraints and sets the valid flag.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

EMPTY

private static final java.lang.String EMPTY

VALUE_IF_ABSENT_KEY

private static final java.lang.String VALUE_IF_ABSENT_KEY

name

protected final java.lang.String name

key

protected final java.lang.String key

displayName

protected java.lang.String displayName

mapToObject

protected final java.lang.String mapToObject

validator

protected Validator validator

getter

protected final java.lang.reflect.Method getter

setter

protected final java.lang.reflect.Method setter

ifRequiredMessage

protected final java.lang.String ifRequiredMessage

isMultiValued

protected final boolean isMultiValued

group

protected final Group group

alwaysRequired

protected boolean alwaysRequired

onError

protected java.lang.Object onError

defaultValue

protected java.lang.Object defaultValue

set_flag

protected boolean set_flag

valid_flag

protected boolean valid_flag

required

protected boolean required

initialized

protected boolean initialized

message

protected java.lang.String message

retrievable

protected Retrievable retrievable

validValue

private java.lang.Object validValue

testValue

private java.lang.Object testValue

valArray

private java.lang.Object[] valArray

data

protected RunData data
The object containing the request data
Constructor Detail

Field

public Field(XmlField field,
             Group group)
      throws java.lang.Exception
Constructs a field based on data in the xml specification and assigns it to a Group.
Parameters:
field - a XmlField value
group - a Group value
Throws:
java.lang.Exception - if an error occurs
Method Detail

init

public Field init(RunData data)
           throws TurbineException
Method called when this field (the group it belongs to) is pulled from the pool. The request data is searched to determine if a value has been supplied for this field. if so, the value is validated.
Parameters:
data - a RunData value
Returns:
a Field value
Throws:
TurbineException - if an error occurs

init

public Field init(Retrievable obj)
Method called when this field or the group it belongs to is pulled from the pool. The retrievable object can provide a default value for the field, or using setProperty the field's value can be transferred to the retrievable.
Parameters:
obj - a Retrievable value
Returns:
a Field value

getDefaultValidator

protected java.lang.String getDefaultValidator()

getValidator

public Validator getValidator()

isRequired

public boolean isRequired()
Flag to determine whether the field has been declared as required.
Returns:
value of required.

setRequired

public void setRequired(boolean v)
Set whether this field is required to have a value.
Parameters:
v - Value to assign to required.

setRequired

public void setRequired(boolean v,
                        java.lang.String message)
Set the value of required.
Parameters:
v - a boolean value
message, - override the value from intake.xml

removeFromRequest

public void removeFromRequest()
Removes references to this group and its fields from the query parameters

dispose

public void dispose()
Disposes the object after use. The method is called when the Group is returned to its pool. if overridden, super.dispose() should be called.

getKey

public java.lang.String getKey()
Get the key used to identify the field.
Returns:
the query data key.

getValueIfAbsent

public java.lang.String getValueIfAbsent()
Use in a hidden field assign a default value in the event the field is absent from the query parameters. Used to track checkboxes, since they only show up if checked.

isValid

public boolean isValid()
Flag set to true, if the test value met the constraints. Is also true, in the case the test value was not set, unless this field has been marked as required.
Returns:
a boolean value

isSet

public boolean isSet()
Flag set to true, if the test value has been set to anything other than an empty value.
Returns:
a boolean value

getDisplayName

public java.lang.String getDisplayName()
Get the display name of the field. Useful for building data entry forms. Returns name of field if no display name has been assigned to the field by xml input file
Returns:
a String value

setDisplayName

public void setDisplayName(java.lang.String newDisplayName)
Set the display name of the field. Display names are used in building data entry forms and serve as a user friendly description of the data contained in the field.

getMessage

public java.lang.String getMessage()
Get any error message resulting from invalid input.
Returns:
a String value

setMessage

public void setMessage(java.lang.String message)
Sets an error message. The field is also marked as invalid.

validate

protected boolean validate(ParameterParser pp)
Compares request data with constraints and sets the valid flag.

doSetValue

protected abstract void doSetValue(ParameterParser pp)
Compares request data with constraints and sets the valid flag. To be implemented in subclasses

setDefaultValue

protected abstract void setDefaultValue(java.lang.String prop)
Set the default Value

setInitialValue

void setInitialValue(java.lang.Object obj)
Set the value used as a default, in the event the field has not been set yet.
Parameters:
obj - an Object value

getInitialValue

public java.lang.Object getInitialValue()
                                 throws java.lang.Exception
Get the value used as a default. If the initial value has not been set and a Retrievable object has been associated with this field, the objects property will be used as the initial value.
Returns:
an Object value
Throws:
java.lang.Exception - if an error occurs

setTestValue

void setTestValue(java.lang.Object obj)
Set the value input by a user that will be validated.
Parameters:
obj - an Object value

getTestValue

public java.lang.Object getTestValue()
Get the value input by a user that will be validated.
Returns:
an Object value

getValue

public java.lang.Object getValue()
Get the value of the field. if a test value has been set, it will be returned as is, unless it is so badly formed that the validation could not parse it. In most cases the test value is returned even though invalid, so that it can be returned to the user to make modifications. if the test value is not set the initial value is returned.
Returns:
an Object value

toString

public java.lang.String toString()
Calls toString() on the object returned by getValue(), unless null; and then it returns "", the empty String.
Overrides:
toString in class java.lang.Object
Returns:
a String value

getProperty

public void getProperty(java.lang.Object obj)
                 throws java.lang.Exception
Loads the valid value from a bean

getDefault

public void getDefault()
Loads the default value from the object

setProperty

public void setProperty(java.lang.Object obj)
                 throws TurbineException
Calls a setter method on obj, if this field has been set.
Throws:
throws - a TurbineException if called and the input was not valid.

getDefaultValue

public java.lang.Object getDefaultValue()
Get the default Value


Copyright © 2000-2002 Apache Software Foundation. All Rights Reserved.