summaryrefslogtreecommitdiffstats
path: root/sandbox/old/contrib/implementation-spring/container/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/context/SCAApplicationContext.java49
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/context/SCANamespaceHandlerResolver.java51
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/context/ScaNamespaceHandler.java38
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/context/ScaReferenceBeanDefinitionParser.java38
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/context/ScaServiceBeanDefinitionParser.java38
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/impl/BeanMethodNotFound.java40
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/impl/SpringCompositeBuilder.java51
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/impl/SpringCompositeComponent.java311
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/impl/SpringInvoker.java106
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/loader/SpringImplementationLoader.java203
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/loader/SpringXMLComponentTypeLoader.java128
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/model/ReferenceDeclaration.java43
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/model/ServiceDeclaration.java57
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/model/SpringComponentType.java91
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/model/SpringImplementation.java74
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/main/resources/META-INF/sca/spring.system.scdl46
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/main/resources/META-INF/spring.handlers3
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/main/resources/META-INF/spring.schemas1
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/main/resources/org/springframework/sca/xml/spring-sca.xsd83
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/SpringConfigSchemaTestCase.java52
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/SpringTestUtils.java73
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/TestClassResource.java45
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/impl/ReferenceWiringTestCase.java151
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/impl/SpringCompositeBuilderTestCase.java131
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/impl/SpringCompositeComponentTestCase.java76
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/impl/SpringInvocationTestCase.java57
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/mock/TestBean.java31
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/mock/TestBeanImpl.java42
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/mock/TestReference.java8
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/test/resources/META-INF/sca/application-context.xml14
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/test/resources/META-INF/sca/default.scdl37
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/test/resources/META-INF/sca/testReferenceContext.xml15
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/test/resources/META-INF/sca/testServiceContext.xml13
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/test/resources/META-INF/tuscany/xsystem.scdl37
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/test/resources/org/apache/tuscany/container/spring/ExplicitSpring.xml14
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/test/resources/org/apache/tuscany/container/spring/SpringConfigSchemaTest.xml17
-rw-r--r--sandbox/old/contrib/implementation-spring/container/src/test/resources/test.xml11
37 files changed, 2275 insertions, 0 deletions
diff --git a/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/context/SCAApplicationContext.java b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/context/SCAApplicationContext.java
new file mode 100644
index 0000000000..343c76d7a2
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/context/SCAApplicationContext.java
@@ -0,0 +1,49 @@
+/*
+ * 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.container.spring.context;
+
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.core.io.Resource;
+
+/**
+ * An <code>ApplicationContext</code> specialization that registers namespace handlers for SCA elements
+ *
+ * @version $Rev$ $Date$
+ */
+public class SCAApplicationContext extends AbstractXmlApplicationContext {
+ public static final String APP_CONTEXT_PROP = "org.springframework.sca.application.context";
+ private Resource appXml;
+
+ public SCAApplicationContext(ApplicationContext parent, Resource appXml) {
+ super(parent);
+ this.appXml = appXml;
+ refresh();
+ }
+
+ protected void initBeanDefinitionReader(XmlBeanDefinitionReader beanDefinitionReader) {
+ ClassLoader cl = getClassLoader();
+ beanDefinitionReader.setNamespaceHandlerResolver(new SCANamespaceHandlerResolver(cl));
+ }
+
+ protected Resource[] getConfigResources() {
+ return new Resource[]{appXml};
+ }
+}
diff --git a/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/context/SCANamespaceHandlerResolver.java b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/context/SCANamespaceHandlerResolver.java
new file mode 100644
index 0000000000..b524846fc9
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/context/SCANamespaceHandlerResolver.java
@@ -0,0 +1,51 @@
+/*
+ * 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.container.spring.context;
+
+import org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver;
+import org.springframework.beans.factory.xml.NamespaceHandler;
+
+/**
+ * Overrides the default Spring namespace resolver to automatically register {@link ScaNamespaceHandler} instead of
+ * requiring a value to be supplied in a Spring configuration
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class SCANamespaceHandlerResolver extends DefaultNamespaceHandlerResolver {
+ private static final String SCA_NAMESPACE = "http://www.springframework.org/schema/sca";
+
+ private ScaNamespaceHandler handler;
+
+ public SCANamespaceHandlerResolver(ClassLoader classLoader) {
+ super(classLoader);
+ handler = new ScaNamespaceHandler(/*componentType*/);
+ }
+
+ public SCANamespaceHandlerResolver(String handlerMappingsLocation, ClassLoader classLoader) {
+ super(classLoader, handlerMappingsLocation);
+ handler = new ScaNamespaceHandler(/*componentType*/);
+ }
+
+ public NamespaceHandler resolve(String namespaceUri) {
+ if (SCA_NAMESPACE.equals(namespaceUri)) {
+ return handler;
+ }
+ return super.resolve(namespaceUri);
+ }
+}
diff --git a/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/context/ScaNamespaceHandler.java b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/context/ScaNamespaceHandler.java
new file mode 100644
index 0000000000..5ce7edbc2d
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/context/ScaNamespaceHandler.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2002-2006 the original author or authors.
+ *
+ * Licensed 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.
+ *
+ * Created on 10-Apr-2006 by Adrian Colyer
+ */
+package org.apache.tuscany.container.spring.context;
+
+import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
+
+/**
+ * Handler for the &lt;sca:&gt; namespace in an application context
+ *
+ * @version $Rev$ $Date$
+ */
+public class ScaNamespaceHandler extends NamespaceHandlerSupport {
+
+ public ScaNamespaceHandler() {
+ init();
+ }
+
+ public final void init() {
+ registerBeanDefinitionParser("reference", new ScaReferenceBeanDefinitionParser());
+ registerBeanDefinitionParser("service", new ScaServiceBeanDefinitionParser());
+ }
+
+}
diff --git a/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/context/ScaReferenceBeanDefinitionParser.java b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/context/ScaReferenceBeanDefinitionParser.java
new file mode 100644
index 0000000000..d872cefc3a
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/context/ScaReferenceBeanDefinitionParser.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2002-2006 the original author or authors.
+ *
+ * Licensed 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.
+ *
+ * Created on 10-Apr-2006 by Adrian Colyer
+ */
+package org.apache.tuscany.container.spring.context;
+
+import org.w3c.dom.Element;
+
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.xml.BeanDefinitionParser;
+import org.springframework.beans.factory.xml.ParserContext;
+
+/**
+ * Parser for the &lt;sca:reference&gt; element
+ *
+ * @version $Rev$ $Date$
+ */
+public class ScaReferenceBeanDefinitionParser implements BeanDefinitionParser {
+
+ public BeanDefinition parse(Element element, ParserContext parserContext) {
+ // do nothing, this is handled by Tuscany
+ return null;
+ }
+
+}
diff --git a/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/context/ScaServiceBeanDefinitionParser.java b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/context/ScaServiceBeanDefinitionParser.java
new file mode 100644
index 0000000000..567904d6cf
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/context/ScaServiceBeanDefinitionParser.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2002-2006 the original author or authors.
+ *
+ * Licensed 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.
+ *
+ * Created on 10-Apr-2006 by Adrian Colyer
+ */
+package org.apache.tuscany.container.spring.context;
+
+import org.w3c.dom.Element;
+
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.xml.BeanDefinitionParser;
+import org.springframework.beans.factory.xml.ParserContext;
+
+/**
+ * Parser for the &lt;sca:service/&gt; element
+ *
+ * @version $Rev$ $Date$
+ */
+public class ScaServiceBeanDefinitionParser implements BeanDefinitionParser {
+
+ public BeanDefinition parse(Element element, ParserContext parserContext) {
+ // do nothing, handled by Tuscany
+ return null;
+ }
+
+}
diff --git a/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/impl/BeanMethodNotFound.java b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/impl/BeanMethodNotFound.java
new file mode 100644
index 0000000000..4aad7cd35c
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/impl/BeanMethodNotFound.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.container.spring.impl;
+
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.model.Operation;
+
+/**
+ * Thrown when a service contract Operation cannot be mapped to a method on a Spring Bean class
+ *
+ * @version $Rev$ $Date$
+ */
+public class BeanMethodNotFound extends TargetInvokerCreationException {
+ private Operation operation;
+
+ public BeanMethodNotFound(Operation operation) {
+ super("Bean method not found");
+ this.operation = operation;
+ }
+
+ public Operation getOperation() {
+ return operation;
+ }
+}
diff --git a/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/impl/SpringCompositeBuilder.java b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/impl/SpringCompositeBuilder.java
new file mode 100644
index 0000000000..9647b8857a
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/impl/SpringCompositeBuilder.java
@@ -0,0 +1,51 @@
+/*
+ * 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.container.spring.impl;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ComponentBuilderExtension;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+
+import org.apache.tuscany.container.spring.model.SpringImplementation;
+import org.springframework.core.io.Resource;
+
+/**
+ * Creates a {@link org.apache.tuscany.container.spring.impl.SpringCompositeComponent} from an assembly model
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class SpringCompositeBuilder extends ComponentBuilderExtension<SpringImplementation> {
+
+ public Component build(ComponentDefinition<SpringImplementation> componentDefinition, DeploymentContext context)
+ throws BuilderException {
+ URI uri = componentDefinition.getUri();
+ SpringImplementation implementation = componentDefinition.getImplementation();
+ Resource resource = implementation.getApplicationResource();
+ ClassLoader cl = implementation.getClassLoader();
+ return new SpringCompositeComponent(uri, resource, proxyService, null, cl);
+ }
+
+ protected Class<SpringImplementation> getImplementationType() {
+ return SpringImplementation.class;
+ }
+}
diff --git a/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/impl/SpringCompositeComponent.java b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/impl/SpringCompositeComponent.java
new file mode 100644
index 0000000000..d11c3054b7
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/impl/SpringCompositeComponent.java
@@ -0,0 +1,311 @@
+/*
+ * 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.container.spring.impl;
+
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.net.URI;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import org.w3c.dom.Document;
+
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.SCAObject;
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.extension.CompositeComponentExtension;
+import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findMethod;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.physical.PhysicalWireSourceDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireTargetDefinition;
+import org.apache.tuscany.spi.wire.ProxyService;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+import org.apache.tuscany.container.spring.context.SCAApplicationContext;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.BeanNotOfRequiredTypeException;
+import org.springframework.beans.factory.NoSuchBeanDefinitionException;
+import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationEvent;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.MessageSourceResolvable;
+import org.springframework.context.NoSuchMessageException;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.core.io.Resource;
+
+/**
+ * A composite implementation responsible for managing Spring application contexts.
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class SpringCompositeComponent extends CompositeComponentExtension {
+ private static final String[] EMPTY_ARRAY = new String[0];
+ private AbstractApplicationContext springContext;
+ private Resource resource;
+ private ProxyService proxyService;
+ private ClassLoader loader;
+
+ /**
+ * Creates a new composite
+ *
+ * @param uri the uri of the SCA composite
+ * @param resource a resource pointing to the application context
+ * @param propertyValues the values of this composite's Properties
+ */
+ public SpringCompositeComponent(URI uri,
+ Resource resource,
+ ProxyService proxyService,
+ Map<String, Document> propertyValues,
+ ClassLoader loader) {
+ super(uri);
+ this.resource = resource;
+ this.proxyService = proxyService;
+ this.loader = loader;
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, Operation operation)
+ throws TargetInvokerCreationException {
+ TargetInvoker invoker = super.createTargetInvoker(targetName, operation);
+ if (invoker != null) {
+ return invoker;
+ }
+ // no service found, wire to a bean using the service name as the bean name
+ ServiceContract contract = operation.getServiceContract();
+ Method method;
+ try {
+ method = findMethod(contract.getInterfaceClass(), operation);
+ } catch (NoSuchMethodException e) {
+ throw new BeanMethodNotFound(operation);
+ }
+ return new SpringInvoker(targetName, method, this);
+ }
+
+ public List<Wire> getWires(String name) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void attachCallbackWire(Wire wire) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void attachWire(Wire wire) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void attachWires(List<Wire> wires) {
+ throw new UnsupportedOperationException();
+ }
+
+ public ConfigurableApplicationContext getApplicationContext() {
+ return springContext;
+ }
+
+ public void prepare() {
+ // TODO handle only references with a composite binding
+ }
+
+ public void start() {
+ super.start();
+ for (SCAObject child : children.values()) {
+ child.start();
+ }
+ if (springContext == null) {
+ SCAParentApplicationContext scaApplicationContext = new SCAParentApplicationContext();
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ try {
+ // FIXME this is horrible
+ Thread.currentThread().setContextClassLoader(loader);
+ springContext = new SCAApplicationContext(scaApplicationContext, resource);
+ springContext.start();
+ } finally {
+ Thread.currentThread().setContextClassLoader(cl);
+
+ }
+ }
+ }
+
+ public void stop() {
+ super.stop();
+ springContext.stop();
+ }
+
+ public <T> T getBean(Class<T> serviceInterface, String name) {
+ return serviceInterface.cast(springContext.getBean(name));
+ }
+
+ /**
+ * Used in unit testing
+ */
+ void setSpringContext(AbstractApplicationContext springContext) {
+ this.springContext = springContext;
+ }
+
+ /**
+ * TODO remove need for inner class as SCA.getParent() has been removed and no longer clashes with
+ * ApplicaitonContext.getParent
+ */
+ private class SCAParentApplicationContext implements ApplicationContext {
+
+ public Object getBean(String name) throws BeansException {
+ return getBean(name, null);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object getBean(String name, Class requiredType) throws BeansException {
+ SCAObject object = children.get(name); // keep cast due to compiler error
+ if (object == null) {
+ return null;
+ }
+ Class<?> type = null;
+ if (object instanceof Reference) {
+ Reference reference = (Reference) object;
+ Wire wire = null;
+ if (!reference.getReferenceBindings().isEmpty()) {
+ // FIXME JFM provide a better way for the runtime to select the binding as opposed to the first one
+ wire = reference.getReferenceBindings().get(0).getWire();
+ type = wire.getSourceContract().getInterfaceClass();
+ }
+ if (requiredType != null && requiredType.isAssignableFrom(type)) {
+ // need null check since Spring may pass in a null
+ throw new BeanNotOfRequiredTypeException(name, requiredType, type);
+ }
+ return proxyService.createProxy(type, wire);
+ } else if (object instanceof ServiceBinding) {
+ ServiceBinding serviceBinding = (ServiceBinding) object;
+ type = serviceBinding.getWire().getSourceContract().getInterfaceClass();
+ if (requiredType != null && requiredType.isAssignableFrom(type)) {
+ // need null check since Spring may pass in a null
+ throw new BeanNotOfRequiredTypeException(name, requiredType, type);
+ }
+ return proxyService.createProxy(type, serviceBinding.getWire());
+ } else {
+ throw new AssertionError("Illegal object type [" + name + "]");
+ }
+ }
+
+ public boolean containsBean(String name) {
+ return children.get(name) != null;
+ }
+
+ public boolean isSingleton(String name) throws NoSuchBeanDefinitionException {
+ return children.get(name) != null;
+ }
+
+ public boolean isTypeMatch(String name, Class targetType) throws NoSuchBeanDefinitionException {
+ throw new UnsupportedOperationException();
+ }
+
+ public Class getType(String name) throws NoSuchBeanDefinitionException {
+ return null;
+ }
+
+ public String[] getAliases(String name) throws NoSuchBeanDefinitionException {
+ return EMPTY_ARRAY;
+ }
+
+ public ApplicationContext getParent() {
+ return null;
+ }
+
+ public AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException {
+ return null;
+ }
+
+ public String getDisplayName() {
+ return getUri().toString();
+ }
+
+ public long getStartupDate() {
+ return 0;
+ }
+
+ public boolean containsBeanDefinition(String beanName) {
+ return false;
+ }
+
+ public int getBeanDefinitionCount() {
+ return 0;
+ }
+
+ public String[] getBeanDefinitionNames() {
+ return new String[0];
+ }
+
+ public String[] getBeanNamesForType(Class type) {
+ return new String[0];
+ }
+
+ public String[] getBeanNamesForType(Class type, boolean includePrototypes, boolean includeFactoryBeans) {
+ return new String[0];
+ }
+
+ public Map getBeansOfType(Class type) throws BeansException {
+ return null;
+ }
+
+ public Map getBeansOfType(Class type, boolean includePrototypes, boolean includeFactoryBeans)
+ throws BeansException {
+ return null;
+ }
+
+ public BeanFactory getParentBeanFactory() {
+ return null;
+ }
+
+ public boolean containsLocalBean(String name) {
+ return false;
+ }
+
+ public String getMessage(String code, Object[] args, String defaultMessage, Locale locale) {
+ return null;
+ }
+
+ public String getMessage(String code, Object[] args, Locale locale) throws NoSuchMessageException {
+ return null;
+ }
+
+ public String getMessage(MessageSourceResolvable resolvable, Locale locale) throws NoSuchMessageException {
+ return null;
+ }
+
+ public void publishEvent(ApplicationEvent event) {
+
+ }
+
+ public Resource[] getResources(String locationPattern) throws IOException {
+ return new Resource[0];
+ }
+
+ public Resource getResource(String location) {
+ return null;
+ }
+
+ public ClassLoader getClassLoader() {
+ // REVIEW: this is almost certainly flawed, but it's not clear how the SCA runtime's
+ // resource loading mechanism is exposed right now.
+ return this.getClass().getClassLoader();
+ }
+ }
+}
diff --git a/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/impl/SpringInvoker.java b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/impl/SpringInvoker.java
new file mode 100644
index 0000000000..ff0b215f4a
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/impl/SpringInvoker.java
@@ -0,0 +1,106 @@
+/*
+ * 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.container.spring.impl;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.component.TargetNotFoundException;
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+import org.springframework.beans.BeansException;
+
+/**
+ * Dispatches to an operation on a Spring bean. Since Spring manages bean lifecycle and scope through resolution in the
+ * target proxy, the invoker can safely cache the target proxy.
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class SpringInvoker implements TargetInvoker {
+ private SpringCompositeComponent component;
+ // default to true since Spring handles resolution
+ private boolean cacheable = true;
+ private String beanName;
+ private Method method;
+ // caching is thread-safe since Spring handles resolution
+ private Object bean;
+
+ public SpringInvoker(String beanName, Method method, SpringCompositeComponent component) {
+ this.beanName = beanName;
+ this.method = method;
+ this.component = component;
+ }
+
+ public Object invokeTarget(final Object object, final short sequence) throws InvocationTargetException {
+ if (bean == null) {
+ try {
+ bean = component.getBean(Object.class, beanName);
+ if (bean == null) {
+ throw new InvocationTargetException(new TargetNotFoundException(beanName));
+ }
+ } catch (BeansException e) {
+ throw new InvocationTargetException(e);
+ }
+ }
+ try {
+ if (object != null && !object.getClass().isArray()) {
+ return method.invoke(bean, object);
+ } else {
+ return method.invoke(bean, (Object[]) object);
+ }
+ } catch (IllegalAccessException e) {
+ throw new InvocationTargetException(e);
+ }
+ }
+
+ public Message invoke(Message msg) throws InvocationRuntimeException {
+ try {
+ Object resp = invokeTarget(msg.getBody(), TargetInvoker.NONE);
+ msg.setBody(resp);
+ } catch (InvocationTargetException e) {
+ msg.setBodyWithFault(e.getCause());
+ } catch (Throwable e) {
+ msg.setBodyWithFault(e);
+ }
+ return msg;
+ }
+
+ public boolean isCacheable() {
+ return cacheable;
+ }
+
+ public void setCacheable(boolean cacheable) {
+ this.cacheable = cacheable;
+ }
+
+ public boolean isOptimizable() {
+ return false;
+ }
+
+
+ public SpringInvoker clone() throws CloneNotSupportedException {
+ SpringInvoker invoker = (SpringInvoker) super.clone();
+ invoker.bean = null;
+ return invoker;
+ }
+
+
+}
diff --git a/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/loader/SpringImplementationLoader.java b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/loader/SpringImplementationLoader.java
new file mode 100644
index 0000000000..150440cdf9
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/loader/SpringImplementationLoader.java
@@ -0,0 +1,203 @@
+/*
+ * 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.container.spring.loader;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.util.jar.Attributes;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+import javax.xml.namespace.QName;
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.osoa.sca.Constants;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.MissingResourceException;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import org.apache.tuscany.container.spring.model.SpringComponentType;
+import org.apache.tuscany.container.spring.model.SpringImplementation;
+import org.apache.tuscany.host.RuntimeInfo;
+import org.apache.tuscany.runtime.webapp.WebappRuntimeInfo;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.UrlResource;
+
+/**
+ * Loader for handling Spring <implementation.spring> elements.
+ *
+ * @version $Rev$ $Date$
+ */
+public class SpringImplementationLoader extends LoaderExtension<SpringImplementation> {
+ private static final QName IMPLEMENTATION_SPRING = new QName("http://www.osoa.org/xmlns/sca/1.0",
+ "implementation.spring");
+ private static final String APPLICATION_CONTEXT = "applicationContext.xml";
+ private static final QName SERVICE_ELEMENT = new QName(Constants.SCA_NS, "service");
+ private static final QName REFERENCE_ELEMENT = new QName(Constants.SCA_NS, "reference");
+
+ private final RuntimeInfo runtimeInfo;
+
+ public SpringImplementationLoader(@Reference LoaderRegistry registry, @Reference RuntimeInfo runtimeInfo) {
+ super(registry);
+ this.runtimeInfo = runtimeInfo;
+ }
+
+ public QName getXMLType() {
+ return IMPLEMENTATION_SPRING;
+ }
+
+ @SuppressWarnings("unchecked")
+ public SpringImplementation load(
+ ModelObject object, XMLStreamReader reader,
+ DeploymentContext deploymentContext)
+ throws XMLStreamException, LoaderException {
+
+ String locationAttr = reader.getAttributeValue(null, "location");
+ if (locationAttr == null) {
+ throw new MissingResourceException("No location supplied");
+ }
+
+ ClassLoader classLoader = deploymentContext.getClassLoader();
+ SpringImplementation implementation = new SpringImplementation(classLoader);
+ implementation.setApplicationResource(getApplicationContextResource(locationAttr, classLoader));
+ registry.loadComponentType(implementation, deploymentContext);
+ SpringComponentType type = implementation.getComponentType();
+ while (true) {
+ switch (reader.next()) {
+ case START_ELEMENT:
+ QName qname = reader.getName();
+ if (SERVICE_ELEMENT.equals(qname)) {
+ ServiceDefinition service =
+ (ServiceDefinition) registry.load(null, reader, deploymentContext);
+ if (!type.isExposeAllBeans()) {
+ URI name = service.getUri();
+ if (!type.getServiceDeclarations().containsKey(name)) {
+ throw new LoaderException("No service defined in Spring context for ", name.toString());
+ }
+ }
+ type.getDeclaredServices().put(service.getUri(), service);
+ } else if (REFERENCE_ELEMENT.equals(qname)) {
+ ReferenceDefinition reference =
+ (ReferenceDefinition) registry.load(null, reader, deploymentContext);
+ type.getDeclaredReferences().put(reference.getUri(), reference);
+ }
+ break;
+ case END_ELEMENT:
+ if (IMPLEMENTATION_SPRING.equals(reader.getName())) {
+ return implementation;
+ }
+ }
+ }
+ }
+
+ protected Resource getApplicationContextResource(String locationAttr, ClassLoader cl) throws LoaderException {
+ assert runtimeInfo != null;
+ File manifestFile = null;
+ File appXmlFile;
+ File locationFile = new File(locationAttr);
+
+// if (!locationFile.isAbsolute()) {
+// locationFile = new File(runtimeInfo.getApplicationRootDirectory(), locationAttr);
+// }
+ if (!locationFile.exists()) {
+ // FIXME hack
+ URL url;
+ if (runtimeInfo instanceof WebappRuntimeInfo) {
+ try {
+ url = ((WebappRuntimeInfo) runtimeInfo).getServletContext().getResource(locationAttr);
+ } catch (MalformedURLException e) {
+ throw new LoaderException(e);
+ }
+ } else {
+ url = cl.getResource(locationAttr);
+ }
+ if (url != null) {
+ return new UrlResource(url);
+ }
+ throw new MissingResourceException(locationFile.toString());
+ }
+
+ if (locationFile.isDirectory()) {
+ try {
+ manifestFile = new File(locationFile, "META-INF/MANIFEST.MF");
+ if (manifestFile.exists()) {
+ Manifest mf = new Manifest(new FileInputStream(manifestFile));
+ Attributes mainAttrs = mf.getMainAttributes();
+ String appCtxPath = mainAttrs.getValue("Spring-Context");
+ if (appCtxPath != null) {
+ appXmlFile = new File(locationFile, appCtxPath);
+ if (appXmlFile.exists()) {
+ return new UrlResource(appXmlFile.toURL());
+ }
+ }
+ }
+ // no manifest-specified Spring context, use default
+ appXmlFile = new File(locationFile, APPLICATION_CONTEXT);
+ if (appXmlFile.exists()) {
+ return new UrlResource(appXmlFile.toURL());
+ }
+ } catch (IOException e) {
+ throw new LoaderException("Error reading manifest " + manifestFile);
+ }
+ } else {
+ try {
+ JarFile jf = new JarFile(locationFile);
+ JarEntry je;
+ Manifest mf = jf.getManifest();
+ if (mf != null) {
+ Attributes mainAttrs = mf.getMainAttributes();
+ String appCtxPath = mainAttrs.getValue("Spring-Context");
+ if (appCtxPath != null) {
+ je = jf.getJarEntry(appCtxPath);
+ if (je != null) {
+ // TODO return a Spring specific Resouce type for jars
+ return new UrlResource(new URL("jar:" + locationFile.toURL() + "!/" + appCtxPath));
+ }
+ }
+ }
+ je = jf.getJarEntry(APPLICATION_CONTEXT);
+ if (je != null) {
+ return new UrlResource(new URL("jar:" + locationFile.toURI().toURL() + "!" + APPLICATION_CONTEXT));
+ }
+ } catch (IOException e) {
+ // bad archive
+ // TODO: create a more appropriate exception type
+ throw new MissingResourceException(locationAttr, e);
+ }
+ }
+
+ throw new
+
+ MissingResourceException(APPLICATION_CONTEXT);
+ }
+}
diff --git a/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/loader/SpringXMLComponentTypeLoader.java b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/loader/SpringXMLComponentTypeLoader.java
new file mode 100644
index 0000000000..21fb5b7b5b
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/loader/SpringXMLComponentTypeLoader.java
@@ -0,0 +1,128 @@
+/*
+ * 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.container.spring.loader;
+
+import java.io.IOException;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ComponentTypeLoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.MissingResourceException;
+import org.apache.tuscany.spi.model.Property;
+
+import org.apache.tuscany.container.spring.model.ReferenceDeclaration;
+import org.apache.tuscany.container.spring.model.ServiceDeclaration;
+import org.apache.tuscany.container.spring.model.SpringComponentType;
+import org.apache.tuscany.container.spring.model.SpringImplementation;
+import org.springframework.core.io.Resource;
+
+/**
+ * Introspects a Spring XML configuration file for its component type information. Other loader implementations may
+ * support alternative Spring configuration mechanisms.
+ *
+ * @version $Rev$ $Date$
+ */
+public class SpringXMLComponentTypeLoader extends ComponentTypeLoaderExtension<SpringImplementation> {
+ private static final String SCA_NS = "http://www.springframework.org/schema/sca";
+ private static final QName SERVICE_ELEMENT = new QName(SCA_NS, "service");
+ private static final QName REFERENCE_ELEMENT = new QName(SCA_NS, "reference");
+ private static final QName BEANS_ELEMENT = new QName("http://www.springframework.org/schema/beans", "beans");
+
+ public SpringXMLComponentTypeLoader(@Reference LoaderRegistry loaderRegistry) {
+ super(loaderRegistry);
+ }
+
+ @Override
+ protected Class<SpringImplementation> getImplementationClass() {
+ return SpringImplementation.class;
+ }
+
+ public void load(
+ SpringImplementation implementation,
+ DeploymentContext context) throws LoaderException {
+ if (implementation.getComponentType() != null) {
+ // FIXME hack since the builder registry loads the implementation type and the Spring implementation
+ // loader needs to as well. The second call is done by the builder registry and we just ignore it.
+ return;
+ }
+ SpringComponentType<Property<?>> type = new SpringComponentType<Property<?>>();
+ Resource resource = implementation.getApplicationResource();
+ loadFromXML(type, resource, context);
+ implementation.setComponentType(type);
+ }
+
+ private void loadFromXML(SpringComponentType<Property<?>> type, Resource resource, DeploymentContext context)
+ throws LoaderException {
+ XMLStreamReader reader;
+ try {
+ XMLInputFactory factory = context.getXmlFactory();
+ ClassLoader cl = context.getClassLoader();
+ reader = factory.createXMLStreamReader(resource.getInputStream());
+ boolean exposeAllBeans = true;
+ while (true) {
+ switch (reader.next()) {
+ case START_ELEMENT:
+ QName qname = reader.getName();
+ if (SERVICE_ELEMENT.equals(qname)) {
+ exposeAllBeans = false;
+ String name = reader.getAttributeValue(SCA_NS, "name");
+ Class<?> serviceType;
+ try {
+ serviceType = cl.loadClass(reader.getAttributeValue(SCA_NS, "type"));
+ } catch (ClassNotFoundException e) {
+ throw new MissingResourceException("Error loading service class", name, e);
+ }
+ String target = reader.getAttributeValue(SCA_NS, "target");
+ type.addServiceDeclaration(new ServiceDeclaration(name, serviceType, target));
+ } else if (REFERENCE_ELEMENT.equals(qname)) {
+ String name = reader.getAttributeValue(SCA_NS, "name");
+ Class<?> serviceType;
+ try {
+ serviceType = cl.loadClass(reader.getAttributeValue(SCA_NS, "type"));
+ } catch (ClassNotFoundException e) {
+ throw new MissingResourceException("Error loading service class", name, e);
+ }
+ type.addReferenceDeclaration(new ReferenceDeclaration(name, serviceType));
+ }
+ break;
+ case END_ELEMENT:
+ if (BEANS_ELEMENT.equals(reader.getName())) {
+ type.setExposeAllBeans(exposeAllBeans);
+ return;
+ }
+ }
+ }
+
+ } catch (IOException e) {
+ throw new LoaderException(e);
+ } catch (XMLStreamException e) {
+ throw new LoaderException(e);
+ }
+
+ }
+} \ No newline at end of file
diff --git a/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/model/ReferenceDeclaration.java b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/model/ReferenceDeclaration.java
new file mode 100644
index 0000000000..b53ddbe18f
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/model/ReferenceDeclaration.java
@@ -0,0 +1,43 @@
+/*
+ * 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.container.spring.model;
+
+/**
+ * Represents a <code>sca:reference<code> declaration in an application context. Used as component type metadata for a
+ * Spring composite
+ *
+ * @version $Rev$ $Date$
+ */
+public class ReferenceDeclaration {
+ private String name;
+ private Class<?> serviceType;
+
+ public ReferenceDeclaration(String name, Class<?> serviceType) {
+ this.name = name;
+ this.serviceType = serviceType;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Class<?> getServiceType() {
+ return serviceType;
+ }
+}
diff --git a/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/model/ServiceDeclaration.java b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/model/ServiceDeclaration.java
new file mode 100644
index 0000000000..4872028215
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/model/ServiceDeclaration.java
@@ -0,0 +1,57 @@
+/*
+ * 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.container.spring.model;
+
+/**
+ * Represents a <code>sca:service<code> declaration in an application context. Used as component type metadata for a
+ * Spring composite
+ *
+ * @version $Rev$ $Date$
+ */
+public class ServiceDeclaration {
+ private String name;
+ private Class<?> serviceType;
+ private String target;
+
+ /**
+ * Constructor
+ *
+ * @param name the service name
+ * @param serviceType the service contract type
+ * @param target the name of the target the service is wired to
+ */
+ public ServiceDeclaration(String name, Class<?> serviceType, String target) {
+ this.name = name;
+ this.serviceType = serviceType;
+ this.target = target;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Class<?> getClazz() {
+ return serviceType;
+ }
+
+ public String getTarget() {
+ return target;
+ }
+
+}
diff --git a/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/model/SpringComponentType.java b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/model/SpringComponentType.java
new file mode 100644
index 0000000000..e44656046f
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/model/SpringComponentType.java
@@ -0,0 +1,91 @@
+/*
+ * 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.container.spring.model;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+/**
+ * Component type information for a Spring composite component implementation type. A component type is associated with
+ * a Spring application context
+ *
+ * @version $Rev$ $Date$
+ */
+public class SpringComponentType<P extends Property<?>>
+ extends CompositeComponentType<ServiceDefinition, ReferenceDefinition, P> {
+ private Map<String, ServiceDeclaration> serviceDeclarations = new HashMap<String, ServiceDeclaration>();
+ private Map<String, ReferenceDeclaration> referenceDeclarations = new HashMap<String, ReferenceDeclaration>();
+ private boolean exposeAllBeans;
+
+ public SpringComponentType() {
+ }
+
+ /**
+ * Returns true if all beans in the Spring application context may be service targets or false if service types are
+ * defined
+ */
+ public boolean isExposeAllBeans() {
+ return exposeAllBeans;
+ }
+
+ /**
+ * Sets if all beans in the Spring application context may be service targets or false if service types are defined
+ */
+ public void setExposeAllBeans(boolean exposeAllBeans) {
+ this.exposeAllBeans = exposeAllBeans;
+ }
+
+ /**
+ * Returns the service declarations for the composite
+ *
+ * @return Returns the service declarations for the composite
+ */
+ public Map<String, ServiceDeclaration> getServiceDeclarations() {
+ return serviceDeclarations;
+ }
+
+ /**
+ * Adds a service declaration for the composite
+ */
+ public void addServiceDeclaration(ServiceDeclaration declaration) {
+ serviceDeclarations.put(declaration.getName(), declaration);
+ }
+
+ /**
+ * Returns the reference declarations for the composite
+ *
+ * @return Returns the reference declarations for the composite
+ */
+ public Map<String, ReferenceDeclaration> getReferenceDeclarations() {
+ return referenceDeclarations;
+ }
+
+ /**
+ * Adds a service declarations for the composite
+ */
+ public void addReferenceDeclaration(ReferenceDeclaration declaration) {
+ referenceDeclarations.put(declaration.getName(), declaration);
+ }
+
+}
diff --git a/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/model/SpringImplementation.java b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/model/SpringImplementation.java
new file mode 100644
index 0000000000..4842e75e0e
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/main/java/org/apache/tuscany/container/spring/model/SpringImplementation.java
@@ -0,0 +1,74 @@
+/*
+ * 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.container.spring.model;
+
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.Property;
+
+import org.springframework.core.io.Resource;
+
+/**
+ * Represents a composite whose implementation type is a Spring application context.
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class SpringImplementation extends Implementation<SpringComponentType<Property<?>>> {
+ private String location;
+ private Resource applicationResource;
+ private ClassLoader classLoader;
+
+ public SpringImplementation(ClassLoader classloader) {
+ this.classLoader = classloader;
+ }
+
+ /**
+ * Returns the classloader of the Spring application context
+ */
+ public ClassLoader getClassLoader() {
+ return classLoader;
+ }
+
+ /**
+ * Returns the path of the Spring application context configuration
+ */
+ public String getLocation() {
+ return location;
+ }
+
+ /**
+ * Sets the path of the Spring application context configuration
+ */
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
+ /**
+ * Returns the Spring configuration resource for the application context
+ */
+ public Resource getApplicationResource() {
+ return applicationResource;
+ }
+
+ /**
+ * Sets the Spring configuration resource for the application context
+ */
+ public void setApplicationResource(Resource applicationXml) {
+ this.applicationResource = applicationXml;
+ }
+}
diff --git a/sandbox/old/contrib/implementation-spring/container/src/main/resources/META-INF/sca/spring.system.scdl b/sandbox/old/contrib/implementation-spring/container/src/main/resources/META-INF/sca/spring.system.scdl
new file mode 100644
index 0000000000..0eb781a5f1
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/main/resources/META-INF/sca/spring.system.scdl
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+ -->
+<!--
+ Spring implementation extension configuration for the launcher environment.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT"
+ name="org.apache.tuscany.launcher.SpringImplementation"
+ autowire="true">
+
+ <!-- <dependency xmlns="http://tuscany.apache.org/xmlns/1.0-SNAPSHOT">
+ <group>org.apache.tuscany.sca.extensions.spring</group>
+ <name>tuscany-spring</name>
+ <version>1.0-incubator-SNAPSHOT</version>
+ </dependency> -->
+
+ <component name="spring.implementationLoader">
+ <system:implementation.system class="org.apache.tuscany.container.spring.loader.SpringImplementationLoader"/>
+ </component>
+
+ <component name="spring.componentTypeLoader">
+ <system:implementation.system class="org.apache.tuscany.container.spring.loader.SpringXMLComponentTypeLoader"/>
+ </component>
+
+ <component name="spring.componentBuilder">
+ <system:implementation.system class="org.apache.tuscany.container.spring.impl.SpringCompositeBuilder"/>
+ </component>
+
+</composite> \ No newline at end of file
diff --git a/sandbox/old/contrib/implementation-spring/container/src/main/resources/META-INF/spring.handlers b/sandbox/old/contrib/implementation-spring/container/src/main/resources/META-INF/spring.handlers
new file mode 100644
index 0000000000..689b49e2ae
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/main/resources/META-INF/spring.handlers
@@ -0,0 +1,3 @@
+http\://www.springframework.org/schema/sca=org.springframework.sca.config.ScaNamespaceHandler
+
+
diff --git a/sandbox/old/contrib/implementation-spring/container/src/main/resources/META-INF/spring.schemas b/sandbox/old/contrib/implementation-spring/container/src/main/resources/META-INF/spring.schemas
new file mode 100644
index 0000000000..33f7004be9
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/main/resources/META-INF/spring.schemas
@@ -0,0 +1 @@
+http\://www.springframework.org/schema/sca/spring-sca.xsd=org/springframework/sca/xml/spring-sca.xsd
diff --git a/sandbox/old/contrib/implementation-spring/container/src/main/resources/org/springframework/sca/xml/spring-sca.xsd b/sandbox/old/contrib/implementation-spring/container/src/main/resources/org/springframework/sca/xml/spring-sca.xsd
new file mode 100644
index 0000000000..3e61ee96dc
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/main/resources/org/springframework/sca/xml/spring-sca.xsd
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsd:schema xmlns="http://www.springframework.org/schema/sca"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ attributeFormDefault="unqualified"
+ elementFormDefault="qualified"
+ targetNamespace="http://www.springframework.org/schema/sca">
+
+ <xsd:element name="composite">
+ <xsd:complexType>
+ <xsd:attribute name="component" use="required">
+ <xsd:simpleType>
+ <xsd:restriction base="xsd:string"/>
+ </xsd:simpleType>
+ </xsd:attribute>
+ <xsd:attribute name="sca-adapter-class" use="optional">
+ <xsd:simpleType>
+ <xsd:restriction base="xsd:string"/>
+ </xsd:simpleType>
+ </xsd:attribute>
+ </xsd:complexType>
+ </xsd:element>
+
+ <xsd:element name="reference">
+ <xsd:complexType>
+ <xsd:attribute name="name" use="required">
+ <xsd:simpleType>
+ <xsd:restriction base="xsd:string"/>
+ </xsd:simpleType>
+ </xsd:attribute>
+ <xsd:attribute name="type" use="required">
+ <xsd:simpleType>
+ <xsd:restriction base="xsd:string"/>
+ </xsd:simpleType>
+ </xsd:attribute>
+ <xsd:attribute name="default" use="optional">
+ <xsd:simpleType>
+ <xsd:restriction base="xsd:string"/>
+ </xsd:simpleType>
+ </xsd:attribute>
+ </xsd:complexType>
+ </xsd:element>
+
+ <xsd:element name="property">
+ <xsd:complexType>
+ <xsd:attribute name="id" use="required">
+ <xsd:simpleType>
+ <xsd:restriction base="xsd:string"/>
+ </xsd:simpleType>
+ </xsd:attribute>
+ <xsd:attribute name="name" use="required">
+ <xsd:simpleType>
+ <xsd:restriction base="xsd:string"/>
+ </xsd:simpleType>
+ </xsd:attribute>
+ <xsd:attribute name="type" use="required">
+ <xsd:simpleType>
+ <xsd:restriction base="xsd:string"/>
+ </xsd:simpleType>
+ </xsd:attribute>
+ </xsd:complexType>
+ </xsd:element>
+
+ <xsd:element name="service">
+ <xsd:complexType>
+ <xsd:attribute name="name" use="required">
+ <xsd:simpleType>
+ <xsd:restriction base="xsd:string"/>
+ </xsd:simpleType>
+ </xsd:attribute>
+ <xsd:attribute name="type" use="required">
+ <xsd:simpleType>
+ <xsd:restriction base="xsd:string"/>
+ </xsd:simpleType>
+ </xsd:attribute>
+ <xsd:attribute name="target" use="required">
+ <xsd:simpleType>
+ <xsd:restriction base="xsd:string"/>
+ </xsd:simpleType>
+ </xsd:attribute>
+ </xsd:complexType>
+ </xsd:element>
+
+</xsd:schema>
diff --git a/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/SpringConfigSchemaTestCase.java b/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/SpringConfigSchemaTestCase.java
new file mode 100644
index 0000000000..13b2c684d7
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/SpringConfigSchemaTestCase.java
@@ -0,0 +1,52 @@
+/*
+ * 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.container.spring;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests the SCA extensible schema elements for Spring's XML configuration files
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+
+public class SpringConfigSchemaTestCase extends TestCase {
+
+// private ConfigurableApplicationContext applicationContext;
+//
+// public void setUp() {
+// applicationContext =
+// new ScaApplicationContext(null,
+// new ClassPathResource("org/apache/tuscany/container/spring/SpringConfigSchemaTest.xml"));
+// }
+//
+ public void testSCAService() {
+// ScaServiceExporter service = (ScaServiceExporter) applicationContext.getBean("fooService");
+// // FIXME andyp -- this is not really right.
+//// TestBean service = (TestBean) applicationContext.getBean("fooService");
+//// assertEquals("call me", service.echo("call me"));
+ }
+//
+// public void testSCAReference() {
+// ScaServiceProxyFactoryBean pf = (ScaServiceProxyFactoryBean) applicationContext.getBean("&fooReference");
+// assertEquals("fooReference", pf.getReferenceName());
+// TestReference ref = (TestReference) applicationContext.getBean("fooReference");
+//// assertNotNull(ref);
+// }
+}
diff --git a/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/SpringTestUtils.java b/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/SpringTestUtils.java
new file mode 100644
index 0000000000..4a73b6628b
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/SpringTestUtils.java
@@ -0,0 +1,73 @@
+/*
+ * 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.container.spring;
+
+import java.net.URI;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.builder.WiringException;
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.extension.ServiceBindingExtension;
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+import org.apache.tuscany.container.spring.mock.TestBeanImpl;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.support.RootBeanDefinition;
+import org.springframework.context.support.GenericApplicationContext;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+
+public final class SpringTestUtils {
+ private SpringTestUtils() {
+ }
+
+ public static <T> ServiceBinding createService(URI uri, Class<T> serviceInterface)
+ throws InvalidServiceContractException, WiringException {
+ return new ServiceBindingExtension(uri) {
+ public QName getBindingType() {
+ return null;
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, Operation operation)
+ throws TargetInvokerCreationException {
+ return null;
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, PhysicalOperationDefinition operation)
+ throws TargetInvokerCreationException {
+ return null;
+ }
+ };
+ }
+
+
+ public static GenericApplicationContext createContext() {
+ GenericApplicationContext ctx = new GenericApplicationContext();
+ BeanDefinition definition = new RootBeanDefinition(TestBeanImpl.class);
+ ctx.registerBeanDefinition("foo", definition);
+ return ctx;
+ }
+
+}
diff --git a/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/TestClassResource.java b/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/TestClassResource.java
new file mode 100644
index 0000000000..f93957cb8b
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/TestClassResource.java
@@ -0,0 +1,45 @@
+/*
+ * 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.container.spring;
+
+import java.io.InputStream;
+import java.io.IOException;
+
+import org.springframework.core.io.AbstractResource;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TestClassResource extends AbstractResource {
+ private Class<?> clazz;
+ private String fileName;
+
+ public TestClassResource(Class<?> clazz, String fileName) {
+ this.clazz = clazz;
+ this.fileName = fileName;
+ }
+
+ public String getDescription() {
+ return "test resource";
+ }
+
+ public InputStream getInputStream() throws IOException {
+ return clazz.getResourceAsStream(fileName);
+ }
+}
diff --git a/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/impl/ReferenceWiringTestCase.java b/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/impl/ReferenceWiringTestCase.java
new file mode 100644
index 0000000000..b1e5733cd8
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/impl/ReferenceWiringTestCase.java
@@ -0,0 +1,151 @@
+/*
+ * 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.container.spring.impl;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.osoa.sca.CallableReference;
+
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.wire.ChainHolder;
+import org.apache.tuscany.spi.wire.IncompatibleServiceContractException;
+import org.apache.tuscany.spi.wire.ProxyCreationException;
+import org.apache.tuscany.spi.wire.ProxyService;
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.extension.ReferenceBindingExtension;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.container.spring.mock.TestBean;
+import org.easymock.EasyMock;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.UrlResource;
+
+/**
+ * Verifies wiring from a Spring bean to an SCA composite reference
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class ReferenceWiringTestCase extends TestCase {
+
+ public void testInvocation() throws Exception {
+ ClassLoader loader = getClass().getClassLoader();
+ URL url = loader.getResource("META-INF/sca/testReferenceContext.xml");
+ Resource resource = new UrlResource(url);
+ URI uri = URI.create("spring");
+ ProxyService proxyService = new MockProxyService();
+ SpringCompositeComponent parent = new SpringCompositeComponent(uri, resource, proxyService, null, loader);
+ Wire wire = EasyMock.createMock(Wire.class);
+ ServiceContract<?> contract = new ServiceContract(TestBean.class) {
+ };
+ EasyMock.expect(wire.getSourceContract()).andReturn(contract).atLeastOnce();
+ EasyMock.replay(wire);
+ ReferenceBinding referenceBinding = EasyMock.createMock(ReferenceBinding.class);
+ EasyMock.expect(referenceBinding.getWire()).andStubReturn(wire);
+ referenceBinding.start();
+ EasyMock.replay(referenceBinding);
+
+ URI referenceUri = URI.create("spring#testReference");
+ ReferenceBinding binding = new ReferenceBindingExtension(referenceUri, null){
+
+ public QName getBindingType() {
+ return null;
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, Operation operation)
+ throws TargetInvokerCreationException {
+ throw new UnsupportedOperationException();
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, PhysicalOperationDefinition operation)
+ throws TargetInvokerCreationException {
+ return null;
+ }
+ };
+ binding.setWire(wire);
+ List<ReferenceBinding> bindings = new ArrayList<ReferenceBinding>();
+ bindings.add(binding);
+ Reference reference = EasyMock.createMock(Reference.class);
+ EasyMock.expect(reference.getUri()).andReturn(referenceUri).anyTimes();
+ EasyMock.expect(reference.getReferenceBindings()).andReturn(bindings).atLeastOnce();
+ reference.start();
+ EasyMock.replay(reference);
+ parent.register(reference);
+ parent.start();
+ TestBean bean = parent.getBean(TestBean.class, "testBean");
+ assertNotNull(bean.getBean());
+ EasyMock.verify(reference);
+ }
+
+ private class MockInvocationHandler implements InvocationHandler {
+
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ return null;
+ }
+ }
+
+ private class MockProxyService implements ProxyService {
+
+ public <T> T createProxy(Class<T> interfaze, Wire wire) throws ProxyCreationException {
+ ClassLoader cl = interfaze.getClassLoader();
+ Class[] interfaces = new Class[]{interfaze};
+ MockInvocationHandler handler = new MockInvocationHandler();
+ return interfaze.cast(Proxy.newProxyInstance(cl, interfaces, handler));
+ }
+
+ public <T> T createProxy(Class<T> interfaze, Wire wire, Map<Method, ChainHolder> mapping)
+ throws ProxyCreationException {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object createCallbackProxy(Class<?> interfaze, List<Wire> wires) throws ProxyCreationException {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object createCallbackProxy(Class<?> interfaze) throws ProxyCreationException {
+ throw new UnsupportedOperationException();
+ }
+
+ public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean checkCompatibility(ServiceContract<?> source,
+ ServiceContract<?> target,
+ boolean ignoreCallback,
+ boolean silent) throws IncompatibleServiceContractException {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+}
diff --git a/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/impl/SpringCompositeBuilderTestCase.java b/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/impl/SpringCompositeBuilderTestCase.java
new file mode 100644
index 0000000000..fb9d107b71
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/impl/SpringCompositeBuilderTestCase.java
@@ -0,0 +1,131 @@
+/*
+ * 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.container.spring.impl;
+
+import java.net.URI;
+import java.net.URL;
+
+import org.apache.tuscany.spi.builder.BuilderRegistry;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.container.spring.model.SpringComponentType;
+import org.apache.tuscany.container.spring.model.SpringImplementation;
+import org.easymock.EasyMock;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.UrlResource;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public class SpringCompositeBuilderTestCase extends TestCase {
+
+ /**
+ * Verifies that the builder calls back into the registry to load services and references when no
+ * <code>sca:service</code> tag is specified in the Spring application.xml
+ */
+ public void testImplicitServiceWiring() throws Exception {
+ Service service = EasyMock.createMock(Service.class);
+ // Configure the mock builder registry
+ BuilderRegistry registry = EasyMock.createMock(BuilderRegistry.class);
+ EasyMock.expect(registry.build(
+ EasyMock.isA(ServiceDefinition.class),
+ EasyMock.isA(DeploymentContext.class))).andStubReturn(service);
+ EasyMock.replay(registry);
+ SpringCompositeBuilder builder = new SpringCompositeBuilder();
+ builder.setBuilderRegistry(registry);
+ ComponentDefinition<SpringImplementation> definition = createDefinitionWithService();
+ Component component = builder.build(definition, null);
+ assertNotNull(component);
+ EasyMock.verify(registry);
+ }
+
+ /**
+ * Verifies that the builder calls back into the registry to load services and references when no
+ * <code>sca:reference</code> tag is specified in the Spring application.xml
+ */
+ public void testImplicitReferenceWiring() throws Exception {
+ Service service = EasyMock.createMock(Service.class);
+ // Configure the mock builder registry
+ BuilderRegistry registry = EasyMock.createMock(BuilderRegistry.class);
+ EasyMock.expect(registry.build(
+ EasyMock.isA(ServiceDefinition.class),
+ EasyMock.isA(DeploymentContext.class))).andStubReturn(service);
+ EasyMock.replay(registry);
+ SpringCompositeBuilder builder = new SpringCompositeBuilder();
+ builder.setBuilderRegistry(registry);
+ ComponentDefinition<SpringImplementation> definition = createDefinitionWithReference();
+ Component component = builder.build(definition, null);
+ assertNotNull(component);
+ EasyMock.verify(registry);
+ }
+
+ protected ComponentDefinition<SpringImplementation> createDefinitionWithService() throws Exception {
+ super.setUp();
+ ClassLoader loader = getClass().getClassLoader();
+ URL url = loader.getResource("META-INF/sca/testServiceContext.xml");
+ Resource resource = new UrlResource(url);
+ SpringComponentType<Property<?>> type = createComponentTypeWithService();
+ SpringImplementation impl = new SpringImplementation(loader);
+ impl.setComponentType(type);
+ URI uri = URI.create("composite");
+ ComponentDefinition<SpringImplementation> definition = new ComponentDefinition<SpringImplementation>(uri, impl);
+ impl.setApplicationResource(resource);
+ return definition;
+ }
+
+ protected ComponentDefinition<SpringImplementation> createDefinitionWithReference() throws Exception {
+ super.setUp();
+ ClassLoader loader = getClass().getClassLoader();
+ URL url = loader.getResource("META-INF/sca/testServiceContext.xml");
+ Resource resource = new UrlResource(url);
+ SpringComponentType<Property<?>> type = createComponentTypeWithReference();
+ SpringImplementation impl = new SpringImplementation(loader);
+ impl.setComponentType(type);
+ URI uri = URI.create("composite");
+ ComponentDefinition<SpringImplementation> definition = new ComponentDefinition<SpringImplementation>(uri, impl);
+ impl.setApplicationResource(resource);
+ return definition;
+ }
+
+ private SpringComponentType<Property<?>> createComponentTypeWithService() {
+ SpringComponentType<Property<?>> componentType = new SpringComponentType<Property<?>>();
+ ServiceDefinition serviceDefinition = new ServiceDefinition();
+ serviceDefinition.setUri(URI.create("fooService"));
+ serviceDefinition.setTarget(URI.create("testBean"));
+ componentType.add(serviceDefinition);
+ return componentType;
+ }
+
+ private SpringComponentType<Property<?>> createComponentTypeWithReference() {
+ SpringComponentType<Property<?>> componentType = new SpringComponentType<Property<?>>();
+ ReferenceDefinition referenceDefinition = new ReferenceDefinition();
+ referenceDefinition.setUri(URI.create("fooReference"));
+ componentType.add(referenceDefinition);
+ return componentType;
+ }
+
+
+}
diff --git a/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/impl/SpringCompositeComponentTestCase.java b/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/impl/SpringCompositeComponentTestCase.java
new file mode 100644
index 0000000000..d014d99ad7
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/impl/SpringCompositeComponentTestCase.java
@@ -0,0 +1,76 @@
+/*
+ * 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.container.spring.impl;
+
+import java.lang.reflect.Type;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+import junit.framework.TestCase;
+import org.easymock.classextension.EasyMock;
+import org.springframework.context.support.AbstractApplicationContext;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SpringCompositeComponentTestCase extends TestCase {
+ private SpringCompositeComponent component;
+
+ public void testChildStart() throws Exception {
+ AbstractApplicationContext appContext = EasyMock.createNiceMock(AbstractApplicationContext.class);
+ EasyMock.replay(appContext);
+ Service service = EasyMock.createMock(Service.class);
+ URI uri = URI.create("composite#service");
+ EasyMock.expect(service.getUri()).andReturn(uri).atLeastOnce();
+ service.start();
+ EasyMock.replay(service);
+ component.setSpringContext(appContext);
+ component.register(service);
+ component.start();
+ EasyMock.verify(service);
+ }
+
+ public void testTargetInvokerCreation() throws Exception {
+ ServiceContract<Type> contract = new ServiceContract<Type>(Foo.class) {
+ };
+ Operation<Type> operation = new Operation<Type>("operation", null, null, null);
+ Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>();
+ operations.put("operation", operation);
+ contract.setOperations(operations);
+ operation.setServiceContract(contract);
+ component.createTargetInvoker("bean", operation);
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ URI compositeUri = URI.create("composite");
+ component = new SpringCompositeComponent(compositeUri, null, null, null, null);
+
+ }
+
+ private interface Foo {
+ void operation();
+ }
+}
diff --git a/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/impl/SpringInvocationTestCase.java b/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/impl/SpringInvocationTestCase.java
new file mode 100644
index 0000000000..e4a6ad0eb7
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/impl/SpringInvocationTestCase.java
@@ -0,0 +1,57 @@
+/*
+ * 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.container.spring.impl;
+
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+
+import junit.framework.TestCase;
+import org.easymock.classextension.EasyMock;
+
+/**
+ * Verifies a simple invocation on a Spring bean
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class SpringInvocationTestCase extends TestCase {
+
+ /**
+ * Verifies the invoker can resolve a bean in an application context and call a method l
+ */
+ public void testInvocation() throws Exception {
+ TestBean bean = EasyMock.createMock(TestBean.class);
+ bean.test("bar");
+ EasyMock.expectLastCall();
+ EasyMock.replay(bean);
+ SpringCompositeComponent context = EasyMock.createMock(SpringCompositeComponent.class);
+ EasyMock.expect(context.getBean(Object.class, "foo")).andReturn(bean);
+ EasyMock.replay(context);
+ SpringInvoker invoker = new SpringInvoker("foo", TestBean.class.getMethod("test", String.class), context);
+ Message msg = new MessageImpl();
+ msg.setBody(new String[]{"bar"});
+ invoker.invoke(msg);
+ EasyMock.verify(context);
+ EasyMock.verify(bean);
+ }
+
+
+ private interface TestBean {
+ void test(String msg);
+ }
+}
diff --git a/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/mock/TestBean.java b/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/mock/TestBean.java
new file mode 100644
index 0000000000..1c768e53cc
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/mock/TestBean.java
@@ -0,0 +1,31 @@
+/*
+ * 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.container.spring.mock;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public interface TestBean {
+ String echo(String msg);
+
+ TestBean getBean();
+
+ void setBean(TestBean bean);
+
+}
diff --git a/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/mock/TestBeanImpl.java b/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/mock/TestBeanImpl.java
new file mode 100644
index 0000000000..db04d8bcad
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/mock/TestBeanImpl.java
@@ -0,0 +1,42 @@
+/*
+ * 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.container.spring.mock;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public class TestBeanImpl implements TestBean {
+
+ private TestBean bean;
+
+ public TestBeanImpl() {
+ }
+
+ public String echo(String msg) {
+ return msg;
+ }
+
+ public TestBean getBean() {
+ return bean;
+ }
+
+ public void setBean(TestBean bean) {
+ this.bean = bean;
+ }
+}
diff --git a/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/mock/TestReference.java b/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/mock/TestReference.java
new file mode 100644
index 0000000000..73d53bdbb7
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/test/java/org/apache/tuscany/container/spring/mock/TestReference.java
@@ -0,0 +1,8 @@
+package org.apache.tuscany.container.spring.mock;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public interface TestReference {
+ String echo(String msg);
+}
diff --git a/sandbox/old/contrib/implementation-spring/container/src/test/resources/META-INF/sca/application-context.xml b/sandbox/old/contrib/implementation-spring/container/src/test/resources/META-INF/sca/application-context.xml
new file mode 100644
index 0000000000..7fa1ff34b0
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/test/resources/META-INF/sca/application-context.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:sca="http://www.springframework.org/schema/sca"
+ xsi:schemaLocation="
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+http://www.springframework.org/schema/sca http://www.springframework.org/schema/sca/spring-sca.xsd">
+
+ <bean id="testBean" class="org.apache.tuscany.container.spring.mock.TestBeanImpl" lazy-init="true">
+ <property name="bean" ref="testReference"/>
+ </bean>
+ <!-- <sca:reference name="testReference" type="org.apache.tuscany.container.spring.mock.TestReference"/> -->
+
+</beans>
diff --git a/sandbox/old/contrib/implementation-spring/container/src/test/resources/META-INF/sca/default.scdl b/sandbox/old/contrib/implementation-spring/container/src/test/resources/META-INF/sca/default.scdl
new file mode 100644
index 0000000000..0b2c92c667
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/test/resources/META-INF/sca/default.scdl
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+ -->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ name="spring.test">
+
+ <component name="Spring">
+ <implementation.spring location="META-INF/sca/application-context.xml">
+ <service name="fooService">
+ <binding.test/>
+ <interface.java class="org.apache.tuscany.container.spring.mock.TestBean"/>
+ <reference>testBean</reference>
+ </service>
+ <reference name="testReference">
+ <interface.java class="org.apache.tuscany.container.spring.mock.TestBean"/>
+ <binding.test/>
+ </reference>
+ </implementation.spring>
+ </component>
+
+</composite>
diff --git a/sandbox/old/contrib/implementation-spring/container/src/test/resources/META-INF/sca/testReferenceContext.xml b/sandbox/old/contrib/implementation-spring/container/src/test/resources/META-INF/sca/testReferenceContext.xml
new file mode 100644
index 0000000000..00cd6fabbc
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/test/resources/META-INF/sca/testReferenceContext.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:sca="http://www.springframework.org/schema/sca"
+ xsi:schemaLocation="
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+http://www.springframework.org/schema/sca http://www.springframework.org/schema/sca/spring-sca.xsd">
+
+ <bean id="testBean" class="org.apache.tuscany.container.spring.mock.TestBeanImpl">
+ <property name="bean" ref="testReference"/>
+ </bean>
+
+ <sca:reference name="testReference" type="org.apache.tuscany.container.spring.mock.TestBean"/>
+
+</beans>
diff --git a/sandbox/old/contrib/implementation-spring/container/src/test/resources/META-INF/sca/testServiceContext.xml b/sandbox/old/contrib/implementation-spring/container/src/test/resources/META-INF/sca/testServiceContext.xml
new file mode 100644
index 0000000000..deca82f191
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/test/resources/META-INF/sca/testServiceContext.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:sca="http://www.springframework.org/schema/sca"
+ xsi:schemaLocation="
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+http://www.springframework.org/schema/sca http://www.springframework.org/schema/sca/spring-sca.xsd">
+
+ <sca:service name="fooService" type="org.apache.tuscany.container.spring.mock.TestBeanImpl" target="testBean"/>
+
+ <bean id="testBean" class="org.apache.tuscany.container.spring.mock.TestBeanImpl"/>
+
+</beans>
diff --git a/sandbox/old/contrib/implementation-spring/container/src/test/resources/META-INF/tuscany/xsystem.scdl b/sandbox/old/contrib/implementation-spring/container/src/test/resources/META-INF/tuscany/xsystem.scdl
new file mode 100644
index 0000000000..0ef2781492
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/test/resources/META-INF/tuscany/xsystem.scdl
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+ -->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ name="spring.test">
+ <!--
+ <component name="Spring">
+ <implementation.spring location="META-INF/sca/application-context.xml">
+ <service name="fooService">
+ <binding.test/>
+ <interface.java class="org.apache.tuscany.container.spring.mock.TestBean"/>
+ <reference>testBean</reference>
+ </service>
+ <reference name="testReference">
+ <interface.java class="org.apache.tuscany.container.spring.mock.TestBean"/>
+ <binding.test/>
+ </reference>
+ </implementation.spring>
+ </component> -->
+
+</composite>
diff --git a/sandbox/old/contrib/implementation-spring/container/src/test/resources/org/apache/tuscany/container/spring/ExplicitSpring.xml b/sandbox/old/contrib/implementation-spring/container/src/test/resources/org/apache/tuscany/container/spring/ExplicitSpring.xml
new file mode 100644
index 0000000000..127592c1f0
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/test/resources/org/apache/tuscany/container/spring/ExplicitSpring.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:sca="http://www.springframework.org/schema/sca"
+ xsi:schemaLocation="
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+http://www.springframework.org/schema/sca http://www.springframework.org/schema/sca/spring-sca.xsd">
+
+ <sca:service name="fooBean" type="org.apache.tuscany.container.spring.mock.TestBeanImpl" target="testBean"/>
+
+ <bean id="testBean" class="org.apache.tuscany.container.spring.mock.TestBeanImpl">
+ </bean>
+
+</beans>
diff --git a/sandbox/old/contrib/implementation-spring/container/src/test/resources/org/apache/tuscany/container/spring/SpringConfigSchemaTest.xml b/sandbox/old/contrib/implementation-spring/container/src/test/resources/org/apache/tuscany/container/spring/SpringConfigSchemaTest.xml
new file mode 100644
index 0000000000..c9a4c7e076
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/test/resources/org/apache/tuscany/container/spring/SpringConfigSchemaTest.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:sca="http://www.springframework.org/schema/sca"
+ xsi:schemaLocation="
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+http://www.springframework.org/schema/sca http://www.springframework.org/schema/sca/spring-sca.xsd">
+
+ <bean id="testBean" class="org.apache.tuscany.container.spring.mock.TestBeanImpl">
+ </bean>
+
+ <sca:service name="fooService" type="org.apache.tuscany.container.spring.mock.TestBean" target="testBean"/>
+
+ <sca:reference name="fooReference" type="org.apache.tuscany.container.spring.mock.TestReference"/>
+
+
+</beans>
diff --git a/sandbox/old/contrib/implementation-spring/container/src/test/resources/test.xml b/sandbox/old/contrib/implementation-spring/container/src/test/resources/test.xml
new file mode 100644
index 0000000000..00dd841ba3
--- /dev/null
+++ b/sandbox/old/contrib/implementation-spring/container/src/test/resources/test.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:sca="http://www.springframework.org/schema/sca"
+ xsi:schemaLocation="
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+http://www.springframework.org/schema/sca http://www.springframework.org/schema/sca/spring-sca.xsd">
+
+ <bean id="testBean" class="org.apache.tuscany.container.spring.mock.TestBeanImpl"/>
+
+</beans>