1 16 package javax.faces.application; 17 18 import java.io.Serializable ; 19 import java.util.*; 20 21 25 public class FacesMessage 26 implements Serializable 27 { 28 public static final String 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 _summary; 49 private String _detail; 50 51 public FacesMessage() 52 { 53 } 54 55 public FacesMessage(String summary) 56 { 57 _summary = summary; 58 } 59 60 public FacesMessage(String summary, String detail) 61 { 62 _summary = summary; 63 _detail = detail; 64 } 65 66 public FacesMessage(FacesMessage.Severity severity, 67 String summary, 68 String 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 getSummary() 86 { 87 return _summary; 88 } 89 90 public void setSummary(String summary) 91 { 92 _summary = summary; 93 } 94 95 public String getDetail() 96 { 97 if (_detail == null) 98 { 99 return _summary; 102 } 103 return _detail; 104 } 105 106 public void setDetail(String detail) 107 { 108 _detail = detail; 109 } 110 111 112 public static class Severity 113 implements Comparable 114 { 115 private String _name; 116 private int _ordinal; 117 118 private Severity(String 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 toString() 130 { 131 return _name; 132 } 133 134 public int compareTo(Object o) 135 { 136 if (!(o instanceof Severity)) 137 { 138 throw new IllegalArgumentException (o.getClass().getName()); 139 } 140 return getOrdinal() - ((Severity)o).getOrdinal(); 141 } 142 } 143 144 } 145 | Popular Tags |