You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by an...@apache.org on 2010/07/04 12:56:00 UTC

svn commit: r960319 - /tuscany/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java

Author: antelder
Date: Sun Jul  4 10:55:59 2010
New Revision: 960319

URL: http://svn.apache.org/viewvc?rev=960319&view=rev
Log:
Update with initial impls for the domain operations described in section 10 of the assembly spec

Modified:
    tuscany/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java

Modified: tuscany/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java?rev=960319&r1=960318&r2=960319&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java Sun Jul  4 10:55:59 2010
@@ -25,13 +25,14 @@ import static java.lang.System.out;
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 import java.util.concurrent.Callable;
 
+import javax.xml.stream.XMLStreamException;
+
 import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
 import org.apache.tuscany.sca.monitor.ValidationException;
 import org.apache.tuscany.sca.node2.Node;
@@ -43,48 +44,98 @@ import org.apache.tuscany.sca.runtime.Ac
  * A little SCA command shell.
  */
 public class Shell {
+    
     final NodeFactory nodeFactory = NodeFactory.newInstance();
+    Node node;
+    
+    public Shell(String domainURI) {
+        this.node = nodeFactory.createNode(domainURI);
+    }
+
+    final List<String> history = new ArrayList<String>();
+    
+    public static void main(final String[] args) throws Exception {
+        new Shell(args.length > 0 ? args[0] : "default").run();
+    }
+
+    boolean addDeploymentComposite(final String curi, String content) throws ContributionReadException, XMLStreamException, ActivationException, ValidationException {
+        node.addDeploymentComposite(curi, new StringReader(content));
+        return true;
+    }
 
-    public static class NodeInfo {
-        final String name;
-        final String curi;
-        final String cloc;
-        final Node node;
-
-        NodeInfo(final String name, final String curi, final String cloc, final Node node) {
-            this.name = name;
-            this.curi = curi;
-            this.cloc = cloc;
-            this.node = node;
+    boolean addToDomainLevelComposite(final String uri) throws ContributionReadException, ActivationException, ValidationException {
+        node.addToDomainLevelComposite(uri);
+        return true;
+    }
+
+    boolean install(final String cloc) throws ContributionReadException, ActivationException, ValidationException {
+        node.installContribution(cloc, cloc, null, null, true);
+        return true;
+    }
+
+    boolean listDeployedCompostes(String curi) throws ContributionReadException, ActivationException, ValidationException {
+        for (String uri : node.getDeployedCompostes(curi)) {
+            out.println(uri.substring(curi.length()+1));
         }
+        return true;
+    }
 
-        public String toString() {
-            return name + " " + curi + " " + cloc;
+    boolean listInstalledContributions() throws ContributionReadException, ActivationException, ValidationException {
+        for (String uri : node.getInstalledContributions()) {
+            out.println(uri);
         }
+        return true;
     }
-    final Map<String, NodeInfo> nodes = new HashMap<String, NodeInfo>();
 
-    final List<String> history = new ArrayList<String>();
+    boolean printDomainLevelComposite() throws ContributionReadException, ActivationException, ValidationException {
+        out.println(node.getDomainLevelCompositeAsString());
+        return true;
+    }
     
-    public static void main(final String[] args) throws Exception {
-        new Shell().run();
+    boolean getQNameDefinition(final String curi, String definintion, String symbolSpace) throws ContributionReadException, ActivationException, ValidationException {
+        // TODO:
+        return true;
+    }
+
+    boolean remove(final String curi) throws ContributionReadException, ActivationException, ValidationException {
+        node.removeContribution(curi);
+        return true;
     }
 
-    boolean start(final String name, final String curi, final String cloc) throws ContributionReadException, ActivationException, ValidationException {
-        final Node node = nodeFactory.createNode("default");
-        node.installContribution(curi, cloc, null, null, true);
-        nodes.put(name, new NodeInfo(name, curi, cloc, node));
+    boolean removeFromDomainLevelComposite(final String uri) throws ContributionReadException, ActivationException, ValidationException {
+        node.removeFromDomainLevelComposite(uri);
         return true;
     }
 
-    boolean stop(final String name) {
-        nodes.get(name).node.stop();
-        nodes.remove(name);
+    boolean help() {
+        out.println("Commands:");
+        out.println();
+        out.println("   install <contributionURL>");
+        out.println("   remove <contributionURL>");
+        out.println("   addDeploymentComposite <contributionURL> <content>");
+        out.println("   addToDomainLevelComposite <contributionURI/compositeURI>");
+        out.println("   removeFromDomainLevelComposite <contributionURI/compositeURI>");
+        out.println("   listDeployedCompostes <contributionURI>");
+        out.println("   listInstalledContributions");
+        out.println("   printDomainLevelComposite");
+        out.println("   stop");
+        out.println();
         return true;
     }
 
+    boolean stop() {
+        node.stop();
+        return false;
+    }
+
     boolean status() {
-        out.println(nodes.values());
+        out.println("Domain: " + node.getDomainName());
+        out.println("   installed contributions: " + node.getInstalledContributions().size());
+        int x = 0;
+        for (String curi : node.getInstalledContributions()) {
+            x += node.getDeployedCompostes(curi).size();
+        }
+        out.println("   deployed composites: " + x);
         return true;
     }
 
@@ -94,10 +145,6 @@ public class Shell {
         return true;
     }
 
-    static boolean bye() {
-        return false;
-    }
-
     List<String> read(final BufferedReader r) throws IOException {
         out.print("=> ");
         final String l = r.readLine();
@@ -107,11 +154,39 @@ public class Shell {
        
     Callable<Boolean> eval(final List<String> toks) {
         final String op = toks.get(0);
-        if (op.equals("start")) return new Callable<Boolean>() { public Boolean call() throws Exception {
-            return start(toks.get(1), toks.get(2), toks.get(3));
+
+        if (op.equals("addDeploymentComposite")) return new Callable<Boolean>() { public Boolean call() throws Exception {
+            return addDeploymentComposite(toks.get(1), toks.get(2));
+        }};
+        if (op.equals("addToDomainLevelComposite")) return new Callable<Boolean>() { public Boolean call() throws Exception {
+            return addToDomainLevelComposite(toks.get(1));
+        }};
+        if (op.equals("install")) return new Callable<Boolean>() { public Boolean call() throws Exception {
+            return install(toks.get(1));
+        }};
+        if (op.equals("listDeployedCompostes")) return new Callable<Boolean>() { public Boolean call() throws Exception {
+            return listDeployedCompostes(toks.get(1));
+        }};
+        if (op.equals("printDomainLevelComposite")) return new Callable<Boolean>() { public Boolean call() throws Exception {
+            return printDomainLevelComposite();
+        }};
+        if (op.equals("listInstalledContributions")) return new Callable<Boolean>() { public Boolean call() throws Exception {
+            return listInstalledContributions();
+        }};
+        if (op.equals("getQNameDefinition")) return new Callable<Boolean>() { public Boolean call() throws Exception {
+            return getQNameDefinition(toks.get(1), toks.get(2), toks.get(3));
+        }};
+        if (op.equals("remove")) return new Callable<Boolean>() { public Boolean call() throws Exception {
+            return remove(toks.get(1));
+        }};
+        if (op.equals("removeFromDomainLevelComposite")) return new Callable<Boolean>() { public Boolean call() throws Exception {
+            return removeFromDomainLevelComposite(toks.get(1));
+        }};
+        if (op.equals("help")) return new Callable<Boolean>() { public Boolean call() {
+            return help();
         }};
         if (op.equals("stop")) return new Callable<Boolean>() { public Boolean call() {
-            return stop(toks.get(1));
+            return stop();
         }};
         if (op.equals("status")) return new Callable<Boolean>() { public Boolean call() {
             return status();
@@ -119,9 +194,6 @@ public class Shell {
         if (op.equals("history")) return new Callable<Boolean>() { public Boolean call() {
             return history();
         }};
-        if (op.equals("bye")) return new Callable<Boolean>() { public Boolean call() {
-            return bye();
-        }};
         return new Callable<Boolean>() { public Boolean call() {
             return true;
         }};
@@ -136,9 +208,8 @@ public class Shell {
         }
     }
 
-    public Map<String, NodeInfo> run() throws IOException {
+    public void run() throws IOException {
         final BufferedReader r = new BufferedReader(new InputStreamReader(in));
         while(apply(eval(read(r))));
-        return nodes;
     }
 }