Coverage Report - org.kuali.rice.core.framework.persistence.ojb.conversion.OjbKualiPercentFieldConversion
 
Classes in this File Line Coverage Branch Coverage Complexity
OjbKualiPercentFieldConversion
0%
0/10
0%
0/6
3
 
 1  
 /**
 2  
  * Copyright 2005-2011 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  
 import org.kuali.rice.core.api.util.type.KualiPercent;
 20  
 
 21  
 import java.math.BigDecimal;
 22  
 
 23  
 /**
 24  
  * Creates a KualiPercent object from the data field. Field is stored as a percentage.
 25  
  * 
 26  
  * 
 27  
  */
 28  0
 public class OjbKualiPercentFieldConversion implements FieldConversion {
 29  
 
 30  
     /**
 31  
      * @see FieldConversion#javaToSql(Object)
 32  
      */
 33  
     public Object javaToSql(Object source) {
 34  0
         Object converted = source;
 35  
 
 36  0
         if (source instanceof KualiPercent) {
 37  0
             converted = ((KualiPercent) source).bigDecimalValue();
 38  
         }
 39  
 
 40  0
         return converted;
 41  
     }
 42  
 
 43  
     /**
 44  
      * @see FieldConversion#sqlToJava(Object)
 45  
      */
 46  
     public Object sqlToJava(Object source) {
 47  
 
 48  
         // Check for null, and verify object type.
 49  
         // Do conversion if our type is correct (BigDecimal).
 50  0
         if (source != null && source instanceof BigDecimal) {
 51  0
             BigDecimal converted = (BigDecimal) source;
 52  
 
 53  
             // Once we have converted, we need to convert again to KualiPercent.
 54  0
             KualiPercent percentConverted = new KualiPercent((BigDecimal) converted);
 55  
 
 56  0
             return percentConverted;
 57  
 
 58  
         }
 59  
         else {
 60  0
             return null;
 61  
         }
 62  
     }
 63  
 }