summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Section10Impl.java
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2010-05-24 09:13:18 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2010-05-24 09:13:18 +0000
commita8074709a9b925de4b49180da52218d7b149fcc2 (patch)
tree7423b4554fa89aaffc8e5a251d4c5ad719f67922 /sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Section10Impl.java
parent8262f6efdd9bf0b99e566e3b7017c1a361f4dd99 (diff)
Handle dependent contribution relationships so removing a contribution also removes those depending on it
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@947572 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Section10Impl.java54
1 files changed, 32 insertions, 22 deletions
diff --git a/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Section10Impl.java b/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Section10Impl.java
index f41023e845..aa12fe8716 100644
--- a/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Section10Impl.java
+++ b/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Section10Impl.java
@@ -24,9 +24,11 @@ import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.Set;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
@@ -84,6 +86,7 @@ public class Section10Impl implements Section10 {
Monitor monitor = deployer.createMonitor();
URL url = IOHelper.getLocationAsURL(contributionURL);
Contribution contribution = deployer.loadContribution(URI.create(uri), url, monitor);
+ // TODO: does this need to do check the monitor
InstalledContribution ic = new InstalledContribution(uri, url.toString(), contribution);
installedContributions.put(uri, ic);
if (autoDeploy) {
@@ -103,14 +106,7 @@ public class Section10Impl implements Section10 {
Composite composite = deployer.loadXMLDocument(compositeXML, monitor);
// TODO: does this need to do check the monitor
- String compositeArtifcatURI = composite.getName().getLocalPart() + ".composite";
- for (Artifact a : ic.getContribution().getArtifacts()) {
- if (compositeArtifcatURI.equals(a.getURI())) {
- throw new IllegalStateException("artifact '" + compositeArtifcatURI + "' already exists in contribution: " + contributionURI);
- }
- }
-
- deployer.attachDeploymentComposite(ic.getContribution(), composite, true);
+ String compositeArtifcatURI = deployer.attachDeploymentComposite(ic.getContribution(), composite, true);
deployComposite(composite, ic);
return compositeArtifcatURI;
}
@@ -124,8 +120,7 @@ public class Section10Impl implements Section10 {
String relativeURI = compositeURI.substring(contributionURI.length()+1);
for (Artifact a : ic.getContribution().getArtifacts()) {
if (a.getURI().equals(relativeURI)) {
- Composite c = (Composite) a.getModel();
- deployComposite(c, ic);
+ deployComposite((Composite) a.getModel(), ic);
return;
}
}
@@ -138,7 +133,6 @@ public class Section10Impl implements Section10 {
String relativeURI = compositeURI.substring(contributionURI.length()+1);
for (DeployedComposite dc : ic.getDeployedComposites()) {
if (relativeURI.equals(dc.getURI())) {
-// undeployComposite(dc, ic);
ic.getDeployedComposites().remove(dc);
dc.unDeploy();
return;
@@ -162,17 +156,20 @@ public class Section10Impl implements Section10 {
return null;
}
- public void removeContribution(String contributionURI) throws ActivationException {
- // TODO: what about dependent contributions
+ public List<String> removeContribution(String contributionURI) throws ActivationException {
+ List<String> removedContributionURIs = new ArrayList<String>();
InstalledContribution ic = installedContributions.remove(contributionURI);
- if (ic == null) {
- throw new IllegalArgumentException("Contribution not installed: " + contributionURI);
- }
- for (DeployedComposite dc : ic.getDeployedComposites()) {
-// undeployComposite(dc, ic);
- dc.unDeploy();
+ if (ic != null) {
+ removedContributionURIs.add(ic.getURI());
+ for (String dependent : getDependentContributions(contributionURI)) {
+ removedContributionURIs.addAll(removeContribution(dependent));
+ }
+ for (DeployedComposite dc : ic.getDeployedComposites()) {
+ dc.unDeploy();
+ }
+ ic.getDeployedComposites().clear();
}
- ic.getDeployedComposites().clear();
+ return removedContributionURIs;
}
public void updateContribution(String uri, String contributionURL) {
@@ -233,7 +230,6 @@ public class Section10Impl implements Section10 {
}
protected void deployComposite(Composite c, InstalledContribution ic) throws ActivationException {
-
List<Contribution> dependentContributions = new ArrayList<Contribution>();
for (InstalledContribution ics : installedContributions.values()) {
dependentContributions.add(ics.getContribution());
@@ -242,5 +238,19 @@ public class Section10Impl implements Section10 {
DeployedComposite dc = Helper.createDeployedComposite(c, ic, dependentContributions, getDomainName(), nodeFactory);
ic.getDeployedComposites().add(dc);
}
-
+
+ public Set<String> getDependentContributions(String contributionURI) {
+ InstalledContribution ic = installedContributions.get(contributionURI);
+ if (ic == null) {
+ throw new IllegalArgumentException("Contribution not installed: " + contributionURI);
+ }
+ Set<String> dependentContributionURIs = new HashSet<String>();
+ for (InstalledContribution icx : installedContributions.values()) {
+ List<Contribution> dependencies = icx.getContribution().getDependencies();
+ if (dependencies != null && dependencies.contains(ic.getContribution())) {
+ dependentContributionURIs.addAll(getDependentContributions(icx.getURI()));
+ }
+ }
+ return dependentContributionURIs;
+ }
}