1 /*
2 * Copyright 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.coa.util;
17
18 import org.kuali.rice.core.framework.persistence.ojb.conversion.OjbCharBooleanConversion;
19
20 /**
21 * This implementation is used to do two conversions on the account closed indicator
22 * 1) convert the closed indicator into the active indicator
23 * 2) convert the indicator as an approperite type
24 */
25 public class OjbAccountActiveIndicatorConversion extends OjbCharBooleanConversion {
26 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OjbAccountActiveIndicatorConversion.class);
27
28 public final static String INDICATOR_NO = "N";
29 public final static String INDICATOR_YES = "Y";
30
31 /**
32 * This handles checking the boolean value coming in and converts it to
33 * the appropriate Y or N value.
34 * @see FieldConversion#javaToSql(Object)
35 */
36 @Override
37 public Object javaToSql(Object source) {
38 Object sqlValue = super.javaToSql(source);
39
40 if(INDICATOR_NO.equals(sqlValue)) {
41 return INDICATOR_YES;
42 }
43 else if(INDICATOR_YES.equals(sqlValue)) {
44 return INDICATOR_NO;
45 }
46
47 return sqlValue;
48 }
49
50 /**
51 * This handles checking the sql coming back from the database and converting
52 * it to the appropriate boolean true or false value.
53 * @see FieldConversion#sqlToJava(Object)
54 */
55 @Override
56 public Object sqlToJava(Object source) {
57 Object javaValue = super.sqlToJava(source);
58
59 if(javaValue == null) {
60 return null;
61 }
62 else if(Boolean.TRUE.equals(javaValue)) {
63 return Boolean.FALSE;
64 }
65 else if(Boolean.FALSE.equals(javaValue)) {
66 return Boolean.TRUE;
67 }
68
69 return javaValue;
70 }
71 }