summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-1.x/modules/contribution-java/src
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-01-13 07:34:35 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-01-13 07:34:35 +0000
commitc953debbe7d1e8785c4c401c1314d9b176281e95 (patch)
tree750ab88cb6ca4aca96aef3aa0a754e899d6fdcf8 /branches/sca-java-1.x/modules/contribution-java/src
parent4c39d8c12de316d28abe711557c60ef000014e62 (diff)
Fix for TUSCANT-2763 & TUSCANY-2764
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@734063 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules/contribution-java/src')
-rw-r--r--branches/sca-java-1.x/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/ContributionClassLoaderProvider.java35
-rw-r--r--branches/sca-java-1.x/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/DefaultContributionClassLoaderProvider.java39
-rw-r--r--branches/sca-java-1.x/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.java28
-rw-r--r--branches/sca-java-1.x/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.java.ContributionClassLoaderProvider17
-rw-r--r--branches/sca-java-1.x/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java2
5 files changed, 114 insertions, 7 deletions
diff --git a/branches/sca-java-1.x/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/ContributionClassLoaderProvider.java b/branches/sca-java-1.x/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/ContributionClassLoaderProvider.java
new file mode 100644
index 0000000000..60e3944e26
--- /dev/null
+++ b/branches/sca-java-1.x/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/ContributionClassLoaderProvider.java
@@ -0,0 +1,35 @@
+/*
+ * 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.contribution.java;
+
+import org.apache.tuscany.sca.contribution.Contribution;
+
+/**
+ * A pluggable utility to provide a classloader for a given contribution
+ */
+public interface ContributionClassLoaderProvider {
+ /**
+ * Get the classloader for the given contribution
+ * @param contribution
+ * @param parent
+ * @return
+ */
+ ClassLoader getClassLoader(Contribution contribution, ClassLoader parent);
+}
diff --git a/branches/sca-java-1.x/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/DefaultContributionClassLoaderProvider.java b/branches/sca-java-1.x/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/DefaultContributionClassLoaderProvider.java
new file mode 100644
index 0000000000..ee62040731
--- /dev/null
+++ b/branches/sca-java-1.x/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/DefaultContributionClassLoaderProvider.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.contribution.java;
+
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.java.impl.ContributionClassLoader;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+
+/**
+ * The default implementation of the ContributionClassLoaderProvider
+ */
+public class DefaultContributionClassLoaderProvider implements ContributionClassLoaderProvider {
+
+ public DefaultContributionClassLoaderProvider(ExtensionPointRegistry registry) {
+ super();
+ }
+
+ public ClassLoader getClassLoader(Contribution contribution, ClassLoader parent) {
+ return new ContributionClassLoader(contribution, parent);
+ }
+
+}
diff --git a/branches/sca-java-1.x/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.java b/branches/sca-java-1.x/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.java
index 962512a745..1011f5d4a7 100644
--- a/branches/sca-java-1.x/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.java
+++ b/branches/sca-java-1.x/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.java
@@ -27,9 +27,12 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.tuscany.sca.contribution.Contribution;
-import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.java.ContributionClassLoaderProvider;
+import org.apache.tuscany.sca.contribution.java.DefaultContributionClassLoaderProvider;
import org.apache.tuscany.sca.contribution.resolver.ClassReference;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
/**
@@ -38,14 +41,16 @@ import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
* @version $Rev: 557916 $ $Date: 2007-07-20 01:04:40 -0700 (Fri, 20 Jul 2007) $
*/
public class ClassReferenceModelResolver implements ModelResolver {
- private Contribution contribution;
+ private final ExtensionPointRegistry registry;
+ private final Contribution contribution;
private WeakReference<ClassLoader> classLoader;
private Map<String, ClassReference> map = new HashMap<String, ClassReference>();
private ModelResolver osgiResolver;
- public ClassReferenceModelResolver(final Contribution contribution, ModelFactoryExtensionPoint modelFactories) {
+ public ClassReferenceModelResolver(final Contribution contribution, ExtensionPointRegistry registry) {
this.contribution = contribution;
+ this.registry = registry;
if (this.contribution != null) {
// Allow privileged access to get ClassLoader. Requires RuntimePermission in security policy.
// ClassLoader cl = contribution.getClassLoader();
@@ -63,7 +68,18 @@ public class ClassReferenceModelResolver implements ModelResolver {
// }
//});
ClassLoader contextClassLoader = ServiceDiscovery.getInstance().getServiceDiscoverer().getClass().getClassLoader();
- cl = new ContributionClassLoader(contribution, contextClassLoader);
+ ContributionClassLoaderProvider provider = null;
+ try {
+ provider =
+ registry.getExtensionPoint(UtilityExtensionPoint.class)
+ .getUtility(ContributionClassLoaderProvider.class);
+ } catch (Throwable e) {
+ // Ignore errors
+ }
+ if (provider == null) {
+ provider = new DefaultContributionClassLoaderProvider(registry);
+ }
+ cl = provider.getClassLoader(contribution, contextClassLoader);
contribution.setClassLoader(cl);
}
this.classLoader = new WeakReference<ClassLoader>(cl);
@@ -84,8 +100,8 @@ public class ClassReferenceModelResolver implements ModelResolver {
Class.forName("org.apache.tuscany.sca.contribution.osgi.impl.OSGiClassReferenceModelResolver");
if (osgiResolverClass != null) {
Constructor constructor =
- osgiResolverClass.getConstructor(Contribution.class, ModelFactoryExtensionPoint.class);
- this.osgiResolver = (ModelResolver)constructor.newInstance(contribution, modelFactories);
+ osgiResolverClass.getConstructor(Contribution.class, ExtensionPointRegistry.class);
+ this.osgiResolver = (ModelResolver)constructor.newInstance(contribution, registry);
}
} catch (Throwable e) {
// Ignore error, non-OSGi classloading is used in this case
diff --git a/branches/sca-java-1.x/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.java.ContributionClassLoaderProvider b/branches/sca-java-1.x/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.java.ContributionClassLoaderProvider
new file mode 100644
index 0000000000..a50d8e77a4
--- /dev/null
+++ b/branches/sca-java-1.x/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.java.ContributionClassLoaderProvider
@@ -0,0 +1,17 @@
+# 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.
+# org.apache.tuscany.sca.contribution.java.DefaultContributionClassLoaderProvider \ No newline at end of file
diff --git a/branches/sca-java-1.x/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java b/branches/sca-java-1.x/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java
index 1405ad4bd5..52c8567f3f 100644
--- a/branches/sca-java-1.x/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java
+++ b/branches/sca-java-1.x/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java
@@ -43,7 +43,7 @@ public class ClassReferenceArtifactResolverTestCase extends TestCase {
ModelResolverExtensionPoint resolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class);
resolvers.addResolver(ClassReference.class, ClassReferenceModelResolver.class);
ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
- resolver = new ExtensibleModelResolver(null, resolvers, modelFactories);
+ resolver = new ExtensibleModelResolver(null, extensionPoints);
}
/**