From 67bed8671084b529f037c8fb8ebb209272e99305 Mon Sep 17 00:00:00 2001 From: nash Date: Tue, 29 Jun 2010 20:52:40 +0000 Subject: Process composites last when loading contributions into the domain (TUSCANY-3561) git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@959098 13f79535-47bb-0310-9956-ffa450edef68 --- .../impl/ContributionContentProcessor.java | 84 +++++++++++++++++----- 1 file changed, 67 insertions(+), 17 deletions(-) (limited to 'sca-java-1.x') diff --git a/sca-java-1.x/trunk/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/processor/impl/ContributionContentProcessor.java b/sca-java-1.x/trunk/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/processor/impl/ContributionContentProcessor.java index 4aa619aa3f..64ba61dfdf 100644 --- a/sca-java-1.x/trunk/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/processor/impl/ContributionContentProcessor.java +++ b/sca-java-1.x/trunk/modules/workspace-impl/src/main/java/org/apache/tuscany/sca/workspace/processor/impl/ContributionContentProcessor.java @@ -21,6 +21,7 @@ package org.apache.tuscany.sca.workspace.processor.impl; import java.io.File; import java.net.URI; import java.net.URL; +import java.util.ArrayList; import java.util.List; import javax.xml.stream.XMLInputFactory; @@ -78,6 +79,8 @@ public class ContributionContentProcessor implements URLArtifactProcessor policyDefinitions = null; + private static final String COMPOSITE_FILE_EXTN = ".composite"; + public ContributionContentProcessor(ExtensionPointRegistry extensionPoints, Monitor monitor) { this.extensionPoints = extensionPoints; this.modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); @@ -149,8 +152,51 @@ public class ContributionContentProcessor implements URLArtifactProcessor artifacts = contribution.getArtifacts(); boolean contributionMetadata = false; + List compositeURIs = new ArrayList(); List artifactURIs = scanner.getArtifacts(contributionURL); for (String artifactURI: artifactURIs) { + if (artifactURI.endsWith(COMPOSITE_FILE_EXTN)) { + // TUSCANY-3561: need to process the composites last + compositeURIs.add(artifactURI); + } else { + 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); + + // Add policy definitions to the list of policy definitions + if (policyDefinitionsResolver != null) { + addPolicyDefinitions(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()); + contribution.getExtensions().addAll(c.getExtensions()); + contribution.getAttributeExtensions().addAll(c.getAttributeExtensions()); + } + } + } + } + + // TUSCANY-3561: process the composites last + for (String artifactURI : compositeURIs) { URL artifactURL = scanner.getArtifactURL(contributionURL, artifactURI); // Add the deployed artifact model to the contribution @@ -167,24 +213,8 @@ public class ContributionContentProcessor implements URLArtifactProcessor composites = new ArrayList(); for (Artifact artifact : contribution.getArtifacts()) { + // TUSCANY-3561: need to process the composites last + if (artifact.getURI().endsWith(COMPOSITE_FILE_EXTN)) { + composites.add(artifact); + } else { + Object model = artifact.getModel(); + if (model != null) { + try { + artifactProcessor.resolve(model, contributionResolver); + } catch (ContributionResolveException e) { + throw e; + } catch (Exception e) { + throw new ContributionResolveException(e); + } + } + } + } + + // TUSCANY-3561: process the composites last + for (Artifact artifact : composites) { Object model = artifact.getModel(); if (model != null) { try { -- cgit v1.2.3