| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 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 | |
|
| 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 | |
} |