001    package org.tynamo.descriptor;
002    
003    import org.apache.commons.beanutils.BeanUtils;
004    import org.tynamo.util.Utils;
005    
006    import java.beans.BeanInfo;
007    import java.beans.PropertyDescriptor;
008    import java.util.ArrayList;
009    import java.util.Collection;
010    
011    
012    public class PropertyDescriptorFactoryImpl implements PropertyDescriptorFactory
013    {
014    
015            private final Collection<String> propertyExcludes;
016    
017            public PropertyDescriptorFactoryImpl(Collection<String> propertyExcludes)
018            {
019                    this.propertyExcludes = propertyExcludes;
020            }
021    
022    
023            /**
024             * Build the set of property descriptors for this type
025             *
026             * @param beanType the aggregating class
027             * @param beanInfo the BeanInfo, already gathered
028             * @return
029             * @throws Exception
030             */
031            public ArrayList<TynamoPropertyDescriptor> buildPropertyDescriptors(Class beanType, BeanInfo beanInfo) throws Exception
032            {
033                    ArrayList<TynamoPropertyDescriptor> result = new ArrayList<TynamoPropertyDescriptor>();
034                    for (PropertyDescriptor beanPropDescriptor : beanInfo.getPropertyDescriptors())
035                    {
036                            if (!Utils.isExcluded(beanPropDescriptor.getName(), propertyExcludes))
037                            {
038                                    Class<?> propertyType = beanPropDescriptor.getPropertyType();
039                                    TynamoPropertyDescriptorImpl propDescriptor = new TynamoPropertyDescriptorImpl(beanType, propertyType);
040                                    BeanUtils.copyProperties(propDescriptor, beanPropDescriptor);
041                                    result.add(propDescriptor);
042                            }
043                    }
044                    return result;
045            }
046    }