Coverage Report - javax.faces.convert.BooleanConverter
 
Classes in this File Line Coverage Branch Coverage Complexity
BooleanConverter
0%
0/24
0%
0/16
7.667
 
 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.convert;
 20  
 
 21  
 import javax.faces.component.UIComponent;
 22  
 import javax.faces.context.FacesContext;
 23  
 
 24  
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFConverter;
 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  
 @JSFConverter
 30  
 public class BooleanConverter
 31  
         implements Converter
 32  
 {
 33  
     // FIELDS
 34  
     public static final String CONVERTER_ID = "javax.faces.Boolean";
 35  
     public static final String STRING_ID = "javax.faces.converter.STRING";
 36  
     public static final String BOOLEAN_ID = "javax.faces.converter.BooleanConverter.BOOLEAN";
 37  
 
 38  
     // CONSTRUCTORS
 39  
     public BooleanConverter()
 40  0
     {
 41  0
     }
 42  
 
 43  
     // METHODS
 44  
     public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String value)
 45  
     {
 46  0
         if (facesContext == null)
 47  
         {
 48  0
             throw new NullPointerException("facesContext");
 49  
         }
 50  0
         if (uiComponent == null)
 51  
         {
 52  0
             throw new NullPointerException("uiComponent");
 53  
         }
 54  
 
 55  0
         if (value != null)
 56  
         {
 57  0
             value = value.trim();
 58  0
             if (value.length() > 0)
 59  
             {
 60  
                 try
 61  
                 {
 62  0
                     return Boolean.valueOf(value);
 63  
                 }
 64  0
                 catch (Exception e)
 65  
                 {
 66  0
                     throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
 67  
                                        BOOLEAN_ID,
 68  
                                        new Object[]{value,_MessageUtils.getLabel(facesContext, uiComponent)}), e);
 69  
                 }
 70  
             }
 71  
         }
 72  0
         return null;
 73  
     }
 74  
 
 75  
     public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object value)
 76  
     {
 77  0
         if (facesContext == null)
 78  
         {
 79  0
             throw new NullPointerException("facesContext");
 80  
         }
 81  0
         if (uiComponent == null)
 82  
         {
 83  0
             throw new NullPointerException("uiComponent");
 84  
         }
 85  
 
 86  0
         if (value == null)
 87  
         {
 88  0
             return "";
 89  
         }
 90  0
         if (value instanceof String)
 91  
         {
 92  0
             return (String)value;
 93  
         }
 94  
         try
 95  
         {
 96  0
             return ((Boolean)value).toString();
 97  
         }
 98  0
         catch (Exception e)
 99  
         {
 100  0
             throw new ConverterException(_MessageUtils.getErrorMessage(facesContext, STRING_ID,
 101  
                     new Object[]{value,_MessageUtils.getLabel(facesContext, uiComponent)}),e);
 102  
         }
 103  
     }
 104  
 }