From e01dfb8674dfc78d9af6ac60f1352d3149e6889b Mon Sep 17 00:00:00 2001 From: rfeng Date: Wed, 28 Jul 2010 21:01:00 +0000 Subject: Format the code based on the Tuscany eclipse formatter git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@980211 13f79535-47bb-0310-9956-ffa450edef68 --- .../ComponentNameAnnotationProcessor.java | 47 ++++++++-------- .../spring/processor/ComponentStub.java | 4 +- .../processor/ConstructorAnnotationProcessor.java | 21 +++---- .../processor/PropertyAnnotationProcessor.java | 48 ++++++++-------- .../spring/processor/PropertyValueStub.java | 4 +- .../processor/ReferenceAnnotationProcessor.java | 49 ++++++++--------- .../context/SCAGenericApplicationContext.java | 35 ++++++------ .../context/SCAParentApplicationContext.java | 6 +- .../spring/runtime/context/SpringContextTie.java | 64 +++++++++++----------- .../runtime/context/SpringImplementationStub.java | 26 ++++----- 10 files changed, 149 insertions(+), 155 deletions(-) (limited to 'sca-java-2.x/trunk/modules/implementation-spring-runtime/src') 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 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 { *

Processes a beans fields for injection if it has a {@link Reference} annotation.

*/ 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 constructorAnnotationType - = org.oasisopen.sca.annotation.Constructor.class; - + private Class constructorAnnotationType = org.oasisopen.sca.annotation.Constructor.class; + private Class 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 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 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 { *

Processes a beans fields for injection if it has a {@link Property} annotation.

*/ 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 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 { *

Processes a beans fields for injection if it has a {@link Reference} annotation.

*/ 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); } diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SCAGenericApplicationContext.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SCAGenericApplicationContext.java index 6426306f26..3e0aacdb40 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SCAGenericApplicationContext.java +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SCAGenericApplicationContext.java @@ -25,23 +25,22 @@ import org.springframework.context.support.GenericApplicationContext; public class SCAGenericApplicationContext extends GenericApplicationContext { - ClassLoader classloader = null; - - public SCAGenericApplicationContext(DefaultListableBeanFactory beanFactory, - ApplicationContext parent, - ClassLoader classloader) { - super(beanFactory, parent); - this.classloader = classloader; - } - - public SCAGenericApplicationContext(ApplicationContext parent, - ClassLoader classloader) { - super(parent); - this.classloader = classloader; - } + ClassLoader classloader = null; - @Override - protected void postProcessBeanFactory (ConfigurableListableBeanFactory beanFactory) { - beanFactory.setBeanClassLoader(classloader); - } + public SCAGenericApplicationContext(DefaultListableBeanFactory beanFactory, + ApplicationContext parent, + ClassLoader classloader) { + super(beanFactory, parent); + this.classloader = classloader; + } + + public SCAGenericApplicationContext(ApplicationContext parent, ClassLoader classloader) { + super(parent); + this.classloader = classloader; + } + + @Override + protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) { + beanFactory.setBeanClassLoader(classloader); + } } diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SCAParentApplicationContext.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SCAParentApplicationContext.java index 36f1f6d761..88be5b720f 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SCAParentApplicationContext.java +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SCAParentApplicationContext.java @@ -58,7 +58,7 @@ class SCAParentApplicationContext implements ApplicationContext { } // end constructor public Object getBean(String name) throws BeansException { - return getBean(name, (Class) null); + return getBean(name, (Class)null); } /** @@ -73,7 +73,7 @@ class SCAParentApplicationContext implements ApplicationContext { } // end method getBean( String, Class ) public Object getBean(String name, Object[] args) throws BeansException { - return getBean(name, ((Class)null)); + return getBean(name, ((Class)null)); } public T getBean(Class clazz) throws BeansException { @@ -119,7 +119,7 @@ class SCAParentApplicationContext implements ApplicationContext { } public String getId() { - return this.toString(); + return this.toString(); } public String getDisplayName() { diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java index 77681b600f..d5a330c916 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java @@ -32,8 +32,8 @@ import org.apache.tuscany.sca.implementation.spring.processor.ReferenceAnnotatio import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; +import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.GenericApplicationContext; import org.springframework.core.io.UrlResource; @@ -48,11 +48,11 @@ public class SpringContextTie { private AbstractApplicationContext springContext; private SpringImplementationStub implementation; - + public SpringContextTie(SpringImplementationStub implementation, List resource) { this.implementation = implementation; SCAParentApplicationContext scaParentContext = new SCAParentApplicationContext(implementation); - springContext = createApplicationContext(scaParentContext, resource); + springContext = createApplicationContext(scaParentContext, resource); } public void start() { @@ -71,30 +71,29 @@ public class SpringContextTie { /** * Include BeanPostProcessor to deal with SCA Annotations in Spring Bean */ - private AbstractApplicationContext createApplicationContext(SCAParentApplicationContext scaParentContext, List resources) { - - XmlBeanFactory beanFactory = null; - AbstractApplicationContext appContext = null; - - if (resources.size() > 1) { - GenericApplicationContext appCtx = - new SCAGenericApplicationContext(scaParentContext, implementation.getClassLoader()); - XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(appCtx); - for (URL resource : resources) { - xmlReader.loadBeanDefinitions(new UrlResource(resource)); - } - xmlReader.setBeanClassLoader(implementation.getClassLoader()); - includeAnnotationProcessors(appCtx.getBeanFactory()); - return appCtx; - } - - // use the generic application context as default - beanFactory = new XmlBeanFactory(new UrlResource(resources.get(0))); + private AbstractApplicationContext createApplicationContext(SCAParentApplicationContext scaParentContext, + List resources) { + + XmlBeanFactory beanFactory = null; + AbstractApplicationContext appContext = null; + + if (resources.size() > 1) { + GenericApplicationContext appCtx = + new SCAGenericApplicationContext(scaParentContext, implementation.getClassLoader()); + XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(appCtx); + for (URL resource : resources) { + xmlReader.loadBeanDefinitions(new UrlResource(resource)); + } + xmlReader.setBeanClassLoader(implementation.getClassLoader()); + includeAnnotationProcessors(appCtx.getBeanFactory()); + return appCtx; + } + + // use the generic application context as default + beanFactory = new XmlBeanFactory(new UrlResource(resources.get(0))); beanFactory.setBeanClassLoader(implementation.getClassLoader()); includeAnnotationProcessors(beanFactory); - appContext = new SCAGenericApplicationContext(beanFactory, - scaParentContext, - implementation.getClassLoader()); + appContext = new SCAGenericApplicationContext(beanFactory, scaParentContext, implementation.getClassLoader()); return appContext; } @@ -106,7 +105,7 @@ public class SpringContextTie { * Include BeanPostProcessor to deal with SCA Annotations in Spring Bean */ private void includeAnnotationProcessors(ConfigurableListableBeanFactory beanFactory) { - + // Processor to deal with @Init and @Destroy SCA Annotations BeanPostProcessor initDestroyProcessor = new InitDestroyAnnotationProcessor(); beanFactory.addBeanPostProcessor(initDestroyProcessor); @@ -115,19 +114,20 @@ public class SpringContextTie { ComponentStub component = new ComponentStub(implementation.getComponentTie()); BeanPostProcessor referenceProcessor = new ReferenceAnnotationProcessor(component); beanFactory.addBeanPostProcessor(referenceProcessor); - + // Processor to deal with @Property SCA Annotations PropertyValueStub pvs = new PropertyValueStub(implementation.getPropertyValueTie()); BeanPostProcessor propertyProcessor = new PropertyAnnotationProcessor(pvs); beanFactory.addBeanPostProcessor(propertyProcessor); - + // Processor to deal with @ComponentName SCA Annotations - BeanPostProcessor componentNameProcessor = new ComponentNameAnnotationProcessor(implementation.getComponentName()); + BeanPostProcessor componentNameProcessor = + new ComponentNameAnnotationProcessor(implementation.getComponentName()); beanFactory.addBeanPostProcessor(componentNameProcessor); - + // Processor to deal with @Constructor SCA Annotations BeanPostProcessor constructorProcessor = new ConstructorAnnotationProcessor(); - beanFactory.addBeanPostProcessor(constructorProcessor); + beanFactory.addBeanPostProcessor(constructorProcessor); } -} \ No newline at end of file +} diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringImplementationStub.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringImplementationStub.java index af39869522..298d8944fb 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringImplementationStub.java +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringImplementationStub.java @@ -40,13 +40,13 @@ public class SpringImplementationStub { Method getComponentTie; Method getPropertyValueTie; Method getClassLoader; - + public SpringImplementationStub(Object tie) { this.tie = tie; Class tieClass = tie.getClass(); try { - getURI = tieClass.getMethod("getURI", new Class[]{}); - getBean = tieClass.getMethod("getBean", new Class[]{String.class, Class.class}); + getURI = tieClass.getMethod("getURI", new Class[] {}); + getBean = tieClass.getMethod("getBean", new Class[] {String.class, Class.class}); getComponentName = tieClass.getMethod("getComponentName"); getComponentTie = tieClass.getMethod("getComponentTie"); getPropertyValueTie = tieClass.getMethod("getPropertyValueTie"); @@ -55,7 +55,7 @@ public class SpringImplementationStub { throw new RuntimeException(e); } } - + public String getURI() { try { @@ -116,14 +116,14 @@ public class SpringImplementationStub { throw new RuntimeException(e); } } - + public ClassLoader getClassLoader() { - try { - - return (ClassLoader) getClassLoader.invoke(tie); - - } catch (Exception e) { - throw new RuntimeException(e); - } + try { + + return (ClassLoader)getClassLoader.invoke(tie); + + } catch (Exception e) { + throw new RuntimeException(e); + } } -} \ No newline at end of file +} -- cgit v1.2.3