001/**
002 * Copyright 2005-2018 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 */
016package org.kuali.rice.core.framework.persistence.ojb.conversion;
017
018import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
019
020/**
021 * This class originates from a similar class in the Kuali Financial System and has been adapted from 
022 * that original state which was originally authored by the Kuali Nervous System team.
023 * 
024 * For records in the KEW tables, "0" and "1" are used to represent "false" and "true"
025 * respectively which is the standard way to represent these values in OJB.
026 * This differs from other pieces of the KNS where "N" and "Y" are used.
027 * 
028 * @author Kuali Rice Team (rice.collab@kuali.org)
029 */
030public class OjbCharBooleanConversion3 implements FieldConversion {
031    
032        /**
033     * This handles checking any incoming String value and converts them
034     * to the appropriate Boolean value. 
035     * @see FieldConversion#javaToSql(Object)
036     */
037    public Object javaToSql(Object source) {
038        if (source instanceof String) {
039            if ("Y".equals(source)) {
040                return Boolean.TRUE;
041            }
042            else if ("N".equals(source)) {
043                return Boolean.FALSE;
044            }
045        }
046        return source;
047    }
048
049    public Object sqlToJava(Object source) {
050        return source;
051    }
052}