summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor
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')
-rw-r--r--sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ComponentNameAnnotationProcessor.java47
-rw-r--r--sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ComponentStub.java4
-rw-r--r--sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ConstructorAnnotationProcessor.java21
-rw-r--r--sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyAnnotationProcessor.java48
-rw-r--r--sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyValueStub.java4
-rw-r--r--sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ReferenceAnnotationProcessor.java49
6 files changed, 84 insertions, 89 deletions
diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ComponentNameAnnotationProcessor.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ComponentNameAnnotationProcessor.java
index 7613f8166d..68d49bbc24 100644
--- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ComponentNameAnnotationProcessor.java
+++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ComponentNameAnnotationProcessor.java
@@ -36,13 +36,13 @@ import org.springframework.util.ReflectionUtils;
public class ComponentNameAnnotationProcessor implements BeanPostProcessor {
private Class<? extends Annotation> componentNameAnnotationType = ComponentName.class;
-
+
private String componentName;
-
- public ComponentNameAnnotationProcessor (String componentName) {
+
+ public ComponentNameAnnotationProcessor(String componentName) {
this.componentName = componentName;
}
-
+
/**
* Gets componentName annotation type.
*/
@@ -63,8 +63,7 @@ public class ComponentNameAnnotationProcessor 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;
}
@@ -74,8 +73,7 @@ public class ComponentNameAnnotationProcessor 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;
}
@@ -83,7 +81,7 @@ public class ComponentNameAnnotationProcessor implements BeanPostProcessor {
* <p>Processes a beans fields for injection if it has a {@link Reference} annotation.</p>
*/
protected void processAnnotation(final Object bean) {
-
+
final Class<?> clazz = bean.getClass();
ReflectionUtils.doWithFields(clazz, new ReflectionUtils.FieldCallback() {
@@ -94,19 +92,20 @@ public class ComponentNameAnnotationProcessor implements BeanPostProcessor {
if (Modifier.isStatic(field.getModifiers())) {
throw new IllegalStateException("ComponentName annotation is not supported on static fields");
}
-
+
if (Modifier.isPrivate(field.getModifiers())) {
throw new IllegalStateException("ComponentName annotation is not supported on private fields");
}
ReflectionUtils.makeAccessible(field);
-
+
if (field.getType().getName().equals("java.lang.String")) {
- Object nameObj = componentName;
+ Object nameObj = componentName;
if (nameObj != null)
ReflectionUtils.setField(field, bean, nameObj);
} else {
- throw new IllegalStateException("ComponentName annotation is supported only on java.lang.String field type.");
+ throw new IllegalStateException(
+ "ComponentName annotation is supported only on java.lang.String field type.");
}
}
}
@@ -115,33 +114,35 @@ public class ComponentNameAnnotationProcessor implements BeanPostProcessor {
ReflectionUtils.doWithMethods(clazz, new ReflectionUtils.MethodCallback() {
public void doWith(Method method) {
Annotation annotation = method.getAnnotation(getComponentNameAnnotationType());
-
+
if (annotation != null) {
if (Modifier.isStatic(method.getModifiers())) {
throw new IllegalStateException("ComponentName annotation is not supported on static methods");
}
-
+
if (Modifier.isPrivate(method.getModifiers())) {
throw new IllegalStateException("ComponentName annotation is not supported on private methods");
}
if (method.getParameterTypes().length == 0) {
- throw new IllegalStateException("ComponentName annotation requires at least one argument: " + method);
+ throw new IllegalStateException(
+ "ComponentName annotation requires at least one argument: " + method);
}
-
- PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method);
-
+
+ PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method);
+
if (pd.getPropertyType().getName().equals("java.lang.String")) {
- Object nameObj = componentName;
+ Object nameObj = componentName;
if (nameObj != null) {
- try {
- pd.getWriteMethod().invoke(bean, new Object[] { nameObj });
+ try {
+ pd.getWriteMethod().invoke(bean, new Object[] {nameObj});
} catch (Throwable e) {
throw new FatalBeanException("Problem injecting reference: " + e.getMessage(), e);
}
}
} else {
- throw new IllegalStateException("ComponentName annotation is supported only on java.lang.String field type.");
+ throw new IllegalStateException(
+ "ComponentName annotation is supported only on java.lang.String field type.");
}
}
}
diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ComponentStub.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ComponentStub.java
index c72ccd6636..b087c45ab4 100644
--- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ComponentStub.java
+++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ComponentStub.java
@@ -31,12 +31,12 @@ public class ComponentStub {
private Object tie;
private Method getService;
-
+
public ComponentStub(Object tie) {
this.tie = tie;
Class<?> tieClass = tie.getClass();
try {
- getService = tieClass.getMethod("getService", new Class<?>[]{Class.class, String.class});
+ getService = tieClass.getMethod("getService", new Class<?>[] {Class.class, String.class});
} catch (Exception e) {
throw new RuntimeException(e);
}
diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ConstructorAnnotationProcessor.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ConstructorAnnotationProcessor.java
index 7eb63678f6..a52a85ff3a 100644
--- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ConstructorAnnotationProcessor.java
+++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ConstructorAnnotationProcessor.java
@@ -28,15 +28,14 @@ import org.springframework.util.Assert;
public class ConstructorAnnotationProcessor extends InstantiationAwareBeanPostProcessorAdapter {
- private Class<? extends Annotation> constructorAnnotationType
- = org.oasisopen.sca.annotation.Constructor.class;
-
+ private Class<? extends Annotation> constructorAnnotationType = org.oasisopen.sca.annotation.Constructor.class;
+
private Class<? extends Annotation> autowiredAnnotationType = Autowired.class;
-
- public ConstructorAnnotationProcessor () {
+
+ public ConstructorAnnotationProcessor() {
// Default constructor.
}
-
+
/**
* Set the 'autowired' annotation type, to be used on constructors, fields,
* setter methods and arbitrary config methods.
@@ -52,7 +51,7 @@ public class ConstructorAnnotationProcessor extends InstantiationAwareBeanPostPr
protected Class<? extends Annotation> getAutowiredAnnotationType() {
return this.autowiredAnnotationType;
}
-
+
/**
* Return the 'constructor' annotation type.
*/
@@ -73,8 +72,7 @@ public class ConstructorAnnotationProcessor extends InstantiationAwareBeanPostPr
*
* @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 {
return bean;
}
@@ -83,11 +81,10 @@ public class ConstructorAnnotationProcessor extends InstantiationAwareBeanPostPr
*
* @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;
}
-
+
public Constructor[] determineCandidateConstructors(Class beanClass, String beanName) throws BeansException {
/*Constructor[] declaredConstructors = beanClass.getDeclaredConstructors();
Method[] declaredMethods = beanClass.getDeclaredMethods();
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);
}
}
}
-
+
}
diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyValueStub.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyValueStub.java
index ea8f560ae1..9a95f818de 100644
--- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyValueStub.java
+++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyValueStub.java
@@ -31,12 +31,12 @@ public class PropertyValueStub {
private Object tie;
private Method getPropertyObj;
-
+
public PropertyValueStub(Object tie) {
this.tie = tie;
Class<?> tieClass = tie.getClass();
try {
- getPropertyObj = tieClass.getMethod("getPropertyObj", new Class<?>[]{Class.class, String.class});
+ getPropertyObj = tieClass.getMethod("getPropertyObj", new Class<?>[] {Class.class, String.class});
} catch (Exception e) {
throw new RuntimeException(e);
}
diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ReferenceAnnotationProcessor.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ReferenceAnnotationProcessor.java
index dd43d63d97..6b86f0962e 100644
--- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ReferenceAnnotationProcessor.java
+++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ReferenceAnnotationProcessor.java
@@ -36,11 +36,11 @@ public class ReferenceAnnotationProcessor implements BeanPostProcessor {
private Class<? extends Annotation> referenceAnnotationType = Reference.class;
private ComponentStub component;
-
- public ReferenceAnnotationProcessor (ComponentStub component) {
+
+ public ReferenceAnnotationProcessor(ComponentStub component) {
this.component = component;
}
-
+
/**
* Gets referece annotation type.
*/
@@ -61,8 +61,7 @@ public class ReferenceAnnotationProcessor 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;
}
@@ -72,8 +71,7 @@ public class ReferenceAnnotationProcessor 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;
}
@@ -81,27 +79,28 @@ public class ReferenceAnnotationProcessor implements BeanPostProcessor {
* <p>Processes a beans fields for injection if it has a {@link Reference} 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) {
- Reference annotation = (Reference) method.getAnnotation(getReferenceAnnotationType());
-
+ Reference annotation = (Reference)method.getAnnotation(getReferenceAnnotationType());
+
if (annotation != null) {
if (Modifier.isStatic(method.getModifiers())) {
throw new IllegalStateException("Reference annotation is not supported on static methods");
}
-
+
if (Modifier.isPrivate(method.getModifiers())) {
throw new IllegalStateException("Reference annotation is not supported on private methods");
}
if (method.getParameterTypes().length == 0) {
- throw new IllegalStateException("Reference annotation requires at least one argument: " + method);
+ throw new IllegalStateException(
+ "Reference annotation requires at least one argument: " + method);
}
-
+
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method);
if (pd != null) {
String refName = annotation.name();
@@ -114,31 +113,31 @@ public class ReferenceAnnotationProcessor implements BeanPostProcessor {
}
}
});
-
+
ReflectionUtils.doWithFields(clazz, new ReflectionUtils.FieldCallback() {
public void doWith(Field field) {
- Reference annotation = (Reference) field.getAnnotation(getReferenceAnnotationType());
-
+ Reference annotation = (Reference)field.getAnnotation(getReferenceAnnotationType());
+
if (annotation != null) {
if (Modifier.isStatic(field.getModifiers())) {
throw new IllegalStateException("Reference annotation is not supported on static fields");
}
-
+
if (Modifier.isPrivate(field.getModifiers())) {
throw new IllegalStateException("Reference annotation is not supported on private fields");
}
ReflectionUtils.makeAccessible(field);
-
+
Object referenceObj = null;
String refName = annotation.name();
if ("".equals(refName)) {
referenceObj = component.getService(field.getType(), field.getName());
} else {
referenceObj = component.getService(field.getType(), refName);
- }
-
+ }
+
if (referenceObj != null)
ReflectionUtils.setField(field, bean, referenceObj);
}
@@ -150,12 +149,12 @@ public class ReferenceAnnotationProcessor implements BeanPostProcessor {
* Processes a property descriptor to inject a service.
*/
public void injectReference(Object bean, PropertyDescriptor pd, String name) {
-
+
Object referenceObj = component.getService(pd.getPropertyType(), name);
-
+
if (referenceObj != null) {
- try {
- pd.getWriteMethod().invoke(bean, new Object[] { referenceObj });
+ try {
+ pd.getWriteMethod().invoke(bean, new Object[] {referenceObj});
} catch (Throwable e) {
throw new FatalBeanException("Problem injecting reference: " + e.getMessage(), e);
}