pt.digitalis.dif.dem.objects.parameters.types
Class AbstractParameter<T>

java.lang.Object
  extended by pt.digitalis.dif.dem.objects.parameters.types.AbstractParameter<T>
Type Parameters:
T - generic type of the parameter
All Implemented Interfaces:
Cloneable, IEditableParameter, IParameter<T>
Direct Known Subclasses:
BigDecimalParameter, BooleanParameter, DateParameter, DocumentParameter, DoubleParameter, LongParameter, StringParameter

public abstract class AbstractParameter<T>
extends Object
implements IParameter<T>, IEditableParameter

This class will define a Parameter.

It will hold information relative to the Parameter value, ID key and validation constraints.

Author:
Pedro Viegas pviegas@digitalis.pt
, Rodrigo Gonçalves rgoncalves@digitalis.pt
Created on:
2007/05/04

Constructor Summary
AbstractParameter()
           
 
Method Summary
 void addRule(IParameterRule<T> rule)
          Modifier for the 'rules' attribute.
protected  String automaticConstraints()
          To override in each parameter type class as needed
 IParameter<T> clone()
          Creates a new instance of the current object
protected  String convertObjectToString(Object obj)
          Converts an object to strong format, according to any rules necessary in conversion of the given parameter type
 void forceInitialize(boolean allowAnonymous, Map<String,IParameterConstraint> constraints, T defaultValue, String formLinked, String id, ParameterScope parameterScope, String parentID, Entity parentType, boolean persistToRepository, boolean readonly, boolean referencedInARuleFromAnotherParameter, boolean required, boolean formConfigurable, List<IParameterRule<T>> rules, Map<String,IParameterValidator> validators, T value)
          Parameter Initializer.
 Map<String,IParameterConstraint> getConstraints()
           
 String getFormLinked()
           
 String getId()
           
protected  String getLanguage(IDIFContext context)
          Return the language from the context of the default if not available
static MessageList getMessages()
          Lazy loading getter of messages
 ParameterScope getParameterScope()
           
 String getParentID()
           
 Entity getParentType()
           
 List<IParameterRule<T>> getRules()
          Inspector for the 'rules' attribute.
 Map<String,IParameterValidator> getValidators()
           
 T getValue(IDIFContext context)
          Returns the parameter value.
 DocumentRepositoryEntry getValueAsDocument(IDIFContext context)
          Returns the parameter value as a Document Note: Only Document types parameters will correctly respond to this method.
 String getValueAsString(IDIFContext context)
          Returns the parameter value as a String
protected  boolean hasFormBeenSubmited(IDIFContext context)
           
protected  boolean hasValue()
           
 void initialize(String id, Entity parentType, String parentID, boolean formConfigurable, boolean persistToRepository, boolean allowAnonymousAccess, ParameterScope parameterScope, String defaultValue, String constraintDefinition, Map<String,IParameterValidator> validators, List<IParameterRule<T>> rules)
          Parameter Initializer.
 boolean isAllowAnonymous()
           
 boolean isFirstInitialization()
          Inspector for the 'firstInitialization' attribute.
 boolean isFormConfigurable()
          Inspector for the 'formConfigurable' attribute.
 boolean isPersistToRepository()
           
 boolean isReadonly()
           
 boolean isReferencedInARuleFromAnotherParameter()
          Inspector for the 'referencedInARuleFromAnotherParameter' attribute.
 boolean isRequired()
           
 boolean isStringSetterSupported()
           
