Coverage Report - javax.faces.validator.ValidatorException
 
Classes in this File Line Coverage Branch Coverage Complexity
ValidatorException
28%
11/38
22%
4/18
2.5
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *   http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package javax.faces.validator;
 20  
 
 21  
 import java.util.Collection;
 22  
 
 23  
 import javax.faces.FacesException;
 24  
 import javax.faces.application.FacesMessage;
 25  
 
 26  
 /**
 27  
  * see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
 28  
  */
 29  
 public class ValidatorException
 30  
         extends FacesException
 31  
 {
 32  
     private static final long serialVersionUID = 5965885122446047949L;
 33  
     private FacesMessage _facesMessage;
 34  
     private Collection<FacesMessage> _facesMessages;
 35  
 
 36  
     public ValidatorException(Collection<FacesMessage> messages)
 37  
     {
 38  0
         super(facesMessagesToString(messages));
 39  0
         _facesMessages = messages;
 40  0
     }
 41  
     
 42  
     public ValidatorException(Collection<FacesMessage> messages, Throwable cause)
 43  
     {
 44  0
         super(facesMessagesToString(messages),cause);
 45  0
         _facesMessages = messages;
 46  0
     }
 47  
     
 48  
     public ValidatorException(FacesMessage message)
 49  
     {
 50  4
         super(facesMessageToString(message));
 51  4
         _facesMessage = message;
 52  4
     }
 53  
 
 54  
     public ValidatorException(FacesMessage message,
 55  
                               Throwable cause)
 56  
     {
 57  0
         super(facesMessageToString(message), cause);
 58  0
         _facesMessage = message;
 59  0
     }
 60  
 
 61  
     public FacesMessage getFacesMessage()
 62  
     {
 63  2
         return _facesMessage;
 64  
     }
 65  
     
 66  
     public Collection<FacesMessage> getFacesMessages()
 67  
     {
 68  2
         return _facesMessages;
 69  
     }
 70  
 
 71  
     private static String facesMessageToString(FacesMessage message)
 72  
     {
 73  4
         String summary = message.getSummary();
 74  4
         String detail = message.getDetail();
 75  
         
 76  4
         if (summary != null)
 77  
         {
 78  2
             if (detail != null)
 79  
             {
 80  2
                 return summary + ": " + detail;
 81  
             }
 82  
             
 83  0
             return summary;
 84  
         }
 85  
         
 86  2
         return detail != null ? detail : "";
 87  
     }
 88  
     
 89  
     private static String facesMessagesToString(Collection<FacesMessage> messages)
 90  
     {
 91  0
         if (messages == null || messages.isEmpty())
 92  
         {
 93  0
             return "";
 94  
         }
 95  0
         StringBuilder sb = new StringBuilder();
 96  
 
 97  0
         String separator = "";
 98  0
         for (FacesMessage message : messages)
 99  
         {
 100  0
             if (message != null)
 101  
             {
 102  0
                 String summary = message.getSummary();
 103  0
                 String detail = message.getDetail();
 104  
                 
 105  0
                 if (summary != null)
 106  
                 {
 107  0
                     sb.append(separator);
 108  0
                     sb.append(summary);
 109  0
                     if (detail != null)
 110  
                     {
 111  0
                         sb.append(": ");
 112  0
                         sb.append(detail);
 113  
                     }
 114  0
                     separator = ", ";
 115  
                 }
 116  
             }
 117  0
         }
 118  0
         return sb.toString();
 119  
     }
 120  
 }