tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r1103284 - /tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl2.java
Date Sun, 15 May 2011 07:05:12 GMT
Author: antelder
Date: Sun May 15 07:05:12 2011
New Revision: 1103284

URL: http://svn.apache.org/viewvc?rev=1103284&view=rev
Log:
Update for the spi intefrcae changes, clean up some of the redundant code, and add in some
of the other old Node methods

Modified:
    tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl2.java

Modified: tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl2.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl2.java?rev=1103284&r1=1103283&r2=1103284&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl2.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl2.java
Sun May 15 07:05:12 2011
@@ -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.B
 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<String> 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<String> getDeployableCompositeURIs(String contributionURI) {
-        InstalledContribution ic = endpointRegistry.getInstalledContribution(contributionURI);
-        return new ArrayList<String>(ic.getDeployables());
-    }
-
     public List<String> getInstalledContributionURIs() {
         return new ArrayList<String>(endpointRegistry.getInstalledContributionURIs());
     }
@@ -142,15 +155,18 @@ public class NodeImpl2 {
         return loadContribution(getInstalledContribution(contributionURI));
     }
 
+    public List<String> getDeployableCompositeURIs(String contributionURI) {
+        InstalledContribution ic = endpointRegistry.getInstalledContribution(contributionURI);
+        return new ArrayList<String>(ic.getDeployables());
+    }
+
     public void validateContribution(String contributionURI) throws ContributionReadException,
ValidationException {
         InstalledContribution ic = getInstalledContribution(contributionURI);
         Contribution contribution = loadContribution(ic);
 
-        List<Contribution> 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;
-    }
 }



Mime
View raw message