KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > util > RollerMessages


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */

18 package org.apache.roller.util;
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23
24 /**
25  * Holds collection of error messages and collection of status messages.
26  * @author David M Johnson
27  */

28 public class RollerMessages
29 {
30     private List JavaDoc mErrors = new ArrayList JavaDoc();
31     private List JavaDoc mMessages = new ArrayList JavaDoc();
32     
33     public RollerMessages()
34     {
35     }
36     public void addError(String JavaDoc key)
37     {
38         mErrors.add(new RollerMessage(key, null));
39     }
40     public void addError(String JavaDoc key, String JavaDoc arg)
41     {
42         mErrors.add(new RollerMessage(key, new String JavaDoc[]{arg}));
43     }
44     public void addError(String JavaDoc key, String JavaDoc[] args)
45     {
46         mErrors.add(new RollerMessage(key, args));
47     }
48     public void addMessage(String JavaDoc key)
49     {
50         mMessages.add(new RollerMessage(key, null));
51     }
52     public void addMessage(String JavaDoc key, String JavaDoc arg)
53     {
54         mMessages.add(new RollerMessage(key, new String JavaDoc[]{arg}));
55     }
56     public void addMessage(String JavaDoc key, String JavaDoc[] args)
57     {
58         mMessages.add(new RollerMessage(key, args));
59     }
60     public Iterator JavaDoc getErrors()
61     {
62         return mErrors.iterator();
63     }
64     public Iterator JavaDoc getMessages()
65     {
66         return mMessages.iterator();
67     }
68     public int getErrorCount()
69     {
70         return mErrors.size();
71     }
72     public int getMessageCount()
73     {
74         return mMessages.size();
75     }
76     public String JavaDoc toString()
77     {
78         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
79         Iterator JavaDoc msgs = mMessages.iterator();
80         while (msgs.hasNext())
81         {
82             RollerMessage msg = (RollerMessage) msgs.next();
83             sb.append(msg.getKey());
84             sb.append(" : ");
85         }
86         Iterator JavaDoc errs = mErrors.iterator();
87         while (errs.hasNext())
88         {
89             RollerMessage msg = (RollerMessage) errs.next();
90             sb.append(msg.getKey());
91             sb.append(" : ");
92         }
93         return sb.toString();
94     }
95     public static class RollerMessage
96     {
97         private String JavaDoc mKey;
98         private String JavaDoc[] mArgs;
99         public RollerMessage(String JavaDoc key, String JavaDoc[] args)
100         {
101             mKey = key;
102             mArgs = args;
103         }
104         public String JavaDoc[] getArgs()
105         {
106             return mArgs;
107         }
108         public void setArgs(String JavaDoc[] args)
109         {
110             mArgs = args;
111         }
112         public String JavaDoc getKey()
113         {
114             return mKey;
115         }
116         public void setKey(String JavaDoc key)
117         {
118             mKey = key;
119         }
120     }
121 }
122
Popular Tags