diff options
Diffstat (limited to 'sca-java-2.x/trunk/modules/implementation-spring-runtime/src')
31 files changed, 886 insertions, 879 deletions
diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/context/SCAGenericApplicationContext.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/context/SCAGenericApplicationContext.java new file mode 100644 index 0000000000..44a3ee2b88 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/context/SCAGenericApplicationContext.java @@ -0,0 +1,145 @@ +/* + * 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.context; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.implementation.spring.SpringBeanElement; +import org.apache.tuscany.sca.implementation.spring.SpringConstructorArgElement; +import org.apache.tuscany.sca.implementation.spring.SpringPropertyElement; +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.springframework.beans.MutablePropertyValues; +import org.springframework.beans.PropertyValue; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.config.BeanReference; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.beans.factory.config.ConstructorArgumentValues; +import org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder; +import org.springframework.beans.factory.config.TypedStringValue; +import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.GenericApplicationContext; + +public class SCAGenericApplicationContext extends GenericApplicationContext { + + private ClassLoader classloader = null; + private List<SpringSCAPropertyElement> propertyElements = new ArrayList<SpringSCAPropertyElement>(); + private List<SpringSCAServiceElement> serviceElements = new ArrayList<SpringSCAServiceElement>(); + private List<SpringSCAReferenceElement> referenceElements = new ArrayList<SpringSCAReferenceElement>(); + private List<SpringBeanElement> beanElements; + + 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); + } + + public void addSCAPropertyElement(SpringSCAPropertyElement propertyElement) { + propertyElements.add(propertyElement); + } + + public void addSCAServiceElement(SpringSCAServiceElement serviceElement) { + serviceElements.add(serviceElement); + } + + public void addSCAReferenceElement(SpringSCAReferenceElement referenceElement) { + referenceElements.add(referenceElement); + } + + public synchronized List<SpringBeanElement> getBeanElements() { + if (beanElements == null) { + beanElements = new ArrayList<SpringBeanElement>(); + for (String name : getBeanDefinitionNames()) { + BeanDefinition def = getBeanDefinition(name); + SpringBeanElement beanElement = new SpringBeanElement(name, def.getBeanClassName()); + beanElements.add(beanElement); + beanElement.setAbstractBean(def.isAbstract()); + beanElement.setFactoryBeanAttribute(def.getFactoryBeanName() != null); + beanElement.setFactoryMethodAttribute(def.getFactoryMethodName() != null); + beanElement.setParentAttribute(def.getParentName() != null); + beanElement.setInnerBean(beanElement.getId() == null); + + ConstructorArgumentValues args = def.getConstructorArgumentValues(); + for (Map.Entry<Integer, ValueHolder> e: args.getIndexedArgumentValues().entrySet()) { + ValueHolder holder = e.getValue(); + SpringConstructorArgElement arg = new SpringConstructorArgElement(holder.getType()); + arg.setIndex(e.getKey()); + beanElement.addCustructorArgs(arg); + } + + MutablePropertyValues values = def.getPropertyValues(); + for (PropertyValue p : values.getPropertyValueList()) { + SpringPropertyElement propertyElement = new SpringPropertyElement(p.getName()); + Object value = p.getValue(); + configurePropertyElement(propertyElement, value); + beanElement.getProperties().add(propertyElement); + } + } + } + return beanElements; + } + + public void configurePropertyElement(SpringPropertyElement propertyElement, Object value) { + if (value instanceof BeanReference) { + BeanReference beanRef = (BeanReference)value; + propertyElement.addRef(beanRef.getBeanName()); + } else if (value instanceof Collection) { + Collection collection = (Collection)value; + for (Object item : collection) { + configurePropertyElement(propertyElement, item); + } + } else if (value instanceof TypedStringValue) { + TypedStringValue stringValue = (TypedStringValue)value; + propertyElement.addValue(stringValue.getValue()); + } else { + if (value != null) { + propertyElement.addValue(value.toString()); + } + } + } + + public List<SpringSCAPropertyElement> getPropertyElements() { + return propertyElements; + } + + public List<SpringSCAServiceElement> getServiceElements() { + return serviceElements; + } + + public List<SpringSCAReferenceElement> getReferenceElements() { + return referenceElements; + } + +} 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/context/SCAParentApplicationContext.java index 13fe341881..cd81facc3d 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/context/SCAParentApplicationContext.java @@ -16,13 +16,14 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.tuscany.sca.implementation.spring.runtime.context; +package org.apache.tuscany.sca.implementation.spring.context; import java.io.IOException; import java.lang.annotation.Annotation; import java.util.Locale; import java.util.Map; +import org.apache.tuscany.sca.implementation.spring.provider.SpringImplementationWrapper; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.NoSuchBeanDefinitionException; @@ -46,14 +47,14 @@ import org.springframework.core.io.Resource; * * @version $Rev$ $Date$ */ -class SCAParentApplicationContext implements ApplicationContext { +public class SCAParentApplicationContext implements ApplicationContext { // The Spring implementation for which this is the parent application context - private SpringImplementationStub implementation; + private SpringImplementationWrapper implementation; private static final String[] EMPTY_ARRAY = new String[0]; - public SCAParentApplicationContext(SpringImplementationStub implementation) { + public SCAParentApplicationContext(SpringImplementationWrapper implementation) { this.implementation = implementation; } // end constructor diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/context/SpringApplicationContextAccessor.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/context/SpringApplicationContextAccessor.java new file mode 100644 index 0000000000..2d18b5aa6c --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/context/SpringApplicationContextAccessor.java @@ -0,0 +1,41 @@ +/* + * 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.context; + +import org.springframework.context.ApplicationContext; + +/** + * A utility to receive the parent Spring application context + */ +public interface SpringApplicationContextAccessor { + /** + * Get the parent Spring application context for the hosting environment. This will be used as the parent + * application context for implementation.spring components + * @return The parent application context + */ + ApplicationContext getParentApplicationContext(); + + /** + * Set the root Spring application context. This is particually useful for Spring web integration where Spring + * creates WebApplicationContext and keeps it in the ServletContext + * @param parentApplicationContext The parent application context + */ + void setParentApplicationContext(ApplicationContext parentApplicationContext); +} 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/context/SpringContextWrapper.java index b3b18abbd4..4b0ad72972 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/context/SpringContextWrapper.java @@ -17,23 +17,24 @@ * under the License. */ -package org.apache.tuscany.sca.implementation.spring.runtime.context; +package org.apache.tuscany.sca.implementation.spring.context; import java.net.URL; import java.util.List; import org.apache.tuscany.sca.implementation.spring.processor.ComponentNameAnnotationProcessor; -import org.apache.tuscany.sca.implementation.spring.processor.ComponentStub; import org.apache.tuscany.sca.implementation.spring.processor.ConstructorAnnotationProcessor; import org.apache.tuscany.sca.implementation.spring.processor.InitDestroyAnnotationProcessor; import org.apache.tuscany.sca.implementation.spring.processor.PropertyAnnotationProcessor; -import org.apache.tuscany.sca.implementation.spring.processor.PropertyValueStub; import org.apache.tuscany.sca.implementation.spring.processor.ReferenceAnnotationProcessor; +import org.apache.tuscany.sca.implementation.spring.provider.ComponentWrapper; +import org.apache.tuscany.sca.implementation.spring.provider.PropertyValueWrapper; +import org.apache.tuscany.sca.implementation.spring.provider.SpringImplementationWrapper; 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.XmlBeanDefinitionReader; -import org.springframework.context.support.AbstractApplicationContext; +import org.springframework.context.ApplicationContext; import org.springframework.context.support.GenericApplicationContext; import org.springframework.core.io.UrlResource; @@ -43,17 +44,21 @@ import org.springframework.core.io.UrlResource; * needing to know about any Spring classes. See the SpringContextStub class * in the implementation-spring module for what the stub does. */ -public class SpringContextTie { +public class SpringContextWrapper { - private AbstractApplicationContext springContext; - private SpringImplementationStub implementation; + private GenericApplicationContext springContext; + private SpringImplementationWrapper implementation; - public SpringContextTie(SpringImplementationStub implementation, List<URL> resource) { + public SpringContextWrapper(SpringImplementationWrapper implementation, List<URL> resource) { this.implementation = implementation; SCAParentApplicationContext scaParentContext = new SCAParentApplicationContext(implementation); springContext = createApplicationContext(scaParentContext, resource); } + public ApplicationContext getApplicationContext() { + return springContext; + } + public void start() { // Do refresh here to ensure that Spring Beans are not touched before the SCA config process is complete... springContext.refresh(); @@ -70,16 +75,16 @@ public class SpringContextTie { /** * Include BeanPostProcessor to deal with SCA Annotations in Spring Bean */ - private AbstractApplicationContext createApplicationContext(SCAParentApplicationContext scaParentContext, + private GenericApplicationContext createApplicationContext(SCAParentApplicationContext scaParentContext, List<URL> resources) { GenericApplicationContext appCtx = new SCAGenericApplicationContext(scaParentContext, implementation.getClassLoader()); 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)); } @@ -103,12 +108,12 @@ public class SpringContextTie { beanFactory.addBeanPostProcessor(initDestroyProcessor); // Processor to deal with @Reference SCA Annotations - ComponentStub component = new ComponentStub(implementation.getComponentTie()); + ComponentWrapper component = implementation.getComponentWrapper(); BeanPostProcessor referenceProcessor = new ReferenceAnnotationProcessor(component); beanFactory.addBeanPostProcessor(referenceProcessor); // Processor to deal with @Property SCA Annotations - PropertyValueStub pvs = new PropertyValueStub(implementation.getPropertyValueTie()); + PropertyValueWrapper pvs = implementation.getPropertyValueWrapper(); BeanPostProcessor propertyProcessor = new PropertyAnnotationProcessor(pvs); beanFactory.addBeanPostProcessor(propertyProcessor); diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/metadata/SpringBeanElement.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/metadata/SpringBeanElement.java deleted file mode 100644 index d954195980..0000000000 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/metadata/SpringBeanElement.java +++ /dev/null @@ -1,129 +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.metadata; - -import java.util.ArrayList; -import java.util.List; - -/** - * Represents a <bean> element in a Spring application-context - * - this has id and className attributes - * - plus zero or more property elements as children - * - * @version $Rev$ $Date$ - */ -public class SpringBeanElement { - - private String id; - private String className = null; - private boolean innerBean = false; - private boolean abstractBean = false; - private boolean parentAttribute = false; - private boolean factoryBeanAttribute = false; - private boolean factoryMethodAttribute = false; - - private List<SpringPropertyElement> properties = new ArrayList<SpringPropertyElement>(); - private List<SpringConstructorArgElement> constructorargs = new ArrayList<SpringConstructorArgElement>(); - - public SpringBeanElement(String id, String className) { - this.id = id; - this.className = className; - } - - public String getClassName() { - return className; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public List<SpringPropertyElement> getProperties() { - return properties; - } - - public void addProperty(SpringPropertyElement property) { - properties.add(property); - } - - public List<SpringConstructorArgElement> getCustructorArgs() { - return constructorargs; - } - - public void addCustructorArgs(SpringConstructorArgElement args) { - constructorargs.add(args); - } - - public boolean isInnerBean() { - return innerBean; - } - - public void setInnerBean(boolean innerBean) { - this.innerBean = innerBean; - } - - public boolean isAbstractBean() { - return abstractBean; - } - - public void setAbstractBean(boolean abstractBean) { - this.abstractBean = abstractBean; - } - - public boolean hasParentAttribute() { - return parentAttribute; - } - - public void setParentAttribute(boolean parentAttribute) { - this.parentAttribute = parentAttribute; - } - - public boolean hasFactoryBeanAttribute() { - return factoryBeanAttribute; - } - - public void setFactoryBeanAttribute(boolean factoryBeanAttribute) { - this.factoryBeanAttribute = factoryBeanAttribute; - } - - public boolean hasFactoryMethodAttribute() { - return factoryMethodAttribute; - } - - public void setFactoryMethodAttribute(boolean factoryMethodAttribute) { - this.factoryMethodAttribute = factoryMethodAttribute; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("SpringBeanElement [id=").append(id).append(", className=").append(className) - .append(", innerBean=").append(innerBean).append(", abstractBean=").append(abstractBean) - .append(", parentAttribute=").append(parentAttribute).append(", factoryBeanAttribute=") - .append(factoryBeanAttribute).append(", factoryMethodAttribute=").append(factoryMethodAttribute) - .append(", properties=").append(properties).append(", constructorargs=").append(constructorargs) - .append("]"); - return builder.toString(); - } - -} // end class SpringBeanElement diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/metadata/SpringConstructorArgElement.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/metadata/SpringConstructorArgElement.java deleted file mode 100644 index 5571029c61..0000000000 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/metadata/SpringConstructorArgElement.java +++ /dev/null @@ -1,77 +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.metadata; - -import java.util.ArrayList; -import java.util.List; - -/** - * Represents a <constructor-arg> element in a Spring application-context - * - this has ref attribute - * - * @version $Rev$ $Date$ - */ -public class SpringConstructorArgElement { - - private String type; - private int autoIndex = -1; - private int index = -1; - private List<String> refs = new ArrayList<String>(); - private List<String> values = new ArrayList<String>(); - - public SpringConstructorArgElement(String type) { - this.type = type; - } - - public String getType() { - return this.type; - } - - public List<String> getRefs() { - return this.refs; - } - - public void addRef(String ref) { - this.refs.add(ref); - } - - public int getIndex() { - return this.index; - } - - public void setIndex(int index) { - this.index = index; - } - - public int getAutoIndex() { - return this.autoIndex; - } - - public void setAutoIndex(int index) { - this.autoIndex = index; - } - - public List<String> getValues() { - return this.values; - } - - public void addValue(String value) { - this.values.add(value); - } -} diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/metadata/SpringElementTie.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/metadata/SpringElementTie.java deleted file mode 100644 index df4b077819..0000000000 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/metadata/SpringElementTie.java +++ /dev/null @@ -1,70 +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.metadata; - -import java.lang.reflect.Field; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * A hacking utility to copy beans field by field between two class loaders - */ -public class SpringElementTie { - public static <T> T copy(Object source, Class<T> cls, Type genericType) { - if (source == null) { - return null; - } - if (cls.isPrimitive()) { - return (T)source; - } - if (Collection.class.isAssignableFrom(cls)) { - ParameterizedType pType = (ParameterizedType)genericType; - Type itemType = pType.getActualTypeArguments()[0]; - Collection col = (Collection)source; - List target = new ArrayList(); - for (Object item : col) { - target.add(copy(item, (Class<?>)itemType, itemType)); - } - return (T)target; - } - if (cls.isInstance(source)) { - return cls.cast(source); - } - try { - Class<?> sourceClass = source.getClass(); - T target = cls.newInstance(); - for (Field sourceField : sourceClass.getDeclaredFields()) { - sourceField.setAccessible(true); - Field targetField = cls.getDeclaredField(sourceField.getName()); - targetField.setAccessible(true); - Object sourceFieldValue = sourceField.get(source); - Object targetFieldValue = copy(sourceFieldValue, targetField.getType(), targetField.getGenericType()); - targetField.set(target, targetFieldValue); - } - return target; - } catch (Throwable e) { - throw new IllegalArgumentException(e); - } - } - -} diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/metadata/SpringPropertyElement.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/metadata/SpringPropertyElement.java deleted file mode 100644 index 585b3d3381..0000000000 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/metadata/SpringPropertyElement.java +++ /dev/null @@ -1,68 +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.metadata; - -import java.util.ArrayList; -import java.util.List; - -/** - * Represents a <property> element in a Spring application-context - * - this has name and ref attributes - * - * @version $Rev$ $Date$ - */ -public class SpringPropertyElement { - - private String name; - private List<String> refs = new ArrayList<String>(); - private List<String> values = new ArrayList<String>(); - - public SpringPropertyElement(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public List<String> getRefs() { - return this.refs; - } - - public void addRef(String ref) { - this.refs.add(ref); - } - - public List<String> getValues() { - return this.values; - } - - public void addValue(String value) { - this.values.add(value); - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("SpringPropertyElement [name=").append(name).append(", refs=").append(refs).append(", values=") - .append(values).append("]"); - return builder.toString(); - } - -} // end class SpringPropertyElement diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/metadata/SpringSCAPropertyElement.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/metadata/SpringSCAPropertyElement.java deleted file mode 100644 index f721b21042..0000000000 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/metadata/SpringSCAPropertyElement.java +++ /dev/null @@ -1,59 +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.metadata; - -/** - * Represents an <sca:property> element in a Spring application-context - * - this has name and type attributes - * @version $Rev$ $Date$ - */ -public class SpringSCAPropertyElement { - - private String name; - private String type; - - public SpringSCAPropertyElement(String name, String type) { - this.name = name; - this.type = type; - } - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public void setType(String type) { - this.type = type; - } - - public String getType() { - return type; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("SpringSCAPropertyElement [name=").append(name).append(", type=").append(type).append("]"); - return builder.toString(); - } - -} // end class SpringPropertyElement diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/metadata/SpringSCAReferenceElement.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/metadata/SpringSCAReferenceElement.java deleted file mode 100644 index ffa91ad179..0000000000 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/metadata/SpringSCAReferenceElement.java +++ /dev/null @@ -1,73 +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.metadata; - - -/** - * Represents a <sca:reference> element in a Spring application-context - * - this has id and className attributes - * - plus zero or more property elements as children - * - * @version $Rev$ $Date$ - */ -public class SpringSCAReferenceElement { - - private String name; - private String type; - private String defaultBean; - - public SpringSCAReferenceElement(String name, String type) { - this.name = name; - this.type = type; - } - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public void setType(String type) { - this.type = type; - } - - public String getType() { - return type; - } - - public void setDefaultBean(String defaultBean) { - this.defaultBean = defaultBean; - } - - public String getDefaultBean() { - return defaultBean; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("SpringSCAReferenceElement [name=").append(name).append(", type=").append(type) - .append(", defaultBean=").append(defaultBean).append("]"); - return builder.toString(); - } - - -} // end class SpringSCAReferenceElement diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/metadata/SpringSCAServiceElement.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/metadata/SpringSCAServiceElement.java deleted file mode 100644 index 6dee35f46e..0000000000 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/metadata/SpringSCAServiceElement.java +++ /dev/null @@ -1,73 +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.metadata; - - -/** - * Represents a <sca:service> element in a Spring application-context - * - this has id and className attributes - * - plus zero or more property elements as children - * - * @version $Rev$ $Date$ - */ -public class SpringSCAServiceElement { - - private String name; - private String type; - private String target; - - - public SpringSCAServiceElement(String name, String target) { - this.name = name; - this.target = target; - } - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public void setType(String type) { - this.type = type; - } - - public String getType() { - return type; - } - - public void setTarget(String target) { - this.target = target; - } - - public String getTarget() { - return target; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("SpringSCAServiceElement [name=").append(name).append(", type=").append(type) - .append(", target=").append(target).append("]"); - return builder.toString(); - } - -} // end class SpringSCAServiceElement diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaNamespaceHandler.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaNamespaceHandler.java index f136e45b87..89c87ad1d1 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaNamespaceHandler.java +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaNamespaceHandler.java @@ -26,10 +26,10 @@ import org.springframework.beans.factory.xml.NamespaceHandlerSupport; public class ScaNamespaceHandler extends NamespaceHandlerSupport { public ScaNamespaceHandler() { - init(); } - public final void init() { + @Override + public void init() { registerBeanDefinitionParser("reference", new ScaReferenceBeanDefinitionParser()); registerBeanDefinitionParser("service", new ScaServiceBeanDefinitionParser()); registerBeanDefinitionParser("property", new ScaPropertyBeanDefinitionParser()); diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaPropertyBeanDefinitionParser.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaPropertyBeanDefinitionParser.java index 5b1064d8d8..bff0aa84e0 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaPropertyBeanDefinitionParser.java +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaPropertyBeanDefinitionParser.java @@ -16,7 +16,10 @@ */ package org.apache.tuscany.sca.implementation.spring.namespace; +import org.apache.tuscany.sca.implementation.spring.SpringSCAPropertyElement; +import org.apache.tuscany.sca.implementation.spring.context.SCAGenericApplicationContext; import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.xml.BeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; import org.w3c.dom.Element; @@ -28,8 +31,14 @@ import org.w3c.dom.Element; public class ScaPropertyBeanDefinitionParser implements BeanDefinitionParser { public BeanDefinition parse(Element element, ParserContext parserContext) { + BeanDefinitionRegistry registry = parserContext.getRegistry(); + if (registry instanceof SCAGenericApplicationContext) { + SCAGenericApplicationContext context = (SCAGenericApplicationContext)registry; + SpringSCAPropertyElement propertyElement = + new SpringSCAPropertyElement(element.getAttributeNS(null, "name"), element.getAttributeNS(null, "type")); + context.addSCAPropertyElement(propertyElement); + } // do nothing, this is handled by Tuscany return null; } - } diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaReferenceBeanDefinitionParser.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaReferenceBeanDefinitionParser.java index fac02760c9..6cb4978a47 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaReferenceBeanDefinitionParser.java +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaReferenceBeanDefinitionParser.java @@ -16,7 +16,10 @@ */ package org.apache.tuscany.sca.implementation.spring.namespace; +import org.apache.tuscany.sca.implementation.spring.SpringSCAReferenceElement; +import org.apache.tuscany.sca.implementation.spring.context.SCAGenericApplicationContext; import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.xml.BeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; import org.w3c.dom.Element; @@ -29,6 +32,16 @@ import org.w3c.dom.Element; public class ScaReferenceBeanDefinitionParser implements BeanDefinitionParser { public BeanDefinition parse(Element element, ParserContext parserContext) { + BeanDefinitionRegistry registry = parserContext.getRegistry(); + if (registry instanceof SCAGenericApplicationContext) { + SCAGenericApplicationContext context = (SCAGenericApplicationContext)registry; + SpringSCAReferenceElement referenceElement = + new SpringSCAReferenceElement(element.getAttributeNS(null, "name"), + element.getAttributeNS(null, "type")); + referenceElement.setDefaultBean(element.getAttributeNS(null, "default")); + context.addSCAReferenceElement(referenceElement); + } + // do nothing, this is handled by Tuscany return null; } diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaServiceBeanDefinitionParser.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaServiceBeanDefinitionParser.java index 3020dca8bc..e5eabd2a4b 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaServiceBeanDefinitionParser.java +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaServiceBeanDefinitionParser.java @@ -16,7 +16,10 @@ */ package org.apache.tuscany.sca.implementation.spring.namespace; +import org.apache.tuscany.sca.implementation.spring.SpringSCAServiceElement; +import org.apache.tuscany.sca.implementation.spring.context.SCAGenericApplicationContext; import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.xml.BeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; import org.w3c.dom.Element; @@ -29,6 +32,15 @@ import org.w3c.dom.Element; public class ScaServiceBeanDefinitionParser implements BeanDefinitionParser { public BeanDefinition parse(Element element, ParserContext parserContext) { + BeanDefinitionRegistry registry = parserContext.getRegistry(); + if (registry instanceof SCAGenericApplicationContext) { + SCAGenericApplicationContext context = (SCAGenericApplicationContext)registry; + SpringSCAServiceElement serviceElement = + new SpringSCAServiceElement(element.getAttributeNS(null, "name"), + element.getAttributeNS(null, "target")); + serviceElement.setType(element.getAttributeNS(null, "type")); + context.addSCAServiceElement(serviceElement); + } // do nothing, handled by Tuscany return null; } 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 deleted file mode 100644 index b087c45ab4..0000000000 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/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; - -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/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 565d0118d9..4763714a38 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 @@ -24,6 +24,7 @@ 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; @@ -36,9 +37,9 @@ public class PropertyAnnotationProcessor implements BeanPostProcessor { private Class<? extends Annotation> propertyAnnotationType = Property.class; - private PropertyValueStub propertyValue; + private PropertyValueWrapper propertyValue; - public PropertyAnnotationProcessor(PropertyValueStub propertyValue) { + public PropertyAnnotationProcessor(PropertyValueWrapper propertyValue) { this.propertyValue = propertyValue; } 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 deleted file mode 100644 index 9a95f818de..0000000000 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/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; - -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/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 280c723430..ad79db840e 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 @@ -24,6 +24,7 @@ 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; @@ -35,9 +36,9 @@ import org.springframework.util.ReflectionUtils; public class ReferenceAnnotationProcessor implements BeanPostProcessor { private Class<? extends Annotation> referenceAnnotationType = Reference.class; - private ComponentStub component; + private ComponentWrapper component; - public ReferenceAnnotationProcessor(ComponentStub component) { + public ReferenceAnnotationProcessor(ComponentWrapper component) { this.component = component; } diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/SpringXMLLoaderTie.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/SpringXMLBeanDefinitionLoaderImpl.java index b3f0a4a883..71feddb9f5 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/SpringXMLLoaderTie.java +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/SpringXMLBeanDefinitionLoaderImpl.java @@ -22,7 +22,13 @@ package org.apache.tuscany.sca.implementation.spring.processor; import java.net.URL; import java.util.List; -import org.apache.tuscany.sca.implementation.spring.runtime.context.SCAGenericApplicationContext; +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; @@ -30,11 +36,11 @@ 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 class SpringXMLBeanDefinitionLoaderImpl implements SpringXMLBeanDefinitionLoader { - public static ApplicationContext createApplicationContext(Object scaParentContext, - ClassLoader classLoader, - List<URL> resources) { + private static SCAGenericApplicationContext createApplicationContext(Object scaParentContext, + ClassLoader classLoader, + List<URL> resources) { if (classLoader == null) { classLoader = Thread.currentThread().getContextClassLoader(); } @@ -54,4 +60,19 @@ public class SpringXMLLoaderTie { } + @Override + public Object load(List<URL> resources, + List<SpringSCAServiceElement> serviceElements, + List<SpringSCAReferenceElement> referenceElements, + List<SpringSCAPropertyElement> propertyElements, + List<SpringBeanElement> beanElements, + ProcessorContext context) { + SCAGenericApplicationContext applicationContext = createApplicationContext(null, null, resources); + serviceElements.addAll(applicationContext.getServiceElements()); + referenceElements.addAll(applicationContext.getReferenceElements()); + propertyElements.addAll(applicationContext.getPropertyElements()); + beanElements.addAll(applicationContext.getBeanElements()); + return applicationContext; + } + } diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/provider/ComponentWrapper.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/provider/ComponentWrapper.java new file mode 100644 index 0000000000..5bddd8a006 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/provider/ComponentWrapper.java @@ -0,0 +1,38 @@ +/* + * 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.provider; + +/** + * Wrapper for the Component + */ +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +public class ComponentWrapper { + + private RuntimeComponent component; + + public ComponentWrapper(RuntimeComponent component) { + this.component = component; + } + + public Object getService(Class<?> type, String name) { + return component.getComponentContext().getService(type, name); + } +} diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/provider/PropertyValueWrapper.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/provider/PropertyValueWrapper.java new file mode 100644 index 0000000000..eca1492081 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/provider/PropertyValueWrapper.java @@ -0,0 +1,50 @@ +/* + * 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.provider; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.ComponentProperty; +import org.apache.tuscany.sca.context.PropertyValueFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * Wrapper for PropertyValue + */ +public class PropertyValueWrapper { + + private RuntimeComponent component; + private PropertyValueFactory propertyFactory; + + public PropertyValueWrapper(RuntimeComponent component, PropertyValueFactory propertyFactory) { + this.component = component; + this.propertyFactory = propertyFactory; + } + + public Object getPropertyObj(Class<?> type, String name) { + List<ComponentProperty> props = component.getProperties(); + for (ComponentProperty prop : props) { + if (prop.getName().equals(name)) { + return propertyFactory.createPropertyValue(prop, type); + } + } + return null; // property name not found + } +} diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/provider/SpringImplementationProvider.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/provider/SpringImplementationProvider.java new file mode 100644 index 0000000000..db7831322a --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/provider/SpringImplementationProvider.java @@ -0,0 +1,81 @@ +/* + * 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.provider; + +import org.apache.tuscany.sca.context.PropertyValueFactory; +import org.apache.tuscany.sca.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.implementation.spring.context.SpringContextWrapper; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.springframework.context.ApplicationContext; + +/** + * A provider class for runtime Spring implementation instances + * @version $Rev$ $Date$ + */ +public class SpringImplementationProvider implements ImplementationProvider { + private RuntimeComponent component; + + // A Spring application context object + private SpringContextWrapper springContext; + + /** + * Constructor for the provider - takes a component definition and a Spring implementation + * description + * @param component - the component in the assembly + * @param implementation - the implementation + */ + public SpringImplementationProvider(RuntimeComponent component, + SpringImplementationWrapper implementation, + ApplicationContext parentApplicationContext, + ProxyFactory proxyService, + PropertyValueFactory propertyValueObjectFactory) { + super(); + this.component = component; + + springContext = new SpringContextWrapper(implementation, implementation.getResource()); + + } // end constructor + + public Invoker createInvoker(RuntimeComponentService service, Operation operation) { + return new SpringInvoker(component, springContext, service, operation); + } + + public boolean supportsOneWayInvocation() { + return false; + } + + /** + * Start this Spring implementation instance + */ + public void start() { + springContext.start(); + } + + /** + * Stop this implementation instance + */ + public void stop() { + springContext.close(); + } + +} // end class SpringImplementationProvider diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/provider/SpringImplementationProviderFactory.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/provider/SpringImplementationProviderFactory.java new file mode 100644 index 0000000000..be16fb3251 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/provider/SpringImplementationProviderFactory.java @@ -0,0 +1,78 @@ +/* + * 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.provider; + +import org.apache.tuscany.sca.context.PropertyValueFactory; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory; +import org.apache.tuscany.sca.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.implementation.spring.SpringImplementation; +import org.apache.tuscany.sca.implementation.spring.context.SpringApplicationContextAccessor; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.provider.ImplementationProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.springframework.context.ApplicationContext; + +/** + * ImplementationProviderFactory for Spring implementation type + * @version $Rev$ $Date$ + * + */ +public class SpringImplementationProviderFactory implements ImplementationProviderFactory<SpringImplementation> { + private ProxyFactory proxyFactory; + private PropertyValueFactory propertyFactory; + private SpringApplicationContextAccessor contextAccessor; + + /** + * Simple constructor + * + */ + public SpringImplementationProviderFactory(ExtensionPointRegistry registry) { + super(); + UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); + contextAccessor = utilities.getUtility(SpringApplicationContextAccessor.class); + proxyFactory = ExtensibleProxyFactory.getInstance(registry); + propertyFactory = utilities.getUtility(PropertyValueFactory.class); + } + + /** + * Returns a SpringImplementationProvider for a given component and Spring implementation + * @param component the component for which implementation instances are required + * @param implementation the Spring implementation with details of the component + * implementation + * @return the SpringImplementationProvider for the specified component + */ + public ImplementationProvider createImplementationProvider(RuntimeComponent component, + SpringImplementation implementation) { + ApplicationContext parentApplicationContext = + (contextAccessor != null) ? contextAccessor.getParentApplicationContext() : null; + SpringImplementationWrapper tie = + new SpringImplementationWrapper(implementation, parentApplicationContext, component, propertyFactory); + return new SpringImplementationProvider(component, tie, parentApplicationContext, proxyFactory, propertyFactory); + } + + /** + * Returns the class of the Spring implementation + */ + public Class<SpringImplementation> getModelType() { + return SpringImplementation.class; + } + +} // end class SpringImplementationProviderFactory diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/provider/SpringImplementationWrapper.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/provider/SpringImplementationWrapper.java new file mode 100644 index 0000000000..e5593f5eaa --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/provider/SpringImplementationWrapper.java @@ -0,0 +1,158 @@ +/* + * 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.provider; + +import java.net.URL; +import java.util.List; + +import org.apache.tuscany.sca.assembly.ComponentProperty; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.context.PropertyValueFactory; +import org.apache.tuscany.sca.implementation.spring.SpringImplementation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.springframework.context.ApplicationContext; + +/** + * Wrapper for SpringImplementation + */ +public class SpringImplementationWrapper { + + private SpringImplementation implementation; + private ApplicationContext parentApplicationContext; + private RuntimeComponent component; + private PropertyValueFactory propertyFactory; + + public SpringImplementationWrapper(SpringImplementation implementation, + ApplicationContext parentApplicationContext, + RuntimeComponent component, + PropertyValueFactory propertyFactory) { + this.implementation = implementation; + this.component = component; + this.propertyFactory = propertyFactory; + this.parentApplicationContext = parentApplicationContext; + } + + public String getURI() { + return implementation.getURI(); + } + + public List<URL> getResource() { + return implementation.getResource(); + } + + public String getComponentName() { + return component.getName(); + } + + /** + * Method to create a Java Bean for a Property value + * @param <B> the class type of the Bean + * @param requiredType - a Class object for the required type + * @param name - the Property name + * @return - a Bean of the specified property, with value set + */ + private <B> B getPropertyBean(Class<?> requiredType, String name) { + B propertyObject = null; + // Get the component's list of properties + List<ComponentProperty> props = component.getProperties(); + for (ComponentProperty prop : props) { + if (prop.getName().equals(name)) { + // On finding the property, create a factory for it and create a Bean using + // the factory + propertyObject = (B)propertyFactory.createPropertyValue(prop, requiredType); + } // end if + } // end for + + return propertyObject; + } + + /** + * Creates a proxy Bean for a reference + * @param <B> the Business interface type for the reference + * @param businessInterface - the business interface as a Class + * @param referenceName - the name of the Reference + * @return an Bean of the type defined by <B> + */ + private <B> B getService(Class<B> businessInterface, String referenceName) { + return component.getComponentContext().getService(businessInterface, referenceName); + } + + /** + * Get a Bean for a reference or for a property. + * + * @param name - the name of the Bean required + * @param requiredType - the required type of the Bean (either a Java class or a Java interface) + * @return Object - a Bean which matches the requested bean + */ + public Object getBean(String name, Class<?> requiredType) { + // The expectation is that the requested Bean is either a reference or a property + // from the Spring context + for (Reference reference : implementation.getReferences()) { + if (reference.getName().equals(name)) { + // Extract the Java interface for the reference (it can't be any other interface type + // for a Spring application context) + if (requiredType == null) { + JavaInterface javaInterface = (JavaInterface)reference.getInterfaceContract().getInterface(); + requiredType = javaInterface.getJavaClass(); + } + // Create and return the proxy for the reference + return getService(requiredType, reference.getName()); + } // end if + } // end for + + // For a property, get the name and the required Java type and create a Bean + // of that type with the value inserted. + for (Property property : implementation.getProperties()) { + if (property.getName().equals(name)) { + if (requiredType == null) { + // The following code only deals with a subset of types and was superceded + // by the information from the implementation (which uses Classes as found + // in the Spring implementation itself. + //requiredType = JavaXMLMapper.getJavaType( property.getXSDType() ); + requiredType = implementation.getPropertyClass(name); + } + return getPropertyBean(requiredType, property.getName()); + } // end if + } // end for + // TODO: NoSuchBeanException + // throw new RuntimeException("Unable to find Bean with name " + name); + return null; + + } // end method getBean( String, Class ) + + public ComponentWrapper getComponentWrapper() { + return new ComponentWrapper(component); + } + + public PropertyValueWrapper getPropertyValueWrapper() { + return new PropertyValueWrapper(component, propertyFactory); + } + + public ClassLoader getClassLoader() { + return implementation.getClassLoader(); + } + + public ApplicationContext getParentApplicationContext() { + return parentApplicationContext; + } + +} diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/provider/SpringInvocationException.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/provider/SpringInvocationException.java new file mode 100644 index 0000000000..0e1d3f5b5a --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/provider/SpringInvocationException.java @@ -0,0 +1,40 @@ +/* + * 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.provider; + +/** + * @version $Rev$ $Date$ + */ +public class SpringInvocationException extends Exception { + + private static final long serialVersionUID = -1157790036638157513L; + + public SpringInvocationException(String msg) { + super(msg); + } + + public SpringInvocationException(Throwable e) { + super(e); + } + + public SpringInvocationException(String msg, Throwable e) { + super(msg, e); + } + +} diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/provider/SpringInvoker.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/provider/SpringInvoker.java new file mode 100644 index 0000000000..ea1d6e6755 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/provider/SpringInvoker.java @@ -0,0 +1,126 @@ +/* + * 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.provider; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import org.apache.tuscany.sca.implementation.spring.SpringBeanElement; +import org.apache.tuscany.sca.implementation.spring.SpringImplementation; +import org.apache.tuscany.sca.implementation.spring.context.SpringContextWrapper; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * Initial implementation of a Spring bean invoker + * @version $Rev$ $Date$ + */ +public class SpringInvoker implements Invoker { + + private Method theMethod = null; + private Object bean; + private SpringBeanElement beanElement; + private boolean badInvoker = false; + + private SpringContextWrapper springContext; + private Operation operation; + + /** + * SpringInvoker constructor + * @param component - the Spring component to invoke + * @param service - the service to invoke + * @param operation - the operation to invoke + */ + public SpringInvoker(RuntimeComponent component, + SpringContextWrapper springContext, + RuntimeComponentService service, + Operation operation) { + + this.springContext = springContext; + this.operation = operation; + + // From the component and the service, identify the Spring Bean which is the target + SpringImplementation theImplementation = (SpringImplementation)component.getImplementation(); + beanElement = theImplementation.getBeanFromService(service.getService()); + + if (beanElement == null) { + badInvoker = true; + return; + } + + } // end constructor SpringInvoker + + // Lazy-load the method to avoid timing problems with the Spring Context + private void setupMethod() throws SpringInvocationException { + try { + bean = springContext.getBean(beanElement.getId()); + Class<?> beanClass = bean.getClass(); + theMethod = JavaInterfaceUtil.findMethod(beanClass, operation); + //System.out.println("SpringInvoker - found method " + theMethod.getName() ); + } catch (NoSuchMethodException e) { + throw new SpringInvocationException(e); + } + } + + private Object doInvoke(Object payload) throws SpringInvocationException { + if (theMethod == null) + setupMethod(); + + if (badInvoker) + throw new SpringInvocationException("Spring invoker incorrectly configured"); + // Invoke the method on the Spring bean using the payload, returning the results + try { + Object ret; + + if (payload != null && !payload.getClass().isArray()) { + ret = theMethod.invoke(bean, payload); + } else { + ret = theMethod.invoke(bean, (Object[])payload); + } + return ret; + } catch (InvocationTargetException e) { + throw new SpringInvocationException("Spring invoker invoke method '" + theMethod.getName() + "' error.", + e.getCause()); + } catch (Exception e) { + throw new SpringInvocationException("Spring invoker invoke method '" + theMethod.getName() + "' error.", e); + } + + } // end method doInvoke + + /** + * @param msg the message to invoke on the target bean + */ + public Message invoke(Message msg) { + try { + Object resp = doInvoke(msg.getBody()); + msg.setBody(resp); + } catch (SpringInvocationException e) { + msg.setFaultBody(e.getCause()); + } catch (Throwable e) { + msg.setFaultBody(e); + } + //System.out.println("Spring Invoker - invoke called"); + return msg; + } // end method invoke + +} // end class SpringInvoker 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 deleted file mode 100644 index 3e0aacdb40..0000000000 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SCAGenericApplicationContext.java +++ /dev/null @@ -1,46 +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.runtime.context; - -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.context.ApplicationContext; -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; - } - - @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/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 deleted file mode 100644 index 20e5d6b8d2..0000000000 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringImplementationStub.java +++ /dev/null @@ -1,146 +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.runtime.context; - -import java.lang.reflect.Method; - -import org.springframework.beans.BeansException; -import org.springframework.context.ApplicationContext; - -/** - * This is the runtime side stub for the corresponding Tuscany-side stub class. - * It enables the Spring code in the runtime module to invoke methods on a - * Tuscany SpringImplementation without the Spring runtime module - * needing to know about any Tuscany classes. See the SpringImplementationTie class - * in the implementation-spring module for what the tie does. - */ -public class SpringImplementationStub { - - Object tie; - Method getURI; - Method getBean; - Method getComponentName; - Method getComponentTie; - Method getPropertyValueTie; - Method getClassLoader; - Method getParentApplicationContext; - - 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}); - getComponentName = tieClass.getMethod("getComponentName"); - getComponentTie = tieClass.getMethod("getComponentTie"); - getPropertyValueTie = tieClass.getMethod("getPropertyValueTie"); - getClassLoader = tieClass.getMethod("getClassLoader"); - getParentApplicationContext = tieClass.getMethod("getParentApplicationContext"); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public String getURI() { - try { - - return (String)getURI.invoke(tie); - - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - /** - * Get a Bean for a reference or for a property. - * - * @param name - the name of the Bean required - * @param requiredType - the required type of the Bean (either a Java class or a Java interface) - * @return Object - a Bean which matches the requested bean - */ - public Object getBean(String name, Class<?> requiredType) throws BeansException { - try { - - Object bean = getBean.invoke(tie, new Object[] {name, requiredType}); -// if (bean == null) { -// throw new NoSuchBeanDefinitionException("Unable to find Bean with name " + name); -// } - return bean; - - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public String getComponentName() { - try { - - return (String)getComponentName.invoke(tie); - - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public Object getComponentTie() { - try { - - return getComponentTie.invoke(tie); - - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public Object getPropertyValueTie() { - try { - - return getPropertyValueTie.invoke(tie); - - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public ClassLoader getClassLoader() { - try { - - return (ClassLoader)getClassLoader.invoke(tie); - - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - /** - * Get the parent Spring application context set by the Tuscany runtime - * @return - */ - public ApplicationContext getParentApplicationContext() { - try { - - return (ApplicationContext)getParentApplicationContext.invoke(tie); - - } catch (Exception e) { - throw new RuntimeException(e); - } - - } -} diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.spring.xml.SpringXMLBeanDefinitionLoader b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.spring.xml.SpringXMLBeanDefinitionLoader new file mode 100644 index 0000000000..4c8fa09951 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.spring.xml.SpringXMLBeanDefinitionLoader @@ -0,0 +1,17 @@ +# 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. +org.apache.tuscany.sca.implementation.spring.processor.SpringXMLBeanDefinitionLoaderImpl;ranking=100
\ No newline at end of file diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory new file mode 100644 index 0000000000..e6c8d70fe1 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory @@ -0,0 +1,20 @@ +# 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.
+
+# Implementation class for the implementation extension
+org.apache.tuscany.sca.implementation.spring.provider.SpringImplementationProviderFactory;model=org.apache.tuscany.sca.implementation.spring.SpringImplementation;ranking=100
+
|