001: /*
002: * Copyright 2006-2007 Dan Shellman
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.iscreen;
017:
018: import java.util.ArrayList;
019: import java.util.Collection;
020:
021: /**
022: * A validation failure represents a single failure reported by a Validator
023: * (Validators can report multiple failures, each represented by a separate
024: * instance of this class). Each failure has a message (usually designed
025: * to be accessible to the end user), a label (usually used to associate
026: * the failure with an UI component, though a label is not required), and
027: * the Collection of fields (these are really the OGNL expressions used to 'get'
028: * properties from the JavaBean being validated) from the JavaBean that was
029: * originally validated (normally, there's just one field). <br />
030: * <br />
031: * Interface code (such as a web framework) can use instances of this
032: * class to display the validation failures. There should be sufficient
033: * information associated with each failure to apply the message to
034: * the correct location within the interface.
035: *
036: * @author Shellman, Dan
037: */
038: public class ValidationFailure {
039: protected String label;
040: protected String name;
041: protected String message;
042: protected Collection fields = new ArrayList();
043: protected Integer index;
044:
045: /**
046: * Default constructor.
047: */
048: public ValidationFailure() {
049: } //end ValidationFailure()
050:
051: public void setLabel(String theLabel) {
052: label = theLabel;
053: } //end setLabel()
054:
055: /**
056: * Retrieves the label associated with this failure.
057: *
058: * @return Returns the label associated with this failure.
059: */
060: public String getLabel() {
061: return label;
062: } //end getLabel()
063:
064: /**
065: * Sets the name for this failure message. The name is used to identify the
066: * failure message and relate it to a particular validator (the one that
067: * reported the failure).
068: *
069: * @param theName The name of the validator causing this failure.
070: */
071: public void setName(String theName) {
072: name = theName;
073: } //end setName()
074:
075: /**
076: * Retrieves the name of the validator reporting the failure message.
077: *
078: * @return Returns the name of the validator.
079: */
080: public String getName() {
081: return name;
082: } //end getName()
083:
084: /**
085: * Retrieves the failure message (which has already been evaluated
086: * and localized.
087: *
088: * @return Returns the failure message.
089: */
090: public String getMessage() {
091: return message;
092: } //end getMessage()
093:
094: public void setMessage(String theMessage) {
095: message = theMessage;
096: } //end setMessage()
097:
098: /**
099: * Retrieves the fields (the OGNL expression used to 'get' the properties
100: * from the JavaBean being validated) of the JavaBean being validated.
101: *
102: * @return Returns the fields of the JavaBean being validated.
103: */
104: public Collection getFields() {
105: return fields;
106: } //end getFields()
107:
108: public void setFields(Collection theFields) {
109: fields.clear();
110: fields.addAll(theFields);
111: } //end setFields()
112:
113: /**
114: * Retrieves the index of the JavaBean/Object being validated that was
115: * an element within an array/Collection of a 'parent' JavaBean being
116: * validated (i.e. an object was being validated, and it had a property
117: * that was an array/Collection that was 'forwarded' on to another
118: * validation set and iterated over. The subsequent members of that
119: * array/Collection would have an index of which was being validated
120: * at a particular time. This is that index.). If no indexed property
121: * was being validated, then this will return null. Note that a null
122: * value is different than a zero value, as a zero value represents the
123: * first element in an array/Collection, where a null value implies that
124: * the JavaBean/Object wasn't involved in an array/Collection in the
125: * first place.
126: *
127: * @return Returns the index of the JavaBean/Object that was being validated.
128: */
129: public Integer getIndex() {
130: return index;
131: } //end getIndex()
132:
133: public void setIndex(Integer theIndex) {
134: index = theIndex;
135: } //end setIndex()
136: } //end ValidationFailure
|