Coverage Report - javax.faces.convert.BigIntegerConverter
 
Classes in this File Line Coverage Branch Coverage Complexity
BigIntegerConverter
0%
0/20
0%
0/16
0
 
 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  
 import java.math.BigInteger;
 27  
 
 28  
 /**
 29  
  * see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
 30  
  *
 31  
  * @author Thomas Spiegl (latest modification by $Author: lu4242 $)
 32  
  * @version $Revision: 693358 $ $Date: 2008-09-08 22:54:29 -0500 (Mon, 08 Sep 2008) $
 33  
  */
 34  
 @JSFConverter
 35  
 public class BigIntegerConverter
 36  
         implements Converter
 37  
 {
 38  
     // FIELDS
 39  
     public static final String CONVERTER_ID = "javax.faces.BigInteger";
 40  
     public static final String STRING_ID = "javax.faces.converter.STRING";
 41  
     public static final String BIGINTEGER_ID = "javax.faces.converter.BigIntegerConverter.BIGINTEGER";
 42  
 
 43  
     // CONSTRUCTORS
 44  
     public BigIntegerConverter()
 45  0
     {
 46  0
     }
 47  
 
 48  
     // METHODS
 49  
     public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String value)
 50  
     {
 51  0
         if (facesContext == null) throw new NullPointerException("facesContext");
 52  0
         if (uiComponent == null) throw new NullPointerException("uiComponent");
 53  
 
 54  0
         if (value != null)
 55  
         {
 56  0
             value = value.trim();
 57  0
             if (value.length() > 0)
 58  
             {
 59  
                 try
 60  
                 {
 61  0
                     return new BigInteger(value.trim());
 62  
                 }
 63  0
                 catch (NumberFormatException e)
 64  
                 {
 65  0
                     throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
 66  
                                                                                BIGINTEGER_ID,
 67  
                                                                                new Object[]{value,"2345",_MessageUtils.getLabel(facesContext, uiComponent)}), e);
 68  
                 }
 69  
             }
 70  
         }
 71  0
         return null;
 72  
     }
 73  
 
 74  
     public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object value)
 75  
     {
 76  0
         if (facesContext == null) throw new NullPointerException("facesContext");
 77  0
         if (uiComponent == null) throw new NullPointerException("uiComponent");
 78  
 
 79  0
         if (value == null)
 80  
         {
 81  0
             return "";
 82  
         }
 83  0
         if (value instanceof String)
 84  
         {
 85  0
             return (String)value;
 86  
         }
 87  
         try
 88  
         {
 89  0
             return ((BigInteger)value).toString();
 90  
         }
 91  0
         catch (Exception e)
 92  
         {
 93  0
             throw new ConverterException(_MessageUtils.getErrorMessage(facesContext, STRING_ID, new Object[]{value,_MessageUtils.getLabel(facesContext, uiComponent)}),e);
 94  
         }
 95  
     }
 96  
 
 97  
 }