01: /*
02: * Copyright 2006-2007 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: * This class converts the "A" or "I" value from the database into a true or false in Java.
22: *
23: *
24: */
25: public class OjbCharBooleanFieldAIConversion implements FieldConversion {
26: private static final String TRUE = "A";
27: private static final String FALSE = "I";
28:
29: /**
30: * @see org.apache.ojb.broker.accesslayer.conversions.FieldConversion#javaToSql(java.lang.Object)
31: */
32: public Object javaToSql(Object source) {
33: if (source instanceof Boolean) {
34: if (source.equals(Boolean.TRUE)) {
35: return TRUE;
36: } else {
37: return FALSE;
38: }
39: } else if (source instanceof String) {
40: if ("Y".equalsIgnoreCase((String) source)) {
41: return TRUE;
42: } else if ("N".equalsIgnoreCase((String) source)) {
43: return FALSE;
44: }
45: }
46: return source;
47: }
48:
49: /**
50: * @see org.apache.ojb.broker.accesslayer.conversions.FieldConversion#sqlToJava(java.lang.Object)
51: */
52: public Object sqlToJava(Object source) {
53: if (source instanceof String) {
54: if (TRUE.equals(source)) {
55: return Boolean.TRUE;
56: } else {
57: return Boolean.FALSE;
58: }
59: } else {
60: return source;
61: }
62: }
63:
64: }
|