Coverage Report - org.seasar.teeda.core.util.UIValueUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
UIValueUtil
60%
9/15
60%
12/20
5
 
 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.util;
 17  
 
 18  
 import java.lang.reflect.Array;
 19  
 import java.util.List;
 20  
 
 21  
 import javax.faces.FacesException;
 22  
 import javax.faces.component.UIComponent;
 23  
 import javax.faces.context.FacesContext;
 24  
 import javax.faces.convert.Converter;
 25  
 
 26  
 import org.seasar.framework.log.Logger;
 27  
 
 28  
 /**
 29  
  * @author manhole
 30  
  */
 31  0
 public class UIValueUtil {
 32  
 
 33  2
     private static Logger logger_ = Logger.getLogger(UIValueUtil.class);
 34  
 
 35  
     public static String getValueAsString(FacesContext context,
 36  
             UIComponent component, Object value, Converter converter) {
 37  273
         if (converter == null && value != null) {
 38  208
             if (value instanceof String) {
 39  208
                 return (String) value;
 40  
             }
 41  
             try {
 42  0
                 converter = context.getApplication().createConverter(
 43  
                         value.getClass());
 44  0
             } catch (FacesException ex) {
 45  0
                 logger_.log(ex);
 46  0
             }
 47  
         }
 48  65
         if (converter == null) {
 49  61
             if (value == null) {
 50  61
                 return "";
 51  
             }
 52  0
             return value.toString();
 53  
         }
 54  4
         return converter.getAsString(context, component, value);
 55  
     }
 56  
 
 57  
     public static final boolean isManyEmpty(Object value) {
 58  3
         return value == null
 59  
                 || (value.getClass().isArray() && Array.getLength(value) == 0)
 60  
                 || ((value instanceof List) && ((List) value).isEmpty());
 61  
     }
 62  
 
 63  
 }