protected  void logWarning(String warning)
          Logs a warning
 ParameterErrorList refreshParameterValue(IStageInstance stageInstance)
          Updates the value of the parameter from the relevant sources.
 ParameterErrorList setDefaultValue(IStageInstance stageInstance)
          Sets the value of the parameter to its default and runs all constraints and validations
 ParameterErrorList setDefaultValue(IStageInstance stageInstance, boolean initializationInProgress)
          Sets the value of the parameter to its default and runs all constraints and validations
 void setFirstInitialization(boolean firstInitialization)
          Modifier for the 'firstInitialization' attribute.
 void setFormConfigurable(boolean formConfigurable)
          Modifier for the 'formConfigurable' attribute.
 void setFormLinked(String formLinked)
           
 void setReferencedInARuleFromAnotherParameter(boolean referencedInARuleFromAnotherParameter)
          Modifier for the 'referencedInARuleFromAnotherParameter' attribute.
 void setRequired(boolean required)
           
 ParameterErrorList setValue(T value, IStageInstance stageInstance)
          Sets the value of the parameter and runs all constraints and validations
 ParameterErrorList setValue(T value, IStageInstance stageInstance, boolean initializationInProgress)
          Sets the value of the parameter and runs all constraints and validations
 ParameterErrorList setValueFromString(String value, IStageInstance stageInstance)
          Sets the value of the parameter converting if from a string representation and runs all constraints and validations
 String toString()
           
protected  ParameterErrorList validateParameterValue(T value, IStageInstance stageInstance, boolean initializationInProgress)
          Validate a parameter value on type, constraints, validators and rules, if applied.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface pt.digitalis.dif.dem.objects.parameters.IParameter
getSupportedClasses, getValueAsBigDecimal, getValueAsBoolean, getValueAsDate, getValueAsDouble, getValueAsLong, isNumeric, setValueFromString
 

Constructor Detail

AbstractParameter

public AbstractParameter()
Method Detail

getMessages

public static MessageList getMessages()
Lazy loading getter of messages

Returns:
the messages

addRule

public void addRule(IParameterRule<T> rule)
Modifier for the 'rules' attribute.

Parameters:
rule - the new rule to add

automaticConstraints

protected String automaticConstraints()
To override in each parameter type class as needed

Returns:
the list of automatic constraints that each parameter type adds

clone

public IParameter<T> clone()
                    throws CloneNotSupportedException
Description copied from interface: IParameter
Creates a new instance of the current object

Specified by:
clone in interface IParameter<T>
Overrides:
clone in class Object
Returns:
IParameter clone
Throws:
CloneNotSupportedException
See Also:
Object.clone()

convertObjectToString

protected String convertObjectToString(Object obj)
Converts an object to strong format, according to any rules necessary in conversion of the given parameter type

Parameters:
obj - the object to convert
Returns:
the object in a string representation

forceInitialize

public void forceInitialize(boolean allowAnonymous,
                            Map<String,IParameterConstraint> constraints,
                            T defaultValue,
                            String formLinked,
                            String id,
                            ParameterScope parameterScope,
                            String parentID,
                            Entity parentType,
                            boolean persistToRepository,
                            boolean readonly,
                            boolean referencedInARuleFromAnotherParameter,
                            boolean required,
                            boolean formConfigurable,
                            List<IParameterRule<T>> rules,
                            Map<String,IParameterValidator> validators,
                            T value)
Description copied from interface: IParameter
Parameter Initializer. Since IoC provides the construction this should be called after TODO: Refactor this method!! This is a bad coding practice! Methods should have between 3 and 7 arguments. Nine is too much. Use encapsulation.

Specified by:
forceInitialize in interface IParameter<T>
Parameters:
allowAnonymous - if a USER scoped parameter should allow anonymous access
constraints - the string that defines the constraints to apply
defaultValue - the parameter default value
formLinked - the form name of null if not set
id - the parameter id
parameterScope - the scope of the parameter
parentID - the id of the parent entity
parentType - the parent entity type
persistToRepository - if the parameter value should be persisted to the repository
referencedInARuleFromAnotherParameter - the new referencedInARuleFromAnotherParameter value to set
formConfigurable - T if the form is configurable
rules - the parameter rules
validators - a validator list to validate the parameter values
See Also:
IParameter.forceInitialize(boolean, java.util.Map, java.lang.Object, java.lang.String, java.lang.String, pt.digitalis.dif.dem.objects.parameters.ParameterScope, java.lang.String, pt.digitalis.dif.dem.Entity, boolean, boolean, boolean, boolean, boolean, java.util.List, java.util.Map, java.lang.Object)

