From 276bd890b43d7d85b60a1fa2b7b317c5621d2192 Mon Sep 17 00:00:00 2001 From: antelder Date: Tue, 1 May 2012 14:07:20 +0000 Subject: 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 --- .../tuscany/sca/impl/ContributionHelper.java | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/ContributionHelper.java (limited to 'sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache') 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); + } + +} -- cgit v1.2.3