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