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.sys;
017
018 import org.kuali.rice.kns.util.KualiDecimal;
019 import org.kuali.rice.kns.util.KualiInteger;
020
021 import uk.ltd.getahead.dwr.ConversionException;
022 import uk.ltd.getahead.dwr.Converter;
023 import uk.ltd.getahead.dwr.ConverterManager;
024 import uk.ltd.getahead.dwr.InboundContext;
025 import uk.ltd.getahead.dwr.InboundVariable;
026 import uk.ltd.getahead.dwr.Messages;
027 import uk.ltd.getahead.dwr.OutboundContext;
028 import uk.ltd.getahead.dwr.compat.BaseV10Converter;
029
030 /**
031 * Converter for all Kuali Numbers (KualiDecimal & KualiInteger)
032 *
033 * @see org.kuali.rice.kns.util.KualiDecimal
034 * @see org.kuali.rice.kns.util.KualiInteger
035 */
036 public class KualiNumberConverter extends BaseV10Converter implements Converter {
037 /**
038 * @see uk.ltd.getahead.dwr.Converter#init(uk.ltd.getahead.dwr.DefaultConfiguration)
039 */
040 public void setConverterManager(ConverterManager config) {
041 }
042
043 /**
044 * @see uk.ltd.getahead.dwr.Converter#convertInbound(java.lang.Class, java.util.List, uk.ltd.getahead.dwr.InboundVariable,
045 * uk.ltd.getahead.dwr.InboundContext)
046 */
047 public Object convertInbound(Class paramType, InboundVariable iv, InboundContext inctx) throws ConversionException {
048 String value = iv.getValue();
049 try {
050 if (paramType == KualiDecimal.class) {
051 return new KualiDecimal(value.trim());
052 }
053
054 if (paramType == KualiInteger.class) {
055 return new KualiInteger(value.trim());
056 }
057
058 throw new ConversionException(Messages.getString("BigNumberConverter.NonPrimitive", paramType.getName())); //$NON-NLS-1$
059 }
060 catch (NumberFormatException ex) {
061 throw new ConversionException(Messages.getString("BigNumberConverter.FormatError", value, paramType.getName()), ex); //$NON-NLS-1$
062 }
063 }
064
065 /*
066 * (non-Javadoc)
067 *
068 * @see uk.ltd.getahead.dwr.Converter#convertOutbound(java.lang.Object, java.lang.String, uk.ltd.getahead.dwr.OutboundContext)
069 */
070 public String convertOutbound(Object object, String varname, OutboundContext outctx) {
071 return "var " + varname + "=" + object.toString() + ';'; //$NON-NLS-1$ //$NON-NLS-2$
072 }
073 }