diff options
Diffstat (limited to '')
19 files changed, 1451 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 <sca:> 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 <sca:reference> 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 <sca:service/> 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> |