View Javadoc

1   /**
2    * Copyright 2004-2013 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.kfs.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       */
35      @Override
36      public Object javaToSql(Object source) {
37          Object sqlValue = super.javaToSql(source);
38  
39          if(INDICATOR_NO.equals(sqlValue)) {
40              return INDICATOR_YES;
41          }
42          else if(INDICATOR_YES.equals(sqlValue)) {
43              return INDICATOR_NO;
44          }
45  
46          return sqlValue;
47      }
48  
49      /**
50       * This handles checking the sql coming back from the database and converting 
51       * it to the appropriate boolean true or false value.
52       */
53      @Override
54      public Object sqlToJava(Object source) {
55          Object javaValue = super.sqlToJava(source);
56  
57          if(javaValue == null) {
58              return null;
59          }
60          else if(Boolean.TRUE.equals(javaValue)) {
61              return Boolean.FALSE;
62          }
63          else if(Boolean.FALSE.equals(javaValue)) {
64              return Boolean.TRUE;
65          }
66  
67          return javaValue;
68      }
69  }