org.araneaframework.uilib.form.constraint
Class BaseConstraint

java.lang.Object
  extended by org.araneaframework.uilib.form.constraint.BaseConstraint
All Implemented Interfaces:
Serializable, Constraint
Direct Known Subclasses:
BaseCompositeConstraint, BaseFieldConstraint, GroupedConstraint, RangeConstraint, ReverseConstraint

public abstract class BaseConstraint
extends Object
implements Serializable, Constraint

Base class for constraints. A Constraint operates on the form elements or forms providing means to constrain their content.

Author:
Jevgeni Kabanov (ekabanov at araneaframework dot org)
See Also:
Serialized Form

Field Summary
protected  String customErrorMessage
          Holds the custom error message for this constraint.
 
Constructor Summary
BaseConstraint()
           
 
Method Summary
protected  void addError(String error)
          Adds the given error message to the errors list to be displayed later.
protected  void addErrors(Collection errorList)
          Adds the given error messages to the errors list to be displayed later.
 void clearErrors()
          Clears the the errors produced while validating this Constraint.
protected  ConfigurationContext getConfiguration()
          Finds the ConfigurationContext from the Environment.
 Environment getEnvironment()
          Provides the Environment of the constraint.
 Set getErrors()
          Returns the validation errors produced while validating this Constraint.
 boolean isValid()
          Returns whether the constraint is satisfied/valid.
 void setCustomErrorMessage(String customErrorMessage)
          Sets the custom error message, that will be used in place of default ones when this Constraint does not hold.
 void setEnvironment(Environment environment)
          Sets the Environment of this Constraint.
protected  String t(String key)
          Transletes the given message key according to the LocalizationContext.
 boolean validate()
          This method validates this Constraint conditions.
protected abstract  void validateConstraint()
          This method should validate the constraint conditions adding error messages and add messages about unsatisfied conditions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

customErrorMessage

protected String customErrorMessage
Holds the custom error message for this constraint.

Constructor Detail

BaseConstraint

public BaseConstraint()
Method Detail

validate

public boolean validate()
                 throws Exception
Description copied from interface: Constraint
This method validates this Constraint conditions.

Specified by:
validate in interface Constraint
Throws:
Exception

isValid

public boolean isValid()
Returns whether the constraint is satisfied/valid. Constraint is valid when no validation errors were produced.


getErrors

public Set getErrors()
Description copied from interface: Constraint
Returns the validation errors produced while validating this Constraint.

Specified by:
getErrors in interface Constraint
Returns:
validation errors.

clearErrors

public void clearErrors()
Description copied from interface: Constraint
Clears the the errors produced while validating this Constraint.

Specified by:
clearErrors in interface Constraint

setCustomErrorMessage

public void setCustomErrorMessage(String customErrorMessage)
Description copied from interface: Constraint
Sets the custom error message, that will be used in place of default ones when this Constraint does not hold.

Specified by:
setCustomErrorMessage in interface Constraint
Parameters:
customErrorMessage - custom error message

setEnvironment

public void setEnvironment(Environment environment)
Description copied from interface: Constraint
Sets the Environment of this Constraint. Environment should come from whatever Component that this Constraint is operating on.

The Environment of a Constraint may be set to non-null value only once, further calls are ignored. Application programmer typically never calls this method as Environment is propagated seamlessly.

Specified by:
setEnvironment in interface Constraint
Parameters:
environment - the Environment for this constraint.

getEnvironment

public Environment getEnvironment()
Provides the Environment of the constraint.

Returns:
the Environment of the constraint.

addError

protected void addError(String error)
Adds the given error message to the errors list to be displayed later.

Parameters:
error - an error message

addErrors

protected void addErrors(Collection errorList)
Adds the given error messages to the errors list to be displayed later.

Parameters:
errorList - A list of error messages (Strings).

getConfiguration

protected ConfigurationContext getConfiguration()
Finds the ConfigurationContext from the Environment.

Returns:
the ConfigurationContext from the Environment.

t

protected String t(String key)
Transletes the given message key according to the LocalizationContext.

Parameters:
key - The key to find the correct message.
Returns:
The localized message from the LocalizationContext.

validateConstraint

protected abstract void validateConstraint()
                                    throws Exception
This method should validate the constraint conditions adding error messages and add messages about unsatisfied conditions.

Throws:
Exception - Any runtime exception that may occur.