1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package javax.faces.application;
20
21 import java.io.IOException;
22 import java.io.ObjectInputStream;
23 import java.io.ObjectOutputStream;
24 import java.io.Serializable;
25 import java.util.*;
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 public class FacesMessage
42 implements Serializable
43 {
44 private static final long serialVersionUID = 4851488727794169661L;
45
46 public static final String FACES_MESSAGES = "javax.faces.Messages";
47
48 public static final FacesMessage.Severity SEVERITY_INFO = new Severity("Info", 1);
49 public static final FacesMessage.Severity SEVERITY_WARN = new Severity("Warn", 2);
50 public static final FacesMessage.Severity SEVERITY_ERROR = new Severity("Error", 3);
51 public static final FacesMessage.Severity SEVERITY_FATAL = new Severity("Fatal", 4);
52 public static final List VALUES;
53 public static final Map VALUES_MAP;
54 static
55 {
56 Map map = new HashMap(7);
57 map.put(SEVERITY_INFO.toString(), SEVERITY_INFO);
58 map.put(SEVERITY_WARN.toString(), SEVERITY_WARN);
59 map.put(SEVERITY_ERROR.toString(), SEVERITY_ERROR);
60 map.put(SEVERITY_FATAL.toString(), SEVERITY_FATAL);
61 VALUES_MAP = Collections.unmodifiableMap(map);
62
63 List severityList = new ArrayList(map.values());
64 Collections.sort(severityList);
65 VALUES = Collections.unmodifiableList(severityList);
66 }
67
68 private transient FacesMessage.Severity _severity;
69 private String _summary;
70 private String _detail;
71
72 public FacesMessage()
73 {
74 _severity = SEVERITY_INFO;
75 }
76
77 public FacesMessage(String summary)
78 {
79 _summary = summary;
80 _severity = SEVERITY_INFO;
81 }
82
83 public FacesMessage(String summary, String detail)
84 {
85 _summary = summary;
86 _detail = detail;
87 _severity = SEVERITY_INFO;
88 }
89
90 public FacesMessage(FacesMessage.Severity severity,
91 String summary,
92 String detail)
93 {
94 if(severity == null) throw new NullPointerException("severity");
95 _severity = severity;
96 _summary = summary;
97 _detail = detail;
98 }
99
100 public FacesMessage.Severity getSeverity()
101 {
102 return _severity;
103 }
104
105 public void setSeverity(FacesMessage.Severity severity)
106 {
107 if(severity == null) throw new NullPointerException("severity");
108 _severity = severity;
109 }
110
111 public String getSummary()
112 {
113 return _summary;
114 }
115
116 public void setSummary(String summary)
117 {
118 _summary = summary;
119 }
120
121 public String getDetail()
122 {
123 if (_detail == null)
124 {
125
126
127 return _summary;
128 }
129 return _detail;
130 }
131
132 public void setDetail(String detail)
133 {
134 _detail = detail;
135 }
136
137 private void writeObject(ObjectOutputStream out) throws IOException
138 {
139 out.defaultWriteObject();
140 out.writeInt(_severity._ordinal);
141 }
142
143 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
144 {
145 in.defaultReadObject();
146
147
148 int severityOrdinal = in.readInt();
149 _severity = (Severity) VALUES.get(severityOrdinal - 1);
150 }
151
152
153 public static class Severity
154 implements Comparable
155 {
156 private String _name;
157 private int _ordinal;
158
159 private Severity(String name, int ordinal)
160 {
161 _name = name;
162 _ordinal = ordinal;
163 }
164
165 public int getOrdinal()
166 {
167 return _ordinal;
168 }
169
170 public String toString()
171 {
172 return _name;
173 }
174
175 public int compareTo(Object o)
176 {
177 if (!(o instanceof Severity))
178 {
179 throw new IllegalArgumentException(o.getClass().getName());
180 }
181 return getOrdinal() - ((Severity)o).getOrdinal();
182 }
183 }
184
185 }