1 16 package org.directwebremoting.convert; 17 18 import java.lang.reflect.Method ; 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.MarshallException; 25 import org.directwebremoting.extend.OutboundContext; 26 import org.directwebremoting.extend.OutboundVariable; 27 import org.directwebremoting.util.LocalUtil; 28 29 33 public class EnumConverter extends BaseV20Converter implements Converter 34 { 35 38 public Object convertInbound(Class paramType, InboundVariable iv, InboundContext inctx) throws MarshallException 39 { 40 String value = LocalUtil.decode(iv.getValue()); 41 42 Object [] values; 43 try 44 { 45 Method getter = paramType.getMethod("values", new Class [0]); 46 values = (Object []) getter.invoke(paramType, (Object []) null); 47 } 48 catch (NoSuchMethodException ex) 49 { 50 throw new MarshallException(paramType); 53 } 54 catch (Exception ex) 55 { 56 throw new MarshallException(paramType, ex); 57 } 58 59 for (int i = 0; i < values.length; i++) 60 { 61 Object en = values[i]; 62 if (value.equals(en.toString())) 63 { 64 return en; 65 } 66 } 67 68 throw new MarshallException(paramType); 69 } 70 71 74 public OutboundVariable convertOutbound(Object object, OutboundContext outctx) 75 { 76 return new SimpleOutboundVariable('\'' + object.toString() + '\'', outctx, true); 77 } 78 } 79
| Popular Tags
|