KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > faces > application > FacesMessage


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 JavaDoc;
19 import java.util.*;
20
21 /**
22  * @author Manfred Geiler (latest modification by $Author: manolito $)
23  * @version $Revision: 1.5 $ $Date: 2004/10/05 08:23:33 $
24  */

25 public class FacesMessage
26         implements Serializable JavaDoc
27 {
28     public static final String JavaDoc FACES_MESSAGES = "javax.faces.Messages";
29
30     public static final FacesMessage.Severity SEVERITY_INFO = new Severity("Info", 1);
31     public static final FacesMessage.Severity SEVERITY_WARN = new Severity("Warn", 2);
32     public static final FacesMessage.Severity SEVERITY_ERROR = new Severity("Error", 3);
33     public static final FacesMessage.Severity SEVERITY_FATAL = new Severity("Fatal", 4);
34     public static final List VALUES;
35     public static final Map VALUES_MAP;
36     static
37     {
38         Map map = new HashMap(7);
39         map.put(SEVERITY_INFO.toString(), SEVERITY_INFO);
40         map.put(SEVERITY_WARN.toString(), SEVERITY_WARN);
41         map.put(SEVERITY_ERROR.toString(), SEVERITY_ERROR);
42         map.put(SEVERITY_FATAL.toString(), SEVERITY_FATAL);
43         VALUES = Collections.unmodifiableList(new ArrayList(map.values()));
44         VALUES_MAP = Collections.unmodifiableMap(map);
45     }
46
47     private FacesMessage.Severity _severity;
48     private String JavaDoc _summary;
49     private String JavaDoc _detail;
50
51     public FacesMessage()
52     {
53     }
54
55     public FacesMessage(String JavaDoc summary)
56     {
57         _summary = summary;
58     }
59
60     public FacesMessage(String JavaDoc summary, String JavaDoc detail)
61     {
62         _summary = summary;
63         _detail = detail;
64     }
65
66     public FacesMessage(FacesMessage.Severity severity,
67                         String JavaDoc summary,
68                         String JavaDoc detail)
69     {
70         _severity = severity;
71         _summary = summary;
72         _detail = detail;
73     }
74
75     public FacesMessage.Severity getSeverity()
76     {
77         return _severity;
78     }
79
80     public void setSeverity(FacesMessage.Severity severity)
81     {
82         _severity = severity;
83     }
84
85     public String JavaDoc getSummary()
86     {
87         return _summary;
88     }
89
90     public void setSummary(String JavaDoc summary)
91     {
92         _summary = summary;
93     }
94
95     public String JavaDoc getDetail()
96     {
97         if (_detail == null)
98         {
99             // Javadoc:
100
// If no localized detail text has been defined for this message, return the localized summary text instead
101
return _summary;
102         }
103         return _detail;
104     }
105
106     public void setDetail(String JavaDoc detail)
107     {
108         _detail = detail;
109     }
110
111
112     public static class Severity
113             implements Comparable JavaDoc
114     {
115         private String JavaDoc _name;
116         private int _ordinal;
117
118         private Severity(String JavaDoc name, int ordinal)
119         {
120             _name = name;
121             _ordinal = ordinal;
122         }
123
124         public int getOrdinal()
125         {
126             return _ordinal;
127         }
128
129         public String JavaDoc toString()
130         {
131             return _name;
132         }
133
134         public int compareTo(Object JavaDoc o)
135         {
136             if (!(o instanceof Severity))
137             {
138                 throw new IllegalArgumentException JavaDoc(o.getClass().getName());
139             }
140             return getOrdinal() - ((Severity)o).getOrdinal();
141         }
142     }
143
144 }
145
Popular Tags