001    /**
002     * Copyright 2004-2013 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.core.framework.persistence.ojb.conversion.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         */
035        @Override
036        public Object javaToSql(Object source) {
037            Object sqlValue = super.javaToSql(source);
038    
039            if(INDICATOR_NO.equals(sqlValue)) {
040                return INDICATOR_YES;
041            }
042            else if(INDICATOR_YES.equals(sqlValue)) {
043                return INDICATOR_NO;
044            }
045    
046            return sqlValue;
047        }
048    
049        /**
050         * This handles checking the sql coming back from the database and converting 
051         * it to the appropriate boolean true or false value.
052         */
053        @Override
054        public Object sqlToJava(Object source) {
055            Object javaValue = super.sqlToJava(source);
056    
057            if(javaValue == null) {
058                return null;
059            }
060            else if(Boolean.TRUE.equals(javaValue)) {
061                return Boolean.FALSE;
062            }
063            else if(Boolean.FALSE.equals(javaValue)) {
064                return Boolean.TRUE;
065            }
066    
067            return javaValue;
068        }
069    }