Coverage Report - org.kuali.rice.kew.ojb.IdentityTypeConversion
 
Classes in this File Line Coverage Branch Coverage Complexity
IdentityTypeConversion
0%
0/15
0%
0/10
6.5
 
 1  
 /*
 2  
  * Copyright 2005-2008 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.kew.ojb;
 18  
 
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 import org.apache.ojb.broker.accesslayer.conversions.ConversionException;
 21  
 import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
 22  
 import org.kuali.rice.kew.identity.IdentityType;
 23  
 
 24  
 /**
 25  
  *
 26  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 27  
  */
 28  0
 public class IdentityTypeConversion implements FieldConversion {
 29  
 
 30  
         public Object javaToSql(Object object) throws ConversionException {
 31  0
                 if (object instanceof IdentityType) {
 32  0
                         return ((IdentityType)object).getCode();
 33  
                 }
 34  0
                 return object;
 35  
         }
 36  
 
 37  
         public Object sqlToJava(Object object) throws ConversionException {
 38  0
                 if (object == null) {
 39  0
                         return null;
 40  
                 }
 41  0
                 if (object instanceof String) {
 42  0
                         String code = (String)object;
 43  0
                         if (StringUtils.isBlank(code)) {
 44  0
                                 return null;
 45  
                         }
 46  0
                         IdentityType type = IdentityType.fromCode(code);
 47  0
                         if (type == null) {
 48  0
                                 throw new ConversionException("Could not convert from code '" + code + "' to IdentityType.");
 49  
                         }
 50  0
                         return type;
 51  
                 }
 52  0
                 throw new ConversionException("Invalid incoming object type for conversion to IdentityType: " + object.getClass());
 53  
         }
 54  
 
 55  
 }