KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.roller.util;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.List JavaDoc;
6
7 /**
8  * Holds collection of error messages and collection of status messages.
9  * @author David M Johnson
10  */

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