Coverage Report - org.seasar.teeda.core.el.impl.commons.CoercionsUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
CoercionsUtil
44%
7/16
0%
0/2
2.333
 
 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.el.impl.commons;
 17  
 
 18  
 import javax.faces.el.EvaluationException;
 19  
 import javax.servlet.jsp.el.ELException;
 20  
 
 21  
 import org.apache.commons.el.Coercions;
 22  
 import org.apache.commons.el.Logger;
 23  
 
 24  
 /**
 25  
  * @author shot
 26  
  */
 27  
 public class CoercionsUtil {
 28  
 
 29  1
     private static final org.seasar.framework.log.Logger logger_ = org.seasar.framework.log.Logger
 30  1
             .getLogger(CoercionsUtil.class);
 31  
 
 32  0
     private CoercionsUtil() {
 33  0
     }
 34  
 
 35  
     public static Integer coerceToInteger(Object index) {
 36  13
         return coerceToInteger(index, CommonsElLogger.getLogger());
 37  
     }
 38  
 
 39  
     public static Integer coerceToInteger(Object index, Logger logger) {
 40  
         try {
 41  13
             return Coercions.coerceToInteger(index, logger);
 42  0
         } catch (ELException e) {
 43  0
             logger_.error(e + " occured at " + CoercionsUtil.class);
 44  0
             return null;
 45  
         }
 46  
     }
 47  
 
 48  
     public static boolean coerceToPrimitiveBoolean(Object value)
 49  
             throws EvaluationException {
 50  6
         return coerceToPrimitiveBoolean(value, CommonsElLogger.getLogger());
 51  
     }
 52  
 
 53  
     public static boolean coerceToPrimitiveBoolean(Object value, Logger logger)
 54  
             throws EvaluationException {
 55  
         try {
 56  6
             return Coercions.coerceToBoolean(value, logger).booleanValue();
 57  0
         } catch (ELException e) {
 58  0
             throw new EvaluationException(e);
 59  
         }
 60  
     }
 61  
 
 62  
     public static Object coerce(Object newValue, Class type)
 63  
             throws EvaluationException {
 64  
         try {
 65  6
             return Coercions
 66  
                     .coerce(newValue, type, CommonsElLogger.getLogger());
 67  0
         } catch (ELException e) {
 68  0
             throw new EvaluationException(e);
 69  
         }
 70  
     }
 71  
 
 72  
 }