Ignore:
Timestamp:
08/14/10 15:10:12 (22 months ago)
Author:
kasper
Message:

Made it possible to configure jobs using "configurable bean" acting as a prototype for actual executed beans

File:
1 edited

Legend:

Unmodified
Added
Removed
  • AnalyzerBeans/trunk/src/main/java/org/eobjects/analyzer/job/AbstractBeanJobBuilder.java

    r975 r976  
    55import java.util.HashMap; 
    66import java.util.Map; 
     7import java.util.Set; 
    78 
    89import org.eobjects.analyzer.descriptors.BeanDescriptor; 
    910import org.eobjects.analyzer.descriptors.ConfiguredPropertyDescriptor; 
    1011import org.eobjects.analyzer.util.ReflectionUtils; 
     12import org.slf4j.Logger; 
     13import org.slf4j.LoggerFactory; 
    1114 
    1215@SuppressWarnings("unchecked") 
    1316class AbstractBeanJobBuilder<D extends BeanDescriptor<E>, E, B> { 
    1417 
    15         private Map<ConfiguredPropertyDescriptor, Object> _properties = new HashMap<ConfiguredPropertyDescriptor, Object>(); 
     18        private final Logger logger = LoggerFactory.getLogger(getClass()); 
     19 
    1620        private D _descriptor; 
     21        private E _configurableBean; 
    1722 
    1823        public AbstractBeanJobBuilder(D descriptor, Class<?> builderClass) { 
     24                if (descriptor == null) { 
     25                        throw new IllegalArgumentException("descriptor cannot be null"); 
     26                } 
     27                if (builderClass == null) { 
     28                        throw new IllegalArgumentException("builderClass cannot be null"); 
     29                } 
    1930                _descriptor = descriptor; 
    2031                if (!ReflectionUtils.is(getClass(), builderClass)) { 
    2132                        throw new IllegalArgumentException( 
    2233                                        "Builder class does not correspond to actual class of builder"); 
     34                } 
     35                try { 
     36                        _configurableBean = _descriptor.getBeanClass().newInstance(); 
     37                } catch (Exception e) { 
     38                        throw new IllegalArgumentException( 
     39                                        "Could not instantiate bean class: " 
     40                                                        + _descriptor.getBeanClass(), e); 
    2341                } 
    2442        } 
     
    2846        } 
    2947 
     48        public E getConfigurableBean() { 
     49                return _configurableBean; 
     50        } 
     51 
    3052        public boolean isConfigured() { 
    3153                for (ConfiguredPropertyDescriptor configuredProperty : _descriptor 
    3254                                .getConfiguredProperties()) { 
    33                         if (!getConfiguredProperties().containsKey(configuredProperty)) { 
    34                                 return false; 
     55                        if (configuredProperty.isRequired()) { 
     56                                if (!getConfiguredProperties().containsKey(configuredProperty)) { 
     57                                        logger.debug("Configured property is not set: " 
     58                                                        + configuredProperty); 
     59                                        return false; 
     60                                } 
    3561                        } 
    3662                } 
     
    86112                        } 
    87113                } 
    88                 _properties.put(configuredProperty, value); 
     114 
     115                configuredProperty.setValue(_configurableBean, value); 
    89116                return (B) this; 
    90117        } 
    91118 
    92119        public Map<ConfiguredPropertyDescriptor, Object> getConfiguredProperties() { 
    93                 return Collections.unmodifiableMap(_properties); 
     120                Map<ConfiguredPropertyDescriptor, Object> map = new HashMap<ConfiguredPropertyDescriptor, Object>(); 
     121                Set<ConfiguredPropertyDescriptor> configuredProperties = getDescriptor() 
     122                                .getConfiguredProperties(); 
     123                for (ConfiguredPropertyDescriptor propertyDescriptor : configuredProperties) { 
     124                        Object value = propertyDescriptor.getValue(getConfigurableBean()); 
     125                        if (value != null) { 
     126                                map.put(propertyDescriptor, value); 
     127                        } 
     128                } 
     129                return Collections.unmodifiableMap(map); 
    94130        } 
    95131} 
Note: See TracChangeset for help on using the changeset viewer.