From c953debbe7d1e8785c4c401c1314d9b176281e95 Mon Sep 17 00:00:00 2001 From: rfeng Date: Tue, 13 Jan 2009 07:34:35 +0000 Subject: Fix for TUSCANT-2763 & TUSCANY-2764 git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@734063 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/itest/builder/CustomCompositeBuilder.java | 6 +- .../test/java/domain/CustomCompositeBuilder.java | 12 +- .../service/impl/ContributionServiceImpl.java | 12 +- .../resolver/ExtensibleModelResolverTestCase.java | 4 +- .../java/ContributionClassLoaderProvider.java | 35 +++ .../DefaultContributionClassLoaderProvider.java | 39 +++ .../java/impl/ClassReferenceModelResolver.java | 28 ++- ...ntribution.java.ContributionClassLoaderProvider | 17 ++ .../ClassReferenceArtifactResolverTestCase.java | 2 +- .../osgi/impl/OSGiClassReferenceModelResolver.java | 4 +- .../DefaultURLArtifactProcessorExtensionPoint.java | 12 +- .../DefaultModelResolverExtensionPoint.java | 7 +- .../resolver/ExtensibleModelResolver.java | 56 +++-- .../impl/CompositeConfigurationServiceImpl.java | 7 +- .../impl/CompositeGeneratorServiceImpl.java | 2 +- .../impl/DeployableCompositeCollectionImpl.java | 2 +- .../tuscany/sca/binding/sca/EndpointTestCase.java | 5 +- .../ClassLoaderServiceDiscoverer.java | 262 +++++++++++++++++++++ .../ContextClassLoaderServiceDiscoverer.java | 248 ------------------- .../sca/extensibility/ServiceDiscovery.java | 2 +- .../ClassLoaderServiceDiscovererTestCase.java | 72 ++++++ ...ontextClassLoaderServiceDiscovererTestCase.java | 72 ------ .../embedded/impl/ReallySmallRuntimeBuilder.java | 2 +- .../embedded/impl/ReallySmallRuntimeBuilder.java | 2 +- .../interfacedef/wsdl/AbstractWSDLTestCase.java | 2 +- .../tuscany/sca/node/impl/RuntimeBuilder.java | 4 +- .../impl/ContributionContentProcessor.java | 20 +- .../processor/impl/ContributionInfoProcessor.java | 19 +- .../java/manager/DistributeAndRunComponents.java | 6 +- .../main/java/manager/DistributeComponents.java | 8 +- .../src/main/java/manager/ListComponents.java | 6 +- .../src/main/java/manager/WireComponents.java | 6 +- 32 files changed, 570 insertions(+), 411 deletions(-) create mode 100644 branches/sca-java-1.x/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/ContributionClassLoaderProvider.java create mode 100644 branches/sca-java-1.x/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/DefaultContributionClassLoaderProvider.java create mode 100644 branches/sca-java-1.x/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.java.ContributionClassLoaderProvider create mode 100644 branches/sca-java-1.x/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ClassLoaderServiceDiscoverer.java delete mode 100644 branches/sca-java-1.x/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscoverer.java create mode 100644 branches/sca-java-1.x/modules/extensibility/src/test/java/org/apache/tuscany/sca/extensibility/ClassLoaderServiceDiscovererTestCase.java delete mode 100644 branches/sca-java-1.x/modules/extensibility/src/test/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscovererTestCase.java (limited to 'branches') diff --git a/branches/sca-java-1.x/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/CustomCompositeBuilder.java b/branches/sca-java-1.x/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/CustomCompositeBuilder.java index 6d829033a3..d4996c7418 100644 --- a/branches/sca-java-1.x/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/CustomCompositeBuilder.java +++ b/branches/sca-java-1.x/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/CustomCompositeBuilder.java @@ -37,7 +37,6 @@ import org.apache.tuscany.sca.assembly.SCABindingFactory; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; import org.apache.tuscany.sca.assembly.xml.Constants; -import org.apache.tuscany.sca.contribution.Artifact; import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; @@ -63,6 +62,7 @@ import org.apache.tuscany.sca.workspace.builder.ContributionDependencyBuilder; import org.apache.tuscany.sca.workspace.builder.impl.ContributionDependencyBuilderImpl; public class CustomCompositeBuilder { + private ExtensionPointRegistry extensionPoints; private URLArtifactProcessor contributionProcessor; private ModelResolverExtensionPoint modelResolvers; private ModelFactoryExtensionPoint modelFactories; @@ -85,7 +85,7 @@ public class CustomCompositeBuilder { private void init() { // Create extension point registry - ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + extensionPoints = new DefaultExtensionPointRegistry(); // Create a monitor UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); @@ -137,7 +137,7 @@ public class CustomCompositeBuilder { // Create workspace model workspace = workspaceFactory.createWorkspace(); - workspace.setModelResolver(new ExtensibleModelResolver(workspace, modelResolvers, modelFactories)); + workspace.setModelResolver(new ExtensibleModelResolver(workspace, extensionPoints)); // Read the test contribution URI artifactURI = URI.create(sourceURI); diff --git a/branches/sca-java-1.x/itest/validation/src/test/java/domain/CustomCompositeBuilder.java b/branches/sca-java-1.x/itest/validation/src/test/java/domain/CustomCompositeBuilder.java index 65814470a4..7f3199d472 100644 --- a/branches/sca-java-1.x/itest/validation/src/test/java/domain/CustomCompositeBuilder.java +++ b/branches/sca-java-1.x/itest/validation/src/test/java/domain/CustomCompositeBuilder.java @@ -47,7 +47,6 @@ import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint; import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver; -import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.ModuleActivator; @@ -66,8 +65,8 @@ import org.apache.tuscany.sca.workspace.builder.ContributionDependencyBuilder; import org.apache.tuscany.sca.workspace.builder.impl.ContributionDependencyBuilderImpl; public class CustomCompositeBuilder { + private ExtensionPointRegistry extensionPoints; private URLArtifactProcessor contributionProcessor; - private ModelResolverExtensionPoint modelResolvers; private ModelFactoryExtensionPoint modelFactories; private WorkspaceFactory workspaceFactory; private AssemblyFactory assemblyFactory; @@ -98,7 +97,7 @@ public class CustomCompositeBuilder { private void init() { // Create extension point registry - ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + extensionPoints = new DefaultExtensionPointRegistry(); // Create a monitor UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); @@ -136,9 +135,6 @@ public class CustomCompositeBuilder { URLArtifactProcessorExtensionPoint docProcessorExtensions = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); contributionProcessor = docProcessorExtensions.getProcessor(Contribution.class); - // Get the model resolvers - modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class); - // Create a contribution dependency builder contributionDependencyBuilder = new ContributionDependencyBuilderImpl(monitor); @@ -157,7 +153,7 @@ public class CustomCompositeBuilder { // Create workspace model workspace = workspaceFactory.createWorkspace(); - workspace.setModelResolver(new ExtensibleModelResolver(workspace, modelResolvers, modelFactories)); + workspace.setModelResolver(new ExtensibleModelResolver(workspace, extensionPoints)); // Read the sample store contribution URI artifactURI = URI.create(sourceURI); @@ -218,7 +214,7 @@ public class CustomCompositeBuilder { // Create workspace model workspace = workspaceFactory.createWorkspace(); - workspace.setModelResolver(new ExtensibleModelResolver(workspace, modelResolvers, modelFactories)); + workspace.setModelResolver(new ExtensibleModelResolver(workspace, extensionPoints)); // Read the sample store contribution URI artifactURI = URI.create(sourceURI); diff --git a/branches/sca-java-1.x/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java b/branches/sca-java-1.x/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java index 7b8b12ca9d..6471042fed 100644 --- a/branches/sca-java-1.x/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java +++ b/branches/sca-java-1.x/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java @@ -55,13 +55,14 @@ import org.apache.tuscany.sca.contribution.service.ContributionService; import org.apache.tuscany.sca.contribution.service.ExtensibleContributionListener; import org.apache.tuscany.sca.contribution.service.util.IOHelper; import org.apache.tuscany.sca.contribution.xml.ContributionMetadataDocumentProcessor; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.definitions.SCADefinitions; -import org.apache.tuscany.sca.policy.Intent; -import org.apache.tuscany.sca.policy.IntentAttachPointType; -import org.apache.tuscany.sca.policy.PolicySet; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.Problem; import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; /** * Service interface that manages artifacts contributed to a Tuscany runtime. @@ -69,6 +70,7 @@ import org.apache.tuscany.sca.monitor.Problem.Severity; * @version $Rev$ $Date$ */ public class ContributionServiceImpl implements ContributionService { + private ExtensionPointRegistry extensionPoints; /** * Repository where contributions are stored. Usually set by injection. @@ -145,8 +147,10 @@ public class ContributionServiceImpl implements ContributionService { ContributionFactory contributionFactory, XMLInputFactory xmlFactory, List policyDefinitions, + ExtensionPointRegistry extensionPoints, Monitor monitor) { super(); + this.extensionPoints = extensionPoints; this.contributionRepository = repository; this.packageProcessor = packageProcessor; this.artifactProcessor = documentProcessor; @@ -341,7 +345,7 @@ public class ContributionServiceImpl implements ContributionService { if (modelResolver == null) { //FIXME Remove this domain resolver, visibility of policy declarations should be handled by // the contribution import/export mechanism instead of this domainResolver hack. - modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, modelFactories, policyDefinitionsResolver); + modelResolver = new ExtensibleModelResolver(contribution, extensionPoints, modelResolvers, modelFactories, policyDefinitionsResolver); } //set contribution initial information diff --git a/branches/sca-java-1.x/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolverTestCase.java b/branches/sca-java-1.x/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolverTestCase.java index 01083cc6a6..f66b429d65 100644 --- a/branches/sca-java-1.x/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolverTestCase.java +++ b/branches/sca-java-1.x/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolverTestCase.java @@ -40,12 +40,12 @@ public class ExtensibleModelResolverTestCase extends TestCase { @Override protected void setUp() throws Exception { - ModelResolverExtensionPoint resolvers = new DefaultModelResolverExtensionPoint(); + ModelResolverExtensionPoint resolvers = new DefaultModelResolverExtensionPoint(null); resolvers.addResolver(Model.class, TestModelResolver.class); ModelFactoryExtensionPoint factories = new DefaultModelFactoryExtensionPoint(); - resolver = new ExtensibleModelResolver(null, resolvers, factories, null); + resolver = new ExtensibleModelResolver(null, null, resolvers, factories, null); factory = new DefaultContributionFactory(); } 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; private Map map = new HashMap(); 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(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); } /** diff --git a/branches/sca-java-1.x/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiClassReferenceModelResolver.java b/branches/sca-java-1.x/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiClassReferenceModelResolver.java index 528a287328..39cdd6fcd3 100644 --- a/branches/sca-java-1.x/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiClassReferenceModelResolver.java +++ b/branches/sca-java-1.x/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiClassReferenceModelResolver.java @@ -24,9 +24,9 @@ import java.util.Map; import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.contribution.Import; -import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; 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.osgi.runtime.OSGiRuntime; import org.osgi.framework.Bundle; @@ -42,7 +42,7 @@ public class OSGiClassReferenceModelResolver implements ModelResolver { private boolean initialized; private boolean useOSGi; - public OSGiClassReferenceModelResolver(Contribution contribution, ModelFactoryExtensionPoint modelFactories) { + public OSGiClassReferenceModelResolver(Contribution contribution, ExtensionPointRegistry registry) { this.contribution = contribution; } diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java index 045c201638..8a30129343 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java @@ -67,9 +67,11 @@ public class DefaultURLArtifactProcessorExtensionPoint XMLOutputFactory outputFactory = modelFactories.getFactory(XMLOutputFactory.class); UtilityExtensionPoint utilities = this.extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); - if (monitorFactory != null) - this.monitor = monitorFactory.createMonitor(); - StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + if (monitorFactory != null) { + this.monitor = monitorFactory.createMonitor(); + } + StAXArtifactProcessorExtensionPoint staxProcessors = + extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, this.monitor); } @@ -203,8 +205,8 @@ public class DefaultURLArtifactProcessorExtensionPoint Constructor constructor = processorClass.getConstructor(ModelFactoryExtensionPoint.class, StAXArtifactProcessor.class, Monitor.class); processor = constructor.newInstance(modelFactories, staxProcessor, monitor); } catch (NoSuchMethodException e2) { - Constructor constructor = processorClass.getConstructor(ExtensionPointRegistry.class, StAXArtifactProcessor.class, Monitor.class); - processor = constructor.newInstance(extensionPoints, staxProcessor, monitor); + Constructor constructor = processorClass.getConstructor(ExtensionPointRegistry.class, Monitor.class); + processor = constructor.newInstance(extensionPoints, monitor); } } } catch (Exception e) { diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java index 77570aa13d..5c3242e6b3 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java @@ -23,6 +23,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.extensibility.ServiceDeclaration; import org.apache.tuscany.sca.extensibility.ServiceDiscovery; @@ -33,14 +34,16 @@ import org.apache.tuscany.sca.extensibility.ServiceDiscovery; * @version $Rev$ $Date$ */ public class DefaultModelResolverExtensionPoint implements ModelResolverExtensionPoint { - + private final ExtensionPointRegistry registry; private final Map, Class> resolvers = new HashMap, Class>(); private Map loadedResolvers; /** * Constructs a new DefaultModelResolverExtensionPoint. + * @param registry The ExtensionPointRegistry */ - public DefaultModelResolverExtensionPoint() { + public DefaultModelResolverExtensionPoint(ExtensionPointRegistry registry) { + this.registry = registry; } public void addResolver(Class modelType, Class resolver) { diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolver.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolver.java index de54d54f94..04352fd242 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolver.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolver.java @@ -23,9 +23,9 @@ import java.lang.reflect.Constructor; import java.util.HashMap; import java.util.Map; -import org.apache.tuscany.sca.assembly.Base; import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; /** * An implementation of an extensible model resolver which delegates to the @@ -34,6 +34,7 @@ import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; * @version $Rev$ $Date$ */ public class ExtensibleModelResolver implements ModelResolver { + private ExtensionPointRegistry extensionPoints; private final ModelResolverExtensionPoint resolverExtensions; private final ModelFactoryExtensionPoint modelFactories; private final Contribution contribution; @@ -47,16 +48,18 @@ public class ExtensibleModelResolver implements ModelResolver { * Constructs an extensible model resolver * * @param contribution + * @param extensionPoints TODO * @param resolverExtensions * @param modelFactories * @param defaultResolver */ @Deprecated public ExtensibleModelResolver(Contribution contribution, + ExtensionPointRegistry extensionPoints, ModelResolverExtensionPoint resolverExtensions, - ModelFactoryExtensionPoint modelFactories, - ModelResolver defaultResolver) { + ModelFactoryExtensionPoint modelFactories, ModelResolver defaultResolver) { this.contribution = contribution; + this.extensionPoints = extensionPoints; this.resolverExtensions = resolverExtensions; this.modelFactories = modelFactories; //FIXME Remove this default resolver, this is currently used to resolve policy declarations @@ -64,20 +67,16 @@ public class ExtensibleModelResolver implements ModelResolver { // defaultResolver hack. this.defaultResolver = defaultResolver; } - + /** - * Constructs an extensible model resolver - * - * @param resolverExtensions * @param contribution - * @param modelFactories + * @param extensionPoints */ - public ExtensibleModelResolver(Contribution contribution, - ModelResolverExtensionPoint resolverExtensions, - ModelFactoryExtensionPoint modelFactories) { + public ExtensibleModelResolver(Contribution contribution, ExtensionPointRegistry extensionPoints) { this.contribution = contribution; - this.resolverExtensions = resolverExtensions; - this.modelFactories = modelFactories; + this.extensionPoints = extensionPoints; + this.resolverExtensions = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class); + this.modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); } /** @@ -116,15 +115,28 @@ public class ExtensibleModelResolver implements ModelResolver { return resolverInstance; } try { - Constructor constructor = - resolverClass - .getConstructor(new Class[] {Contribution.class, ModelFactoryExtensionPoint.class}); - if (constructor != null) { - - resolverInstance = constructor.newInstance(contribution, modelFactories); - resolversByImplementationClass.put(resolverClass, resolverInstance); - resolversByModelType.put(c, resolverInstance); - return resolverInstance; + try { + Constructor constructor = + resolverClass.getConstructor(new Class[] {Contribution.class, + ModelFactoryExtensionPoint.class}); + if (constructor != null) { + + resolverInstance = constructor.newInstance(contribution, modelFactories); + resolversByImplementationClass.put(resolverClass, resolverInstance); + resolversByModelType.put(c, resolverInstance); + return resolverInstance; + } + } catch (NoSuchMethodException e) { + Constructor constructor = + resolverClass.getConstructor(new Class[] {Contribution.class, + ExtensionPointRegistry.class}); + if (constructor != null) { + + resolverInstance = constructor.newInstance(contribution, extensionPoints); + resolversByImplementationClass.put(resolverClass, resolverInstance); + resolversByModelType.put(c, resolverInstance); + return resolverInstance; + } } } catch (Exception e) { throw new IllegalStateException(e); diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/CompositeConfigurationServiceImpl.java b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/CompositeConfigurationServiceImpl.java index 09bb05cf87..b61553e640 100644 --- a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/CompositeConfigurationServiceImpl.java +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/CompositeConfigurationServiceImpl.java @@ -115,6 +115,7 @@ public class CompositeConfigurationServiceImpl extends HttpServlet implements Se @Reference public LocalItemCollection cloudCollection; + private ExtensionPointRegistry extensionPoints; private ModelFactoryExtensionPoint modelFactories; private ModelResolverExtensionPoint modelResolvers; private AssemblyFactory assemblyFactory; @@ -135,7 +136,7 @@ public class CompositeConfigurationServiceImpl extends HttpServlet implements Se @Init public void initialize() throws ParserConfigurationException { - ExtensionPointRegistry extensionPoints = domainManagerConfiguration.getExtensionPoints(); + extensionPoints = domainManagerConfiguration.getExtensionPoints(); // Create a monitor UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); @@ -160,7 +161,7 @@ public class CompositeConfigurationServiceImpl extends HttpServlet implements Se // Create contribution processor modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class); - contributionProcessor = new ContributionContentProcessor(modelFactories, modelResolvers, urlProcessor, staxProcessor, monitor); + contributionProcessor = new ContributionContentProcessor(extensionPoints, monitor); // Create contribution and composite builders DocumentBuilderFactory documentBuilderFactory = modelFactories.getFactory(DocumentBuilderFactory.class); @@ -221,7 +222,7 @@ public class CompositeConfigurationServiceImpl extends HttpServlet implements Se // Populate the domain composite Workspace workspace = workspaceFactory.createWorkspace(); - workspace.setModelResolver(new ExtensibleModelResolver(workspace, modelResolvers, modelFactories)); + workspace.setModelResolver(new ExtensibleModelResolver(workspace, extensionPoints)); Map contributionMap = new HashMap(); for (Entry domainEntry: domainEntries) { diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/CompositeGeneratorServiceImpl.java b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/CompositeGeneratorServiceImpl.java index 9e024d2d6b..c476d82e72 100644 --- a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/CompositeGeneratorServiceImpl.java +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/CompositeGeneratorServiceImpl.java @@ -139,7 +139,7 @@ public class CompositeGeneratorServiceImpl extends HttpServlet implements Servle // Create contribution processor modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class); - contributionProcessor = new ContributionContentProcessor(modelFactories, modelResolvers, urlProcessor, staxProcessor, monitor); + contributionProcessor = new ContributionContentProcessor(extensionPoints, monitor); } @Override diff --git a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DeployableCompositeCollectionImpl.java b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DeployableCompositeCollectionImpl.java index e66a8b6684..1eb70cce77 100644 --- a/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DeployableCompositeCollectionImpl.java +++ b/branches/sca-java-1.x/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DeployableCompositeCollectionImpl.java @@ -142,7 +142,7 @@ public class DeployableCompositeCollectionImpl implements ItemCollection, LocalI // Create contribution processor modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class); - contributionProcessor = new ContributionContentProcessor(modelFactories, modelResolvers, urlProcessor, staxProcessor, monitor); + contributionProcessor = new ContributionContentProcessor(extensionPoints, monitor); // Create contribution and composite builders contributionDependencyBuilder = new ContributionDependencyBuilderImpl(monitor); diff --git a/branches/sca-java-1.x/modules/endpoint/src/test/java/org/apace/tuscany/sca/binding/sca/EndpointTestCase.java b/branches/sca-java-1.x/modules/endpoint/src/test/java/org/apace/tuscany/sca/binding/sca/EndpointTestCase.java index 5a2d9babf4..371f6e624d 100644 --- a/branches/sca-java-1.x/modules/endpoint/src/test/java/org/apace/tuscany/sca/binding/sca/EndpointTestCase.java +++ b/branches/sca-java-1.x/modules/endpoint/src/test/java/org/apace/tuscany/sca/binding/sca/EndpointTestCase.java @@ -44,7 +44,6 @@ import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.ModuleActivator; @@ -70,7 +69,6 @@ import org.junit.Test; public class EndpointTestCase { private static URLArtifactProcessor contributionProcessor; - private static ModelResolverExtensionPoint modelResolvers; private static ModelFactoryExtensionPoint modelFactories; private static AssemblyFactory assemblyFactory; private static XMLOutputFactory outputFactory; @@ -117,8 +115,7 @@ public class EndpointTestCase { contributionProcessor = docProcessorExtensions.getProcessor(Contribution.class); // Get the model resolvers - modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class); - modelResolver = new ExtensibleModelResolver(null, modelResolvers, modelFactories); + modelResolver = new ExtensibleModelResolver(null, extensionPoints); // Create a composite builder SCABindingFactory scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class); diff --git a/branches/sca-java-1.x/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ClassLoaderServiceDiscoverer.java b/branches/sca-java-1.x/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ClassLoaderServiceDiscoverer.java new file mode 100644 index 0000000000..c9bed94692 --- /dev/null +++ b/branches/sca-java-1.x/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ClassLoaderServiceDiscoverer.java @@ -0,0 +1,262 @@ +/* + * 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.extensibility; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.ref.WeakReference; +import java.net.URL; +import java.net.URLConnection; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.StringTokenizer; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * A ServiceDiscoverer that find META-INF/services/... using the Context ClassLoader. + * + * @version $Rev$ $Date$ + */ +public class ClassLoaderServiceDiscoverer implements ServiceDiscoverer { + private static final Logger logger = Logger.getLogger(ClassLoaderServiceDiscoverer.class.getName()); + + public class ServiceDeclarationImpl implements ServiceDeclaration { + private URL url; + private String className; + private Class javaClass; + private Map attributes; + + public ServiceDeclarationImpl(URL url, String className, Map attributes) { + super(); + this.url = url; + this.className = className; + this.attributes = attributes; + } + + public Map getAttributes() { + return attributes; + } + + public String getClassName() { + return className; + } + + public URL getLocation() { + return url; + } + + public Class loadClass() throws ClassNotFoundException { + if (className == null) { + return null; + } + if (javaClass == null) { + javaClass = loadClass(className); + } + return javaClass; + } + + public Class loadClass(String className) throws ClassNotFoundException { + return classLoaderReference.get().loadClass(className); + } + + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("ClassLoader: ").append(classLoaderReference.get()); + sb.append(" Attributes: ").append(attributes); + return sb.toString(); + } + + public URL getResource(final String name) { + return AccessController.doPrivileged(new PrivilegedAction() { + public URL run() { + return classLoaderReference.get().getResource(name); + } + }); + } + + } + + private WeakReference classLoaderReference; + + /** + * Construct a service discoverer based on TCCL + */ + public ClassLoaderServiceDiscoverer() { + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + this.classLoaderReference = new WeakReference(classLoader); + } + + /** + * Construct a service discoverer using the given classloader + * @param classLoader + */ + public ClassLoaderServiceDiscoverer(ClassLoader classLoader) { + if (classLoader == null) { + classLoader = Thread.currentThread().getContextClassLoader(); + } + this.classLoaderReference = new WeakReference(classLoader); + } + + private List getResources(final String name, final boolean firstOnly) throws IOException { + try { + return AccessController.doPrivileged(new PrivilegedExceptionAction>() { + public List run() throws IOException { + if (firstOnly) { + URL url = classLoaderReference.get().getResource(name); + if (url != null) { + return Arrays.asList(url); + } else { + return Collections.emptyList(); + } + } else { + List urls = Collections.list(classLoaderReference.get().getResources(name)); + return urls; + } + } + }); + } catch (PrivilegedActionException e) { + throw (IOException)e.getException(); + } + } + + /** + * Parse a service declaration in the form class;attr=value,attr=value and + * return a map of attributes + * + * @param declaration + * @return a map of attributes + */ + private static Map parseServiceDeclaration(String declaration) { + Map attributes = new HashMap(); + int index = declaration.indexOf(';'); + if (index != -1) { + attributes.put("class", declaration.substring(0, index).trim()); + declaration = declaration.substring(index); + } else { + int j = declaration.indexOf('='); + if (j == -1) { + attributes.put("class", declaration.trim()); + return attributes; + } else { + declaration = ";" + declaration; + } + } + StringTokenizer tokens = new StringTokenizer(declaration); + for (; tokens.hasMoreTokens();) { + String key = tokens.nextToken("=").substring(1).trim(); + if (key == null) + break; + String value = tokens.nextToken(",").substring(1).trim(); + if (value == null) + break; + attributes.put(key, value); + } + return attributes; + } + + public Set discover(String serviceName, boolean firstOnly) { + Set descriptors = new HashSet(); + + String name = "META-INF/services/" + serviceName; + boolean debug = logger.isLoggable(Level.FINE); + try { + for (final URL url : getResources(name, firstOnly)) { + if (debug) { + logger.fine("Reading service provider file: " + url.toExternalForm()); + } + + // Allow privileged access to open URL stream. Add FilePermission to added to security + // policy file. + InputStream is; + try { + is = AccessController.doPrivileged(new PrivilegedExceptionAction() { + public InputStream run() throws IOException { + URLConnection connection = url.openConnection(); + // TUSCANY-2539 + // Don't cache connections by default to stop Tuscany locking contribution jar files + // done here as this is one of the first places we open a stream and the only way to + // set the default is to set it on an instance of URLConnection + connection.setDefaultUseCaches(false); + connection.setUseCaches(false); + return url.openStream(); + } + }); + } catch (PrivilegedActionException e) { + throw (IOException)e.getException(); + } + BufferedReader reader = null; + try { + reader = new BufferedReader(new InputStreamReader(is)); + int count = 0; + while (true) { + String line = reader.readLine(); + if (line == null) + break; + line = line.trim(); + if (!line.startsWith("#") && !"".equals(line)) { + String reg = line.trim(); + if (debug) { + logger.fine("Registering service provider: " + reg); + } + + Map attributes = parseServiceDeclaration(reg); + String className = attributes.get("class"); + if (className == null) { + // Add a unique class name to prevent equals() from returning true + className = "_class_" + count; + count++; + } + ServiceDeclarationImpl descriptor = new ServiceDeclarationImpl(url, className, attributes); + descriptors.add(descriptor); + if (firstOnly) { + return descriptors; + } + } + } + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException e) { + // Ignore + } + } + } + } + } catch (IOException e) { + logger.log(Level.SEVERE, e.getMessage(), e); + } + return descriptors; + + } + +} diff --git a/branches/sca-java-1.x/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscoverer.java b/branches/sca-java-1.x/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscoverer.java deleted file mode 100644 index 2e11234095..0000000000 --- a/branches/sca-java-1.x/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscoverer.java +++ /dev/null @@ -1,248 +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.extensibility; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.lang.ref.WeakReference; -import java.net.URL; -import java.net.URLConnection; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.StringTokenizer; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A ServiceDiscoverer that find META-INF/services/... using the Context ClassLoader. - * - * @version $Rev: $ $Date: $ - */ -public class ContextClassLoaderServiceDiscoverer implements ServiceDiscoverer { - private static final Logger logger = Logger.getLogger(ContextClassLoaderServiceDiscoverer.class.getName()); - - public class ServiceDeclarationImpl implements ServiceDeclaration { - private URL url; - private String className; - private Class javaClass; - private Map attributes; - - public ServiceDeclarationImpl(URL url, String className, Map attributes) { - super(); - this.url = url; - this.className = className; - this.attributes = attributes; - } - - public Map getAttributes() { - return attributes; - } - - public String getClassName() { - return className; - } - - public URL getLocation() { - return url; - } - - public Class loadClass() throws ClassNotFoundException { - if (className == null) { - return null; - } - if (javaClass == null) { - javaClass = loadClass(className); - } - return javaClass; - } - - public Class loadClass(String className) throws ClassNotFoundException { - return classLoaderReference.get().loadClass(className); - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("ClassLoader: ").append(classLoaderReference.get()); - sb.append(" Attributes: ").append(attributes); - return sb.toString(); - } - - public URL getResource(final String name) { - return AccessController.doPrivileged(new PrivilegedAction() { - public URL run() { - return classLoaderReference.get().getResource(name); - } - }); - } - - } - - private WeakReference classLoaderReference; - - public ContextClassLoaderServiceDiscoverer() { - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - this.classLoaderReference = new WeakReference(classLoader); - } - - private List getResources(final String name, final boolean firstOnly) throws IOException { - try { - return AccessController.doPrivileged(new PrivilegedExceptionAction>() { - public List run() throws IOException { - if (firstOnly) { - URL url = classLoaderReference.get().getResource(name); - if (url != null) { - return Arrays.asList(url); - } else { - return Collections.emptyList(); - } - } else { - List urls = Collections.list(classLoaderReference.get().getResources(name)); - return urls; - } - } - }); - } catch (PrivilegedActionException e) { - throw (IOException)e.getException(); - } - } - - /** - * Parse a service declaration in the form class;attr=value,attr=value and - * return a map of attributes - * - * @param declaration - * @return a map of attributes - */ - private static Map parseServiceDeclaration(String declaration) { - Map attributes = new HashMap(); - int index = declaration.indexOf(';'); - if (index != -1) { - attributes.put("class", declaration.substring(0, index).trim()); - declaration = declaration.substring(index); - } else { - int j = declaration.indexOf('='); - if (j == -1) { - attributes.put("class", declaration.trim()); - return attributes; - } else { - declaration = ";" + declaration; - } - } - StringTokenizer tokens = new StringTokenizer(declaration); - for (; tokens.hasMoreTokens();) { - String key = tokens.nextToken("=").substring(1).trim(); - if (key == null) - break; - String value = tokens.nextToken(",").substring(1).trim(); - if (value == null) - break; - attributes.put(key, value); - } - return attributes; - } - - public Set discover(String serviceName, boolean firstOnly) { - Set descriptors = new HashSet(); - - String name = "META-INF/services/" + serviceName; - boolean debug = logger.isLoggable(Level.FINE); - try { - for (final URL url : getResources(name, firstOnly)) { - if (debug) { - logger.fine("Reading service provider file: " + url.toExternalForm()); - } - - // Allow privileged access to open URL stream. Add FilePermission to added to security - // policy file. - InputStream is; - try { - is = AccessController.doPrivileged(new PrivilegedExceptionAction() { - public InputStream run() throws IOException { - URLConnection connection = url.openConnection(); - // TUSCANY-2539 - // Don't cache connections by default to stop Tuscany locking contribution jar files - // done here as this is one of the first places we open a stream and the only way to - // set the default is to set it on an instance of URLConnection - connection.setDefaultUseCaches(false); - connection.setUseCaches(false); - return url.openStream(); - } - }); - } catch (PrivilegedActionException e) { - throw (IOException)e.getException(); - } - BufferedReader reader = null; - try { - reader = new BufferedReader(new InputStreamReader(is)); - int count = 0; - while (true) { - String line = reader.readLine(); - if (line == null) - break; - line = line.trim(); - if (!line.startsWith("#") && !"".equals(line)) { - String reg = line.trim(); - if (debug) { - logger.fine("Registering service provider: " + reg); - } - - Map attributes = parseServiceDeclaration(reg); - String className = attributes.get("class"); - if (className == null) { - // Add a unique class name to prevent equals() from returning true - className = "_class_" + count; - count++; - } - ServiceDeclarationImpl descriptor = new ServiceDeclarationImpl(url, className, attributes); - descriptors.add(descriptor); - if (firstOnly) { - return descriptors; - } - } - } - } finally { - if (reader != null) { - try { - reader.close(); - } catch (IOException e) { - // Ignore - } - } - } - } - } catch (IOException e) { - logger.log(Level.SEVERE, e.getMessage(), e); - } - return descriptors; - - } - -} diff --git a/branches/sca-java-1.x/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java b/branches/sca-java-1.x/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java index ce41a44068..a95ab253ae 100644 --- a/branches/sca-java-1.x/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java +++ b/branches/sca-java-1.x/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java @@ -57,7 +57,7 @@ public class ServiceDiscovery { public ServiceDiscoverer getServiceDiscoverer() { if (discoverer == null) { - discoverer = new ContextClassLoaderServiceDiscoverer(); + discoverer = new ClassLoaderServiceDiscoverer(); } return discoverer; } diff --git a/branches/sca-java-1.x/modules/extensibility/src/test/java/org/apache/tuscany/sca/extensibility/ClassLoaderServiceDiscovererTestCase.java b/branches/sca-java-1.x/modules/extensibility/src/test/java/org/apache/tuscany/sca/extensibility/ClassLoaderServiceDiscovererTestCase.java new file mode 100644 index 0000000000..92164eccc7 --- /dev/null +++ b/branches/sca-java-1.x/modules/extensibility/src/test/java/org/apache/tuscany/sca/extensibility/ClassLoaderServiceDiscovererTestCase.java @@ -0,0 +1,72 @@ +/* + * 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.extensibility; + +import java.util.Set; + +import junit.framework.Assert; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Test Case for ClasspathServiceDiscover + */ +public class ClassLoaderServiceDiscovererTestCase { + private static ClassLoaderServiceDiscoverer discover; + + /** + * @throws java.lang.Exception + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception { + discover = new ClassLoaderServiceDiscoverer(); + } + + @Test + public void testDiscovery() { + Set discriptors = + discover.discover("org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint", false); + Assert.assertEquals(1, discriptors.size()); + discriptors = + discover.discover("notthere", false); + Assert.assertEquals(0, discriptors.size()); + } + + @Test + public void testDiscoveryFirst() { + Set discriptors = + discover.discover("org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint", true); + Assert.assertEquals(1, discriptors.size()); + discriptors = + discover.discover("notthere", true); + Assert.assertEquals(0, discriptors.size()); + } + + + /** + * @throws java.lang.Exception + */ + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + +} diff --git a/branches/sca-java-1.x/modules/extensibility/src/test/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscovererTestCase.java b/branches/sca-java-1.x/modules/extensibility/src/test/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscovererTestCase.java deleted file mode 100644 index fd508402fc..0000000000 --- a/branches/sca-java-1.x/modules/extensibility/src/test/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscovererTestCase.java +++ /dev/null @@ -1,72 +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.extensibility; - -import java.util.Set; - -import junit.framework.Assert; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * Test Case for ClasspathServiceDiscover - */ -public class ContextClassLoaderServiceDiscovererTestCase { - private static ContextClassLoaderServiceDiscoverer discover; - - /** - * @throws java.lang.Exception - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { - discover = new ContextClassLoaderServiceDiscoverer(); - } - - @Test - public void testDiscovery() { - Set discriptors = - discover.discover("org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint", false); - Assert.assertEquals(1, discriptors.size()); - discriptors = - discover.discover("notthere", false); - Assert.assertEquals(0, discriptors.size()); - } - - @Test - public void testDiscoveryFirst() { - Set discriptors = - discover.discover("org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint", true); - Assert.assertEquals(1, discriptors.size()); - discriptors = - discover.discover("notthere", true); - Assert.assertEquals(0, discriptors.size()); - } - - - /** - * @throws java.lang.Exception - */ - @AfterClass - public static void tearDownAfterClass() throws Exception { - } - -} diff --git a/branches/sca-java-1.x/modules/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java b/branches/sca-java-1.x/modules/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java index 738e5e6248..1111558c60 100644 --- a/branches/sca-java-1.x/modules/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java +++ b/branches/sca-java-1.x/modules/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java @@ -250,7 +250,7 @@ public class ReallySmallRuntimeBuilder { ContributionService contributionService = new ContributionServiceImpl(repository, packageProcessor, documentProcessor, staxProcessor, contributionListener, policyDefinitionResolver, modelResolvers, modelFactories, - assemblyFactory, contributionFactory, inputFactory, policyDefinitions, monitor); + assemblyFactory, contributionFactory, inputFactory, policyDefinitions, registry, monitor); return contributionService; } diff --git a/branches/sca-java-1.x/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java b/branches/sca-java-1.x/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java index 738e5e6248..1111558c60 100644 --- a/branches/sca-java-1.x/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java +++ b/branches/sca-java-1.x/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java @@ -250,7 +250,7 @@ public class ReallySmallRuntimeBuilder { ContributionService contributionService = new ContributionServiceImpl(repository, packageProcessor, documentProcessor, staxProcessor, contributionListener, policyDefinitionResolver, modelResolvers, modelFactories, - assemblyFactory, contributionFactory, inputFactory, policyDefinitions, monitor); + assemblyFactory, contributionFactory, inputFactory, policyDefinitions, registry, monitor); return contributionService; } diff --git a/branches/sca-java-1.x/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/AbstractWSDLTestCase.java b/branches/sca-java-1.x/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/AbstractWSDLTestCase.java index f0228edb1f..b68d0cc175 100644 --- a/branches/sca-java-1.x/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/AbstractWSDLTestCase.java +++ b/branches/sca-java-1.x/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/AbstractWSDLTestCase.java @@ -58,7 +58,7 @@ public abstract class AbstractWSDLTestCase extends TestCase { ContributionFactory contributionFactory = modelFactories.getFactory(ContributionFactory.class); Contribution contribution = contributionFactory.createContribution(); ModelResolverExtensionPoint modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class); - resolver = new ExtensibleModelResolver(contribution, modelResolvers, modelFactories); + resolver = new ExtensibleModelResolver(contribution, extensionPoints); contribution.setModelResolver(resolver); URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); diff --git a/branches/sca-java-1.x/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBuilder.java b/branches/sca-java-1.x/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBuilder.java index 6c93fa7800..fe05a93992 100644 --- a/branches/sca-java-1.x/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBuilder.java +++ b/branches/sca-java-1.x/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBuilder.java @@ -20,8 +20,6 @@ package org.apache.tuscany.sca.node.impl; import java.io.IOException; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.List; import javax.xml.parsers.DocumentBuilderFactory; @@ -233,7 +231,7 @@ public class RuntimeBuilder { ContributionService contributionService = new ContributionServiceImpl(repository, packageProcessor, documentProcessor, staxProcessor, contributionListener, policyDefinitionResolver, modelResolvers, modelFactories, - assemblyFactory, contributionFactory, inputFactory, policyDefinitions, monitor); + assemblyFactory, contributionFactory, inputFactory, policyDefinitions, registry, monitor); return contributionService; } diff --git a/branches/sca-java-1.x/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/processor/impl/ContributionContentProcessor.java b/branches/sca-java-1.x/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/processor/impl/ContributionContentProcessor.java index d0f769c9d1..e3f0844e35 100644 --- a/branches/sca-java-1.x/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/processor/impl/ContributionContentProcessor.java +++ b/branches/sca-java-1.x/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/processor/impl/ContributionContentProcessor.java @@ -23,6 +23,9 @@ import java.net.URI; import java.net.URL; import java.util.List; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; + import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.contribution.Artifact; import org.apache.tuscany.sca.contribution.Contribution; @@ -33,8 +36,10 @@ import org.apache.tuscany.sca.contribution.DefaultImport; import org.apache.tuscany.sca.contribution.Export; import org.apache.tuscany.sca.contribution.Import; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.contribution.resolver.ClassReference; @@ -58,6 +63,7 @@ import org.apache.tuscany.sca.workspace.scanner.impl.JarContributionScanner; * @version $Rev$ $Date$ */ public class ContributionContentProcessor implements URLArtifactProcessor{ + private ExtensionPointRegistry extensionPoints; private ContributionFactory contributionFactory; private ModelResolverExtensionPoint modelResolvers; private ModelFactoryExtensionPoint modelFactories; @@ -66,17 +72,24 @@ public class ContributionContentProcessor implements URLArtifactProcessor extensionProcessor, Monitor monitor) { + public ContributionContentProcessor(ExtensionPointRegistry extensionPoints, Monitor monitor) { + this.extensionPoints = extensionPoints; this.modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); this.modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class); hackResolvers(modelResolvers); this.monitor = monitor; URLArtifactProcessorExtensionPoint artifactProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); this.artifactProcessor = new ExtensibleURLArtifactProcessor(artifactProcessors, this.monitor); - this.extensionProcessor = extensionProcessor; + + // Get and initialize artifact processors + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class); + XMLOutputFactory outputFactory = modelFactories.getFactory(XMLOutputFactory.class); + this.extensionProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, monitor); this.contributionFactory = modelFactories.getFactory(ContributionFactory.class); } + /* public ContributionContentProcessor(ModelFactoryExtensionPoint modelFactories, ModelResolverExtensionPoint modelResolvers, URLArtifactProcessor artifactProcessor, StAXArtifactProcessor extensionProcessor, Monitor monitor) { this.modelFactories = modelFactories; @@ -87,6 +100,7 @@ public class ContributionContentProcessor implements URLArtifactProcessor{ + private ExtensionPointRegistry extensionPoints; private ContributionFactory contributionFactory; private ModelResolverExtensionPoint modelResolvers; private ModelFactoryExtensionPoint modelFactories; @@ -66,17 +72,23 @@ public class ContributionInfoProcessor implements URLArtifactProcessor artifactProcessor; private StAXArtifactProcessor extensionProcessor; - public ContributionInfoProcessor(ExtensionPointRegistry extensionPoints, StAXArtifactProcessor extensionProcessor, Monitor monitor) { + public ContributionInfoProcessor(ExtensionPointRegistry extensionPoints, Monitor monitor) { + this.extensionPoints = extensionPoints; this.modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); this.modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class); hackResolvers(modelResolvers); URLArtifactProcessorExtensionPoint artifactProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); this.artifactProcessors = artifactProcessors; this.artifactProcessor = new ExtensibleURLArtifactProcessor(artifactProcessors, monitor); - this.extensionProcessor = extensionProcessor; + // Get and initialize artifact processors + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class); + XMLOutputFactory outputFactory = modelFactories.getFactory(XMLOutputFactory.class); + this.extensionProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, monitor); this.contributionFactory = modelFactories.getFactory(ContributionFactory.class); } + /* public ContributionInfoProcessor(ModelFactoryExtensionPoint modelFactories, ModelResolverExtensionPoint modelResolvers, URLArtifactProcessor artifactProcessor) { this.modelFactories = modelFactories; this.modelResolvers = modelResolvers; @@ -84,6 +96,7 @@ public class ContributionInfoProcessor implements URLArtifactProcessor contributionProcessor; private static ModelResolverExtensionPoint modelResolvers; private static ModelFactoryExtensionPoint modelFactories; @@ -113,7 +113,7 @@ public class DistributeAndRunComponents { private static void init() { // Create extension point registry - ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + extensionPoints = new DefaultExtensionPointRegistry(); // Create a monitor UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); @@ -171,7 +171,7 @@ public class DistributeAndRunComponents { // Create workspace model Workspace workspace = workspaceFactory.createWorkspace(); - workspace.setModelResolver(new ExtensibleModelResolver(workspace, modelResolvers, modelFactories)); + workspace.setModelResolver(new ExtensibleModelResolver(workspace, extensionPoints)); // Read the sample store contribution URI storeURI = URI.create("store"); diff --git a/branches/sca-java-1.x/samples/domain-management/src/main/java/manager/DistributeComponents.java b/branches/sca-java-1.x/samples/domain-management/src/main/java/manager/DistributeComponents.java index def0a1894f..08ddc8875e 100644 --- a/branches/sca-java-1.x/samples/domain-management/src/main/java/manager/DistributeComponents.java +++ b/branches/sca-java-1.x/samples/domain-management/src/main/java/manager/DistributeComponents.java @@ -49,7 +49,6 @@ import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; import org.apache.tuscany.sca.binding.atom.AtomBindingFactory; import org.apache.tuscany.sca.contribution.Contribution; -import org.apache.tuscany.sca.contribution.ContributionFactory; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; @@ -71,7 +70,6 @@ import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.MonitorFactory; import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; -import org.apache.tuscany.sca.policy.PolicyFactory; import org.apache.tuscany.sca.workspace.Workspace; import org.apache.tuscany.sca.workspace.WorkspaceFactory; import org.apache.tuscany.sca.workspace.builder.ContributionDependencyBuilder; @@ -107,7 +105,7 @@ import org.xml.sax.SAXException; * @version $Rev$ $Date$ */ public class DistributeComponents { - + private static ExtensionPointRegistry extensionPoints; private static URLArtifactProcessor contributionProcessor; private static ModelResolverExtensionPoint modelResolvers; private static ModelFactoryExtensionPoint modelFactories; @@ -126,7 +124,7 @@ public class DistributeComponents { private static void init() { // Create extension point registry - ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + extensionPoints = new DefaultExtensionPointRegistry(); // Create a monitor UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); @@ -184,7 +182,7 @@ public class DistributeComponents { // Create workspace model Workspace workspace = workspaceFactory.createWorkspace(); - workspace.setModelResolver(new ExtensibleModelResolver(workspace, modelResolvers, modelFactories)); + workspace.setModelResolver(new ExtensibleModelResolver(workspace, extensionPoints)); // Read the sample store contribution URI storeURI = URI.create("store"); diff --git a/branches/sca-java-1.x/samples/domain-management/src/main/java/manager/ListComponents.java b/branches/sca-java-1.x/samples/domain-management/src/main/java/manager/ListComponents.java index 27cb31d57f..7b3950833a 100644 --- a/branches/sca-java-1.x/samples/domain-management/src/main/java/manager/ListComponents.java +++ b/branches/sca-java-1.x/samples/domain-management/src/main/java/manager/ListComponents.java @@ -66,7 +66,7 @@ import org.apache.tuscany.sca.workspace.builder.impl.ContributionDependencyBuild * @version $Rev$ $Date$ */ public class ListComponents { - + private static ExtensionPointRegistry extensionPoints; private static URLArtifactProcessor contributionProcessor; private static ModelResolverExtensionPoint modelResolvers; private static ModelFactoryExtensionPoint modelFactories; @@ -76,7 +76,7 @@ public class ListComponents { private static void init() { // Create extension point registry - ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + extensionPoints = new DefaultExtensionPointRegistry(); // Initialize the Tuscany module activators ModuleActivatorExtensionPoint moduleActivators = extensionPoints.getExtensionPoint(ModuleActivatorExtensionPoint.class); @@ -110,7 +110,7 @@ public class ListComponents { // Create workspace model Workspace workspace = workspaceFactory.createWorkspace(); - workspace.setModelResolver(new ExtensibleModelResolver(workspace, modelResolvers, modelFactories)); + workspace.setModelResolver(new ExtensibleModelResolver(workspace, extensionPoints)); // Read the sample store contribution URI storeURI = URI.create("store"); diff --git a/branches/sca-java-1.x/samples/domain-management/src/main/java/manager/WireComponents.java b/branches/sca-java-1.x/samples/domain-management/src/main/java/manager/WireComponents.java index d24d5c67c9..16cda9d3e7 100644 --- a/branches/sca-java-1.x/samples/domain-management/src/main/java/manager/WireComponents.java +++ b/branches/sca-java-1.x/samples/domain-management/src/main/java/manager/WireComponents.java @@ -86,7 +86,7 @@ import org.w3c.dom.Document; * @version $Rev$ $Date$ */ public class WireComponents { - + private static ExtensionPointRegistry extensionPoints; private static URLArtifactProcessor contributionProcessor; private static ModelResolverExtensionPoint modelResolvers; private static ModelFactoryExtensionPoint modelFactories; @@ -102,7 +102,7 @@ public class WireComponents { private static void init() { // Create extension point registry - ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + extensionPoints = new DefaultExtensionPointRegistry(); // Create a monitor UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); @@ -155,7 +155,7 @@ public class WireComponents { // Create workspace model Workspace workspace = workspaceFactory.createWorkspace(); - workspace.setModelResolver(new ExtensibleModelResolver(workspace, modelResolvers, modelFactories)); + workspace.setModelResolver(new ExtensibleModelResolver(workspace, extensionPoints)); // Read the sample store contribution URI storeURI = URI.create("store"); -- cgit v1.2.3