More Java work.
[doldaconnect.git] / lib / java / dolda / dolcon / Command.java
diff --git a/lib/java/dolda/dolcon/Command.java b/lib/java/dolda/dolcon/Command.java
new file mode 100644 (file)
index 0000000..fa72357
--- /dev/null
@@ -0,0 +1,37 @@
+package dolda.dolcon;
+
+import java.util.*;
+
+public class Command {
+    List<String> tokens;
+    Set<Listener> listeners = new HashSet<Listener>();
+    Response resp;
+    
+    public interface Listener {
+       public void done(Response resp) throws Exception;
+       public void error(Exception cause);
+    }
+
+    public Command(List<String> tokens) {
+       this.tokens = tokens;
+    }
+    
+    public Command(String... tokens) {
+       this(Arrays.asList(tokens));
+    }
+    
+    public void addListener(Listener l) {
+       listeners.add(l);
+    }
+    
+    public void done(Response resp) throws Exception {
+       this.resp = resp;
+       for(Listener l : listeners)
+           l.done(resp);
+    }
+    
+    public void error(Exception cause) {
+       for(Listener l : listeners)
+           l.error(cause);
+    }
+}