1 16 package org.directwebremoting.impl; 17 18 import java.beans.PropertyDescriptor ; 19 import java.lang.reflect.InvocationTargetException ; 20 import java.lang.reflect.Method ; 21 22 import org.directwebremoting.extend.MarshallException; 23 import org.directwebremoting.extend.Property; 24 25 29 public class PropertyDescriptorProperty implements Property 30 { 31 34 public PropertyDescriptorProperty(PropertyDescriptor descriptor) 35 { 36 this.descriptor = descriptor; 37 } 38 39 42 public String getName() 43 { 44 return descriptor.getName(); 45 } 46 47 50 public Class getPropertyType() 51 { 52 return descriptor.getPropertyType(); 53 } 54 55 58 public Object getValue(Object bean) throws MarshallException 59 { 60 try 61 { 62 return descriptor.getReadMethod().invoke(bean, new Object [0]); 63 } 64 catch (InvocationTargetException ex) 65 { 66 throw new MarshallException(bean.getClass(), ex.getTargetException()); 67 } 68 catch (Exception ex) 69 { 70 throw new MarshallException(bean.getClass(), ex); 71 } 72 } 73 74 77 public void setValue(Object bean, Object value) throws MarshallException 78 { 79 try 80 { 81 descriptor.getWriteMethod().invoke(bean, new Object [] { value }); 82 } 83 catch (InvocationTargetException ex) 84 { 85 throw new MarshallException(bean.getClass(), ex.getTargetException()); 86 } 87 catch (Exception ex) 88 { 89 throw new MarshallException(bean.getClass(), ex); 90 } 91 } 92 93 96 public Method getSetter() 97 { 98 return descriptor.getWriteMethod(); 99 } 100 101 104 protected PropertyDescriptor descriptor; 105 } 106 | Popular Tags |