Coverage Report - org.kuali.rice.core.framework.persistence.ojb.conversion.OjbCharBooleanConversion2
 
Classes in this File Line Coverage Branch Coverage Complexity
OjbCharBooleanConversion2
0%
0/21
0%
0/16
9.5
 
 1  
 /*
 2  
  * Copyright 2007-2008 The Kuali Foundation
 3  
  * 
 4  
  * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
 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, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.core.framework.persistence.ojb.conversion;
 17  
 
 18  
 import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
 19  
 
 20  
 /**
 21  
  * This class originates from a similar class in the Kuali Financial System and has been adapted from 
 22  
  * that original state which was originally authored by the Kuali Nervous System team.
 23  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 24  
  */
 25  0
 public class OjbCharBooleanConversion2 implements FieldConversion {
 26  
     /**
 27  
      * This handles checking the boolean value coming in and converts it to 
 28  
      * the appropriate Y or N value.
 29  
      * @see FieldConversion#javaToSql(Object)
 30  
      */
 31  
     public Object javaToSql(Object source) {
 32  0
         if (source instanceof Boolean) {
 33  0
             if (source != null) {
 34  0
                 Boolean b = (Boolean) source;
 35  0
                 return b.booleanValue() ? "Y" : "N";
 36  
             }
 37  
             else {
 38  0
                 return null;
 39  
             }
 40  
         }
 41  0
         else if (source instanceof String) {
 42  0
             if ("true".equals(source)) {
 43  0
                 return "Y";
 44  
             }
 45  0
             else if ("false".equals(source)) {
 46  0
                 return "N";
 47  
             }
 48  
         }
 49  0
         return source;
 50  
     }
 51  
 
 52  
     /**
 53  
      * This handles checking the sql coming back from the database and converting 
 54  
      * it to the appropriate boolean true or false value.
 55  
      * @see FieldConversion#sqlToJava(Object)
 56  
      */
 57  
     public Object sqlToJava(Object source) {
 58  
         try {
 59  0
             if (source instanceof String) {
 60  0
                 if (source != null) {
 61  0
                     String s = (String) source;
 62  0
                     return Boolean.valueOf("YT1".contains(s));
 63  
                 }
 64  
                 else {
 65  0
                     return null;
 66  
                 }
 67  
             }
 68  0
             return source;
 69  
         }
 70  0
         catch (Throwable t) {
 71  0
             t.printStackTrace();
 72  0
             throw new RuntimeException("I have exploded converting types", t);
 73  
         }
 74  
     }
 75  
 }