getConstraints

public Map<String,IParameterConstraint> getConstraints()
Specified by:
getConstraints in interface IParameter<T>
Returns:
the constraints

getFormLinked

public String getFormLinked()
Specified by:
getFormLinked in interface IParameter<T>
Returns:
the form name of null if not set
See Also:
IParameter.getFormLinked()

getId

public String getId()
Specified by:
getId in interface IParameter<T>
Returns:
the id

getLanguage

protected String getLanguage(IDIFContext context)
Return the language from the context of the default if not available

Parameters:
context - the context
Returns:
the language

getParameterScope

public ParameterScope getParameterScope()
Specified by:
getParameterScope in interface IParameter<T>
Returns:
the parameterScope

getParentID

public String getParentID()
Specified by:
getParentID in interface IParameter<T>
Returns:
the parentID

getParentType

public Entity getParentType()
Specified by:
getParentType in interface IParameter<T>
Returns:
the parentType

getRules

public List<IParameterRule<T>> getRules()
Description copied from interface: IParameter
Inspector for the 'rules' attribute.

Specified by:
getRules in interface IParameter<T>
Returns:
the rules value
See Also:
IParameter.getRules()

getValidators

public Map<String,IParameterValidator> getValidators()
Specified by:
getValidators in interface IParameter<T>
Returns:
the validators

getValue

public T getValue(IDIFContext context)
           throws ParameterException
Description copied from interface: IParameter
Returns the parameter value. This method will check a number of possible sources for the value of the parameter depending on it's scope and attributes.

Specified by:
getValue in interface IParameter<T>
Parameters:
context - the DIF context to read if needed
Returns:
the value
Throws:
ParameterException - if the parameter could not be read
See Also:
IParameter.getValue(IDIFContext)

getValueAsDocument

public DocumentRepositoryEntry getValueAsDocument(IDIFContext context)
                                           throws ParameterException
Description copied from interface: IParameter
Returns the parameter value as a Document Note: Only Document types parameters will correctly respond to this method. All others will report an invalid usage ParameterException

Specified by:
getValueAsDocument in interface IParameter<T>
Parameters:
context - the DIF context to read if needed
Returns:
the string representation of the parameter value
Throws:
ParameterException - if the parameter value cannot be read
See Also:
IParameter.getValueAsDocument(pt.digitalis.dif.controller.interfaces.IDIFContext)

getValueAsString

public String getValueAsString(IDIFContext context)
                        throws ParameterException
Description copied from interface: IParameter
Returns the parameter value as a String

Specified by:
getValueAsString in interface IParameter<T>
Parameters:
context - the DIF context to read if needed
Returns:
the string representation of the parameter value
Throws:
ParameterException - if the parameter value cannot be read
See Also:
IParameter.getValueAsString(IDIFContext)

hasFormBeenSubmited

protected boolean hasFormBeenSubmited(IDIFContext context)
Parameters:
context - the current stage context
Returns:
T if the linked form has been submitted

hasValue

protected boolean hasValue()
Returns:
T when the parameter has a value set

initialize

public void initialize(String id,
                       Entity parentType,
                       String parentID,
                       boolean formConfigurable,
                       boolean persistToRepository,
                       boolean allowAnonymousAccess,
                       ParameterScope parameterScope,
                       String defaultValue,
                       String constraintDefinition,
                       Map<String,IParameterValidator> validators,
                       List<IParameterRule<T>> rules)
                throws ParameterException
Description copied from interface: IParameter
Parameter Initializer. Since IoC provides the construction this should be called after TODO: Refactor this method!! This is a bad coding practice! Methods should have between 3 and 7 arguments. Nine is too much. Use encapsulation.

