From eb7dc287d00e10e561043e859924ebc656235f83 Mon Sep 17 00:00:00 2001 From: rfeng Date: Wed, 8 Sep 2010 05:55:12 +0000 Subject: Remove impl spring modules as now they are in trunk git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@993612 13f79535-47bb-0310-9956-ffa450edef68 --- .../tie/ComponentNameAnnotationProcessor.java | 151 ------------------- .../spring/processor/tie/ComponentStub.java | 54 ------- .../tie/ConstructorAnnotationProcessor.java | 112 -------------- .../tie/InitDestroyAnnotationProcessor.java | 75 --------- .../processor/tie/PropertyAnnotationProcessor.java | 163 -------------------- .../spring/processor/tie/PropertyValueStub.java | 55 ------- .../tie/ReferenceAnnotationProcessor.java | 167 --------------------- .../spring/processor/tie/SpringXMLLoaderTie.java | 57 ------- 8 files changed, 834 deletions(-) delete mode 100644 sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/ComponentNameAnnotationProcessor.java delete mode 100644 sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/ComponentStub.java delete mode 100644 sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/ConstructorAnnotationProcessor.java delete mode 100644 sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/InitDestroyAnnotationProcessor.java delete mode 100644 sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/PropertyAnnotationProcessor.java delete mode 100644 sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/PropertyValueStub.java delete mode 100644 sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/ReferenceAnnotationProcessor.java delete mode 100644 sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/SpringXMLLoaderTie.java (limited to 'sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie') diff --git a/sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/ComponentNameAnnotationProcessor.java b/sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/ComponentNameAnnotationProcessor.java deleted file mode 100644 index 77f9f30bfd..0000000000 --- a/sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/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.tie; - -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 componentNameAnnotationType = ComponentName.class; - - private String componentName; - - public ComponentNameAnnotationProcessor(String componentName) { - this.componentName = componentName; - } - - /** - * Gets componentName annotation type. - */ - protected Class getComponentNameAnnotationType() { - return this.componentNameAnnotationType; - } - - /** - * Sets componentName annotation type. - */ - public void setComponentNameAnnotationType(Class 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; - } - - /** - *

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() { - 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/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/ComponentStub.java b/sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/ComponentStub.java deleted file mode 100644 index 7511ac4bd5..0000000000 --- a/sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/ComponentStub.java +++ /dev/null @@ -1,54 +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.tie; - -import java.lang.reflect.Method; - -/** - * This is the Spring runtime side stub for the corresponding Tuscany tie class. - * It enables the Tuscany code to invoke methods on a Spring context without - * needing to know about any Spring classes. See the ComponentTie class - * in the implementation-spring module for what the tie does. - */ -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}); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public Object getService(Class type, String name) { - try { - - return getService.invoke(tie, type, name); - - } catch (Exception e) { - throw new RuntimeException(e); - } - } -} diff --git a/sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/ConstructorAnnotationProcessor.java b/sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/ConstructorAnnotationProcessor.java deleted file mode 100644 index 503307cfd9..0000000000 --- a/sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/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.tie; - -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 constructorAnnotationType = org.oasisopen.sca.annotation.Constructor.class; - - private Class 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 autowiredAnnotationType) { - Assert.notNull(autowiredAnnotationType, "'autowiredAnnotationType' must not be null"); - this.autowiredAnnotationType = autowiredAnnotationType; - } - - /** - * Return the 'autowired' annotation type. - */ - protected Class getAutowiredAnnotationType() { - return this.autowiredAnnotationType; - } - - /** - * Return the 'constructor' annotation type. - */ - protected Class getConstructorAnnotationType() { - return this.constructorAnnotationType; - } - - /** - * Sets the 'constructor' annotation type. - */ - public void setConstructorAnnotationType(Class 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/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/InitDestroyAnnotationProcessor.java b/sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/InitDestroyAnnotationProcessor.java deleted file mode 100644 index 390ee040f2..0000000000 --- a/sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/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.tie; - -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 initAnnotationType = Init.class; - private Class destroyAnnotationType = Destroy.class; - - /** - * Gets init annotation type. - */ - protected Class getInitAnnotationType() { - return this.initAnnotationType; - } - - /** - * Sets init annotation type. - */ - /* - * public void setInitAnnotationType(Class - * initAnnotationType) { Assert.notNull(initAnnotationType, - * "Init annotation type must not be null."); this.initAnnotationType = - * initAnnotationType; } - */ - - /** - * Gets destroy annotation type. - */ - protected Class getDestroyAnnotationType() { - return this.destroyAnnotationType; - } - - /** - * Sets destroy annotation type. - */ - /* - * public void setDestroyAnnotationType(Class - * 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/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/PropertyAnnotationProcessor.java b/sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/PropertyAnnotationProcessor.java deleted file mode 100644 index ce3aafd3ef..0000000000 --- a/sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/PropertyAnnotationProcessor.java +++ /dev/null @@ -1,163 +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.tie; - -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.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 propertyAnnotationType = Property.class; - - private PropertyValueStub propertyValue; - - public PropertyAnnotationProcessor(PropertyValueStub propertyValue) { - this.propertyValue = propertyValue; - } - - /** - * Gets property annotation type. - */ - protected Class getPropertyAnnotationType() { - return this.propertyAnnotationType; - } - - /** - * Sets property annotation type. - */ - public void setPropertyAnnotationType(Class 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; - } - - /** - *

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

- */ - 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/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/PropertyValueStub.java b/sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/PropertyValueStub.java deleted file mode 100644 index 5a4b57ce81..0000000000 --- a/sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/PropertyValueStub.java +++ /dev/null @@ -1,55 +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.tie; - -import java.lang.reflect.Method; - -/** - * This is the Spring runtime side stub for the corresponding Tuscany tie class. - * It enables the Tuscany code to invoke methods on a Spring context without - * needing to know about any Spring classes. See the PropertyValueTie class - * in the implementation-spring module for what the tie does. - */ -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}); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public Object getPropertyObj(Class propertyType, String name) { - try { - - return getPropertyObj.invoke(tie, propertyType, name); - - } catch (Exception e) { - throw new RuntimeException(e); - } - } - -} diff --git a/sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/ReferenceAnnotationProcessor.java b/sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/ReferenceAnnotationProcessor.java deleted file mode 100644 index 24761d2cfa..0000000000 --- a/sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/ReferenceAnnotationProcessor.java +++ /dev/null @@ -1,167 +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.tie; - -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.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 referenceAnnotationType = Reference.class; - private ComponentStub component; - - public ReferenceAnnotationProcessor(ComponentStub component) { - this.component = component; - } - - /** - * Gets referece annotation type. - */ - protected Class getReferenceAnnotationType() { - return this.referenceAnnotationType; - } - - /** - * Sets referece annotation type. - */ - public void setReferenceAnnotationType(Class 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; - } - - /** - *

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.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/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/SpringXMLLoaderTie.java b/sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/SpringXMLLoaderTie.java deleted file mode 100644 index 82aa176219..0000000000 --- a/sca-java-2.x/trunk/contrib/modules/implementation-spring-tie/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/tie/SpringXMLLoaderTie.java +++ /dev/null @@ -1,57 +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.tie; - -import java.net.URL; -import java.util.List; - -import org.apache.tuscany.sca.implementation.spring.context.tie.SCAGenericApplicationContext; -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 SpringXMLLoaderTie { - - public static ApplicationContext createApplicationContext(Object scaParentContext, - ClassLoader classLoader, - List 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; - - } - -} -- cgit v1.2.3