summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2012-05-01 14:07:20 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2012-05-01 14:07:20 +0000
commit276bd890b43d7d85b60a1fa2b7b317c5621d2192 (patch)
tree2a40096486aade1689c24a09d55a337a794b5fb7 /sca-java-2.x/trunk
parent263f8187d4b75d7c2ec3af0ed1f103d3ccccf06c (diff)
TUSCANY-4034: Move the freeing up of contribution resources to a helper method that can be shared and have that called from remove in Contribution Listener
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1332662 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk')
-rw-r--r--sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/ContributionHelper.java62
1 files changed, 62 insertions, 0 deletions
diff --git a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/ContributionHelper.java b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/ContributionHelper.java
new file mode 100644
index 0000000000..5f45e62036
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/ContributionHelper.java
@@ -0,0 +1,62 @@
+package org.apache.tuscany.sca.impl;
+
+import java.net.URLClassLoader;
+
+import org.apache.tuscany.sca.common.xml.dom.DOMHelper;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.java.impl.ClassLoaderModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ClassReference;
+import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.core.invocation.ProxyFactory;
+import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint;
+import org.apache.tuscany.sca.databinding.jaxb.JAXBContextHelper;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+
+import sun.misc.ClassLoaderUtil;
+
+public class ContributionHelper {
+
+ public static void close(Contribution contribution, ExtensionPointRegistry extensionPointRegistry) {
+ ClassLoader contributionClassloader = contribution.getClassLoader();
+
+ if (contributionClassloader == null && contribution.getModelResolver() instanceof ExtensibleModelResolver) {
+ ModelResolver o = ((ExtensibleModelResolver)contribution.getModelResolver()).getModelResolverInstance(ClassReference.class);
+ if (o instanceof ClassLoader) {
+ contributionClassloader = (ClassLoader)o;
+ contribution.setClassLoader(contributionClassloader);
+ }
+ }
+
+ UtilityExtensionPoint utilityExtensionPoint = extensionPointRegistry.getExtensionPoint(UtilityExtensionPoint.class);
+ FactoryExtensionPoint factoryExtensionPoint = extensionPointRegistry.getExtensionPoint(FactoryExtensionPoint.class);
+
+ JAXBContextHelper jaxbContextHelper = utilityExtensionPoint.getUtility(JAXBContextHelper.class);
+ jaxbContextHelper.removeJAXBContextForContribution(contributionClassloader);
+
+ JavaInterfaceFactory javaInterfaceFactory = factoryExtensionPoint.getFactory(JavaInterfaceFactory.class);
+ javaInterfaceFactory.removeInterfacesForContribution(contributionClassloader);
+
+ ProxyFactoryExtensionPoint proxyFactoryExtensionPoint = extensionPointRegistry.getExtensionPoint(ProxyFactoryExtensionPoint.class);
+ ProxyFactory interfaceProxyFactory = proxyFactoryExtensionPoint.getInterfaceProxyFactory();
+ interfaceProxyFactory.removeProxiesForContribution(contributionClassloader);
+
+ DOMHelper.getInstance(extensionPointRegistry).stop();
+ java.beans.Introspector.flushCaches();
+
+ if (contributionClassloader instanceof URLClassLoader) {
+ ClassLoaderUtil.releaseLoader((URLClassLoader)contributionClassloader);
+ }
+
+ if (contributionClassloader instanceof ClassLoaderModelResolver) {
+ ClassLoaderModelResolver clmr = (ClassLoaderModelResolver) contributionClassloader;
+ clmr.clear();
+ }
+
+ contribution.setClassLoader(null);
+ }
+
+}