001: /*
002: * Copyright 2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package javax.faces.application;
017:
018: import java.io.Serializable;
019: import java.util.*;
020:
021: /**
022: * see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
023: *
024: * @author Manfred Geiler (latest modification by $Author: mbr $)
025: * @version $Revision: 513465 $ $Date: 2007-03-01 20:37:22 +0100 (Do, 01 Mrz 2007) $
026: */
027: public class FacesMessage implements Serializable {
028: private static final long serialVersionUID = 4851488727794169661L;
029:
030: public static final String FACES_MESSAGES = "javax.faces.Messages";
031:
032: public static final FacesMessage.Severity SEVERITY_INFO = new Severity(
033: "Info", 1);
034: public static final FacesMessage.Severity SEVERITY_WARN = new Severity(
035: "Warn", 2);
036: public static final FacesMessage.Severity SEVERITY_ERROR = new Severity(
037: "Error", 3);
038: public static final FacesMessage.Severity SEVERITY_FATAL = new Severity(
039: "Fatal", 4);
040: public static final List VALUES;
041: public static final Map VALUES_MAP;
042: static {
043: Map<String, FacesMessage.Severity> map = new HashMap<String, FacesMessage.Severity>(
044: 7);
045: map.put(SEVERITY_INFO.toString(), SEVERITY_INFO);
046: map.put(SEVERITY_WARN.toString(), SEVERITY_WARN);
047: map.put(SEVERITY_ERROR.toString(), SEVERITY_ERROR);
048: map.put(SEVERITY_FATAL.toString(), SEVERITY_FATAL);
049: VALUES = Collections
050: .unmodifiableList(new ArrayList<FacesMessage.Severity>(
051: map.values()));
052: VALUES_MAP = Collections.unmodifiableMap(map);
053: }
054:
055: private FacesMessage.Severity _severity;
056: private String _summary;
057: private String _detail;
058:
059: public FacesMessage() {
060: _severity = SEVERITY_INFO;
061: }
062:
063: public FacesMessage(String summary) {
064: _summary = summary;
065: _severity = SEVERITY_INFO;
066: }
067:
068: public FacesMessage(String summary, String detail) {
069: _summary = summary;
070: _detail = detail;
071: _severity = SEVERITY_INFO;
072: }
073:
074: public FacesMessage(FacesMessage.Severity severity, String summary,
075: String detail) {
076: if (severity == null)
077: throw new NullPointerException("severity");
078: _severity = severity;
079: _summary = summary;
080: _detail = detail;
081: }
082:
083: public FacesMessage.Severity getSeverity() {
084: return _severity;
085: }
086:
087: public void setSeverity(FacesMessage.Severity severity) {
088: if (severity == null)
089: throw new NullPointerException("severity");
090: _severity = severity;
091: }
092:
093: public String getSummary() {
094: return _summary;
095: }
096:
097: public void setSummary(String summary) {
098: _summary = summary;
099: }
100:
101: public String getDetail() {
102: if (_detail == null) {
103: // Javadoc:
104: // If no localized detail text has been defined for this message, return the localized summary text instead
105: return _summary;
106: }
107: return _detail;
108: }
109:
110: public void setDetail(String detail) {
111: _detail = detail;
112: }
113:
114: public static class Severity implements Comparable {
115: private String _name;
116: private int _ordinal;
117:
118: private Severity(String name, int ordinal) {
119: _name = name;
120: _ordinal = ordinal;
121: }
122:
123: public int getOrdinal() {
124: return _ordinal;
125: }
126:
127: public String toString() {
128: return _name;
129: }
130:
131: public int compareTo(Object o) {
132: if (!(o instanceof Severity)) {
133: throw new IllegalArgumentException(o.getClass()
134: .getName());
135: }
136: return getOrdinal() - ((Severity) o).getOrdinal();
137: }
138: }
139:
140: }
|