diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:07:53 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:07:53 +0000 |
commit | 89d72264d0af4c65c9bf0b7a6f823f13d69162aa (patch) | |
tree | f6a4ea43b576d56a43adf10ccbed4cd75a9eb827 /branches/sca-java-1.3/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/processor/impl/ContributionContentProcessor.java | |
parent | 6a3ca6736c808c1647854e405ef379b609f276db (diff) |
Moving 1.x branches
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835127 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.3/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/processor/impl/ContributionContentProcessor.java')
-rw-r--r-- | branches/sca-java-1.3/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/processor/impl/ContributionContentProcessor.java | 230 |
1 files changed, 0 insertions, 230 deletions
diff --git a/branches/sca-java-1.3/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/processor/impl/ContributionContentProcessor.java b/branches/sca-java-1.3/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/processor/impl/ContributionContentProcessor.java deleted file mode 100644 index 880e95480e..0000000000 --- a/branches/sca-java-1.3/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/processor/impl/ContributionContentProcessor.java +++ /dev/null @@ -1,230 +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.workspace.processor.impl; - -import java.io.File; -import java.net.URI; -import java.net.URL; -import java.util.List; - -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.contribution.Artifact; -import org.apache.tuscany.sca.contribution.Contribution; -import org.apache.tuscany.sca.contribution.ContributionFactory; -import org.apache.tuscany.sca.contribution.ContributionMetadata; -import org.apache.tuscany.sca.contribution.DefaultExport; -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.ExtensibleURLArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; -import org.apache.tuscany.sca.contribution.resolver.ClassReference; -import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver; -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.contribution.scanner.ContributionScanner; -import org.apache.tuscany.sca.contribution.service.ContributionReadException; -import org.apache.tuscany.sca.contribution.service.ContributionResolveException; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.workspace.scanner.impl.DirectoryContributionScanner; -import org.apache.tuscany.sca.workspace.scanner.impl.JarContributionScanner; - -/** - * URLArtifactProcessor that handles contribution files and the artifacts they contain - * and returns a contribution model. - * - * @version $Rev$ $Date$ - */ -public class ContributionContentProcessor implements URLArtifactProcessor<Contribution>{ - private ContributionFactory contributionFactory; - private ModelResolverExtensionPoint modelResolvers; - private ModelFactoryExtensionPoint modelFactories; - private URLArtifactProcessor<Object> artifactProcessor; - private StAXArtifactProcessor<Object> extensionProcessor; - private UtilityExtensionPoint utilities; - private Monitor monitor = null; - - public ContributionContentProcessor(ExtensionPointRegistry extensionPoints, StAXArtifactProcessor<Object> extensionProcessor, Monitor monitor) { - 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; - this.contributionFactory = modelFactories.getFactory(ContributionFactory.class); - } - - public ContributionContentProcessor(ModelFactoryExtensionPoint modelFactories, ModelResolverExtensionPoint modelResolvers, - URLArtifactProcessor<Object> artifactProcessor, StAXArtifactProcessor<Object> extensionProcessor, Monitor monitor) { - this.modelFactories = modelFactories; - this.modelResolvers = modelResolvers; - hackResolvers(modelResolvers); - this.artifactProcessor = artifactProcessor; - this.extensionProcessor = extensionProcessor; - this.contributionFactory = modelFactories.getFactory(ContributionFactory.class); - this.monitor = monitor; - } - - public String getArtifactType() { - return ".contribution/content"; - } - - public Class<Contribution> getModelType() { - return Contribution.class; - } - - public Contribution read(URL parentURL, URI contributionURI, URL contributionURL) throws ContributionReadException { - - // Create contribution model - Contribution contribution = contributionFactory.createContribution(); - contribution.setURI(contributionURI.toString()); - contribution.setLocation(contributionURL.toString()); - ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, modelFactories); - contribution.setModelResolver(modelResolver); - contribution.setUnresolved(true); - - // Create a contribution scanner - ContributionScanner scanner; - if ("file".equals(contributionURL.getProtocol()) && new File(contributionURL.getFile()).isDirectory()) { - scanner = new DirectoryContributionScanner(); - } else { - scanner = new JarContributionScanner(); - } - - // Scan the contribution and list the artifacts contained in it - List<Artifact> artifacts = contribution.getArtifacts(); - boolean contributionMetadata = false; - List<String> artifactURIs = scanner.getArtifacts(contributionURL); - for (String artifactURI: artifactURIs) { - URL artifactURL = scanner.getArtifactURL(contributionURL, artifactURI); - - // Add the deployed artifact model to the contribution - Artifact artifact = this.contributionFactory.createArtifact(); - artifact.setURI(artifactURI); - artifact.setLocation(artifactURL.toString()); - artifacts.add(artifact); - modelResolver.addModel(artifact); - - // Read each artifact - Object model = artifactProcessor.read(contributionURL, URI.create(artifactURI), artifactURL); - if (model != null) { - artifact.setModel(model); - - // Add the loaded model to the model resolver - modelResolver.addModel(model); - - // Merge contribution metadata into the contribution model - if (model instanceof ContributionMetadata) { - contributionMetadata = true; - ContributionMetadata c = (ContributionMetadata)model; - contribution.getImports().addAll(c.getImports()); - contribution.getExports().addAll(c.getExports()); - contribution.getDeployables().addAll(c.getDeployables()); - } - } - } - - // If no sca-contribution.xml file was provided then just consider - // all composites in the contribution as deployables - if (!contributionMetadata) { - for (Artifact artifact: artifacts) { - if (artifact.getModel() instanceof Composite) { - contribution.getDeployables().add((Composite)artifact.getModel()); - } - } - - // Add default contribution import and export - DefaultImport defaultImport = contributionFactory.createDefaultImport(); - defaultImport.setModelResolver(new DefaultModelResolver()); - contribution.getImports().add(defaultImport); - DefaultExport defaultExport = contributionFactory.createDefaultExport(); - contribution.getExports().add(defaultExport); - } - - return contribution; - } - - public void resolve(Contribution contribution, ModelResolver resolver) throws ContributionResolveException { - - // Resolve the contribution model itself - ModelResolver contributionResolver = contribution.getModelResolver(); - contribution.setUnresolved(false); - contributionResolver.addModel(contribution); - - // Resolve imports and exports - for (Export export: contribution.getExports()) { - if (export instanceof DefaultExport) { - - // Initialize the default export's resolver - export.setModelResolver(contributionResolver); - - } else { - extensionProcessor.resolve(export, contributionResolver); - } - } - for (Import import_: contribution.getImports()) { - extensionProcessor.resolve(import_, contributionResolver); - } - - // Resolve all artifact models - for (Artifact artifact : contribution.getArtifacts()) { - Object model = artifact.getModel(); - if (model != null) { - try { - artifactProcessor.resolve(model, contributionResolver); - } catch (Exception e) { - //FIXME this shouldn't happen - } - } - } - - // Resolve deployable composites - List<Composite> deployables = contribution.getDeployables(); - for (int i = 0, n = deployables.size(); i < n; i++) { - Composite deployable = deployables.get(i); - Composite resolved = (Composite)contributionResolver.resolveModel(Composite.class, deployable); - if (resolved != deployable) { - deployables.set(i, resolved); - } - } - } - - /** - * FIXME Temporary hack for testing the ClassLoaderModelResolver. - * - * @param modelResolvers - */ - private static void hackResolvers(ModelResolverExtensionPoint modelResolvers) { - Class<?> resolverClass = modelResolvers.getResolver(ClassReference.class); - if (resolverClass==null || !resolverClass.getName().equals("org.apache.tuscany.sca.contribution.java.impl.ClassLoaderModelResolver")) { - try { - Class<?> loaderResolverClass = Class.forName("org.apache.tuscany.sca.contribution.java.impl.ClassLoaderModelResolver", true, ContributionContentProcessor.class.getClassLoader()); - modelResolvers.addResolver(ClassReference.class, (Class<? extends ModelResolver>)loaderResolverClass); - } catch (ClassNotFoundException e) { - } - } - } -} |