Coverage Report - org.seasar.teeda.core.convert.NullConverter
 
Classes in this File Line Coverage Branch Coverage Complexity
NullConverter
27%
6/22
50%
3/6
1.625
 
 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 org.seasar.teeda.core.convert;
 17  
 
 18  
 import javax.faces.component.StateHolder;
 19  
 import javax.faces.component.UIComponent;
 20  
 import javax.faces.context.FacesContext;
 21  
 import javax.faces.convert.Converter;
 22  
 import javax.faces.convert.ConverterException;
 23  
 
 24  
 /**
 25  
  * @author higa
 26  
  *
 27  
  */
 28  41
 public class NullConverter implements Converter, StateHolder {
 29  
 
 30  1
     private static final String[] DEFAULT_NULL_VALUES = new String[] { "", "on" };
 31  
 
 32  41
     private String[] nullValues = DEFAULT_NULL_VALUES;
 33  
 
 34  
     private boolean transientValue;
 35  
 
 36  
     public String[] getNullValues() {
 37  0
         return nullValues;
 38  
     }
 39  
 
 40  
     public void setNullValues(String[] nullValues) {
 41  0
         this.nullValues = nullValues;
 42  0
     }
 43  
 
 44  
     /**
 45  
      * @see javax.faces.convert.Converter#getAsObject(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.String)
 46  
      */
 47  
     public Object getAsObject(FacesContext context, UIComponent component,
 48  
             String value) throws ConverterException {
 49  
 
 50  3
         for (int i = 0; i < nullValues.length; ++i) {
 51  2
             if (nullValues[i].equalsIgnoreCase(value)) {
 52  0
                 return null;
 53  
             }
 54  
         }
 55  1
         return value;
 56  
     }
 57  
 
 58  
     /**
 59  
      * @see javax.faces.convert.Converter#getAsString(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.Object)
 60  
      */
 61  
     public String getAsString(FacesContext context, UIComponent component,
 62  
             Object value) throws ConverterException {
 63  
 
 64  0
         if (value == null) {
 65  0
             return "";
 66  
         }
 67  0
         return value.toString();
 68  
     }
 69  
 
 70  
     /**
 71  
      * @see javax.faces.component.StateHolder#saveState(javax.faces.context.FacesContext)
 72  
      */
 73  
     public Object saveState(FacesContext context) {
 74  0
         Object[] values = new Object[1];
 75  0
         values[0] = nullValues;
 76  0
         return values;
 77  
     }
 78  
 
 79  
     /**
 80  
      * @see javax.faces.component.StateHolder#restoreState(javax.faces.context.FacesContext, java.lang.Object)
 81  
      */
 82  
     public void restoreState(FacesContext context, Object state) {
 83  0
         Object[] values = (Object[]) state;
 84  0
         nullValues = (String[]) values[0];
 85  
 
 86  0
     }
 87  
 
 88  
     /**
 89  
      * @see javax.faces.component.StateHolder#isTransient()
 90  
      */
 91  
     public boolean isTransient() {
 92  0
         return transientValue;
 93  
     }
 94  
 
 95  
     /**
 96  
      * @see javax.faces.component.StateHolder#setTransient(boolean)
 97  
      */
 98  
     public void setTransient(boolean transientValue) {
 99  0
         this.transientValue = transientValue;
 100  0
     }
 101  
 
 102  
 }