Changeset 974
- Timestamp:
- 08/14/10 11:12:43 (18 months ago)
- Location:
- AnalyzerBeans/trunk/src
- Files:
-
- 15 edited
-
main/java/org/eobjects/analyzer/annotations/Configured.java (modified) (1 diff)
-
main/java/org/eobjects/analyzer/annotations/Provided.java (modified) (1 diff)
-
main/java/org/eobjects/analyzer/descriptors/AbstractBeanDescriptor.java (modified) (3 diffs)
-
main/java/org/eobjects/analyzer/descriptors/AbstractPropertyDescriptor.java (modified) (7 diffs)
-
main/java/org/eobjects/analyzer/descriptors/ConfiguredPropertyDescriptorImpl.java (modified) (2 diffs)
-
main/java/org/eobjects/analyzer/descriptors/PropertyDescriptor.java (modified) (2 diffs)
-
main/java/org/eobjects/analyzer/descriptors/ProvidedPropertyDescriptorImpl.java (modified) (2 diffs)
-
main/java/org/eobjects/analyzer/lifecycle/AssignConfiguredCallback.java (modified) (2 diffs)
-
main/java/org/eobjects/analyzer/lifecycle/AssignProvidedCallback.java (modified) (2 diffs)
-
test/java/org/eobjects/analyzer/beans/JoinMatcherTest.java (modified) (1 diff)
-
test/java/org/eobjects/analyzer/beans/ReferentialIntegrityValidatorTest.java (modified) (1 diff)
-
test/java/org/eobjects/analyzer/beans/mock/ExploringAnalyzerMock.java (modified) (2 diffs)
-
test/java/org/eobjects/analyzer/beans/mock/RowProcessingAnalyzerMock.java (modified) (2 diffs)
-
test/java/org/eobjects/analyzer/descriptors/AnnotationBasedAnalyzerBeanDescriptorTest.java (modified) (3 diffs)
-
test/java/org/eobjects/analyzer/descriptors/ProvidedPropertyDescriptorImplTest.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
AnalyzerBeans/trunk/src/main/java/org/eobjects/analyzer/annotations/Configured.java
r931 r974 38 38 */ 39 39 @Retention(RetentionPolicy.RUNTIME) 40 @Target({ ElementType. METHOD, ElementType.FIELD })40 @Target({ ElementType.FIELD }) 41 41 @Documented 42 42 @Inherited -
AnalyzerBeans/trunk/src/main/java/org/eobjects/analyzer/annotations/Provided.java
r900 r974 45 45 */ 46 46 @Retention(RetentionPolicy.RUNTIME) 47 @Target( { ElementType. METHOD, ElementType.FIELD })47 @Target( { ElementType.FIELD }) 48 48 @Documented 49 49 @Inherited -
AnalyzerBeans/trunk/src/main/java/org/eobjects/analyzer/descriptors/AbstractBeanDescriptor.java
r971 r974 52 52 Configured configuredAnnotation = field 53 53 .getAnnotation(Configured.class); 54 Provided providedAnnotation = field.getAnnotation(Provided.class); 55 56 if (configuredAnnotation != null && providedAnnotation != null) { 57 throw new DescriptorException( 58 "The field " 59 + field 60 + " is annotated with both @Configured and @Provided, which are mutually exclusive."); 61 } 62 54 63 if (configuredAnnotation != null) { 55 64 if (!field.isAnnotationPresent(Inject.class)) { … … 62 71 } 63 72 64 Provided providedAnnotation = field.getAnnotation(Provided.class);65 73 if (providedAnnotation != null) { 66 74 if (!field.isAnnotationPresent(Inject.class)) { … … 87 95 Method[] methods = beanClass.getDeclaredMethods(); 88 96 for (Method method : methods) { 89 Configured configuredAnnotation = method90 .getAnnotation(Configured.class);91 if (configuredAnnotation != null) {92 if (!method.isAnnotationPresent(Inject.class)) {93 logger.warn(94 "No @Inject annotation found for @Configured method: {}",95 method);96 }97 _configuredProperties.add(new ConfiguredPropertyDescriptorImpl(98 method));99 }100 101 Provided providedAnnotation = method.getAnnotation(Provided.class);102 if (providedAnnotation != null) {103 if (!method.isAnnotationPresent(Inject.class)) {104 logger.warn(105 "No @Inject annotation found for @Provided method: {}",106 method);107 }108 _providedProperties.add(new ProvidedPropertyDescriptorImpl(109 method));110 }111 112 97 Initialize initializeAnnotation = method 113 98 .getAnnotation(Initialize.class); -
AnalyzerBeans/trunk/src/main/java/org/eobjects/analyzer/descriptors/AbstractPropertyDescriptor.java
r967 r974 3 3 import java.lang.annotation.Annotation; 4 4 import java.lang.reflect.Field; 5 import java.lang.reflect.Method;6 5 import java.lang.reflect.Type; 7 6 import java.util.Set; … … 11 10 import org.eobjects.analyzer.util.SchemaNavigator; 12 11 13 public class AbstractPropertyDescriptor implements PropertyDescriptor { 12 public class AbstractPropertyDescriptor implements PropertyDescriptor, 13 Comparable<AbstractPropertyDescriptor> { 14 14 15 private final Method _method;16 15 private final Field _field; 17 16 private final Class<?> _baseType; 18 17 private final Type _genericType; 19 18 20 public AbstractPropertyDescriptor(Method setterMethod) { 21 _field = null; 22 _method = setterMethod; 23 _method.setAccessible(true); 24 Class<?>[] parameterTypes = setterMethod.getParameterTypes(); 25 if (parameterTypes.length != 1) { 26 throw new DescriptorException("The method " + setterMethod 27 + " defines " + parameterTypes.length 28 + " parameters, a single parameter is required"); 19 public AbstractPropertyDescriptor(Field field) { 20 if (field == null) { 21 throw new IllegalArgumentException("field cannot be null"); 29 22 } 30 _baseType = parameterTypes[0];31 _genericType = _method.getGenericParameterTypes()[0];32 init();33 }34 35 public AbstractPropertyDescriptor(Field field) {36 _method = null;37 23 _field = field; 38 24 _field.setAccessible(true); … … 52 38 @Override 53 39 public String getName() { 54 return (_method == null ? _field.getName() : _method.getName());40 return _field.getName(); 55 41 } 56 42 57 43 @Override 58 public void assignValue(Object bean, Object value)44 public void setValue(Object bean, Object value) 59 45 throws IllegalArgumentException { 60 46 try { 61 if (_method != null) { 62 _method.invoke(bean, value); 63 } else { 64 _field.set(bean, value); 65 } 47 _field.set(bean, value); 66 48 } catch (Exception e) { 67 49 throw new IllegalStateException("Could not assign value '" + value 68 + "' to " + (_method == null ? _field : _method), e); 50 + "' to " + _field, e); 51 } 52 } 53 54 @Override 55 public Object getValue(Object bean) throws IllegalArgumentException { 56 if (bean == null) { 57 throw new IllegalArgumentException("bean cannot be null"); 58 } 59 try { 60 return _field.get(bean); 61 } catch (Exception e) { 62 throw new IllegalArgumentException("Could not retrieve property '" 63 + getName() + "' from bean: " + bean); 69 64 } 70 65 } … … 72 67 @Override 73 68 public Set<Annotation> getAnnotations() { 74 if (_field == null) { 75 return CollectionUtils.set(_method.getAnnotations()); 76 } else { 77 return CollectionUtils.set(_field.getAnnotations()); 78 } 69 return CollectionUtils.set(_field.getAnnotations()); 79 70 } 80 71 81 72 @Override 82 73 public <A extends Annotation> A getAnnotation(Class<A> annotationClass) { 83 if (_field == null) { 84 return _method.getAnnotation(annotationClass); 85 } else { 86 return _field.getAnnotation(annotationClass); 87 } 74 return _field.getAnnotation(annotationClass); 88 75 } 89 76 … … 116 103 int result = 1; 117 104 result = prime * result + ((_field == null) ? 0 : _field.hashCode()); 118 result = prime * result + ((_method == null) ? 0 : _method.hashCode());119 105 return result; 120 106 } … … 134 120 } else if (!_field.equals(other._field)) 135 121 return false; 136 if (_method == null) {137 if (other._method != null)138 return false;139 } else if (!_method.equals(other._method))140 return false;141 122 return true; 142 123 } … … 144 125 @Override 145 126 public String toString() { 146 if (_field == null) { 147 return getClass().getSimpleName() + "[method=" + _method.getName() 148 + ",baseType=" + _baseType + "]"; 149 } else { 150 return getClass().getSimpleName() + "[field=" + _field.getName() 151 + ",baseType=" + _baseType + "]"; 127 return getClass().getSimpleName() + "[field=" + _field.getName() 128 + ",baseType=" + _baseType + "]"; 129 } 130 131 @Override 132 public int compareTo(AbstractPropertyDescriptor o) { 133 Field otherField = o._field; 134 if (_field == otherField) { 135 return 0; 152 136 } 137 return _field.toString().compareTo(otherField.toString()); 153 138 } 154 139 } -
AnalyzerBeans/trunk/src/main/java/org/eobjects/analyzer/descriptors/ConfiguredPropertyDescriptorImpl.java
r967 r974 2 2 3 3 import java.lang.reflect.Field; 4 import java.lang.reflect.Method;5 4 6 5 import org.eobjects.analyzer.annotations.Configured; … … 14 13 } 15 14 16 public ConfiguredPropertyDescriptorImpl(Method method) throws DescriptorException {17 super(method);18 }19 20 15 @Override 21 16 public String getName() { -
AnalyzerBeans/trunk/src/main/java/org/eobjects/analyzer/descriptors/PropertyDescriptor.java
r962 r974 9 9 public String getName(); 10 10 11 public void assignValue(Object bean, Object value)11 public void setValue(Object bean, Object value) 12 12 throws IllegalArgumentException; 13 14 public Object getValue(Object bean) throws IllegalArgumentException; 13 15 14 16 public Set<Annotation> getAnnotations(); 15 17 16 18 public <A extends Annotation> A getAnnotation(Class<A> annotationClass); 17 19 18 20 public Class<?> getBaseType(); 19 21 … … 21 23 22 24 public Type getTypeArgument(int i) throws IndexOutOfBoundsException; 23 25 24 26 public boolean isArray(); 25 27 } -
AnalyzerBeans/trunk/src/main/java/org/eobjects/analyzer/descriptors/ProvidedPropertyDescriptorImpl.java
r967 r974 2 2 3 3 import java.lang.reflect.Field; 4 import java.lang.reflect.Method;5 4 6 5 import org.eobjects.analyzer.util.ReflectionUtils; … … 14 13 public ProvidedPropertyDescriptorImpl(Field field) throws DescriptorException { 15 14 super(field); 16 }17 18 public ProvidedPropertyDescriptorImpl(Method method) throws DescriptorException {19 super(method);20 15 } 21 16 -
AnalyzerBeans/trunk/src/main/java/org/eobjects/analyzer/lifecycle/AssignConfiguredCallback.java
r968 r974 30 30 Object configuredValue = getValue(property); 31 31 if (configuredValue == null) { 32 property. assignValue(bean, null);32 property.setValue(bean, null); 33 33 } else { 34 34 if (property.isArray()) { 35 property. assignValue(bean, configuredValue);35 property.setValue(bean, configuredValue); 36 36 } else { 37 37 if (configuredValue.getClass().isArray()) { … … 42 42 } 43 43 } 44 property. assignValue(bean, configuredValue);44 property.setValue(bean, configuredValue); 45 45 } 46 46 } -
AnalyzerBeans/trunk/src/main/java/org/eobjects/analyzer/lifecycle/AssignProvidedCallback.java
r968 r974 36 36 List<?> list = collectionProvider.createList(providedDescriptor 37 37 .getTypeArgument(0)); 38 providedDescriptor. assignValue(analyzerBean, list);38 providedDescriptor.setValue(analyzerBean, list); 39 39 providedCollections.add(list); 40 40 } else if (providedDescriptor.isMap()) { … … 42 42 providedDescriptor.getTypeArgument(0), 43 43 providedDescriptor.getTypeArgument(1)); 44 providedDescriptor. assignValue(analyzerBean, map);44 providedDescriptor.setValue(analyzerBean, map); 45 45 providedCollections.add(map); 46 46 } else if (providedDescriptor.isDataContext()) { 47 providedDescriptor. assignValue(analyzerBean,47 providedDescriptor.setValue(analyzerBean, 48 48 dataContextProvider.getDataContext()); 49 49 } else if (providedDescriptor.isSchemaNavigator()) { 50 providedDescriptor. assignValue(analyzerBean,50 providedDescriptor.setValue(analyzerBean, 51 51 dataContextProvider.getSchemaNavigator()); 52 52 } -
AnalyzerBeans/trunk/src/test/java/org/eobjects/analyzer/beans/JoinMatcherTest.java
r962 r974 25 25 assertEquals(4, configuredProperties.size()); 26 26 27 assertEquals("Left table join column", configuredProperties.get(0) 27 assertEquals("Right table", configuredProperties.get(0).getName()); 28 assertEquals("Left table join column", configuredProperties.get(1) 28 29 .getName()); 29 assertEquals("Left table", configuredProperties.get(1).getName()); 30 assertEquals("Right table", configuredProperties.get(2).getName()); 31 assertEquals("Right table join column", configuredProperties.get(3) 30 assertEquals("Right table join column", configuredProperties.get(2) 32 31 .getName()); 32 assertEquals("Left table", configuredProperties.get(3).getName()); 33 33 } 34 34 -
AnalyzerBeans/trunk/src/test/java/org/eobjects/analyzer/beans/ReferentialIntegrityValidatorTest.java
r962 r974 54 54 55 55 assertEquals( 56 "[ConfiguredPropertyDescriptorImpl[field= acceptNullForeignKey,baseType=boolean], "57 + "ConfiguredPropertyDescriptorImpl[field= foreignKeyColumn,baseType=class dk.eobjects.metamodel.schema.Column], "58 + "ConfiguredPropertyDescriptorImpl[field= primaryKeyColumn,baseType=class dk.eobjects.metamodel.schema.Column]]",56 "[ConfiguredPropertyDescriptorImpl[field=primaryKeyColumn,baseType=class dk.eobjects.metamodel.schema.Column], " 57 + "ConfiguredPropertyDescriptorImpl[field=acceptNullForeignKey,baseType=boolean], " 58 + "ConfiguredPropertyDescriptorImpl[field=foreignKeyColumn,baseType=class dk.eobjects.metamodel.schema.Column]]", 59 59 descriptor.getConfiguredProperties().toString()); 60 60 -
AnalyzerBeans/trunk/src/test/java/org/eobjects/analyzer/beans/mock/ExploringAnalyzerMock.java
r957 r974 42 42 } 43 43 44 // A method-level @Configured property44 @Configured 45 45 private Integer configured2; 46 47 @Configured 48 public void setConfigured2(Integer configured2) { 49 this.configured2 = configured2; 50 } 51 46 52 47 public Integer getConfigured2() { 53 48 return configured2; … … 62 57 } 63 58 64 // A method-level @Provided property59 @Provided 65 60 private List<Boolean> providedList; 66 67 @Provided 68 public void setProvidedList(List<Boolean> providedList) { 69 this.providedList = providedList; 70 } 71 61 72 62 public List<Boolean> getProvidedList() { 73 63 return providedList; -
AnalyzerBeans/trunk/src/test/java/org/eobjects/analyzer/beans/mock/RowProcessingAnalyzerMock.java
r957 r974 49 49 } 50 50 51 // A method-level @Configured property51 @Configured 52 52 private Integer configured2; 53 54 @Configured55 public void setConfigured2(Integer configured2) {56 this.configured2 = configured2;57 }58 53 59 54 public Integer getConfigured2() { … … 69 64 } 70 65 71 // A method-level @Provided property66 @Provided 72 67 private List<Boolean> providedList; 73 74 @Provided75 public void setProvidedList(List<Boolean> providedList) {76 this.providedList = providedList;77 }78 68 79 69 public List<Boolean> getProvidedList() { -
AnalyzerBeans/trunk/src/test/java/org/eobjects/analyzer/descriptors/AnnotationBasedAnalyzerBeanDescriptorTest.java
r971 r974 32 32 33 33 assertEquals( 34 "[ConfiguredPropertyDescriptorImpl[ method=setConfigured2,baseType=class java.lang.Integer], ConfiguredPropertyDescriptorImpl[field=configured1,baseType=class java.lang.String]]",34 "[ConfiguredPropertyDescriptorImpl[field=configured2,baseType=class java.lang.Integer], ConfiguredPropertyDescriptorImpl[field=configured1,baseType=class java.lang.String]]", 35 35 Arrays.toString(descriptor.getConfiguredProperties().toArray())); 36 36 } … … 45 45 .getConfiguredProperties(); 46 46 assertEquals( 47 "{ConfiguredPropertyDescriptorImpl[field=configured1,baseType=class java.lang.String],ConfiguredPropertyDescriptorImpl[ method=setConfigured2,baseType=class java.lang.Integer],ConfiguredPropertyDescriptorImpl[field=columns,baseType=class [Lorg.eobjects.analyzer.data.InputColumn;]}",47 "{ConfiguredPropertyDescriptorImpl[field=configured1,baseType=class java.lang.String],ConfiguredPropertyDescriptorImpl[field=configured2,baseType=class java.lang.Integer],ConfiguredPropertyDescriptorImpl[field=columns,baseType=class [Lorg.eobjects.analyzer.data.InputColumn;]}", 48 48 ArrayUtils.toString(configuredProperties.toArray())); 49 49 … … 51 51 ConfiguredPropertyDescriptor configuredProperty = configuredProperties 52 52 .iterator().next(); 53 configuredProperty. assignValue(analyzerBean, "foobar");53 configuredProperty.setValue(analyzerBean, "foobar"); 54 54 assertEquals("foobar", analyzerBean.getConfigured1()); 55 55 } -
AnalyzerBeans/trunk/src/test/java/org/eobjects/analyzer/descriptors/ProvidedPropertyDescriptorImplTest.java
r964 r974 2 2 3 3 import java.lang.reflect.Field; 4 import java.lang.reflect.Method;5 4 import java.util.Map; 6 5 … … 11 10 public class ProvidedPropertyDescriptorImplTest extends TestCase { 12 11 13 class SampleClass { 14 @Provided 15 Map<String, Boolean> stringMap; 12 @Provided 13 Map<String, Boolean> stringMap; 16 14 17 @Provided 18 void setIntMap(Map<String, Integer> map) { 19 20 } 21 } 15 @Provided 16 Map<String, Integer> intMap; 22 17 23 18 public void testGenericTypes() throws Exception { 24 Field stringMapField = SampleClass.class.getDeclaredField("stringMap"); 25 ProvidedPropertyDescriptorImpl descriptor = new ProvidedPropertyDescriptorImpl(stringMapField); 19 Field stringMapField = getClass().getDeclaredField("stringMap"); 20 ProvidedPropertyDescriptorImpl descriptor = new ProvidedPropertyDescriptorImpl( 21 stringMapField); 26 22 27 23 assertEquals( 28 24 "ProvidedPropertyDescriptorImpl[field=stringMap,baseType=interface java.util.Map]", 29 25 descriptor.toString()); 26 27 assertEquals(2, descriptor.getTypeArgumentCount()); 28 assertEquals(String.class, descriptor.getTypeArgument(0)); 29 assertEquals(Boolean.class, descriptor.getTypeArgument(1)); 30 30 31 Method method = SampleClass.class.getDeclaredMethod("setIntMap", 32 Map.class); 33 descriptor = new ProvidedPropertyDescriptorImpl(method); 31 Field intMapField = getClass().getDeclaredField("intMap"); 32 descriptor = new ProvidedPropertyDescriptorImpl(intMapField); 34 33 assertEquals( 35 "ProvidedPropertyDescriptorImpl[ method=setIntMap,baseType=interface java.util.Map]",34 "ProvidedPropertyDescriptorImpl[field=intMap,baseType=interface java.util.Map]", 36 35 descriptor.toString()); 36 37 assertEquals(2, descriptor.getTypeArgumentCount()); 38 assertEquals(String.class, descriptor.getTypeArgument(0)); 39 assertEquals(Integer.class, descriptor.getTypeArgument(1)); 37 40 } 38 41 }
Note: See TracChangeset
for help on using the changeset viewer.
