1 /*
2 * Copyright 2006-2008 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
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.ole.sys.dataaccess;
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 }
37 else {
38 return FALSE;
39 }
40 }
41 else if (source instanceof String) {
42 if ("Y".equalsIgnoreCase((String)source)) {
43 return TRUE;
44 }
45 else if ("N".equalsIgnoreCase((String)source)) {
46 return FALSE;
47 }
48 }
49 return source;
50 }
51
52 /**
53 * @see org.apache.ojb.broker.accesslayer.conversions.FieldConversion#sqlToJava(java.lang.Object)
54 */
55 public Object sqlToJava(Object source) {
56 if (source instanceof String) {
57 if (TRUE.equals(source)) {
58 return Boolean.TRUE;
59 }
60 else {
61 return Boolean.FALSE;
62 }
63 }
64 else {
65 return source;
66 }
67 }
68
69 }