Source code: javax/faces/application/FacesMessage.java
1 /*
2 * Copyright 2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not 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.
15 */
16 package javax.faces.application;
17
18 import java.io.Serializable;
19 import java.util.*;
20
21 /**
22 * @author Manfred Geiler (latest modification by $Author: bdudney $)
23 * @version $Revision: 225333 $ $Date: 2005-07-26 11:49:19 -0400 (Tue, 26 Jul 2005) $
24 */
25 public class FacesMessage
26 implements Serializable
27 {
28 private static final long serialVersionUID = 4851488727794169661L;
29
30 public static final String FACES_MESSAGES = "javax.faces.Messages";
31
32 public static final FacesMessage.Severity SEVERITY_INFO = new Severity("Info", 1);
33 public static final FacesMessage.Severity SEVERITY_WARN = new Severity("Warn", 2);
34 public static final FacesMessage.Severity SEVERITY_ERROR = new Severity("Error", 3);
35 public static final FacesMessage.Severity SEVERITY_FATAL = new Severity("Fatal", 4);
36 public static final List VALUES;
37 public static final Map VALUES_MAP;
38 static
39 {
40 Map map = new HashMap(7);
41 map.put(SEVERITY_INFO.toString(), SEVERITY_INFO);
42 map.put(SEVERITY_WARN.toString(), SEVERITY_WARN);
43 map.put(SEVERITY_ERROR.toString(), SEVERITY_ERROR);
44 map.put(SEVERITY_FATAL.toString(), SEVERITY_FATAL);
45 VALUES = Collections.unmodifiableList(new ArrayList(map.values()));
46 VALUES_MAP = Collections.unmodifiableMap(map);
47 }
48
49 private FacesMessage.Severity _severity;
50 private String _summary;
51 private String _detail;
52
53 public FacesMessage()
54 {
55 _severity = SEVERITY_INFO;
56 }
57
58 public FacesMessage(String summary)
59 {
60 _summary = summary;
61 _severity = SEVERITY_INFO;
62 }
63
64 public FacesMessage(String summary, String detail)
65 {
66 _summary = summary;
67 _detail = detail;
68 _severity = SEVERITY_INFO;
69 }
70
71 public FacesMessage(FacesMessage.Severity severity,
72 String summary,
73 String detail)
74 {
75 if(severity == null) throw new NullPointerException("severity");
76 _severity = severity;
77 _summary = summary;
78 _detail = detail;
79 }
80
81 public FacesMessage.Severity getSeverity()
82 {
83 return _severity;
84 }
85
86 public void setSeverity(FacesMessage.Severity severity)
87 {
88 if(severity == null) throw new NullPointerException("severity");
89 _severity = severity;
90 }
91
92 public String getSummary()
93 {
94 return _summary;
95 }
96
97 public void setSummary(String summary)
98 {
99 _summary = summary;
100 }
101
102 public String getDetail()
103 {
104 if (_detail == null)
105 {
106 // Javadoc:
107 // If no localized detail text has been defined for this message, return the localized summary text instead
108 return _summary;
109 }
110 return _detail;
111 }
112
113 public void setDetail(String detail)
114 {
115 _detail = detail;
116 }
117
118
119 public static class Severity
120 implements Comparable
121 {
122 private String _name;
123 private int _ordinal;
124
125 private Severity(String name, int ordinal)
126 {
127 _name = name;
128 _ordinal = ordinal;
129 }
130
131 public int getOrdinal()
132 {
133 return _ordinal;
134 }
135
136 public String toString()
137 {
138 return _name;
139 }
140
141 public int compareTo(Object o)
142 {
143 if (!(o instanceof Severity))
144 {
145 throw new IllegalArgumentException(o.getClass().getName());
146 }
147 return getOrdinal() - ((Severity)o).getOrdinal();
148 }
149 }
150
151 }