1 16 package org.directwebremoting.convert; 17 18 import org.directwebremoting.dwrp.SimpleOutboundVariable; 19 import org.directwebremoting.extend.Converter; 20 import org.directwebremoting.extend.InboundContext; 21 import org.directwebremoting.extend.InboundVariable; 22 import org.directwebremoting.extend.MarshallException; 23 import org.directwebremoting.extend.OutboundContext; 24 import org.directwebremoting.extend.OutboundVariable; 25 import org.directwebremoting.util.JavascriptUtil; 26 import org.directwebremoting.util.LocalUtil; 27 import org.directwebremoting.util.Messages; 28 29 33 public class PrimitiveConverter extends BaseV20Converter implements Converter 34 { 35 38 public Object convertInbound(Class paramType, InboundVariable iv, InboundContext inctx) throws MarshallException 39 { 40 String value = iv.getValue(); 41 value = LocalUtil.decode(value.trim()); 42 43 try 44 { 45 return LocalUtil.simpleConvert(value, paramType); 46 } 47 catch (NumberFormatException ex) 48 { 49 throw new MarshallException(paramType, Messages.getString("PrimitiveConverter.FormatError", value)); 50 } 51 catch (IllegalArgumentException ex) 52 { 53 throw new MarshallException(paramType); 54 } 55 } 56 57 60 public OutboundVariable convertOutbound(Object object, OutboundContext outctx) 61 { 62 Class paramType = object.getClass(); 63 64 if (object.equals(Boolean.TRUE)) 65 { 66 return new SimpleOutboundVariable("true", outctx, true); 67 } 68 else if (object.equals(Boolean.FALSE)) 69 { 70 return new SimpleOutboundVariable("false", outctx, true); 71 } 72 else if (paramType == Character .class) 73 { 74 return new SimpleOutboundVariable('\"' + JavascriptUtil.escapeJavaScript(object.toString()) + '\"', outctx, true); 76 } 77 else 78 { 79 return new SimpleOutboundVariable(object.toString(), outctx, true); 81 } 82 } 83 } 84
| Popular Tags
|