Coverage Report - javax.faces.application.FacesMessage
 
Classes in this File Line Coverage Branch Coverage Complexity
FacesMessage
100%
35/35
100%
6/6
1.222
FacesMessage$Severity
50%
7/14
N/A
1.222
 
 1  
 /*
 2  
  * Copyright 2004-2011 the Seasar Foundation and the Others.
 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,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package javax.faces.application;
 17  
 
 18  
 import java.io.Serializable;
 19  
 import java.util.Arrays;
 20  
 import java.util.Collections;
 21  
 import java.util.HashMap;
 22  
 import java.util.List;
 23  
 import java.util.Map;
 24  
 
 25  
 /**
 26  
  * @author shot
 27  
  * @author manhole
 28  
  */
 29  
 public class FacesMessage implements Serializable {
 30  
 
 31  
     private static final long serialVersionUID = 3258125843346766128L;
 32  
 
 33  
     public static final String FACES_MESSAGES = "javax.faces.Messages";
 34  
 
 35  1
     public static final Severity SEVERITY_INFO = new Severity("INFO", 1);
 36  
 
 37  1
     public static final Severity SEVERITY_WARN = new Severity("WARN", 2);
 38  
 
 39  1
     public static final Severity SEVERITY_ERROR = new Severity("ERROR", 3);
 40  
 
 41  1
     public static final Severity SEVERITY_FATAL = new Severity("FATAL", 4);
 42  
 
 43  1
     private static final Severity[] values = { SEVERITY_INFO, SEVERITY_WARN,
 44  
             SEVERITY_ERROR, SEVERITY_FATAL };
 45  
 
 46  
     public static final List VALUES;
 47  
 
 48  
     public static final Map VALUES_MAP;
 49  
 
 50  
     static {
 51  1
         VALUES = Collections.unmodifiableList(Arrays.asList(values));
 52  1
         Map map = new HashMap();
 53  5
         for (int i = 0; i < values.length; i++) {
 54  4
             map.put(values[i].toString(), values[i]);
 55  
         }
 56  1
         VALUES_MAP = Collections.unmodifiableMap(map);
 57  1
     }
 58  
 
 59  
     private String summary;
 60  
 
 61  
     private String detail;
 62  
 
 63  
     private Severity severity;
 64  
 
 65  
     public FacesMessage() {
 66  85
         this(SEVERITY_INFO, null, null);
 67  85
     }
 68  
 
 69  
     public FacesMessage(String summary) {
 70  19
         this(SEVERITY_INFO, summary, null);
 71  19
     }
 72  
 
 73  
     public FacesMessage(String summary, String detail) {
 74  5
         this(SEVERITY_INFO, summary, detail);
 75  5
     }
 76  
 
 77  228
     public FacesMessage(Severity severity, String summary, String detail) {
 78  228
         setSeverity(severity);
 79  227
         this.summary = summary;
 80  227
         this.detail = detail;
 81  227
     }
 82  
 
 83  
     public String getDetail() {
 84  175
         return (detail != null) ? detail : summary;
 85  
     }
 86  
 
 87  
     public void setDetail(String detail) {
 88  29
         this.detail = detail;
 89  29
     }
 90  
 
 91  
     public Severity getSeverity() {
 92  175
         return severity;
 93  
     }
 94  
 
 95  
     public void setSeverity(Severity severity) {
 96  612
         for (int i = 0; i < values.length; i++) {
 97  610
             Severity sev = values[i];
 98  610
             if (sev.compareTo(severity) == 0) {
 99  281
                 this.severity = severity;
 100  281
                 return;
 101  
             }
 102  
         }
 103  2
         throw new IllegalArgumentException("severity");
 104  
     }
 105  
 
 106  
     public String getSummary() {
 107  89
         return summary;
 108  
     }
 109  
 
 110  
     public void setSummary(String summary) {
 111  38
         this.summary = summary;
 112  38
     }
 113  
 
 114  
     public static class Severity implements Comparable, Serializable {
 115  
 
 116  
         private static final long serialVersionUID = 1L;
 117  
 
 118  
         private String type;
 119  
 
 120  
         private int ordinal;
 121  
 
 122  0
         public Severity() {
 123  0
         }
 124  
 
 125  6
         public Severity(String type, int ordinal) {
 126  6
             this.type = type;
 127  6
             this.ordinal = ordinal;
 128  6
         }
 129  
 
 130  
         public int getOrdinal() {
 131  10
             return ordinal;
 132  
         }
 133  
 
 134  
         public String getType() {
 135  0
             return type;
 136  
         }
 137  
 
 138  
         public void setOrdinal(int ordinal) {
 139  0
             this.ordinal = ordinal;
 140  0
         }
 141  
 
 142  
         public void setType(String type) {
 143  0
             this.type = type;
 144  0
         }
 145  
 
 146  
         public String toString() {
 147  4
             return type;
 148  
         }
 149  
 
 150  
         public int compareTo(Object o) {
 151  625
             return ordinal - ((Severity) o).ordinal;
 152  
         }
 153  
     }
 154  
 }