KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jaspersoft > jasperserver > api > common > domain > impl > ValidationErrorsImpl


1 /*
2  * Copyright (C) 2006 JasperSoft http://www.jaspersoft.com
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed WITHOUT ANY WARRANTY; and without the
10  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
15  * or write to:
16  *
17  * Free Software Foundation, Inc.,
18  * 59 Temple Place - Suite 330,
19  * Boston, MA USA 02111-1307
20  */

21 package com.jaspersoft.jasperserver.api.common.domain.impl;
22
23 import java.io.Serializable JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27
28 import com.jaspersoft.jasperserver.api.common.domain.ValidationError;
29 import com.jaspersoft.jasperserver.api.common.domain.ValidationErrors;
30
31 /**
32  * @author Lucian Chirita (lucianc@users.sourceforge.net)
33  * @version $Id: ValidationErrorsImpl.java 3550 2006-06-06 18:47:26Z lucian $
34  */

35 public class ValidationErrorsImpl implements ValidationErrors, Serializable JavaDoc {
36     
37     private static final long serialVersionUID = 1L;
38     
39     private final List JavaDoc errors;
40     
41     public ValidationErrorsImpl() {
42         errors = new ArrayList JavaDoc();
43     }
44
45     public boolean isError() {
46         return !errors.isEmpty();
47     }
48
49     public List JavaDoc getErrors() {
50         return errors;
51     }
52
53     public void add(ValidationError error) {
54         errors.add(error);
55     }
56     
57     public String JavaDoc toString() {
58         if (!isError()) {
59             return "No errors";
60         }
61         
62         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
63         sb.append(errors.size());
64         sb.append(" error(s)\n");
65         for (Iterator JavaDoc it = errors.iterator(); it.hasNext();) {
66             ValidationError error = (ValidationError) it.next();
67             sb.append(error.toString());
68             sb.append('\n');
69         }
70         return sb.toString();
71     }
72 }
73
Popular Tags