org.iscreen
Class ValidationFailureImpl

java.lang.Object
  extended by org.iscreen.ValidationFailureImpl
All Implemented Interfaces:
ValidationFailure

public class ValidationFailureImpl
extends java.lang.Object
implements ValidationFailure

A validation failure represents a single failure reported by a Validator (Validators can report multiple failures, each represented by a separate instance of this class). Each failure has a message (usually designed to be accessible to the end user), a label (usually used to associate the failure with an UI component, though a label is not required), and the Collection of fields (these are really the OGNL expressions used to 'get' properties from the JavaBean being validated) from the JavaBean that was originally validated (normally, there's just one field).

Interface code (such as a web framework) can use instances of this class to display the validation failures. There should be sufficient information associated with each failure to apply the message to the correct location within the interface.

Author:
Shellman, Dan

Field Summary
protected  java.lang.Object failureBean
           
protected  java.util.Collection fields
           
protected  java.lang.Integer index
           
protected  java.lang.String label
           
protected  java.lang.String message
           
protected  java.util.Map messages
           
protected  java.lang.String name
           
protected  int severity
           
protected  ValidationTrace trace
           
 
Fields inherited from interface org.iscreen.ValidationFailure
CRITICAL, FAILURE, WARNING
 
Constructor Summary
ValidationFailureImpl()
          Default constructor.
 
Method Summary
 void addMessage(java.lang.String name, java.lang.String theMessage)
          Adds a named message.
 void addMessages(java.util.Map moreMessages)
          Adds a map of messages to the set of messages that can be retrieved from getMessage( messageName ).
 java.lang.Object getFailureBean()
          Obtains a reference to the bean that failed validation.
 java.util.Collection getFields()
          Retrieves the fields (the OGNL expression used to 'get' the properties from the JavaBean being validated) of the JavaBean being validated.
 java.lang.Integer getIndex()
          Retrieves the index of the JavaBean/Object being validated that was an element within an array/Collection of a 'parent' JavaBean being validated (i.e.
 java.lang.String getLabel()
          Retrieves the label associated with this failure.
 java.lang.String getMessage()
          Retrieves the failure message (which has already been evaluated and localized.
 java.lang.String getMessage(java.lang.String messageName)
          Retrieves the failure message based upon the message name.
 java.lang.String getName()
          Retrieves the name of the validator reporting the failure message.
 int getSeverity()
          Retrieves the severity of the failure (i.e.
 ValidationTrace getTrace()
          Retrieves the trace of the failure.
 void setFailureBean(java.lang.Object theFailureBean)
          Sets a reference to the bean that failed validation.
 void setFields(java.util.Collection theFields)
           
 void setIndex(java.lang.Integer theIndex)
           
 void setLabel(java.lang.String theLabel)
           
 void setMessage(java.lang.String theMessage)
           
 void setName(java.lang.String theName)
          Sets the name for this failure message.
 void setSeverity(int theSeverity)
          Sets the severity of this failure.
 void setTrace(ValidationTrace theTrace)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

label

protected java.lang.String label

name

protected java.lang.String name

message

protected java.lang.String message

fields

protected java.util.Collection fields

index

protected java.lang.Integer index

messages

protected java.util.Map messages

severity

protected int severity

trace

protected ValidationTrace trace

failureBean

protected java.lang.Object failureBean
Constructor Detail

ValidationFailureImpl

public ValidationFailureImpl()
Default constructor.

Method Detail

setLabel

public void setLabel(java.lang.String theLabel)

getLabel

public java.lang.String getLabel()
Retrieves the label associated with this failure.

Specified by:
getLabel in interface ValidationFailure
Returns:
Returns the label associated with this failure.

setName

public void setName(java.lang.String theName)
Sets the name for this failure message. The name is used to identify the failure message and relate it to a particular validator (the one that reported the failure).

Parameters:
theName - The name of the validator causing this failure.

getName

public java.lang.String getName()
Retrieves the name of the validator reporting the failure message.

Specified by:
getName in interface ValidationFailure
Returns:
Returns the name of the validator.

getMessage

public java.lang.String getMessage()
Retrieves the failure message (which has already been evaluated and localized.

Specified by:
getMessage in interface ValidationFailure
Returns:
Returns the failure message.

setMessage

public void setMessage(java.lang.String theMessage)

getMessage

public java.lang.String getMessage(java.lang.String messageName)
Description copied from interface: ValidationFailure
Retrieves the failure message based upon the message name. Calling this method with a null name is the same as calling the getMessage() method. This method provides access to different messages related to the failure.

Specified by:
getMessage in interface ValidationFailure
Parameters:
messageName - The 'name' of the message (defined in the configuration.
Returns:
Returns the message for the given name.

addMessages

public void addMessages(java.util.Map moreMessages)
Adds a map of messages to the set of messages that can be retrieved from getMessage( messageName ). The map must use Strings for the keys and values.

Parameters:
moreMessages - Map of messages to add.

addMessage

public void addMessage(java.lang.String name,
                       java.lang.String theMessage)
Adds a named message.

Parameters:
name - The name or key of the message.
theMessage - The message.

getFields

public java.util.Collection getFields()
Retrieves the fields (the OGNL expression used to 'get' the properties from the JavaBean being validated) of the JavaBean being validated.

Specified by:
getFields in interface ValidationFailure
Returns:
Returns the fields of the JavaBean being validated.

setFields

public void setFields(java.util.Collection theFields)

getIndex

public java.lang.Integer getIndex()
Retrieves the index of the JavaBean/Object being validated that was an element within an array/Collection of a 'parent' JavaBean being validated (i.e. an object was being validated, and it had a property that was an array/Collection that was 'forwarded' on to another validation set and iterated over. The subsequent members of that array/Collection would have an index of which was being validated at a particular time. This is that index.). If no indexed property was being validated, then this will return null. Note that a null value is different than a zero value, as a zero value represents the first element in an array/Collection, where a null value implies that the JavaBean/Object wasn't involved in an array/Collection in the first place.

Specified by:
getIndex in interface ValidationFailure
Returns:
Returns the index of the JavaBean/Object that was being validated.

setIndex

public void setIndex(java.lang.Integer theIndex)

setSeverity

public void setSeverity(int theSeverity)
Sets the severity of this failure.

Parameters:
theSeverity - The severity of this failure.

getSeverity

public int getSeverity()
Description copied from interface: ValidationFailure
Retrieves the severity of the failure (i.e. warning, critical, etc.). The greater the number, the higher the severity. See the WARNING, FAILURE, and CRITICAL constants.

Specified by:
getSeverity in interface ValidationFailure
Returns:
Returns the severity of the failure.

setTrace

public void setTrace(ValidationTrace theTrace)

getTrace

public ValidationTrace getTrace()
Description copied from interface: ValidationFailure
Retrieves the trace of the failure. The trace can be used to uniquely know the route taken to reach the failure.

Specified by:
getTrace in interface ValidationFailure
Returns:
Returns the trace of the failure.

setFailureBean

public void setFailureBean(java.lang.Object theFailureBean)
Sets a reference to the bean that failed validation.

Parameters:
theFailureBean - A reference to the bean

getFailureBean

public java.lang.Object getFailureBean()
Obtains a reference to the bean that failed validation.

Specified by:
getFailureBean in interface ValidationFailure
Returns:
Returns a reference to the object