diff options
Diffstat (limited to '')
7 files changed, 43 insertions, 46 deletions
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/ApplicationContextAccessorBean.java index e2f748aba8..a54ef8df17 100644 --- 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/ApplicationContextAccessorBean.java @@ -28,15 +28,15 @@ import org.springframework.context.support.ApplicationObjectSupport; * * 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 class ApplicationContextAccessorBean extends ApplicationObjectSupport implements ApplicationContextAware { public final static String BEAN_ID = "tuscanySpringApplicationContextAccessor"; - private final static ApplicationContextAccessor INSTANCE = new ApplicationContextAccessor(); + private final static ApplicationContextAccessorBean INSTANCE = new ApplicationContextAccessorBean(); - private ApplicationContextAccessor() { + private ApplicationContextAccessorBean() { } // Spring static factory method to create the singleton instance - public static ApplicationContextAccessor getInstance() { + public static ApplicationContextAccessorBean 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/SpringWebApplicationContextAccessor.java index 062e6105a2..623a298b74 100644 --- 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/SpringWebApplicationContextAccessor.java @@ -24,17 +24,18 @@ 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.core.LifeCycleListener; import org.apache.tuscany.sca.host.http.ExtensibleServletHost; -import org.apache.tuscany.sca.implementation.spring.invocation.SpringApplicationContextHelper; +import org.apache.tuscany.sca.implementation.spring.invocation.SpringApplicationContextAccessor; 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()); +public class SpringWebApplicationContextAccessor implements SpringApplicationContextAccessor, LifeCycleListener { + private static Logger log = Logger.getLogger(SpringWebApplicationContextAccessor.class.getName()); private ExtensionPointRegistry registry; + private ApplicationContext parentApplicationContext; - public SpringWebModuleActivator(ExtensionPointRegistry registry) { + public SpringWebApplicationContextAccessor(ExtensionPointRegistry registry) { super(); this.registry = registry; } @@ -42,21 +43,31 @@ public class SpringWebModuleActivator implements ModuleActivator { @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) { + parentApplicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext); + if (parentApplicationContext != null) { log.info("Spring WebApplicationContext is now injected on Tuscany"); - contextHelper.setParentApplicationContext(context); } } + + if (parentApplicationContext == null) { + parentApplicationContext = ApplicationContextAccessorBean.getInstance().getApplicationContext(); + } } @Override public void stop() { - // NO-OP + parentApplicationContext = null; + } + + public Object getParentApplicationContext() { + return parentApplicationContext; + } + + public void setParentApplicationContext(Object parentApplicationContext) { + this.parentApplicationContext = (ApplicationContext) parentApplicationContext; } } 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.implementation.spring.invocation.SpringApplicationContextAccessor index 984e81bf87..506b02c782 100644 --- 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.implementation.spring.invocation.SpringApplicationContextAccessor @@ -14,4 +14,4 @@ # 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 +org.apache.tuscany.sca.implementation.spring.webapp.SpringWebApplicationContextAccessor
\ 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 index 3e9d7deb91..b98374a88b 100644 --- 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 @@ -22,7 +22,7 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="tuscanySpringApplicationContextAccessor" - class="org.apache.tuscany.sca.implementation.spring.webapp.ApplicationContextAccessor" + class="org.apache.tuscany.sca.implementation.spring.webapp.ApplicationContextAccessorBean" scope="singleton" factory-method="getInstance"> </bean> 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 index 4aa8cf5ebb..6a5ae882b1 100644 --- 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 @@ -31,9 +31,9 @@ public class ApplicationContextAccessorTestCase { 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; + Object accessor = context.getBean(ApplicationContextAccessorBean.BEAN_ID); + Assert.assertSame(ApplicationContextAccessorBean.getInstance(), accessor); + ApplicationContextAccessorBean contextAccessor = (ApplicationContextAccessorBean)accessor; Assert.assertSame(context, contextAccessor.getApplicationContext()); } 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/SpringApplicationContextAccessor.java index f1a1d7e1e7..3cdeb332b2 100644 --- 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/SpringApplicationContextAccessor.java @@ -19,38 +19,21 @@ 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); - } - +public interface SpringApplicationContextAccessor { /** * Get the parent Spring application context for the hosting environment. This will be used as the parent * application context for implementation.spring components - * @return + * @return The parent application context */ - public Object getParentApplicationContext() { - return parentApplicationContext; - } + Object getParentApplicationContext(); /** * Set the root Spring application context. This is particually useful for Spring web integration where Spring * creates WebApplicationContext and keeps it in the ServletContext - * @param parentApplicationContext + * @param parentApplicationContext The parent application context */ - public void setParentApplicationContext(Object parentApplicationContext) { - this.parentApplicationContext = parentApplicationContext; - } + void setParentApplicationContext(Object parentApplicationContext); } 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 46d49dbe1a..24533368ff 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 @@ -36,7 +36,7 @@ import org.apache.tuscany.sca.runtime.RuntimeComponent; public class SpringImplementationProviderFactory implements ImplementationProviderFactory<SpringImplementation> { private ProxyFactory proxyFactory; private PropertyValueFactory propertyFactory; - private SpringApplicationContextHelper contextHelper; + private SpringApplicationContextAccessor contextAccessor; /** * Simple constructor @@ -44,9 +44,10 @@ public class SpringImplementationProviderFactory implements ImplementationProvid */ public SpringImplementationProviderFactory(ExtensionPointRegistry registry) { super(); - contextHelper = SpringApplicationContextHelper.getInstance(registry); + UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); + contextAccessor = utilities.getUtility(SpringApplicationContextAccessor.class); proxyFactory = ExtensibleProxyFactory.getInstance(registry); - propertyFactory = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(PropertyValueFactory.class); + propertyFactory = utilities.getUtility(PropertyValueFactory.class); } /** @@ -58,8 +59,10 @@ public class SpringImplementationProviderFactory implements ImplementationProvid */ public ImplementationProvider createImplementationProvider(RuntimeComponent component, SpringImplementation implementation) { - Object parentApplicationContext = contextHelper.getParentApplicationContext(); - return new SpringImplementationProvider(component, implementation, parentApplicationContext, proxyFactory, propertyFactory); + Object parentApplicationContext = + (contextAccessor != null) ? contextAccessor.getParentApplicationContext() : null; + return new SpringImplementationProvider(component, implementation, parentApplicationContext, proxyFactory, + propertyFactory); } /** |