001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.kfs.coa.util;
017
018 import org.kuali.rice.kns.util.OjbCharBooleanConversion;
019
020 /**
021 * This implementation is used to do two conversions on the account closed indicator
022 * 1) convert the closed indicator into the active indicator
023 * 2) convert the indicator as an approperite type
024 */
025 public class OjbAccountActiveIndicatorConversion extends OjbCharBooleanConversion {
026 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OjbAccountActiveIndicatorConversion.class);
027
028 public final static String INDICATOR_NO = "N";
029 public final static String INDICATOR_YES = "Y";
030
031 /**
032 * This handles checking the boolean value coming in and converts it to
033 * the appropriate Y or N value.
034 * @see FieldConversion#javaToSql(Object)
035 */
036 @Override
037 public Object javaToSql(Object source) {
038 Object sqlValue = super.javaToSql(source);
039
040 if(INDICATOR_NO.equals(sqlValue)) {
041 return INDICATOR_YES;
042 }
043 else if(INDICATOR_YES.equals(sqlValue)) {
044 return INDICATOR_NO;
045 }
046
047 return sqlValue;
048 }
049
050 /**
051 * This handles checking the sql coming back from the database and converting
052 * it to the appropriate boolean true or false value.
053 * @see FieldConversion#sqlToJava(Object)
054 */
055 @Override
056 public Object sqlToJava(Object source) {
057 Object javaValue = super.sqlToJava(source);
058
059 if(javaValue == null) {
060 return null;
061 }
062 else if(Boolean.TRUE.equals(javaValue)) {
063 return Boolean.FALSE;
064 }
065 else if(Boolean.FALSE.equals(javaValue)) {
066 return Boolean.TRUE;
067 }
068
069 return javaValue;
070 }
071 }