Coverage Report - javax.faces.convert.ByteConverter
 
Classes in this File Line Coverage Branch Coverage Complexity
ByteConverter
100%
25/25
100%
8/8
3.4
 
 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.convert;
 17  
 
 18  
 import javax.faces.component.UIComponent;
 19  
 import javax.faces.context.FacesContext;
 20  
 import javax.faces.internal.ConvertUtil;
 21  
 import javax.faces.internal.FacesMessageUtil;
 22  
 
 23  
 import org.seasar.framework.util.AssertionUtil;
 24  
 
 25  
 public class ByteConverter implements Converter {
 26  
 
 27  
     public static final String CONVERTER_ID = "javax.faces.Byte";
 28  
 
 29  2
     public static final String CONVERSION_OBJECT_ID = ByteConverter.class
 30  
             .getName()
 31  
             + ".CONVERSION";
 32  
 
 33  1
     public static final String CONVERSION_STRING_ID = ByteConverter.class
 34  
             .getName()
 35  
             + ".CONVERSION_STRING";
 36  
 
 37  13
     public ByteConverter() {
 38  13
     }
 39  
 
 40  
     public Object getAsObject(FacesContext context, UIComponent component,
 41  
             String value) throws ConverterException {
 42  6
         AssertionUtil.assertNotNull("FacesContext", context);
 43  5
         AssertionUtil.assertNotNull("UIComponent", component);
 44  4
         if (value == null) {
 45  1
             return null;
 46  
         }
 47  3
         value = value.trim();
 48  3
         if (value.length() < 1) {
 49  1
             return null;
 50  
         }
 51  
         try {
 52  2
             return Byte.valueOf(value);
 53  1
         } catch (Exception e) {
 54  1
             Object[] args = ConvertUtil.createExceptionMessageArgs(component,
 55  
                     value);
 56  1
             throw new ConverterException(FacesMessageUtil.getMessage(context,
 57  
                     getObjectMessageId(), args), e);
 58  
         }
 59  
     }
 60  
 
 61  
     public String getAsString(FacesContext context, UIComponent component,
 62  
             Object value) throws ConverterException {
 63  6
         AssertionUtil.assertNotNull("FacesContext", context);
 64  5
         AssertionUtil.assertNotNull("UIComponent", component);
 65  4
         if (value == null) {
 66  1
             return "";
 67  
         }
 68  
         try {
 69  3
             return (value instanceof String) ? (String) value : Byte
 70  
                     .toString(((Byte) value).byteValue());
 71  1
         } catch (Exception e) {
 72  1
             Object[] args = ConvertUtil.createExceptionMessageArgs(component,
 73  
                     value);
 74  1
             throw new ConverterException(FacesMessageUtil.getMessage(context,
 75  
                     getStringMessageId(), args), e);
 76  
         }
 77  
     }
 78  
 
 79  
     protected String getObjectMessageId() {
 80  1
         return CONVERSION_OBJECT_ID;
 81  
     }
 82  
 
 83  
     protected String getStringMessageId() {
 84  1
         return CONVERSION_STRING_ID;
 85  
     }
 86  
 
 87  
 }