Changeset 976 for AnalyzerBeans/trunk/src/main/java/org/eobjects/analyzer/job/AbstractBeanJobBuilder.java
- Timestamp:
- 08/14/10 15:10:12 (22 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
AnalyzerBeans/trunk/src/main/java/org/eobjects/analyzer/job/AbstractBeanJobBuilder.java
r975 r976 5 5 import java.util.HashMap; 6 6 import java.util.Map; 7 import java.util.Set; 7 8 8 9 import org.eobjects.analyzer.descriptors.BeanDescriptor; 9 10 import org.eobjects.analyzer.descriptors.ConfiguredPropertyDescriptor; 10 11 import org.eobjects.analyzer.util.ReflectionUtils; 12 import org.slf4j.Logger; 13 import org.slf4j.LoggerFactory; 11 14 12 15 @SuppressWarnings("unchecked") 13 16 class AbstractBeanJobBuilder<D extends BeanDescriptor<E>, E, B> { 14 17 15 private Map<ConfiguredPropertyDescriptor, Object> _properties = new HashMap<ConfiguredPropertyDescriptor, Object>(); 18 private final Logger logger = LoggerFactory.getLogger(getClass()); 19 16 20 private D _descriptor; 21 private E _configurableBean; 17 22 18 23 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 } 19 30 _descriptor = descriptor; 20 31 if (!ReflectionUtils.is(getClass(), builderClass)) { 21 32 throw new IllegalArgumentException( 22 33 "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); 23 41 } 24 42 } … … 28 46 } 29 47 48 public E getConfigurableBean() { 49 return _configurableBean; 50 } 51 30 52 public boolean isConfigured() { 31 53 for (ConfiguredPropertyDescriptor configuredProperty : _descriptor 32 54 .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 } 35 61 } 36 62 } … … 86 112 } 87 113 } 88 _properties.put(configuredProperty, value); 114 115 configuredProperty.setValue(_configurableBean, value); 89 116 return (B) this; 90 117 } 91 118 92 119 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); 94 130 } 95 131 }
Note: See TracChangeset
for help on using the changeset viewer.
