1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.core.util;
17
18 import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
19
20 public abstract class OjbCharBooleanFieldConversionBase implements FieldConversion {
21
22 protected abstract String getTrueValue();
23
24 protected abstract String getFalseValue();
25
26
27
28
29
30 public Object javaToSql(Object source) {
31 Object result = source;
32 if (source instanceof Boolean) {
33 if (source != null) {
34 Boolean b = (Boolean) source;
35 result = b.booleanValue() ? getTrueValue() : getFalseValue();
36 }
37 }
38 return result;
39 }
40
41
42
43
44 public Object sqlToJava(Object source) {
45 Object result = source;
46 if (source instanceof String) {
47 if (source != null) {
48 String s = (String) source;
49 result = getTrueValue().equals(s) ? Boolean.TRUE : getFalseValue().equals(s) ? Boolean.FALSE : null;
50 if (result == null) {
51 throw new RuntimeException("Expected '" + getTrueValue() + "' or '" + getFalseValue() + "' but saw '" + source + "'");
52 }
53 }
54 }
55 return result;
56 }
57
58 }