From 9dafe3e2c4d2476cb3ea7789e3f3063418340059 Mon Sep 17 00:00:00 2001 From: rfeng Date: Wed, 28 Jul 2010 21:01:41 +0000 Subject: Allow Spring WebApplicationContext to be used by Tuscany Bring up a sample web application which demonstrates the integration between Spring and Tuscany git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@980218 13f79535-47bb-0310-9956-ffa450edef68 --- .../http/DefaultServletHostExtensionPoint.java | 6 + .../sca/host/http/ExtensibleServletHost.java | 6 + .../apache/tuscany/sca/host/http/ServletHost.java | 3 + .../apache/tuscany/sca/http/jetty/JettyServer.java | 54 ++++-- .../tuscany/sca/host/webapp/WebAppServletHost.java | 4 + .../processor/PropertyAnnotationProcessor.java | 4 + .../processor/ReferenceAnnotationProcessor.java | 4 + .../context/SCAParentApplicationContext.java | 10 +- .../runtime/context/SpringImplementationStub.java | 18 ++ .../modules/implementation-spring-webapp/LICENSE | 205 +++++++++++++++++++++ .../META-INF/MANIFEST.MF | 29 +++ .../modules/implementation-spring-webapp/NOTICE | 6 + .../modules/implementation-spring-webapp/pom.xml | 60 ++++++ .../spring/webapp/ApplicationContextAccessor.java | 43 +++++ .../spring/webapp/SpringWebModuleActivator.java | 62 +++++++ .../org.apache.tuscany.sca.core.ModuleActivator | 17 ++ .../spring/webapp/spring-webapp-context.xml | 29 +++ .../webapp/ApplicationContextAccessorTestCase.java | 41 +++++ .../implementation-spring/META-INF/MANIFEST.MF | 23 ++- .../spring/invocation/PropertyValueTie.java | 8 +- .../invocation/SpringApplicationContextHelper.java | 56 ++++++ .../spring/invocation/SpringContextStub.java | 12 +- .../invocation/SpringImplementationProvider.java | 13 +- .../SpringImplementationProviderFactory.java | 22 +-- .../spring/invocation/SpringImplementationTie.java | 17 +- .../spring/xml/SpringImplementationProcessor.java | 2 +- .../src/main/java/sample/HelloworldImpl.java | 8 +- .../src/main/resources/helloworld-context.xml | 4 +- .../src/main/resources/helloworld.composite | 7 +- 29 files changed, 702 insertions(+), 71 deletions(-) create mode 100644 sca-java-2.x/trunk/modules/implementation-spring-webapp/LICENSE create mode 100644 sca-java-2.x/trunk/modules/implementation-spring-webapp/META-INF/MANIFEST.MF create mode 100644 sca-java-2.x/trunk/modules/implementation-spring-webapp/NOTICE create mode 100644 sca-java-2.x/trunk/modules/implementation-spring-webapp/pom.xml create mode 100644 sca-java-2.x/trunk/modules/implementation-spring-webapp/src/main/java/org/apache/tuscany/sca/implementation/spring/webapp/ApplicationContextAccessor.java create mode 100644 sca-java-2.x/trunk/modules/implementation-spring-webapp/src/main/java/org/apache/tuscany/sca/implementation/spring/webapp/SpringWebModuleActivator.java create mode 100644 sca-java-2.x/trunk/modules/implementation-spring-webapp/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-2.x/trunk/modules/implementation-spring-webapp/src/main/resources/org/apache/tuscany/sca/implementation/spring/webapp/spring-webapp-context.xml create mode 100644 sca-java-2.x/trunk/modules/implementation-spring-webapp/src/test/java/org/apache/tuscany/sca/implementation/spring/webapp/ApplicationContextAccessorTestCase.java create mode 100644 sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringApplicationContextHelper.java (limited to 'sca-java-2.x/trunk') diff --git a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/DefaultServletHostExtensionPoint.java b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/DefaultServletHostExtensionPoint.java index 3145e90164..8ecb81f843 100644 --- a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/DefaultServletHostExtensionPoint.java +++ b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/DefaultServletHostExtensionPoint.java @@ -27,6 +27,7 @@ import java.util.List; import javax.servlet.RequestDispatcher; import javax.servlet.Servlet; +import javax.servlet.ServletContext; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.LifeCycleListener; @@ -173,6 +174,11 @@ public class DefaultServletHostExtensionPoint implements ServletHostExtensionPoi public void stop() { ServiceHelper.stop(host); } + + @Override + public ServletContext getServletContext() { + return getServletHost().getServletContext(); + } } public void start() { diff --git a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ExtensibleServletHost.java b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ExtensibleServletHost.java index 1b639041f7..107b6b3d5f 100644 --- a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ExtensibleServletHost.java +++ b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ExtensibleServletHost.java @@ -24,6 +24,7 @@ import java.util.List; import javax.servlet.RequestDispatcher; import javax.servlet.Servlet; +import javax.servlet.ServletContext; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.UtilityExtensionPoint; @@ -131,4 +132,9 @@ public class ExtensibleServletHost implements ServletHost { public String getName() { return getDefaultServletHost().getName(); } + + @Override + public ServletContext getServletContext() { + return getDefaultServletHost().getServletContext(); + } } diff --git a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHost.java b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHost.java index 6b38559204..f70a6eddcc 100644 --- a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHost.java +++ b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHost.java @@ -22,6 +22,7 @@ import java.net.URL; import javax.servlet.RequestDispatcher; import javax.servlet.Servlet; +import javax.servlet.ServletContext; /** * Interface implemented by host environments that allow Servlets to be @@ -35,6 +36,8 @@ import javax.servlet.Servlet; */ public interface ServletHost { + ServletContext getServletContext(); + /** * Sets the default port for the server. * diff --git a/sca-java-2.x/trunk/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyServer.java b/sca-java-2.x/trunk/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyServer.java index ba131e0e94..aa53815b7f 100644 --- a/sca-java-2.x/trunk/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyServer.java +++ b/sca-java-2.x/trunk/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyServer.java @@ -32,12 +32,13 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.Map.Entry; +import java.util.Set; import java.util.logging.Logger; import javax.servlet.RequestDispatcher; import javax.servlet.Servlet; +import javax.servlet.ServletContext; import javax.servlet.ServletException; import org.apache.tuscany.sca.core.ExtensionPointRegistry; @@ -80,7 +81,7 @@ public class JettyServer implements ServletHost, LifeCycleListener { private boolean sendServerVersion; private WorkScheduler workScheduler; - + // TODO - this static seems to be set by the JSORPC binding unit test // doesn't look to be a great way of doing things public static int portDefault = 8080; @@ -130,12 +131,12 @@ public class JettyServer implements ServletHost, LifeCycleListener { keyStoreType = System.getProperty("javax.net.ssl.keyStoreType", KeyStore.getDefaultType()); trustStoreType = System.getProperty("javax.net.ssl.trustStoreType", KeyStore.getDefaultType()); - System.setProperty("JETTY_NO_SHUTDOWN_HOOK", "true"); + System.setProperty("JETTY_NO_SHUTDOWN_HOOK", "true"); return null; } }); } - + public String getName() { return "jetty"; } @@ -181,11 +182,14 @@ public class JettyServer implements ServletHost, LifeCycleListener { private void configureSSL(SslSocketConnector connector, SecurityContext securityContext) { connector.setProtocol("TLS"); if (securityContext != null) { - keyStoreType = securityContext.getSSLProperties().getProperty("javax.net.ssl.keyStoreType", KeyStore.getDefaultType()); + keyStoreType = + securityContext.getSSLProperties().getProperty("javax.net.ssl.keyStoreType", KeyStore.getDefaultType()); keyStore = securityContext.getSSLProperties().getProperty("javax.net.ssl.keyStore"); keyStorePassword = securityContext.getSSLProperties().getProperty("javax.net.ssl.keyStorePassword"); - trustStoreType = securityContext.getSSLProperties().getProperty("javax.net.ssl.trustStoreType", KeyStore.getDefaultType()); + trustStoreType = + securityContext.getSSLProperties().getProperty("javax.net.ssl.trustStoreType", + KeyStore.getDefaultType()); trustStore = securityContext.getSSLProperties().getProperty("javax.net.ssl.trustStore"); trustStorePassword = securityContext.getSSLProperties().getProperty("javax.net.ssl.trustStorePassword"); } @@ -203,30 +207,31 @@ public class JettyServer implements ServletHost, LifeCycleListener { } } - + public String addServletMapping(String suri, Servlet servlet) throws ServletMappingException { return addServletMapping(suri, servlet, null); - } + } - public String addServletMapping(String suri, Servlet servlet, final SecurityContext securityContext) throws ServletMappingException { + public String addServletMapping(String suri, Servlet servlet, final SecurityContext securityContext) + throws ServletMappingException { URI uri = URI.create(suri); // Get the URI scheme and port String scheme = null; - if(securityContext != null && securityContext.isSSLEnabled()) { + if (securityContext != null && securityContext.isSSLEnabled()) { scheme = "https"; } else { scheme = uri.getScheme(); if (scheme == null) { scheme = "http"; - } + } } - + String host = uri.getHost(); if ("0.0.0.0".equals(host)) { host = null; } - + int portNumber = uri.getPort(); if (portNumber == -1) { if ("http".equals(scheme)) { @@ -350,21 +355,21 @@ public class JettyServer implements ServletHost, LifeCycleListener { public URL getURLMapping(String suri, SecurityContext securityContext) throws ServletMappingException { return map(suri, securityContext, true); } - + private URL map(String suri, SecurityContext securityContext, boolean resolve) throws ServletMappingException { URI uri = URI.create(suri); - + // Get the URI scheme and port String scheme = null; - if(securityContext != null && securityContext.isSSLEnabled()) { + if (securityContext != null && securityContext.isSSLEnabled()) { scheme = "https"; } else { scheme = uri.getScheme(); if (scheme == null) { scheme = "http"; - } + } } - + int portNumber = uri.getPort(); if (portNumber == -1) { if ("http".equals(scheme)) { @@ -372,7 +377,7 @@ public class JettyServer implements ServletHost, LifeCycleListener { } else { portNumber = defaultSSLPort; } - } + } // Get the host String host = uri.getHost(); @@ -576,7 +581,16 @@ public class JettyServer implements ServletHost, LifeCycleListener { Log.setLog(jettyLogger); } catch (Throwable e) { // Ignore - } + } + } + + @Override + public ServletContext getServletContext() { + if (ports.size() > 0) { + return ports.values().iterator().next().getServletHandler().getServletContext(); + } else { + return null; + } } } diff --git a/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java b/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java index 0c5431a7d8..b927ecaf4c 100644 --- a/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java +++ b/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java @@ -335,4 +335,8 @@ public class WebAppServletHost implements ServletHost { tempAttributes.put(name, value); } } + + public ServletContext getServletContext() { + return servletContext; + } } diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyAnnotationProcessor.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyAnnotationProcessor.java index 3e8bca229f..565d0118d9 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyAnnotationProcessor.java +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyAnnotationProcessor.java @@ -93,9 +93,11 @@ public class PropertyAnnotationProcessor implements BeanPostProcessor { throw new IllegalStateException("Property annotation is not supported on static methods"); } + /* if (Modifier.isPrivate(method.getModifiers())) { throw new IllegalStateException("Property annotation is not supported on private methods"); } + */ if (method.getParameterTypes().length == 0) { throw new IllegalStateException("Property annotation requires at least one argument: " + method); @@ -124,9 +126,11 @@ public class PropertyAnnotationProcessor implements BeanPostProcessor { throw new IllegalStateException("Property annotation is not supported on static fields"); } + /* if (Modifier.isPrivate(field.getModifiers())) { throw new IllegalStateException("Property annotation is not supported on private fields"); } + */ ReflectionUtils.makeAccessible(field); diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ReferenceAnnotationProcessor.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ReferenceAnnotationProcessor.java index 6b86f0962e..280c723430 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ReferenceAnnotationProcessor.java +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ReferenceAnnotationProcessor.java @@ -92,9 +92,11 @@ public class ReferenceAnnotationProcessor implements BeanPostProcessor { throw new IllegalStateException("Reference annotation is not supported on static methods"); } + /* if (Modifier.isPrivate(method.getModifiers())) { throw new IllegalStateException("Reference annotation is not supported on private methods"); } + */ if (method.getParameterTypes().length == 0) { throw new IllegalStateException( @@ -124,9 +126,11 @@ public class ReferenceAnnotationProcessor implements BeanPostProcessor { throw new IllegalStateException("Reference annotation is not supported on static fields"); } + /* if (Modifier.isPrivate(field.getModifiers())) { throw new IllegalStateException("Reference annotation is not supported on private fields"); } + */ ReflectionUtils.makeAccessible(field); diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SCAParentApplicationContext.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SCAParentApplicationContext.java index 88be5b720f..5b4ef9e130 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SCAParentApplicationContext.java +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SCAParentApplicationContext.java @@ -110,10 +110,6 @@ class SCAParentApplicationContext implements ApplicationContext { return EMPTY_ARRAY; } - public ApplicationContext getParent() { - return null; - } - public AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException { return null; } @@ -199,4 +195,10 @@ class SCAParentApplicationContext implements ApplicationContext { // resource loading mechanism is exposed right now. return this.getClass().getClassLoader(); } + + @Override + public ApplicationContext getParent() { + return implementation.getParentApplicationContext(); + } + } diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringImplementationStub.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringImplementationStub.java index 298d8944fb..bf46765f13 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringImplementationStub.java +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringImplementationStub.java @@ -23,6 +23,7 @@ import java.lang.reflect.Method; import org.springframework.beans.BeansException; import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.context.ApplicationContext; /** * This is the runtime side stub for the corresponding Tuscany-side stub class. @@ -40,6 +41,7 @@ public class SpringImplementationStub { Method getComponentTie; Method getPropertyValueTie; Method getClassLoader; + Method getParentApplicationContext; public SpringImplementationStub(Object tie) { this.tie = tie; @@ -51,6 +53,7 @@ public class SpringImplementationStub { getComponentTie = tieClass.getMethod("getComponentTie"); getPropertyValueTie = tieClass.getMethod("getPropertyValueTie"); getClassLoader = tieClass.getMethod("getClassLoader"); + getParentApplicationContext = tieClass.getMethod("getParentApplicationContext"); } catch (Exception e) { throw new RuntimeException(e); } @@ -126,4 +129,19 @@ public class SpringImplementationStub { throw new RuntimeException(e); } } + + /** + * Get the parent Spring application context set by the Tuscany runtime + * @return + */ + public ApplicationContext getParentApplicationContext() { + try { + + return (ApplicationContext)getParentApplicationContext.invoke(tie); + + } catch (Exception e) { + throw new RuntimeException(e); + } + + } } diff --git a/sca-java-2.x/trunk/modules/implementation-spring-webapp/LICENSE b/sca-java-2.x/trunk/modules/implementation-spring-webapp/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-spring-webapp/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. + + + diff --git a/sca-java-2.x/trunk/modules/implementation-spring-webapp/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/implementation-spring-webapp/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..25cede8426 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-spring-webapp/META-INF/MANIFEST.MF @@ -0,0 +1,29 @@ +Manifest-Version: 1.0 +SCA-Version: 1.1 +Bundle-Name: Apache Tuscany SCA Spring Implementation WebApp Integration +Bundle-Vendor: The Apache Software Foundation +Bundle-Version: 2.0.0 +Bundle-ManifestVersion: 2 +Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt +Bundle-Description: Apache Tuscany SCA Spring Implementation Runtime Model +Bundle-SymbolicName: org.apache.tuscany.sca.implementation.spring.webapp +Bundle-DocURL: http://www.apache.org/ +Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6 +Import-Package: javax.servlet, + org.apache.tuscany.sca.core;version="2.0.0", + org.apache.tuscany.sca.extensibility;version="2.0.0", + org.apache.tuscany.sca.implementation.spring;version="2.0.0", + org.apache.tuscany.sca.implementation.spring.invocation;version="2.0.0", + org.apache.tuscany.sca.provider;version="2.0.0", + org.apache.tuscany.sca.runtime;version="2.0.0", + org.springframework.beans;version="3.0.2.RELEASE", + org.springframework.beans.factory;version="3.0.2.RELEASE", + org.springframework.beans.factory.annotation;version="3.0.2.RELEASE", + org.springframework.beans.factory.config;version="3.0.2.RELEASE", + org.springframework.beans.factory.support;version="3.0.2.RELEASE", + org.springframework.beans.factory.xml;version="3.0.2.RELEASE", + org.springframework.context;version="3.0.2.RELEASE", + org.springframework.context.support;version="3.0.2.RELEASE", + org.springframework.core.io;version="3.0.2.RELEASE", + org.springframework.util;version="3.0.2.RELEASE" + diff --git a/sca-java-2.x/trunk/modules/implementation-spring-webapp/NOTICE b/sca-java-2.x/trunk/modules/implementation-spring-webapp/NOTICE new file mode 100644 index 0000000000..1325efd8bf --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-spring-webapp/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2008 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-2.x/trunk/modules/implementation-spring-webapp/pom.xml b/sca-java-2.x/trunk/modules/implementation-spring-webapp/pom.xml new file mode 100644 index 0000000000..cfdce13108 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-spring-webapp/pom.xml @@ -0,0 +1,60 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 2.0-SNAPSHOT + ../pom.xml + + tuscany-implementation-spring-webapp + Apache Tuscany SCA Spring Implementation WebApp Integration + + + + + org.apache.tuscany.sca + tuscany-implementation-spring + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-http + 2.0-SNAPSHOT + + + + + org.springframework + spring-web + 3.0.2.RELEASE + + + + javax.servlet + servlet-api + 2.5 + jar + provided + + + diff --git a/sca-java-2.x/trunk/modules/implementation-spring-webapp/src/main/java/org/apache/tuscany/sca/implementation/spring/webapp/ApplicationContextAccessor.java b/sca-java-2.x/trunk/modules/implementation-spring-webapp/src/main/java/org/apache/tuscany/sca/implementation/spring/webapp/ApplicationContextAccessor.java new file mode 100644 index 0000000000..e2f748aba8 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-spring-webapp/src/main/java/org/apache/tuscany/sca/implementation/spring/webapp/ApplicationContextAccessor.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.sca.implementation.spring.webapp; + +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.support.ApplicationObjectSupport; + +/** + * A singleton utility class that can be added to the Spring application context to receive injection of the containing + * Spring application context. + * + * The Spring bean definition file is: org/apache/tuscany/sca/implementation/spring/webapp/spring-webapp-context.xml + */ +public class ApplicationContextAccessor extends ApplicationObjectSupport implements ApplicationContextAware { + public final static String BEAN_ID = "tuscanySpringApplicationContextAccessor"; + private final static ApplicationContextAccessor INSTANCE = new ApplicationContextAccessor(); + + private ApplicationContextAccessor() { + } + + // Spring static factory method to create the singleton instance + public static ApplicationContextAccessor getInstance() { + return INSTANCE; + } + +} diff --git a/sca-java-2.x/trunk/modules/implementation-spring-webapp/src/main/java/org/apache/tuscany/sca/implementation/spring/webapp/SpringWebModuleActivator.java b/sca-java-2.x/trunk/modules/implementation-spring-webapp/src/main/java/org/apache/tuscany/sca/implementation/spring/webapp/SpringWebModuleActivator.java new file mode 100644 index 0000000000..062e6105a2 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-spring-webapp/src/main/java/org/apache/tuscany/sca/implementation/spring/webapp/SpringWebModuleActivator.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.implementation.spring.webapp; + +import java.util.logging.Logger; + +import javax.servlet.ServletContext; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.ModuleActivator; +import org.apache.tuscany.sca.host.http.ExtensibleServletHost; +import org.apache.tuscany.sca.implementation.spring.invocation.SpringApplicationContextHelper; +import org.springframework.context.ApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; + +public class SpringWebModuleActivator implements ModuleActivator { + private static Logger log = Logger.getLogger(SpringWebModuleActivator.class.getName()); + private ExtensionPointRegistry registry; + + public SpringWebModuleActivator(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + } + + @Override + public void start() { + ExtensibleServletHost servletHost = ExtensibleServletHost.getInstance(registry); + SpringApplicationContextHelper contextHelper = SpringApplicationContextHelper.getInstance(registry); + + ServletContext servletContext = servletHost.getServletContext(); + if (servletContext != null) { + ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext); + if (context != null) { + log.info("Spring WebApplicationContext is now injected on Tuscany"); + contextHelper.setParentApplicationContext(context); + } + } + } + + @Override + public void stop() { + // NO-OP + } + +} diff --git a/sca-java-2.x/trunk/modules/implementation-spring-webapp/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/sca-java-2.x/trunk/modules/implementation-spring-webapp/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator new file mode 100644 index 0000000000..984e81bf87 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-spring-webapp/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +org.apache.tuscany.sca.implementation.spring.webapp.SpringWebModuleActivator \ No newline at end of file diff --git a/sca-java-2.x/trunk/modules/implementation-spring-webapp/src/main/resources/org/apache/tuscany/sca/implementation/spring/webapp/spring-webapp-context.xml b/sca-java-2.x/trunk/modules/implementation-spring-webapp/src/main/resources/org/apache/tuscany/sca/implementation/spring/webapp/spring-webapp-context.xml new file mode 100644 index 0000000000..3e9d7deb91 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-spring-webapp/src/main/resources/org/apache/tuscany/sca/implementation/spring/webapp/spring-webapp-context.xml @@ -0,0 +1,29 @@ + + + + + + + + diff --git a/sca-java-2.x/trunk/modules/implementation-spring-webapp/src/test/java/org/apache/tuscany/sca/implementation/spring/webapp/ApplicationContextAccessorTestCase.java b/sca-java-2.x/trunk/modules/implementation-spring-webapp/src/test/java/org/apache/tuscany/sca/implementation/spring/webapp/ApplicationContextAccessorTestCase.java new file mode 100644 index 0000000000..4aa8cf5ebb --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-spring-webapp/src/test/java/org/apache/tuscany/sca/implementation/spring/webapp/ApplicationContextAccessorTestCase.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.implementation.spring.webapp; + +import org.junit.Assert; +import org.junit.Test; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class ApplicationContextAccessorTestCase { + + @Test + public void testContext() { + ApplicationContext context = + new ClassPathXmlApplicationContext( + new String[] {"org/apache/tuscany/sca/implementation/spring/webapp/spring-webapp-context.xml"}); + Object accessor = context.getBean(ApplicationContextAccessor.BEAN_ID); + Assert.assertSame(ApplicationContextAccessor.getInstance(), accessor); + ApplicationContextAccessor contextAccessor = (ApplicationContextAccessor)accessor; + Assert.assertSame(context, contextAccessor.getApplicationContext()); + + } + +} diff --git a/sca-java-2.x/trunk/modules/implementation-spring/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/implementation-spring/META-INF/MANIFEST.MF index 988718b178..a35bb0ab68 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring/META-INF/MANIFEST.MF +++ b/sca-java-2.x/trunk/modules/implementation-spring/META-INF/MANIFEST.MF @@ -13,6 +13,7 @@ Import-Package: javax.jws, org.apache.tuscany.sca.assembly.builder;version="2.0.0", org.apache.tuscany.sca.assembly.impl;version="2.0.0", org.apache.tuscany.sca.assembly.xml;version="2.0.0", + org.apache.tuscany.sca.context;version="2.0.0", org.apache.tuscany.sca.contribution;version="2.0.0", org.apache.tuscany.sca.contribution.processor;version="2.0.0", org.apache.tuscany.sca.contribution.resolver;version="2.0.0", @@ -39,15 +40,23 @@ Import-Package: javax.jws, Bundle-SymbolicName: org.apache.tuscany.sca.implementation.spring Bundle-DocURL: http://www.apache.org/ Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6 -Export-Package: org.apache.tuscany.sca.implementation.spring;version="2.0.0"; - uses:="org.apache.tuscany.sca.assembly, - org.apache.tuscany.sca.assembly.impl, - org.apache.tuscany.sca.interfacedef, - javax.xml.namespace", +Export-Package: org.apache.tuscany.sca.implementation.spring;version="2.0.0", org.apache.tuscany.sca.implementation.spring.introspect;version="2.0.0"; uses:="org.apache.tuscany.sca.assembly, + org.apache.tuscany.sca.contribution.resolver, org.apache.tuscany.sca.implementation.java.introspect, org.apache.tuscany.sca.implementation.spring, + org.apache.tuscany.sca.contribution.processor, org.apache.tuscany.sca.implementation.java, - org.apache.tuscany.sca.policy, - org.apache.tuscany.sca.interfacedef.java" + org.apache.tuscany.sca.core, + org.apache.tuscany.sca.monitor, + org.apache.tuscany.sca.interfacedef.java", + org.apache.tuscany.sca.implementation.spring.invocation;version="2.0.0"; + uses:="org.apache.tuscany.sca.invocation, + org.apache.tuscany.sca.runtime, + org.apache.tuscany.sca.context, + org.apache.tuscany.sca.provider, + org.apache.tuscany.sca.implementation.spring, + org.apache.tuscany.sca.core, + org.apache.tuscany.sca.core.invocation, + org.apache.tuscany.sca.interfacedef" diff --git a/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/PropertyValueTie.java b/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/PropertyValueTie.java index 6289ec8626..2a1df9bcb5 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/PropertyValueTie.java +++ b/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/PropertyValueTie.java @@ -22,7 +22,7 @@ package org.apache.tuscany.sca.implementation.spring.invocation; import java.util.List; import org.apache.tuscany.sca.assembly.ComponentProperty; -import org.apache.tuscany.sca.implementation.java.injection.JavaPropertyValueObjectFactory; +import org.apache.tuscany.sca.context.PropertyValueFactory; import org.apache.tuscany.sca.runtime.RuntimeComponent; /** @@ -34,9 +34,9 @@ import org.apache.tuscany.sca.runtime.RuntimeComponent; public class PropertyValueTie { private RuntimeComponent component; - private JavaPropertyValueObjectFactory propertyFactory; + private PropertyValueFactory propertyFactory; - public PropertyValueTie(RuntimeComponent component, JavaPropertyValueObjectFactory propertyFactory) { + public PropertyValueTie(RuntimeComponent component, PropertyValueFactory propertyFactory) { this.component = component; this.propertyFactory = propertyFactory; } @@ -45,7 +45,7 @@ public class PropertyValueTie { List props = component.getProperties(); for (ComponentProperty prop : props) { if (prop.getName().equals(name)) { - return propertyFactory.createValueFactory(prop, prop.getValue(), type).getInstance(); + return propertyFactory.createPropertyValue(prop, type); } } return null; // property name not found diff --git a/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringApplicationContextHelper.java b/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringApplicationContextHelper.java new file mode 100644 index 0000000000..f1a1d7e1e7 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringApplicationContextHelper.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.implementation.spring.invocation; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; + +/** + * A utility to receive the parent Spring application context + */ +public class SpringApplicationContextHelper { + private Object parentApplicationContext; + + public SpringApplicationContextHelper(ExtensionPointRegistry registry) { + } + + public static SpringApplicationContextHelper getInstance(ExtensionPointRegistry registry) { + UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); + return utilities.getUtility(SpringApplicationContextHelper.class); + } + + /** + * Get the parent Spring application context for the hosting environment. This will be used as the parent + * application context for implementation.spring components + * @return + */ + public Object getParentApplicationContext() { + return parentApplicationContext; + } + + /** + * Set the root Spring application context. This is particually useful for Spring web integration where Spring + * creates WebApplicationContext and keeps it in the ServletContext + * @param parentApplicationContext + */ + public void setParentApplicationContext(Object parentApplicationContext) { + this.parentApplicationContext = parentApplicationContext; + } +} diff --git a/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringContextStub.java b/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringContextStub.java index 6980b81e5d..2b5b5821c7 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringContextStub.java +++ b/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringContextStub.java @@ -24,8 +24,8 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.List; +import org.apache.tuscany.sca.context.PropertyValueFactory; import org.apache.tuscany.sca.core.invocation.ProxyFactory; -import org.apache.tuscany.sca.implementation.java.injection.JavaPropertyValueObjectFactory; import org.apache.tuscany.sca.implementation.spring.SpringImplementation; import org.apache.tuscany.sca.runtime.RuntimeComponent; @@ -44,16 +44,18 @@ public class SpringContextStub { public SpringContextStub(RuntimeComponent component, SpringImplementation implementation, + Object parentApplicationContext, ProxyFactory proxyService, - JavaPropertyValueObjectFactory propertyValueObjectFactory) { + PropertyValueFactory propertyValueObjectFactory) { - initTie(component, implementation, propertyValueObjectFactory); + initTie(component, implementation, parentApplicationContext, propertyValueObjectFactory); } private void initTie(RuntimeComponent component, SpringImplementation implementation, - JavaPropertyValueObjectFactory propertyValueObjectFactory) { + Object parentApplicationContext, + PropertyValueFactory propertyValueObjectFactory) { // TODO: what class loader to use? ClassLoader cl = Thread.currentThread().getContextClassLoader(); @@ -66,7 +68,7 @@ public class SpringContextStub { cl); Constructor stubConstructor = stubClass.getConstructor(new Class[] {Object.class}); Object stub = - stubConstructor.newInstance(new SpringImplementationTie(implementation, component, + stubConstructor.newInstance(new SpringImplementationTie(implementation, parentApplicationContext, component, propertyValueObjectFactory)); Class tieClass = diff --git a/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProvider.java b/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProvider.java index 304f3e2c1a..1d71514721 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProvider.java +++ b/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProvider.java @@ -18,8 +18,8 @@ */ package org.apache.tuscany.sca.implementation.spring.invocation; +import org.apache.tuscany.sca.context.PropertyValueFactory; import org.apache.tuscany.sca.core.invocation.ProxyFactory; -import org.apache.tuscany.sca.implementation.java.injection.JavaPropertyValueObjectFactory; import org.apache.tuscany.sca.implementation.spring.SpringImplementation; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.Invoker; @@ -37,10 +37,6 @@ public class SpringImplementationProvider implements ImplementationProvider { // A Spring application context object private SpringContextStub springContext; - private SpringImplementation implementation; - - private JavaPropertyValueObjectFactory propertyValueObjectFactory; - /** * Constructor for the provider - takes a component definition and a Spring implementation * description @@ -49,14 +45,13 @@ public class SpringImplementationProvider implements ImplementationProvider { */ public SpringImplementationProvider(RuntimeComponent component, SpringImplementation implementation, + Object parentApplicationContext, ProxyFactory proxyService, - JavaPropertyValueObjectFactory propertyValueObjectFactory) { + PropertyValueFactory propertyValueObjectFactory) { super(); - this.implementation = implementation; this.component = component; - this.propertyValueObjectFactory = propertyValueObjectFactory; - springContext = new SpringContextStub(component, implementation, proxyService, propertyValueObjectFactory); + springContext = new SpringContextStub(component, implementation, parentApplicationContext, proxyService, propertyValueObjectFactory); } // end constructor diff --git a/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProviderFactory.java b/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProviderFactory.java index 5d9d6b31c4..46d49dbe1a 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProviderFactory.java +++ b/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProviderFactory.java @@ -18,11 +18,11 @@ */ package org.apache.tuscany.sca.implementation.spring.invocation; +import org.apache.tuscany.sca.context.PropertyValueFactory; import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory; import org.apache.tuscany.sca.core.invocation.ProxyFactory; -import org.apache.tuscany.sca.databinding.impl.MediatorImpl; -import org.apache.tuscany.sca.implementation.java.injection.JavaPropertyValueObjectFactory; import org.apache.tuscany.sca.implementation.spring.SpringImplementation; import org.apache.tuscany.sca.provider.ImplementationProvider; import org.apache.tuscany.sca.provider.ImplementationProviderFactory; @@ -34,21 +34,19 @@ import org.apache.tuscany.sca.runtime.RuntimeComponent; * */ public class SpringImplementationProviderFactory implements ImplementationProviderFactory { - private ProxyFactory proxyFactory; - private JavaPropertyValueObjectFactory propertyFactory; + private PropertyValueFactory propertyFactory; + private SpringApplicationContextHelper contextHelper; /** * Simple constructor * */ - public SpringImplementationProviderFactory(ExtensionPointRegistry extensionPoints) { + public SpringImplementationProviderFactory(ExtensionPointRegistry registry) { super(); - - proxyFactory = ExtensibleProxyFactory.getInstance(extensionPoints); - - // TODO: could the runtime have a default PropertyValueObjectFactory? - propertyFactory = new JavaPropertyValueObjectFactory(new MediatorImpl(extensionPoints)); + contextHelper = SpringApplicationContextHelper.getInstance(registry); + proxyFactory = ExtensibleProxyFactory.getInstance(registry); + propertyFactory = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(PropertyValueFactory.class); } /** @@ -60,7 +58,8 @@ public class SpringImplementationProviderFactory implements ImplementationProvid */ public ImplementationProvider createImplementationProvider(RuntimeComponent component, SpringImplementation implementation) { - return new SpringImplementationProvider(component, implementation, proxyFactory, propertyFactory); + Object parentApplicationContext = contextHelper.getParentApplicationContext(); + return new SpringImplementationProvider(component, implementation, parentApplicationContext, proxyFactory, propertyFactory); } /** @@ -69,4 +68,5 @@ public class SpringImplementationProviderFactory implements ImplementationProvid public Class getModelType() { return SpringImplementation.class; } + } // end class SpringImplementationProviderFactory diff --git a/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationTie.java b/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationTie.java index 749081e95b..81cbed28dc 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationTie.java +++ b/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationTie.java @@ -24,8 +24,7 @@ import java.util.List; import org.apache.tuscany.sca.assembly.ComponentProperty; import org.apache.tuscany.sca.assembly.Property; import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.core.factory.ObjectFactory; -import org.apache.tuscany.sca.implementation.java.injection.JavaPropertyValueObjectFactory; +import org.apache.tuscany.sca.context.PropertyValueFactory; import org.apache.tuscany.sca.implementation.spring.SpringImplementation; import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.apache.tuscany.sca.runtime.RuntimeComponent; @@ -40,15 +39,18 @@ import org.apache.tuscany.sca.runtime.RuntimeComponent; public class SpringImplementationTie { private SpringImplementation implementation; + private Object parentApplicationContext; private RuntimeComponent component; - private JavaPropertyValueObjectFactory propertyFactory; + private PropertyValueFactory propertyFactory; public SpringImplementationTie(SpringImplementation implementation, + Object parentApplicationContext, RuntimeComponent component, - JavaPropertyValueObjectFactory propertyFactory) { + PropertyValueFactory propertyFactory) { this.implementation = implementation; this.component = component; this.propertyFactory = propertyFactory; + this.parentApplicationContext = parentApplicationContext; } public String getURI() { @@ -74,8 +76,7 @@ public class SpringImplementationTie { if (prop.getName().equals(name)) { // On finding the property, create a factory for it and create a Bean using // the factory - ObjectFactory factory = propertyFactory.createValueFactory(prop, prop.getValue(), requiredType); - propertyObject = (B)factory.getInstance(); + propertyObject = (B) propertyFactory.createPropertyValue(prop, requiredType); } // end if } // end for @@ -146,5 +147,9 @@ public class SpringImplementationTie { public ClassLoader getClassLoader() { return implementation.getClassLoader(); } + + public Object getParentApplicationContext() { + return parentApplicationContext; + } } diff --git a/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringImplementationProcessor.java b/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringImplementationProcessor.java index 086dd3b5cf..af3a16cd5d 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringImplementationProcessor.java +++ b/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringImplementationProcessor.java @@ -129,7 +129,7 @@ public class SpringImplementationProcessor extends BaseStAXArtifactProcessor imp * specified in the header identify the context configuration files. * If there is no MANIFEST.MF file or no Spring-Context header within that file, * then the default behaviour is to build an application context using all the *.xml files - * in the METAINF/spring directory. + * in the META-INF/spring directory. */ public SpringImplementation read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { diff --git a/sca-java-2.x/trunk/samples/helloworld-spring/src/main/java/sample/HelloworldImpl.java b/sca-java-2.x/trunk/samples/helloworld-spring/src/main/java/sample/HelloworldImpl.java index ac03ea3ca6..a44dcacc3a 100644 --- a/sca-java-2.x/trunk/samples/helloworld-spring/src/main/java/sample/HelloworldImpl.java +++ b/sca-java-2.x/trunk/samples/helloworld-spring/src/main/java/sample/HelloworldImpl.java @@ -18,11 +18,17 @@ */ package sample; +import org.oasisopen.sca.annotation.Reference; public class HelloworldImpl implements Helloworld { + @Reference(required = false) + private DateService dateService; public String sayHello(String name) { - return "Hello " + name; + if (dateService == null) { + return "Hello " + name; + } + return "[" + dateService.getDate() + "] Hello " + name; } } diff --git a/sca-java-2.x/trunk/samples/helloworld-spring/src/main/resources/helloworld-context.xml b/sca-java-2.x/trunk/samples/helloworld-spring/src/main/resources/helloworld-context.xml index 89b2cfb6f5..b5fba07d66 100644 --- a/sca-java-2.x/trunk/samples/helloworld-spring/src/main/resources/helloworld-context.xml +++ b/sca-java-2.x/trunk/samples/helloworld-spring/src/main/resources/helloworld-context.xml @@ -24,7 +24,9 @@ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/sca http://www.osoa.org/xmlns/sca/1.0/spring-sca.xsd"> - + + + \ No newline at end of file diff --git a/sca-java-2.x/trunk/samples/helloworld-spring/src/main/resources/helloworld.composite b/sca-java-2.x/trunk/samples/helloworld-spring/src/main/resources/helloworld.composite index 33895dde25..0900c63a84 100644 --- a/sca-java-2.x/trunk/samples/helloworld-spring/src/main/resources/helloworld.composite +++ b/sca-java-2.x/trunk/samples/helloworld-spring/src/main/resources/helloworld.composite @@ -19,11 +19,14 @@ --> + + + + + - -- cgit v1.2.3