Coverage Report - org.kuali.rice.core.framework.persistence.ojb.conversion.OjbCharBooleanConversionBase
 
Classes in this File Line Coverage Branch Coverage Complexity
OjbCharBooleanConversionBase
0%
0/15
0%
0/16
3.25
 
 1  
 /*
 2  
  * Copyright 2005-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  0
 public abstract class OjbCharBooleanConversionBase implements FieldConversion {
 21  
 
 22  
     protected abstract String getTrueValue();
 23  
 
 24  
     protected abstract String getFalseValue();
 25  
 
 26  
 
 27  
     /**
 28  
      * @see FieldConversion#javaToSql(Object)
 29  
      */
 30  
     public Object javaToSql(Object source) {
 31  0
         Object result = source;
 32  0
         if (source instanceof Boolean) {
 33  0
             if (source != null) {
 34  0
                 Boolean b = (Boolean) source;
 35  0
                 result = b.booleanValue() ? getTrueValue() : getFalseValue();
 36  
             }
 37  
         }
 38  0
         return result;
 39  
     }
 40  
 
 41  
     /**
 42  
      * @see FieldConversion#sqlToJava(Object)
 43  
      */
 44  
     public Object sqlToJava(Object source) {
 45  0
         Object result = source;
 46  0
         if (source instanceof String) {
 47  0
             if (source != null) {
 48  0
                 String s = (String) source;
 49  0
                 result = getTrueValue().equals(s) ? Boolean.TRUE : getFalseValue().equals(s) ? Boolean.FALSE : null;
 50  0
                 if (result == null) {
 51  0
                     throw new RuntimeException("Expected '" + getTrueValue() + "' or '" + getFalseValue() + "' but saw '" + source + "'");
 52  
                 }
 53  
             }
 54  
         }
 55  0
         return result;
 56  
     }
 57  
 
 58  
 }