View Javadoc
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.sys;
17  
18  import org.directwebremoting.ConversionException;
19  import org.directwebremoting.extend.Converter;
20  import org.directwebremoting.extend.ConverterManager;
21  import org.directwebremoting.extend.InboundVariable;
22  import org.directwebremoting.extend.OutboundContext;
23  import org.kuali.rice.core.api.util.type.KualiDecimal;
24  import org.kuali.rice.core.api.util.type.KualiInteger;
25  
26  import uk.ltd.getahead.dwr.compat.BaseV10Converter;
27  
28  /**
29   * Converter for all Kuali Numbers (KualiDecimal & KualiInteger)
30   * 
31   * @see org.kuali.rice.core.api.util.type.KualiDecimal
32   * @see org.kuali.rice.core.api.util.type.KualiInteger
33   */
34  public class KualiNumberConverter extends BaseV10Converter implements Converter {
35      /**
36       * @see uk.ltd.getahead.dwr.Converter#init(uk.ltd.getahead.dwr.DefaultConfiguration)
37       */
38      public void setConverterManager(ConverterManager config) {
39      }
40  
41      /**
42       * @see uk.ltd.getahead.dwr.Converter#convertInbound(java.lang.Class, java.util.List, uk.ltd.getahead.dwr.InboundVariable,
43       *      uk.ltd.getahead.dwr.InboundContext)
44       */
45      public Object convertInbound(Class paramType, InboundVariable iv) throws ConversionException {
46          String value = iv.getValue();
47          try {
48              if (paramType == KualiDecimal.class) {
49                  return new KualiDecimal(value.trim());
50              }
51  
52              if (paramType == KualiInteger.class) {
53                  return new KualiInteger(value.trim());
54              }
55              String message = MessageBuilder.buildMessage("BigNumberConverter.NonPrimitive", paramType.getName()).getMessage();
56              throw new ConversionException(paramType,message);
57          }
58          catch (NumberFormatException ex) {
59              String message = MessageBuilder.buildMessage("BigNumberConverter.FormatError", paramType.getName()).getMessage();
60              throw new ConversionException(paramType, message, ex);
61          }
62      }
63  
64      /*
65       * (non-Javadoc)
66       * 
67       * @see uk.ltd.getahead.dwr.Converter#convertOutbound(java.lang.Object, java.lang.String, uk.ltd.getahead.dwr.OutboundContext)
68       */
69      public String convertOutbound(Object object, String varname, OutboundContext outctx) {
70          return "var " + varname + "=" + object.toString() + ';'; //$NON-NLS-1$ //$NON-NLS-2$
71      }
72  }