summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/trunk/modules')
-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);
+ }
+
+}