update to handle returning old version from put() function in JS and functional rm...
[org.ibex.xt-crawshaw.git] / src / java / org / ibex / xt / shell / Shell.java
index f677f28..da77e94 100644 (file)
@@ -40,7 +40,7 @@ public class Shell {
 
     /** Returns the object represented by the given path,
      *  ignoring the current shell path context.*/
-    public Object getFromPath(Object[] path) throws NoSuchPathException, JSExn {
+    public Object getFromPath(Object[] path) throws BadPathException, JSExn {
         if (path.length == 0) return root;
 
         if (root instanceof JSRemote) {
@@ -54,21 +54,30 @@ public class Shell {
             JS cur = root;
             for (int i=0; i < path.length - 1; i++) {
                 Object o =  cur.get(path[i]);
-                if (o == null || !(o instanceof JS)) throw new Shell.NoSuchPathException();
+                if (o == null || !(o instanceof JS)) throw new Shell.BadPathException();
                 cur = (JS)o;
             }
             return cur.get(path[path.length - 1]);
         }
     }
 
+    public void transaction(JS t) {
+        if (root instanceof JSRemote) {
+            ((JSRemote)root).transaction(
+                JS.cloneWithNewParentScope(t, new JSScope(null)));
+        } else {
+            // FIXME JS.eval(JS.cloneWithNewParentScope(t, root));
+        }
+    }
+
     /** Set the current path of the shell, modifiying the result of getScope(). */
-    public void setPath(Object[] s) throws NoSuchPathException {
+    public void setPath(Object[] s) throws BadPathException {
         JS cur = root;
         if (s == null) s = new Object[0];
         for (int i=0; i < s.length; i++) {
             Object o;
-            try { o = cur.get(s[i]); } catch (JSExn e) { throw new NoSuchPathException(); }
-            if (o == null || !(o instanceof JS)) throw new NoSuchPathException();
+            try { o = cur.get(s[i]); } catch (JSExn e) { throw new BadPathException(); }
+            if (o == null || !(o instanceof JS)) throw new BadPathException();
             cur = (JS)o;
         }
         scope = cur;
@@ -174,5 +183,8 @@ public class Shell {
         }
     }
 
-    public static class NoSuchPathException extends Exception {}
+    public static class BadPathException extends Exception {
+        public BadPathException() {}
+        public BadPathException(String msg) { super(msg); }
+    }
 }