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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault Field Packagestatic final StringDefault Validator Packageprotected TDefault value of the fieldprotected TValue of the field to use if the mapped parameter is empty or non-existentprotected org.apache.avalon.framework.logger.LoggerLoggingprotected StringClass name of the object to which the field is mappedprotected org.apache.fulcrum.parser.ValueParserThe object containing the field data. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddispose()Disposes the object after use.protected abstract voidSets the value of the field from data in the parser.voidenableLogging(org.apache.avalon.framework.logger.Logger logger) Enable Avalon LoggingvoidLoads the default value from the objectprotected StringProduces the fully qualified class name of the default validator.Get the default ValueGet the display name of the field.Gets the display size of the field.Get the Value to use if the field is emptygetGroup()Returns theGroupthis field belongs to ornullif unknown.Calls toString() on the object returned by getValue(), unless null; and then it returns "", the empty String.Get the value used as a default.getKey()Get the key used to identify the field.Returns theLocaleused when localizing data for this field, ornullif unknown.Get the name of the object that takes this inputGets the maximum size of the field.Get any error message resulting from invalid input.getName()Gets the name of the field.voidgetProperty(Object obj) Loads the valid value from a beanprotected ObjectProvides access to emptyValue such that the value returned will be acceptable as an argument parameter to Method.invoke.Gets the String representation of the Value.<TT> TTGet the value input by a user that will be validated.Gets the Validator object for this field.getValue()Get the value of the field.Use in a hidden field assign a default value in the event the field is absent from the query parameters.init(Retrievable obj) Method called when this field or the group it belongs to is pulled from the pool.init(org.apache.fulcrum.parser.ValueParser pp) Method called when this field (the group it belongs to) is pulled from the pool.voidInitialize getter and setter from propertiesbooleanFlag to determine whether the field has been declared as multi-valued.booleanFlag to determine whether the field has been declared as required.booleanisSet()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).booleanisValid()Flag set to true, if the test value met the constraints.booleanFlag to determine whether the field has been validated.voidRemoves references to this group and its fields from the query parametersabstract voidsetDefaultValue(String prop) Set the default Value.voidsetDisplayName(String newDisplayName) Set the display name of the field.abstract voidsetEmptyValue(String prop) Set the empty Value.voidsetMessage(String message) Sets an error message.voidsetProperty(Object obj) Calls a setter method on obj, if this field has been set.voidsetRequired(boolean v) Set whether this field is required to have a value.voidsetRequired(boolean v, String message) Set the value of required.protected voidsetSet(boolean setFlag) Set the internal flag that the field has been setprotected voidsetValid(boolean validFlag) Set the internal flag that the field is validprotected voidsetValidated(boolean validated) Set the internal flag that the field has been validatedtoString()Calls toString() on the object returned by getValue(), unless null; and then it returns "", the empty String.booleanvalidate()Compares request data with constraints and sets the valid flag.
-
Field Details
-
defaultValidatorPackage
Default Validator Package- See Also:
-
defaultFieldPackage
Default Field Package- See Also:
-
mapToObject
Class name of the object to which the field is mapped -
defaultValue
Default value of the field -
emptyValue
Value of the field to use if the mapped parameter is empty or non-existent -
parser
protected org.apache.fulcrum.parser.ValueParser parserThe object containing the field data. -
log
protected transient org.apache.avalon.framework.logger.Logger logLogging
-
-
Constructor Details
-
Field
Constructs a field based on data in the xml specification and assigns it to a Group.- Parameters:
field- aXmlFieldvaluegroup- aGroupvalue- Throws:
IntakeException- indicates the validator was not valid or could not be loaded.
-
-
Method Details
-
enableLogging
public void enableLogging(org.apache.avalon.framework.logger.Logger logger) Enable Avalon Logging- Specified by:
enableLoggingin interfaceorg.apache.avalon.framework.logger.LogEnabled
-
initGetterAndSetter
public void initGetterAndSetter()Initialize getter and setter from properties -
init
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- aValueParservalue- Returns:
- a
Fieldvalue - Throws:
IntakeException- this exception is only thrown by subclasses overriding this implementation.
-
init
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- aRetrievablevalue- Returns:
- a
Fieldvalue
-
getGroup
Returns theGroupthis field belongs to ornullif unknown.- Returns:
- The group this field belongs to.
-
getLocale
Returns theLocaleused when localizing data for this field, ornullif unknown.- Returns:
- Where to localize for.
-
getDefaultValidator
Produces the fully qualified class name of the default validator.- Returns:
- class name of the default validator
-
getValidator
Gets the Validator object for this field.- Returns:
- a
Validatorobject
-
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
Set the value of required.- Parameters:
v- abooleanvaluemessage- 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
Get the key used to identify the field.- Returns:
- the query data key.
-
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
booleanvalue
-
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
booleanvalue
-
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
Stringvalue
-
setDisplayName
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
Get any error message resulting from invalid input.- Returns:
- a
Stringvalue
-
setMessage
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
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
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
Get the value used as a default. If the initial value has not been set and aRetrievableobject has been associated with this field, the objects property will be used as the initial value.- Returns:
- an
Objectvalue - 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
TTvalue
-
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
Objectvalue
-
toString
Calls toString() on the object returned by getValue(), unless null; and then it returns "", the empty 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
Stringvalue
-
getProperty
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
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
Get the default Value- Returns:
- the default value
-
getEmptyValue
Get the Value to use if the field is empty- Returns:
- the value to use if the field is empty.
-
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
Gets the name of the field.- Returns:
- name of the field as specified in the XML file.
-
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
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
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
-