From 841c10e3ba7a65bfe8b3362ae27783e7bbc3e63e Mon Sep 17 00:00:00 2001 From: antelder Date: Sun, 15 May 2011 07:05:12 +0000 Subject: Update for the spi intefrcae changes, clean up some of the redundant code, and add in some of the other old Node methods git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1103284 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tuscany/sca/impl/NodeImpl2.java | 88 ++++++++++------------ 1 file changed, 38 insertions(+), 50 deletions(-) (limited to 'sca-java-2.x/trunk/modules/domain-node') diff --git a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl2.java b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl2.java index a61e2a94b2..6080f2ce0d 100644 --- a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl2.java +++ b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl2.java @@ -19,7 +19,6 @@ package org.apache.tuscany.sca.impl; -import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -33,6 +32,7 @@ import org.apache.tuscany.sca.assembly.Base; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.common.java.io.IOHelper; import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ContributionMetadata; import org.apache.tuscany.sca.contribution.Export; import org.apache.tuscany.sca.contribution.Import; import org.apache.tuscany.sca.contribution.java.JavaExport; @@ -79,31 +79,49 @@ public class NodeImpl2 { this.tuscanyRuntime = tuscanyRuntime; } - public void uninstallContribution(String contributionURI) { - loadedContributions.remove(contributionURI); - endpointRegistry.uninstallContribution(contributionURI); - } - public String installContribution(String contributionURL) throws ContributionReadException, ActivationException, ValidationException { return installContribution(null, contributionURL); } public String installContribution(String uri, String contributionURL) throws ContributionReadException, ActivationException, ValidationException { - if (uri == null) { - uri = getDefaultContributionURI(contributionURL); - } + return installContribution(uri, contributionURL, null, null); + } + + public String installContribution(String uri, String contributionURL, String metaDataURL, List dependentContributionURIs) throws ContributionReadException, ActivationException, ValidationException { + InstalledContribution ic = new InstalledContribution(uri, contributionURL); - InstalledContribution ic = new InstalledContribution(); - ic.setURI(uri); - ic.setURL(contributionURL); + if (dependentContributionURIs != null) { + ic.getDependentContributionURIs().addAll(dependentContributionURIs); + } + if (metaDataURL != null) { + mergeContributionMetaData(metaDataURL, loadContribution(ic)); + } + peekIntoContribution(ic); endpointRegistry.installContribution(ic); - return uri; + return ic.getURI(); } - + + public void uninstallContribution(String contributionURI) { + loadedContributions.remove(contributionURI); + endpointRegistry.uninstallContribution(contributionURI); + } + + protected void mergeContributionMetaData(String metaDataURL, Contribution contribution) throws ValidationException { + ContributionMetadata metaData; + Monitor monitor = deployer.createMonitor(); + try { + metaData = deployer.loadXMLDocument(IOHelper.getLocationAsURL(metaDataURL), monitor); + } catch (Exception e) { + throw new ValidationException(e); + } + monitor.analyzeProblems(); + contribution.mergeMetaData(metaData); + } + /** * Peek into the contribution to find its attributes. * ASM12032 and ASM12033 say no error checking should be done during install and that should happen later, but @@ -129,11 +147,6 @@ public class NodeImpl2 { } - public List getDeployableCompositeURIs(String contributionURI) { - InstalledContribution ic = endpointRegistry.getInstalledContribution(contributionURI); - return new ArrayList(ic.getDeployables()); - } - public List getInstalledContributionURIs() { return new ArrayList(endpointRegistry.getInstalledContributionURIs()); } @@ -142,15 +155,18 @@ public class NodeImpl2 { return loadContribution(getInstalledContribution(contributionURI)); } + public List getDeployableCompositeURIs(String contributionURI) { + InstalledContribution ic = endpointRegistry.getInstalledContribution(contributionURI); + return new ArrayList(ic.getDeployables()); + } + public void validateContribution(String contributionURI) throws ContributionReadException, ValidationException { InstalledContribution ic = getInstalledContribution(contributionURI); Contribution contribution = loadContribution(ic); - List dependentContributions = calculateDependentContributions(ic); - Monitor monitor = deployer.createMonitor(); try { - deployer.resolve(contribution, dependentContributions, monitor); + deployer.resolve(contribution, calculateDependentContributions(ic), monitor); } catch (Exception e) { loadedContributions.remove(ic.getURI()); throw new RuntimeException(e); @@ -282,32 +298,4 @@ public class NodeImpl2 { } return ics; } - - /** - * Derives a URI for a contribution based on the contribution URL - */ - protected String getDefaultContributionURI(String contributionURL) { - String uri = null; - try { - File f = new File(contributionURL); - if ("classes".equals(f.getName()) && "target".equals(f.getParentFile().getName())) { - uri = f.getParentFile().getParentFile().getName(); - } else { - uri = f.getName(); - } - } catch (Exception e) { - // ignore - } - if (uri == null) { - uri = contributionURL; - } - if (uri.endsWith(".zip") || uri.endsWith(".jar")) { - uri = uri.substring(0, uri.length() - 4); - } - if (uri.endsWith("SNAPSHOT")) { - uri = uri.substring(0, uri.lastIndexOf('-')); - uri = uri.substring(0, uri.lastIndexOf('-')); - } - return uri; - } } -- cgit v1.2.3