diff options
Diffstat (limited to '')
6 files changed, 0 insertions, 749 deletions
diff --git a/sca-java-2.x/tags/2.0-Beta2-RC2/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ComponentNameAnnotationProcessor.java b/sca-java-2.x/tags/2.0-Beta2-RC2/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ComponentNameAnnotationProcessor.java deleted file mode 100644 index 68d49bbc24..0000000000 --- a/sca-java-2.x/tags/2.0-Beta2-RC2/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ComponentNameAnnotationProcessor.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.implementation.spring.processor; - -import java.beans.PropertyDescriptor; -import java.lang.annotation.Annotation; -import java.lang.ref.Reference; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; - -import org.oasisopen.sca.annotation.ComponentName; -import org.springframework.beans.BeanUtils; -import org.springframework.beans.BeansException; -import org.springframework.beans.FatalBeanException; -import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.util.Assert; -import org.springframework.util.ReflectionUtils; - -public class ComponentNameAnnotationProcessor implements BeanPostProcessor { - - private Class<? extends Annotation> componentNameAnnotationType = ComponentName.class; - - private String componentName; - - public ComponentNameAnnotationProcessor(String componentName) { - this.componentName = componentName; - } - - /** - * Gets componentName annotation type. - */ - protected Class<? extends Annotation> getComponentNameAnnotationType() { - return this.componentNameAnnotationType; - } - - /** - * Sets componentName annotation type. - */ - public void setComponentNameAnnotationType(Class<? extends Annotation> componentNameAnnotationType) { - Assert.notNull(componentNameAnnotationType, "'componentNameAnnotationType' type must not be null."); - this.componentNameAnnotationType = componentNameAnnotationType; - } - - /** - * This method is used to execute before a bean's initialization callback. - * - * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object, java.lang.String) - */ - public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { - processAnnotation(bean); - return bean; - } - - /** - * This method is used to execute after a bean's initialization callback. - * - * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object, java.lang.String) - */ - public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - return bean; - } - - /** - * <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() { - public void doWith(Field field) { - Annotation annotation = field.getAnnotation(getComponentNameAnnotationType()); - - if (annotation != null) { - 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; - if (nameObj != null) - ReflectionUtils.setField(field, bean, nameObj); - } else { - throw new IllegalStateException( - "ComponentName annotation is supported only on java.lang.String field type."); - } - } - } - }); - - 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); - } - - PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method); - - if (pd.getPropertyType().getName().equals("java.lang.String")) { - Object nameObj = componentName; - if (nameObj != null) { - 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."); - } - } - } - }); - } -} diff --git a/sca-java-2.x/tags/2.0-Beta2-RC2/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ConstructorAnnotationProcessor.java b/sca-java-2.x/tags/2.0-Beta2-RC2/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ConstructorAnnotationProcessor.java deleted file mode 100644 index a52a85ff3a..0000000000 --- a/sca-java-2.x/tags/2.0-Beta2-RC2/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ConstructorAnnotationProcessor.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.implementation.spring.processor; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Constructor; - -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter; -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> autowiredAnnotationType = Autowired.class; - - public ConstructorAnnotationProcessor() { - // Default constructor. - } - - /** - * Set the 'autowired' annotation type, to be used on constructors, fields, - * setter methods and arbitrary config methods. - */ - public void setAutowiredAnnotationType(Class<? extends Annotation> autowiredAnnotationType) { - Assert.notNull(autowiredAnnotationType, "'autowiredAnnotationType' must not be null"); - this.autowiredAnnotationType = autowiredAnnotationType; - } - - /** - * Return the 'autowired' annotation type. - */ - protected Class<? extends Annotation> getAutowiredAnnotationType() { - return this.autowiredAnnotationType; - } - - /** - * Return the 'constructor' annotation type. - */ - protected Class<? extends Annotation> getConstructorAnnotationType() { - return this.constructorAnnotationType; - } - - /** - * Sets the 'constructor' annotation type. - */ - public void setConstructorAnnotationType(Class<? extends Annotation> constructorAnnotationType) { - Assert.notNull(constructorAnnotationType, "'constructorAnnotationType' type must not be null."); - this.constructorAnnotationType = constructorAnnotationType; - } - - /** - * This method is used to execute before a bean's initialization callback. - * - * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object, java.lang.String) - */ - public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { - return bean; - } - - /** - * This method is used to execute after a bean's initialization callback. - * - * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object, java.lang.String) - */ - 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(); - List candidates = new ArrayList(declaredConstructors.length); - - for (int i = 0; i < declaredMethods.length; i++) { - Method method = declaredMethods[i]; - Annotation annotation = method.getAnnotation(getConstructorAnnotationType()); - if (annotation != null) { - if (Modifier.isStatic(method.getModifiers())) { - throw new IllegalStateException("Constructor annotation is not supported on static methods"); - } - - if (candidates.size() == 1) { - throw new IllegalStateException("Only one method is allowed to have constructor annotation in a bean: " + method); - } - - candidates.add(method); - } - } - - return (Constructor[]) candidates.toArray(new Constructor[candidates.size()]);*/ - return null; - } -} diff --git a/sca-java-2.x/tags/2.0-Beta2-RC2/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/InitDestroyAnnotationProcessor.java b/sca-java-2.x/tags/2.0-Beta2-RC2/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/InitDestroyAnnotationProcessor.java deleted file mode 100644 index 477582b1d3..0000000000 --- a/sca-java-2.x/tags/2.0-Beta2-RC2/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/InitDestroyAnnotationProcessor.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.implementation.spring.processor; - -import java.lang.annotation.Annotation; - -import org.oasisopen.sca.annotation.Destroy; -import org.oasisopen.sca.annotation.Init; -import org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor; - -public class InitDestroyAnnotationProcessor extends InitDestroyAnnotationBeanPostProcessor { - - private static final long serialVersionUID = 0; - - private Class<? extends Annotation> initAnnotationType = Init.class; - private Class<? extends Annotation> destroyAnnotationType = Destroy.class; - - /** - * Gets init annotation type. - */ - protected Class<? extends Annotation> getInitAnnotationType() { - return this.initAnnotationType; - } - - /** - * Sets init annotation type. - */ - /* - * public void setInitAnnotationType(Class<? extends Annotation> - * initAnnotationType) { Assert.notNull(initAnnotationType, - * "Init annotation type must not be null."); this.initAnnotationType = - * initAnnotationType; } - */ - - /** - * Gets destroy annotation type. - */ - protected Class<? extends Annotation> getDestroyAnnotationType() { - return this.destroyAnnotationType; - } - - /** - * Sets destroy annotation type. - */ - /* - * public void setDestroyAnnotationType(Class<? extends Annotation> - * destroyAnnotationType) { Assert.notNull(destroyAnnotationType, - * "Destroy annotation type must not be null."); this.destroyAnnotationType - * = destroyAnnotationType; } - */ - - public InitDestroyAnnotationProcessor() { - // Set the @Init annotation type - setInitAnnotationType(initAnnotationType); - - // Set the @Destroy annotation type - setDestroyAnnotationType(destroyAnnotationType); - } -} diff --git a/sca-java-2.x/tags/2.0-Beta2-RC2/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyAnnotationProcessor.java b/sca-java-2.x/tags/2.0-Beta2-RC2/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyAnnotationProcessor.java deleted file mode 100644 index 4763714a38..0000000000 --- a/sca-java-2.x/tags/2.0-Beta2-RC2/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyAnnotationProcessor.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.implementation.spring.processor; - -import java.beans.PropertyDescriptor; -import java.lang.annotation.Annotation; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; - -import org.apache.tuscany.sca.implementation.spring.provider.PropertyValueWrapper; -import org.oasisopen.sca.annotation.Property; -import org.springframework.beans.BeanUtils; -import org.springframework.beans.BeansException; -import org.springframework.beans.FatalBeanException; -import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.util.Assert; -import org.springframework.util.ReflectionUtils; - -public class PropertyAnnotationProcessor implements BeanPostProcessor { - - private Class<? extends Annotation> propertyAnnotationType = Property.class; - - private PropertyValueWrapper propertyValue; - - public PropertyAnnotationProcessor(PropertyValueWrapper propertyValue) { - this.propertyValue = propertyValue; - } - - /** - * Gets property annotation type. - */ - protected Class<? extends Annotation> getPropertyAnnotationType() { - return this.propertyAnnotationType; - } - - /** - * Sets property annotation type. - */ - public void setPropertyAnnotationType(Class<? extends Annotation> propertyAnnotationType) { - Assert.notNull(propertyAnnotationType, "'propertyAnnotationType' type must not be null."); - this.propertyAnnotationType = propertyAnnotationType; - } - - /** - * This method is used to execute before a bean's initialization callback. - * - * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object, java.lang.String) - */ - public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { - processAnnotation(bean); - return bean; - } - - /** - * This method is used to execute after a bean's initialization callback. - * - * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object, java.lang.String) - */ - public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - return bean; - } - - /** - * <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(); - - ReflectionUtils.doWithMethods(clazz, new ReflectionUtils.MethodCallback() { - public void doWith(Method method) { - - 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"); - } - */ - - 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(); - if ("".equals(propName)) { - injectProperty(bean, pd, propertyValue.getPropertyObj(pd.getPropertyType(), pd.getName())); - } else { - injectProperty(bean, pd, propertyValue.getPropertyObj(pd.getPropertyType(), propName)); - } - } - } - } - }); - - ReflectionUtils.doWithFields(clazz, new ReflectionUtils.FieldCallback() { - public void doWith(Field field) { - - 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()); - } 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}); - } catch (Throwable e) { - throw new FatalBeanException("Problem injecting property: " + e.getMessage(), e); - } - } - } - -} diff --git a/sca-java-2.x/tags/2.0-Beta2-RC2/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ReferenceAnnotationProcessor.java b/sca-java-2.x/tags/2.0-Beta2-RC2/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ReferenceAnnotationProcessor.java deleted file mode 100644 index ad79db840e..0000000000 --- a/sca-java-2.x/tags/2.0-Beta2-RC2/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ReferenceAnnotationProcessor.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.implementation.spring.processor; - -import java.beans.PropertyDescriptor; -import java.lang.annotation.Annotation; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; - -import org.apache.tuscany.sca.implementation.spring.provider.ComponentWrapper; -import org.oasisopen.sca.annotation.Reference; -import org.springframework.beans.BeanUtils; -import org.springframework.beans.BeansException; -import org.springframework.beans.FatalBeanException; -import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.util.Assert; -import org.springframework.util.ReflectionUtils; - -public class ReferenceAnnotationProcessor implements BeanPostProcessor { - - private Class<? extends Annotation> referenceAnnotationType = Reference.class; - private ComponentWrapper component; - - public ReferenceAnnotationProcessor(ComponentWrapper component) { - this.component = component; - } - - /** - * Gets referece annotation type. - */ - protected Class<? extends Annotation> getReferenceAnnotationType() { - return this.referenceAnnotationType; - } - - /** - * Sets referece annotation type. - */ - public void setReferenceAnnotationType(Class<? extends Annotation> referenceAnnotationType) { - Assert.notNull(referenceAnnotationType, "'referenceAnnotationType' type must not be null."); - this.referenceAnnotationType = referenceAnnotationType; - } - - /** - * This method is used to execute before a bean's initialization callback. - * - * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object, java.lang.String) - */ - public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { - processAnnotation(bean); - return bean; - } - - /** - * This method is used to execute after a bean's initialization callback. - * - * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object, java.lang.String) - */ - public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - return bean; - } - - /** - * <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.doWithMethods(clazz, new ReflectionUtils.MethodCallback() { - public void doWith(Method method) { - - 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); - } - - PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method); - if (pd != null) { - String refName = annotation.name(); - if ("".equals(refName)) { - injectReference(bean, pd, pd.getName()); - } else { - injectReference(bean, pd, refName); - } - } - } - } - }); - - ReflectionUtils.doWithFields(clazz, new ReflectionUtils.FieldCallback() { - public void doWith(Field field) { - - 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); - } - } - }); - } - - /** - * 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}); - } catch (Throwable e) { - throw new FatalBeanException("Problem injecting reference: " + e.getMessage(), e); - } - } - } -} diff --git a/sca-java-2.x/tags/2.0-Beta2-RC2/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/SpringXMLBeanDefinitionLoaderImpl.java b/sca-java-2.x/tags/2.0-Beta2-RC2/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/SpringXMLBeanDefinitionLoaderImpl.java deleted file mode 100644 index 6ba2c65ef0..0000000000 --- a/sca-java-2.x/tags/2.0-Beta2-RC2/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/SpringXMLBeanDefinitionLoaderImpl.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.implementation.spring.processor; - -import java.net.URL; -import java.util.List; - -import org.apache.tuscany.sca.contribution.processor.ProcessorContext; -import org.apache.tuscany.sca.implementation.spring.SpringBeanElement; -import org.apache.tuscany.sca.implementation.spring.SpringSCAPropertyElement; -import org.apache.tuscany.sca.implementation.spring.SpringSCAReferenceElement; -import org.apache.tuscany.sca.implementation.spring.SpringSCAServiceElement; -import org.apache.tuscany.sca.implementation.spring.context.SCAGenericApplicationContext; -import org.apache.tuscany.sca.implementation.spring.xml.SpringXMLBeanDefinitionLoader; -import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.context.ApplicationContext; -import org.springframework.core.io.UrlResource; - -/** - * A tie that allows Tuscany to call Spring library to load the application context for the purpose of introspection - */ -public class SpringXMLBeanDefinitionLoaderImpl implements SpringXMLBeanDefinitionLoader { - - private static SCAGenericApplicationContext createApplicationContext(Object scaParentContext, - ClassLoader classLoader, - List<URL> resources) { - if (classLoader == null) { - classLoader = Thread.currentThread().getContextClassLoader(); - } - - SCAGenericApplicationContext appCtx = - new SCAGenericApplicationContext((ApplicationContext)scaParentContext, classLoader); - XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(appCtx); - - // REVIEW: [rfeng] How do we control the schema validation - xmlReader.setValidating(false); - - for (URL resource : resources) { - xmlReader.loadBeanDefinitions(new UrlResource(resource)); - } - - return appCtx; - - } - - @Override - public Object load(List<URL> resources, - List<SpringSCAServiceElement> serviceElements, - List<SpringSCAReferenceElement> referenceElements, - List<SpringSCAPropertyElement> propertyElements, - List<SpringBeanElement> beanElements, - ProcessorContext context) { - // FIXME: [rfeng] We should try to avoid parsing the Spring xml twice for the deployment and runtime - SCAGenericApplicationContext applicationContext = createApplicationContext(null, null, resources); - serviceElements.addAll(applicationContext.getServiceElements()); - referenceElements.addAll(applicationContext.getReferenceElements()); - propertyElements.addAll(applicationContext.getPropertyElements()); - beanElements.addAll(applicationContext.getBeanElements()); - return applicationContext; - } - -} |