1 16 package org.directwebremoting.convert; 17 18 import java.lang.reflect.Constructor ; 19 20 import org.directwebremoting.dwrp.SimpleOutboundVariable; 21 import org.directwebremoting.extend.Converter; 22 import org.directwebremoting.extend.InboundContext; 23 import org.directwebremoting.extend.InboundVariable; 24 import org.directwebremoting.extend.OutboundContext; 25 import org.directwebremoting.extend.OutboundVariable; 26 import org.directwebremoting.util.JavascriptUtil; 27 28 33 public class ConstructorConverter extends BaseV20Converter implements Converter 34 { 35 38 public Object convertInbound(Class paramType, InboundVariable iv, InboundContext inctx) 39 { 40 try 41 { 42 Constructor converter = paramType.getConstructor(new Class [] { String .class }); 43 return converter.newInstance(new Object [] { iv.getValue() }); 44 } 45 catch (Exception ex) 46 { 47 throw new IllegalArgumentException (ex.toString()); 48 } 49 } 50 51 54 public OutboundVariable convertOutbound(Object data, OutboundContext outctx) 55 { 56 return new SimpleOutboundVariable('\'' + JavascriptUtil.escapeJavaScript(data.toString()) + '\'', outctx, true); 57 } 58 } 59 | Popular Tags |