summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyAnnotationProcessor.java
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyAnnotationProcessor.java')
-rw-r--r--sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyAnnotationProcessor.java48
1 files changed, 23 insertions, 25 deletions
diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyAnnotationProcessor.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyAnnotationProcessor.java
index f800654c34..3e8bca229f 100644
--- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyAnnotationProcessor.java
+++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyAnnotationProcessor.java
@@ -35,10 +35,10 @@ import org.springframework.util.ReflectionUtils;
public class PropertyAnnotationProcessor implements BeanPostProcessor {
private Class<? extends Annotation> propertyAnnotationType = Property.class;
-
+
private PropertyValueStub propertyValue;
-
- public PropertyAnnotationProcessor (PropertyValueStub propertyValue) {
+
+ public PropertyAnnotationProcessor(PropertyValueStub propertyValue) {
this.propertyValue = propertyValue;
}
@@ -62,8 +62,7 @@ public class PropertyAnnotationProcessor implements BeanPostProcessor {
*
* @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object, java.lang.String)
*/
- public Object postProcessBeforeInitialization(Object bean, String beanName)
- throws BeansException {
+ public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
processAnnotation(bean);
return bean;
}
@@ -73,8 +72,7 @@ public class PropertyAnnotationProcessor implements BeanPostProcessor {
*
* @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object, java.lang.String)
*/
- public Object postProcessAfterInitialization(Object bean, String beanName)
- throws BeansException {
+ public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
@@ -82,19 +80,19 @@ public class PropertyAnnotationProcessor implements BeanPostProcessor {
* <p>Processes a beans fields for injection if it has a {@link Property} annotation.</p>
*/
protected void processAnnotation(final Object bean) {
-
- final Class<?> clazz = bean.getClass();
+
+ final Class<?> clazz = bean.getClass();
ReflectionUtils.doWithMethods(clazz, new ReflectionUtils.MethodCallback() {
public void doWith(Method method) {
- Property annotation = (Property) method.getAnnotation(getPropertyAnnotationType());
-
+ Property annotation = (Property)method.getAnnotation(getPropertyAnnotationType());
+
if (annotation != null) {
if (Modifier.isStatic(method.getModifiers())) {
throw new IllegalStateException("Property annotation is not supported on static methods");
}
-
+
if (Modifier.isPrivate(method.getModifiers())) {
throw new IllegalStateException("Property annotation is not supported on private methods");
}
@@ -102,7 +100,7 @@ public class PropertyAnnotationProcessor implements BeanPostProcessor {
if (method.getParameterTypes().length == 0) {
throw new IllegalStateException("Property annotation requires at least one argument: " + method);
}
-
+
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method);
if (pd != null) {
String propName = annotation.name();
@@ -115,47 +113,47 @@ public class PropertyAnnotationProcessor implements BeanPostProcessor {
}
}
});
-
+
ReflectionUtils.doWithFields(clazz, new ReflectionUtils.FieldCallback() {
public void doWith(Field field) {
- Property annotation = (Property) field.getAnnotation(getPropertyAnnotationType());
-
+ Property annotation = (Property)field.getAnnotation(getPropertyAnnotationType());
+
if (annotation != null) {
if (Modifier.isStatic(field.getModifiers())) {
throw new IllegalStateException("Property annotation is not supported on static fields");
}
-
+
if (Modifier.isPrivate(field.getModifiers())) {
throw new IllegalStateException("Property annotation is not supported on private fields");
}
ReflectionUtils.makeAccessible(field);
-
+
Object propertyObj = null;
String propName = annotation.name();
if ("".equals(propName)) {
- propertyObj = propertyValue.getPropertyObj(field.getType(), field.getName());
+ propertyObj = propertyValue.getPropertyObj(field.getType(), field.getName());
} else {
propertyObj = propertyValue.getPropertyObj(field.getType(), propName);
}
-
+
if (propertyObj != null)
ReflectionUtils.setField(field, bean, propertyObj);
}
}
});
}
-
+
public void injectProperty(Object bean, PropertyDescriptor pd, Object propertyObj) {
-
+
if (propertyObj != null) {
- try {
- pd.getWriteMethod().invoke(bean, new Object[] { propertyObj });
+ try {
+ pd.getWriteMethod().invoke(bean, new Object[] {propertyObj});
} catch (Throwable e) {
throw new FatalBeanException("Problem injecting property: " + e.getMessage(), e);
}
}
}
-
+
}