Class ListOfValuesConstraint
- java.lang.Object
-
- org.alfresco.repo.dictionary.constraint.AbstractConstraint
-
- org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint
-
- All Implemented Interfaces:
Constraint
public class ListOfValuesConstraint extends AbstractConstraint
Constraint implementation that ensures the value is one of a constrained list of values. By default, this constraint is case-sensitive.- Author:
- Derek Hulley
- See Also:
setAllowedValues(List),setCaseSensitive(boolean)
-
-
Field Summary
Fields Modifier and Type Field Description static StringALLOWED_VALUES_PARAMstatic StringCASE_SENSITIVE_PARAMprotected booleancaseSensitivestatic StringCONSTRAINT_TYPEprotected booleansortedstatic StringSORTED_PARAM-
Fields inherited from class org.alfresco.repo.dictionary.constraint.AbstractConstraint
ERR_EVALUATE_EXCEPTION, ERR_PROP_NOT_SET
-
-
Constructor Summary
Constructors Constructor Description ListOfValuesConstraint()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidevaluateSingleValue(Object value)Support for evaluation of properties.List<String>getAllowedValues()Get the allowed values.StringgetDisplayLabel(String constraintAllowableValue, MessageLookup messageLookup)Get the display label for the specified allowable value in this constraint.Map<String,Object>getParameters()Returns the parameters passed to the instance of the constraint.protected List<String>getRawAllowedValues()Get the allowed values.StringgetType()Returns the 'type' of the constraint, this is the identifier given to constraint in the configuration.voidinitialize()Initializes the constraint with appropriate values, which will depend on the implementation itself.booleanisCaseSensitive()booleanisSorted()Indicates whether the list of values are sorted or not.voidsetAllowedValues(List<String> allowedValues)Set the values that are allowed by the constraint.voidsetCaseSensitive(boolean caseSensitive)Set the handling of case checking.voidsetSorted(boolean sorted)Set whether the values are ordered or not.StringtoString()-
Methods inherited from class org.alfresco.repo.dictionary.constraint.AbstractConstraint
checkPropertyNotNull, evaluate, evaluateCollection, getShortName, getTitle, set_shortName, setRegistry, setShortName, setTitle
-
-
-
-
Field Detail
-
CONSTRAINT_TYPE
public static final String CONSTRAINT_TYPE
- See Also:
- Constant Field Values
-
CASE_SENSITIVE_PARAM
public static final String CASE_SENSITIVE_PARAM
- See Also:
- Constant Field Values
-
ALLOWED_VALUES_PARAM
public static final String ALLOWED_VALUES_PARAM
- See Also:
- Constant Field Values
-
SORTED_PARAM
public static final String SORTED_PARAM
- See Also:
- Constant Field Values
-
caseSensitive
protected boolean caseSensitive
-
sorted
protected boolean sorted
-
-
Method Detail
-
getType
public String getType()
Returns the 'type' of the constraint, this is the identifier given to constraint in the configuration.- Specified by:
getTypein interfaceConstraint- Overrides:
getTypein classAbstractConstraint- Returns:
- The type
-
getAllowedValues
public List<String> getAllowedValues()
Get the allowed values. Note that these are String instances, but may represent non-String values. It is up to the caller to distinguish. Sorts list if appropriate.- Returns:
- Returns the values allowed
-
getRawAllowedValues
protected List<String> getRawAllowedValues()
Get the allowed values. Note that these are String instances, but may represent non-String values. It is up to the caller to distinguish.- Returns:
- Returns the values allowed
-
getDisplayLabel
public String getDisplayLabel(String constraintAllowableValue, MessageLookup messageLookup)
Get the display label for the specified allowable value in this constraint. A key is constructed as follows:"listconstraint." + constraintName + "." + constraintAllowableValue. e.g. listconstraint.test_listConstraintOne.VALUE_ONE.
This key is then used to look up a properties bundle for the localised display label. Spaces are allowed in the keys, but they should be escaped in the properties file as follows:listconstraint.test_listConstraintOne.VALUE\ WITH\ SPACES=Display label
- Parameters:
constraintAllowableValue- StringmessageLookup- MessageLookup- Returns:
- the localised display label for the specified constraint value in the current locale.
If no localisation is defined, it will return the allowed value itself.
If the specified allowable value is not in the model, returns
null. - Since:
- 4.0
- See Also:
I18NUtil.getLocale()
-
setAllowedValues
public void setAllowedValues(List<String> allowedValues)
Set the values that are allowed by the constraint.- Parameters:
allowedValues- a list of allowed values
-
isCaseSensitive
public boolean isCaseSensitive()
- Returns:
- Returns true if this constraint is case-sensitive (default)
-
setCaseSensitive
public void setCaseSensitive(boolean caseSensitive)
Set the handling of case checking.- Parameters:
caseSensitive- true if the constraint is case-sensitive (default), or false for case-insensitive.
-
isSorted
public boolean isSorted()
Indicates whether the list of values are sorted or not.- Returns:
- true if sorted, false otherwise
-
setSorted
public void setSorted(boolean sorted)
Set whether the values are ordered or not.- Parameters:
sorted- true if sorted, false otherwise
-
initialize
public void initialize()
Description copied from class:AbstractConstraintInitializes the constraint with appropriate values, which will depend on the implementation itself. This method can be implemented as a once-off, i.e. reinitialization does not have to be supported.Registers the constraint with the registry, if present. Call this method if you want the constraint to be auto-registered.
- Specified by:
initializein interfaceConstraint- Overrides:
initializein classAbstractConstraint- See Also:
AbstractConstraint.initialize()
-
getParameters
public Map<String,Object> getParameters()
Description copied from interface:ConstraintReturns the parameters passed to the instance of the constraint.- Specified by:
getParametersin interfaceConstraint- Overrides:
getParametersin classAbstractConstraint- Returns:
- Map of parameters or an empty Map if none exist
- See Also:
AbstractConstraint.getParameters()
-
evaluateSingleValue
protected void evaluateSingleValue(Object value)
Description copied from class:AbstractConstraintSupport for evaluation of properties. The value passed in will never be a Collection and will never be null.- Specified by:
evaluateSingleValuein classAbstractConstraint- See Also:
AbstractConstraint.evaluateSingleValue(java.lang.Object)
-
-