1 16 package org.directwebremoting.convert; 17 18 import java.beans.BeanInfo ; 19 import java.beans.IntrospectionException ; 20 import java.beans.Introspector ; 21 import java.beans.PropertyDescriptor ; 22 import java.util.HashMap ; 23 import java.util.Map ; 24 25 import org.directwebremoting.extend.Converter; 26 import org.directwebremoting.extend.InboundContext; 27 import org.directwebremoting.extend.MarshallException; 28 import org.directwebremoting.extend.Property; 29 import org.directwebremoting.extend.TypeHintContext; 30 import org.directwebremoting.impl.PropertyDescriptorProperty; 31 32 36 public class BeanConverter extends BasicObjectConverter implements Converter 37 { 38 41 public Map getPropertyMapFromObject(Object example, boolean readRequired, boolean writeRequired) throws MarshallException 42 { 43 return getPropertyMapFromClass(example.getClass(), readRequired, writeRequired); 44 } 45 46 49 public Map getPropertyMapFromClass(Class type, boolean readRequired, boolean writeRequired) throws MarshallException 50 { 51 try 52 { 53 BeanInfo info = Introspector.getBeanInfo(type); 54 PropertyDescriptor [] descriptors = info.getPropertyDescriptors(); 55 56 Map properties = new HashMap (); 57 for (int i = 0; i < descriptors.length; i++) 58 { 59 PropertyDescriptor descriptor = descriptors[i]; 60 String name = descriptor.getName(); 61 62 if (name.equals("class")) 64 { 65 continue; 66 } 67 68 if (!isAllowedByIncludeExcludeRules(name)) 70 { 71 continue; 72 } 73 74 if (readRequired && descriptor.getReadMethod() == null) 75 { 76 continue; 77 } 78 79 if (writeRequired && descriptor.getWriteMethod() == null) 80 { 81 continue; 82 } 83 84 properties.put(name, new PropertyDescriptorProperty(descriptor)); 85 } 86 87 return properties; 88 } 89 catch (IntrospectionException ex) 90 { 91 throw new MarshallException(type, ex); 92 } 93 } 94 95 98 protected TypeHintContext createTypeHintContext(InboundContext inctx, Property property) 99 { 100 return new TypeHintContext(converterManager, property.getSetter(), 0); 101 } 102 } 103 | Popular Tags |