01: /*
02: * Copyright 2005-2006 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.core.util;
17:
18: import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
19:
20: /**
21: *
22: */
23: public class OjbCharBooleanConversion implements FieldConversion {
24:
25: /**
26: * @see FieldConversion#javaToSql(Object)
27: */
28: public Object javaToSql(Object source) {
29: if (source instanceof Boolean) {
30: if (source != null) {
31: Boolean b = (Boolean) source;
32: return b.booleanValue() ? "Y" : "N";
33: } else {
34: return null;
35: }
36: } else if (source instanceof String) {
37: if ("true".equals(source)) {
38: return "Y";
39: } else if ("false".equals(source)) {
40: return "N";
41: }
42: }
43: return source;
44: }
45:
46: /**
47: * @see FieldConversion#sqlToJava(Object)
48: */
49: public Object sqlToJava(Object source) {
50: try {
51: if (source instanceof String) {
52: if (source != null) {
53: String s = (String) source;
54: return Boolean.valueOf("YT1".indexOf(s) >= 0);
55: } else {
56: return null;
57: }
58: }
59: return source;
60: } catch (Throwable t) {
61: t.printStackTrace();
62: throw new RuntimeException(
63: "I have exploded converting types", t);
64: }
65: }
66:
67: }
|