From a33dbd3ca68717debdbeba860f58761bf440ae10 Mon Sep 17 00:00:00 2001 From: antelder Date: Sun, 4 Jul 2010 10:55:59 +0000 Subject: Update with initial impls for the domain operations described in section 10 of the assembly spec git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@960319 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/tuscany/sca/shell/Shell.java | 149 +++++++++++++++------ 1 file changed, 110 insertions(+), 39 deletions(-) diff --git a/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java b/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java index 920e834acb..2a5dd5ff2d 100644 --- a/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java +++ b/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java @@ -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.ActivationException; * 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 history = new ArrayList(); + + 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 nodes = new HashMap(); - final List history = new ArrayList(); + 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 "); + out.println(" remove "); + out.println(" addDeploymentComposite "); + out.println(" addToDomainLevelComposite "); + out.println(" removeFromDomainLevelComposite "); + out.println(" listDeployedCompostes "); + 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 read(final BufferedReader r) throws IOException { out.print("=> "); final String l = r.readLine(); @@ -107,11 +154,39 @@ public class Shell { Callable eval(final List toks) { final String op = toks.get(0); - if (op.equals("start")) return new Callable() { public Boolean call() throws Exception { - return start(toks.get(1), toks.get(2), toks.get(3)); + + if (op.equals("addDeploymentComposite")) return new Callable() { public Boolean call() throws Exception { + return addDeploymentComposite(toks.get(1), toks.get(2)); + }}; + if (op.equals("addToDomainLevelComposite")) return new Callable() { public Boolean call() throws Exception { + return addToDomainLevelComposite(toks.get(1)); + }}; + if (op.equals("install")) return new Callable() { public Boolean call() throws Exception { + return install(toks.get(1)); + }}; + if (op.equals("listDeployedCompostes")) return new Callable() { public Boolean call() throws Exception { + return listDeployedCompostes(toks.get(1)); + }}; + if (op.equals("printDomainLevelComposite")) return new Callable() { public Boolean call() throws Exception { + return printDomainLevelComposite(); + }}; + if (op.equals("listInstalledContributions")) return new Callable() { public Boolean call() throws Exception { + return listInstalledContributions(); + }}; + if (op.equals("getQNameDefinition")) return new Callable() { public Boolean call() throws Exception { + return getQNameDefinition(toks.get(1), toks.get(2), toks.get(3)); + }}; + if (op.equals("remove")) return new Callable() { public Boolean call() throws Exception { + return remove(toks.get(1)); + }}; + if (op.equals("removeFromDomainLevelComposite")) return new Callable() { public Boolean call() throws Exception { + return removeFromDomainLevelComposite(toks.get(1)); + }}; + if (op.equals("help")) return new Callable() { public Boolean call() { + return help(); }}; if (op.equals("stop")) return new Callable() { public Boolean call() { - return stop(toks.get(1)); + return stop(); }}; if (op.equals("status")) return new Callable() { public Boolean call() { return status(); @@ -119,9 +194,6 @@ public class Shell { if (op.equals("history")) return new Callable() { public Boolean call() { return history(); }}; - if (op.equals("bye")) return new Callable() { public Boolean call() { - return bye(); - }}; return new Callable() { public Boolean call() { return true; }}; @@ -136,9 +208,8 @@ public class Shell { } } - public Map run() throws IOException { + public void run() throws IOException { final BufferedReader r = new BufferedReader(new InputStreamReader(in)); while(apply(eval(read(r)))); - return nodes; } } -- cgit v1.2.3