1 16 package org.directwebremoting.convert; 17 18 import java.math.BigDecimal ; 19 import java.math.BigInteger ; 20 21 import org.directwebremoting.dwrp.SimpleOutboundVariable; 22 import org.directwebremoting.extend.Converter; 23 import org.directwebremoting.extend.InboundContext; 24 import org.directwebremoting.extend.InboundVariable; 25 import org.directwebremoting.extend.MarshallException; 26 import org.directwebremoting.extend.OutboundContext; 27 import org.directwebremoting.extend.OutboundVariable; 28 import org.directwebremoting.util.Messages; 29 30 34 public class BigNumberConverter extends BaseV20Converter implements Converter 35 { 36 39 public Object convertInbound(Class paramType, InboundVariable iv, InboundContext inctx) throws MarshallException 40 { 41 String value = iv.getValue(); 42 43 if (value == null || value.length() == 0) 44 { 45 return null; 46 } 47 48 try 49 { 50 if (paramType == BigDecimal .class) 51 { 52 return new BigDecimal (value.trim()); 53 } 54 55 if (paramType == BigInteger .class) 56 { 57 return new BigInteger (value.trim()); 58 } 59 60 throw new MarshallException(paramType); 61 } 62 catch (NumberFormatException ex) 63 { 64 throw new MarshallException(paramType, Messages.getString("BigNumberConverter.FormatError", value)); 65 } 66 } 67 68 71 public OutboundVariable convertOutbound(Object object, OutboundContext outctx) 72 { 73 if (object == null) 74 { 75 return new SimpleOutboundVariable("null", outctx, true); 76 } 77 78 return new SimpleOutboundVariable(object.toString(), outctx, true); 79 } 80 } 81
| Popular Tags
|