From b762983667bf7071c9e89f5bcf7603a288e1bd47 Mon Sep 17 00:00:00 2001 From: rfeng Date: Thu, 29 Jul 2010 16:54:18 +0000 Subject: Use a utility instead of ModuleActivator for Spring application context access git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@980505 13f79535-47bb-0310-9956-ffa450edef68 --- .../SpringApplicationContextAccessor.java | 39 +++++++++++++++ .../invocation/SpringApplicationContextHelper.java | 56 ---------------------- .../SpringImplementationProviderFactory.java | 13 +++-- 3 files changed, 47 insertions(+), 61 deletions(-) create mode 100644 sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringApplicationContextAccessor.java delete 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/modules/implementation-spring/src/main/java/org') diff --git a/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringApplicationContextAccessor.java b/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringApplicationContextAccessor.java new file mode 100644 index 0000000000..3cdeb332b2 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringApplicationContextAccessor.java @@ -0,0 +1,39 @@ +/* + * 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; + +/** + * A utility to receive the parent Spring application context + */ +public interface SpringApplicationContextAccessor { + /** + * Get the parent Spring application context for the hosting environment. This will be used as the parent + * application context for implementation.spring components + * @return The parent application context + */ + 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 The parent application context + */ + 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/SpringApplicationContextHelper.java b/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringApplicationContextHelper.java deleted file mode 100644 index f1a1d7e1e7..0000000000 --- a/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringApplicationContextHelper.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.implementation.spring.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/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 { 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); } /** -- cgit v1.2.3