1 /*
2 * Copyright (c) 2001 - 2005 ivata limited.
3 * All rights reserved.
4 * -----------------------------------------------------------------------------
5 * ivata masks may be redistributed under the GNU General Public
6 * License as published by the Free Software Foundation;
7 * version 2 of the License.
8 *
9 * These programs are free software; you can redistribute them and/or
10 * modify them under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; version 2 of the License.
12 *
13 * These programs are distributed in the hope that they will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 *
17 * See the GNU General Public License in the file LICENSE.txt for more
18 * details.
19 *
20 * If you would like a copy of the GNU General Public License write to
21 *
22 * Free Software Foundation, Inc.
23 * 59 Temple Place - Suite 330
24 * Boston, MA 02111-1307, USA.
25 *
26 *
27 * To arrange commercial support and licensing, contact ivata at
28 * http://www.ivata.com/contact.jsp
29 * -----------------------------------------------------------------------------
30 * $Log: ValidationErrors.java,v $
31 * Revision 1.5 2005/04/11 12:27:02 colinmacleod
32 * Added preliminary support for filters.
33 * Added FieldValueConvertor factor interface
34 * to split off value convertors for reuse.
35 *
36 * Revision 1.4 2005/04/09 18:04:16 colinmacleod
37 * Changed copyright text to GPL v2 explicitly.
38 *
39 * Revision 1.3 2005/03/10 10:24:14 colinmacleod
40 * Added toString().
41 *
42 * Revision 1.2 2005/01/06 22:13:22 colinmacleod
43 * Moved up a version number.
44 * Changed copyright notices to 2005.
45 * Updated the documentation:
46 * - started working on multiproject:site docu.
47 * - changed the logo.
48 * Added checkstyle and fixed LOADS of style issues.
49 * Added separate thirdparty subproject.
50 * Added struts (in web), util and webgui (in webtheme) from ivata op.
51 *
52 * Revision 1.1 2004/12/29 20:07:06 colinmacleod
53 * Renamed subproject masks to mask.
54 *
55 * Revision 1.1.1.1 2004/05/16 20:40:32 colinmacleod
56 * Ready for 0.1 release
57 *
58 * Revision 1.3 2004/03/21 21:16:23 colinmacleod
59 * Shortened name to ivata op.
60 *
61 * Revision 1.2 2004/02/01 22:07:29 colinmacleod
62 * Added full names to author tags
63 *
64 * Revision 1.1 2004/01/29 13:48:41 janboros
65 * Moved ivata op to SourceForge
66 *
67 * Revision 1.1 2003/10/16 07:27:45 colin
68 * First version in new repository.
69 *
70 * Revision 1.5 2003/02/26 17:10:38 peter
71 * toActionError: the bundle is located by java.util, not struts
72 *
73 * Revision 1.4 2003/02/24 19:08:17 colin
74 * *** empty log message ***
75 *
76 * Revision 1.3 2003/02/20 20:24:11 colin
77 * improved validation by adding ValidationField and ValidationException
78 *
79 * Revision 1.2 2003/02/04 17:36:47 colin
80 * copyright notice
81 *
82 * Revision 1.1 2002/11/12 10:41:12 colin
83 * first version in CVS. encapsulates Struts class ActionErrors
84 * -----------------------------------------------------------------------------
85 */
86 package com.ivata.mask.validation;
87 import java.io.Serializable;
88 import java.util.Iterator;
89 import java.util.List;
90 import java.util.Vector;
91 /***
92 * <p>
93 * Represents a list of <code>ValidationError</code> instances which have
94 * occurred in data which is being validated for submission.
95 * </p>
96 *
97 * <p>
98 * Currently, this class serves to encapsulate the functionality of the
99 * <strong>Struts </strong> class <code>ActionErrors</code>. In the future,
100 * it could be extended to be used in error handling with another platform.
101 * </p>.
102 *
103 * @since ivata masks 0.4 (2002-11-11)
104 * @author Colin MacLeod
105 * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
106 * @version $Revision: 1.5 $
107 * @see ValidationError
108 * @see org.apache.struts.action.ActionErrors
109 */
110 public class ValidationErrors implements Serializable {
111 /***
112 * <p>
113 * Contains all of the errors represented by the
114 * <code>ValidationErrors</code> instance.
115 * </p>
116 */
117 private List errors = new Vector();
118 /***
119 * <p>
120 * Add a new <code>ValidationError</code> to the list.
121 * </p>
122 *
123 * @param error
124 * new instance of <code>ValidationError</code> to be added.
125 * Cannot be <code>null</code>.
126 */
127 public final void add(final ValidationError error) {
128 errors.add(error);
129 }
130 /***
131 * <p>
132 * Add all elements of another <code>ValidationErrors</code> instance to
133 * the list.
134 * </p>
135 *
136 * @param validationErrors
137 * new instance of <code>ValidationErrors</code> to be added.
138 * Cannot be <code>null</code>.
139 */
140 public final void addAll(final ValidationErrors validationErrors) {
141 Iterator errorIterator = validationErrors.errors.iterator();
142 while (errorIterator.hasNext()) {
143 errors.add(errorIterator.next());
144 }
145 }
146 /***
147 * <p>
148 * Contains all of the errors represented by the
149 * <code>ValidationErrors</code> instance.
150 * </p>
151 *
152 * @return the current value of errors.
153 */
154 public final List getErrors() {
155 return errors;
156 }
157 /***
158 * <p>
159 * Evaluates whether or not this object contains errors.
160 * </p>
161 *
162 * @return <code>true</code> if there are errors in this object, otherwise
163 * <code>false</code>
164 */
165 public final boolean isEmpty() {
166 return errors.size() == 0;
167 }
168 /***
169 * Overridden to show you the errors this object contains.
170 * @return string represeting all errors this object contains.
171 */
172 public String toString() {
173 return "ValidationErrors " + errors.toString();
174 }
175 }