Specified by:
initialize in interface IParameter<T>
Parameters:
id - the parameter id
parentType - the parent entity type
parentID - the id of the parent entity
formConfigurable - if the parameter can be configured for a given form
persistToRepository - if the parameter value should be persisted to the repository
allowAnonymousAccess - if a USER scoped parameter should allow anonymous access
parameterScope - the scope of the parameter
defaultValue - the parameter default value
constraintDefinition - the string that defines the constraints to apply
validators - a validator list to validate the parameter values
rules - the parameter rules
Throws:
ParameterException - if the default value can't be converted to the inner parameter type
See Also:
IParameter.initialize(java.lang.String, pt.digitalis.dif.dem.Entity, java.lang.String, boolean, boolean, boolean, pt.digitalis.dif.dem.objects.parameters.ParameterScope, java.lang.String, java.lang.String, java.util.Map, java.util.List)

isAllowAnonymous

public boolean isAllowAnonymous()
Specified by:
isAllowAnonymous in interface IParameter<T>
Returns:
the allowAnonymous
See Also:
IParameter.isAllowAnonymous()

isFirstInitialization

public boolean isFirstInitialization()
Inspector for the 'firstInitialization' attribute.

Returns:
the firstInitialization value

isFormConfigurable

public boolean isFormConfigurable()
Description copied from interface: IParameter
Inspector for the 'formConfigurable' attribute.

Specified by:
isFormConfigurable in interface IParameter<T>
Returns:
the formConfigurable value
See Also:
IParameter.isFormConfigurable()

isPersistToRepository

public boolean isPersistToRepository()
Specified by:
isPersistToRepository in interface IParameter<T>
Returns:
the persistToRepository

isReadonly

public boolean isReadonly()
Specified by:
isReadonly in interface IParameter<T>
Returns:
the readonly

isReferencedInARuleFromAnotherParameter

public boolean isReferencedInARuleFromAnotherParameter()
Description copied from interface: IParameter
Inspector for the 'referencedInARuleFromAnotherParameter' attribute.

Specified by:
isReferencedInARuleFromAnotherParameter in interface IParameter<T>
Returns:
the referencedInARuleFromAnotherParameter value
See Also:
IParameter.isReferencedInARuleFromAnotherParameter()

isRequired

public boolean isRequired()
Specified by:
isRequired in interface IParameter<T>
Returns:
the required
See Also:
IParameter.isRequired()

isStringSetterSupported

public boolean isStringSetterSupported()
Specified by:
isStringSetterSupported in interface IParameter<T>
Returns:
T if we can set the parameter with a String value representation
See Also:
IParameter.isStringSetterSupported()

logWarning

protected void logWarning(String warning)
Logs a warning

Parameters:
warning - the warning message to log

refreshParameterValue

public ParameterErrorList refreshParameterValue(IStageInstance stageInstance)
Description copied from interface: IParameter
Updates the value of the parameter from the relevant sources. This method will check a number of possible sources for the value of the parameter depending on it's scope and attributes.

Specified by:
refreshParameterValue in interface IParameter<T>
Parameters:
stageInstance - the DIF stage to read if needed
Returns:
return the error message if the validation fails
See Also:
IParameter.refreshParameterValue(pt.digitalis.dif.dem.interfaces.IStageInstance)

setDefaultValue

public ParameterErrorList setDefaultValue(IStageInstance stageInstance)
Description copied from interface: IParameter
Sets the value of the parameter to its default and runs all constraints and validations

Specified by:
setDefaultValue in interface IParameter<T>
Parameters:
stageInstance - the requested stage
Returns:
return the error messages if the validation fails
See Also:
IParameter.setDefaultValue(pt.digitalis.dif.dem.interfaces.IStageInstance)

setDefaultValue

