Package org.apache.fulcrum.intake.model
Class Field<T>
- java.lang.Object
-
- org.apache.fulcrum.intake.model.Field<T>
-
- All Implemented Interfaces:
Serializable
,org.apache.avalon.framework.logger.LogEnabled
- Direct Known Subclasses:
BigDecimalField
,BooleanField
,DateStringField
,DoubleField
,FloatField
,IntegerField
,LongField
,ShortField
,StringField
,UploadPartField
public abstract class Field<T> extends Object implements Serializable, org.apache.avalon.framework.logger.LogEnabled
Base class for Intake generated input processing classes.- Version:
- $Id$
- Author:
- John McNally, Daniel Rall, Henning P. Schmiedehausen, Quinton McCombs, Jürgen Hoffmann, Thomas Vandahl
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
defaultFieldPackage
Default Field Packagestatic String
defaultValidatorPackage
Default Validator Packageprotected T
defaultValue
Default value of the fieldprotected T
emptyValue
Value of the field to use if the mapped parameter is empty or non-existentprotected org.apache.avalon.framework.logger.Logger
log
Loggingprotected String
mapToObject
Class name of the object to which the field is mappedprotected org.apache.fulcrum.parser.ValueParser
parser
The object containing the field data.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
dispose()
Disposes the object after use.protected abstract void
doSetValue()
Sets the value of the field from data in the parser.void
enableLogging(org.apache.avalon.framework.logger.Logger logger)
Enable Avalon Loggingvoid
getDefault()
Loads the default value from the objectprotected String
getDefaultValidator()
Produces the fully qualified class name of the default validator.T
getDefaultValue()
Get the default ValueString
getDisplayName()
Get the display name of the field.String
getDisplaySize()
Gets the display size of the field.T
getEmptyValue()
Get the Value to use if the field is emptyGroup
getGroup()
Returns theGroup
this field belongs to ornull
if unknown.String
getHTMLString()
Calls toString() on the object returned by getValue(), unless null; and then it returns "", the empty String.T
getInitialValue()
Get the value used as a default.String
getKey()
Get the key used to identify the field.Locale
getLocale()
Returns theLocale
used when localizing data for this field, ornull
if unknown.String
getMapToObject()
Get the name of the object that takes this inputString
getMaxSize()
Gets the maximum size of the field.String
getMessage()
Get any error message resulting from invalid input.String
getName()
Gets the name of the field.void
getProperty(Object obj)
Loads the valid value from a beanprotected Object
getSafeEmptyValue()
Provides access to emptyValue such that the value returned will be acceptable as an argument parameter to Method.invoke.String
getStringValue()
Gets the String representation of the Value.<TT> TT
getTestValue()
Get the value input by a user that will be validated.Validator<T>
getValidator()
Gets the Validator object for this field.T
getValue()
Get the value of the field.String
getValueIfAbsent()
Use in a hidden field assign a default value in the event the field is absent from the query parameters.Field<T>
init(Retrievable obj)
Method called when this field or the group it belongs to is pulled from the pool.Field<T>
init(org.apache.fulcrum.parser.ValueParser pp)
Method called when this field (the group it belongs to) is pulled from the pool.void
initGetterAndSetter()
Initialize getter and setter from propertiesboolean
isMultiValued()
Flag to determine whether the field has been declared as multi-valued.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 by the parser (even to an empty value, so don't used this to determine if the field contains a non-empty value).boolean
isValid()
Flag set to true, if the test value met the constraints.boolean
isValidated()
Flag to determine whether the field has been validated.void
removeFromRequest()
Removes references to this group and its fields from the query parametersabstract void
setDefaultValue(String prop)
Set the default Value.void
setDisplayName(String newDisplayName)
Set the display name of the field.abstract void
setEmptyValue(String prop)
Set the empty Value.void
setMessage(String message)
Sets an error message.void
setProperty(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, String message)
Set the value of required.protected void
setSet(boolean setFlag)
Set the internal flag that the field has been setprotected void
setValid(boolean validFlag)
Set the internal flag that the field is validprotected void
setValidated(boolean validated)
Set the internal flag that the field has been validatedString
toString()
Calls toString() on the object returned by getValue(), unless null; and then it returns "", the empty String.boolean
validate()
Compares request data with constraints and sets the valid flag.
-
-
-
Field Detail
-
defaultValidatorPackage
public static final String defaultValidatorPackage
Default Validator Package- See Also:
- Constant Field Values
-
defaultFieldPackage
public static final String defaultFieldPackage
Default Field Package- See Also:
- Constant Field Values
-
mapToObject
protected String mapToObject
Class name of the object to which the field is mapped
-
defaultValue
protected T defaultValue
Default value of the field
-
emptyValue
protected T emptyValue
Value of the field to use if the mapped parameter is empty or non-existent
-
parser
protected org.apache.fulcrum.parser.ValueParser parser
The object containing the field data.
-
log
protected transient org.apache.avalon.framework.logger.Logger log
Logging
-
-
Constructor Detail
-
Field
public Field(XmlField field, Group group) throws IntakeException
Constructs a field based on data in the xml specification and assigns it to a Group.- Parameters:
field
- aXmlField
valuegroup
- aGroup
value- Throws:
IntakeException
- indicates the validator was not valid or could not be loaded.
-
-
Method Detail
-
enableLogging
public void enableLogging(org.apache.avalon.framework.logger.Logger logger)
Enable Avalon Logging- Specified by:
enableLogging
in interfaceorg.apache.avalon.framework.logger.LogEnabled
-
initGetterAndSetter
public void initGetterAndSetter()
Initialize getter and setter from properties
-
init
public Field<T> init(org.apache.fulcrum.parser.ValueParser pp) throws IntakeException
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:
pp
- aValueParser
value- Returns:
- a
Field
value - Throws:
IntakeException
- this exception is only thrown by subclasses overriding this implementation.
-
init
public Field<T> 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
- aRetrievable
value- Returns:
- a
Field
value
-
getGroup
public Group getGroup()
Returns theGroup
this field belongs to ornull
if unknown.- Returns:
- The group this field belongs to.
-
getLocale
public Locale getLocale()
Returns theLocale
used when localizing data for this field, ornull
if unknown.- Returns:
- Where to localize for.
-
getDefaultValidator
protected String getDefaultValidator()
Produces the fully qualified class name of the default validator.- Returns:
- class name of the default validator
-
getValidator
public Validator<T> getValidator()
Gets the Validator object for this field.- Returns:
- a
Validator
object
-
getMapToObject
public String getMapToObject()
Get the name of the object that takes this input- Returns:
- the name of the mapped object
-
isMultiValued
public boolean isMultiValued()
Flag to determine whether the field has been declared as multi-valued.- Returns:
- value of isMultiValued.
-
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. If the field is already required due to a setting in the XML file, this method can not set it to false.- Parameters:
v
- Value to assign to required.
-
setRequired
public void setRequired(boolean v, String message)
Set the value of required.- Parameters:
v
- aboolean
valuemessage
- 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.
-
getValueIfAbsent
public 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.- Returns:
- the value if not in the request
-
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
-
isValidated
public boolean isValidated()
Flag to determine whether the field has been validated.- Returns:
- value of validated.
-
isSet
public boolean isSet()
Flag set to true, if the test value has been set by the parser (even to an empty value, so don't used this to determine if the field contains a non-empty value). Validation will only be executed for fields that have been set in this manner.- Returns:
- a
boolean
value
-
getDisplayName
public 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(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.- Parameters:
newDisplayName
- the new display name for the field
-
getMessage
public String getMessage()
Get any error message resulting from invalid input.- Returns:
- a
String
value
-
setMessage
public void setMessage(String message)
Sets an error message. The field is also marked as invalid.- Parameters:
message
- the new error message
-
setSet
protected void setSet(boolean setFlag)
Set the internal flag that the field has been set- Parameters:
setFlag
- the setFlag to set
-
setValid
protected void setValid(boolean validFlag)
Set the internal flag that the field is valid- Parameters:
validFlag
- the validFlag to set
-
setValidated
protected void setValidated(boolean validated)
Set the internal flag that the field has been validated- Parameters:
validated
- the validated to set
-
validate
public boolean validate()
Compares request data with constraints and sets the valid flag.- Returns:
- true if the validation succeeded
-
setDefaultValue
public abstract void setDefaultValue(String prop)
Set the default Value. This value is used if Intake should map this field to a new object.- Parameters:
prop
- The value to use if the field is mapped to a new object.
-
setEmptyValue
public abstract void setEmptyValue(String prop)
Set the empty Value. This value is used if Intake maps a field to a parameter returned by the user and the corresponding field is either empty (empty string) or non-existent.- Parameters:
prop
- The value to use if the field is empty.
-
doSetValue
protected abstract void doSetValue()
Sets the value of the field from data in the parser.
-
getInitialValue
public T getInitialValue() throws IntakeException
Get the value used as a default. If the initial value has not been set and aRetrievable
object has been associated with this field, the objects property will be used as the initial value.- Returns:
- an
Object
value - Throws:
IntakeException
- indicates the value could not be returned from the mapped object
-
getTestValue
public <TT> TT getTestValue()
Get the value input by a user that will be validated.- Type Parameters:
TT
- the type of the test value- Returns:
- an
TT
value
-
getValue
public T 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 String toString()
Calls toString() on the object returned by getValue(), unless null; and then it returns "", the empty String.
-
getHTMLString
public String getHTMLString()
Calls toString() on the object returned by getValue(), unless null; and then it returns "", the empty String. Escapes " characters to be able to display these in HTML form fields.- Returns:
- a
String
value
-
getProperty
public void getProperty(Object obj) throws IntakeException
Loads the valid value from a bean- Parameters:
obj
- the object whose getter to call- Throws:
IntakeException
- indicates a problem during the execution of the object's getter method
-
getDefault
public void getDefault()
Loads the default value from the object
-
setProperty
public void setProperty(Object obj) throws IntakeException
Calls a setter method on obj, if this field has been set.- Parameters:
obj
- the object whose setter to call- Throws:
IntakeException
- indicates a problem during the execution of the object's setter method
-
getDefaultValue
public T getDefaultValue()
Get the default Value- Returns:
- the default value
-
getEmptyValue
public T getEmptyValue()
Get the Value to use if the field is empty- Returns:
- the value to use if the field is empty.
-
getSafeEmptyValue
protected Object getSafeEmptyValue()
Provides access to emptyValue such that the value returned will be acceptable as an argument parameter to Method.invoke. Subclasses that deal with primitive types should ensure that they return an appropriate value wrapped in the object wrapper class for the primitive type.- Returns:
- the value to use when the field is empty or an Object that wraps the empty value for primitive types.
-
getName
public String getName()
Gets the name of the field.- Returns:
- name of the field as specified in the XML file.
-
getDisplaySize
public String getDisplaySize()
Gets the display size of the field. This is useful when building the HTML input tag. If no displaySize was set, an empty string is returned.- Returns:
- the size information for this field
-
getMaxSize
public String getMaxSize()
Gets the maximum size of the field. This is useful when building the HTML input tag. The maxSize is set with the maxLength rule. If this rule was not set, an empty string is returned.- Returns:
- the maximum size information of the field
-
getStringValue
public String getStringValue()
Gets the String representation of the Value. This is basically a wrapper method for the toString method which doesn't seem to show anything on screen if accessed from Template. Name is also more in line with getValue method which returns the actual Object. This is useful for displaying correctly formatted data such as dates, such as 18/11/1968 instead of the toString dump of a Date Object.- Returns:
- the String Value
-
-