public ParameterErrorList setDefaultValue(IStageInstance stageInstance,
                                          boolean initializationInProgress)
Description copied from interface: IParameter
Sets the value of the parameter to its default and runs all constraints and validations

Specified by:
setDefaultValue in interface IParameter<T>
Parameters:
stageInstance - the requested stage
initializationInProgress - T if called within the dif parameter initialization
Returns:
return the error messages if the validation fails
See Also:
IParameter.setDefaultValue(pt.digitalis.dif.dem.interfaces.IStageInstance, boolean)

setFirstInitialization

public void setFirstInitialization(boolean firstInitialization)
Modifier for the 'firstInitialization' attribute.

Parameters:
firstInitialization - the new firstInitialization value to set

setFormConfigurable

public void setFormConfigurable(boolean formConfigurable)
Description copied from interface: IParameter
Modifier for the 'formConfigurable' attribute.

Specified by:
setFormConfigurable in interface IParameter<T>
Parameters:
formConfigurable - the new formConfigurable value to set
See Also:
IParameter.setFormConfigurable(boolean)

setFormLinked

public void setFormLinked(String formLinked)
Specified by:
setFormLinked in interface IParameter<T>
See Also:
IParameter.setFormLinked(java.lang.String)

setReferencedInARuleFromAnotherParameter

public void setReferencedInARuleFromAnotherParameter(boolean referencedInARuleFromAnotherParameter)
Description copied from interface: IParameter
Modifier for the 'referencedInARuleFromAnotherParameter' attribute.

Specified by:
setReferencedInARuleFromAnotherParameter in interface IParameter<T>
Parameters:
referencedInARuleFromAnotherParameter - the new referencedInARuleFromAnotherParameter value to set
See Also:
IParameter.setReferencedInARuleFromAnotherParameter(boolean)

setRequired

public void setRequired(boolean required)
Specified by:
setRequired in interface IEditableParameter
Parameters:
required - if T the parameter will now become mandatory
See Also:
IEditableParameter.setRequired(boolean)

setValue

public ParameterErrorList setValue(T value,
                                   IStageInstance stageInstance)
Sets the value of the parameter and runs all constraints and validations

Specified by:
setValue in interface IParameter<T>
Parameters:
value - the value to set
stageInstance - the DIF stage to read if needed. WARNING: If null is interpreted like an initialization and no scope repositories will be accessed/updated.
Returns:
return the error messages if the validation fails

setValue

public ParameterErrorList setValue(T value,
                                   IStageInstance stageInstance,
                                   boolean initializationInProgress)
Sets the value of the parameter and runs all constraints and validations

Specified by:
setValue in interface IParameter<T>
Parameters:
value - the value to set
stageInstance - the DIF stage to read if needed. WARNING: If null is interpreted like an initialization and no scope repositories will be accessed/updated.
initializationInProgress - T if called within the dif parameter initialization
Returns:
return the error messages if the validation fails

setValueFromString

public final ParameterErrorList setValueFromString(String value,
                                                   IStageInstance stageInstance)
Description copied from interface: IParameter
Sets the value of the parameter converting if from a string representation and runs all constraints and validations

Specified by:
setValueFromString in interface IParameter<T>
Parameters:
value - the value to set
stageInstance - the DIF stage to read if needed.
Returns:
return the error messages if the validation fails
See Also:
IParameter.setValueFromString(java.lang.String, pt.digitalis.dif.dem.interfaces.IStageInstance)

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()

validateParameterValue

protected ParameterErrorList validateParameterValue(T value,
                                                    IStageInstance stageInstance,
                                                    boolean initializationInProgress)
Validate a parameter value on type, constraints, validators and rules, if applied.

Parameters:
value - the value to validate
stageInstance - the stage where the parameter is being validated
initializationInProgress - T if called within the dif parameter initialization
Returns:
the list of errors found upon validation


Copyright © 2014 Digitalis Informática Lda. All Rights Reserved.