X-Git-Url: http://git.megacz.com/?p=org.ibex.xt-crawshaw.git;a=blobdiff_plain;f=src%2Fjava%2Forg%2Fibex%2Fxt%2Fshell%2FRequest.java;fp=src%2Fjava%2Forg%2Fibex%2Fxt%2Fshell%2FRequest.java;h=2f8524791bd4f2d3e53cfa6f19c0d09be37a4ec1;hp=f0d36976cca5e738dd0e2aed77bfa7b3a3129f68;hb=6430dcd3c8bf58a04a370614e375a74f5f2dce8b;hpb=fc9f528e7acb1baf7c145b22dd0b6469968aaec0 diff --git a/src/java/org/ibex/xt/shell/Request.java b/src/java/org/ibex/xt/shell/Request.java index f0d3697..2f85247 100644 --- a/src/java/org/ibex/xt/shell/Request.java +++ b/src/java/org/ibex/xt/shell/Request.java @@ -100,6 +100,45 @@ public abstract class Request implements Serializable { } } + public static class SetKey extends Key { + protected JS value; + public SetKey() {} + public SetKey(String p, String m, JS val) { super(p, m); this.value = val; } + + public Response process(JSScope root) throws JSExn { + JS js = keyed(path(root)); + if (js == null) throw new JSExn("no such path"); + + js.put(matcher, JS.eval(JS.cloneWithNewParentScope( + value, new JSResolve(root, js)))); + return new Res(); // TODO: return put() value when it has one + } + + public class Res extends Response { + } + + public class JSResolve extends JSScope { + private JS path; + public JSResolve(JSScope parent, JS path) { super(parent); this.path = path; } + public Object get(Object key) throws JSExn { + if (key != null && key instanceof String) { + String k = (String)key; + if (k.startsWith(".")) k = k.substring(1); + else return path.get(k); + } + return super.get(key); + } + public void put(Object key, Object val) throws JSExn { + if (key != null && key instanceof String) { + String k = (String)key; + if (k.startsWith(".")) k = k.substring(1); + else { path.put(key, val); return; } + } + super.put(key, val); + } + } + } + /** Runs a series of requests. */ public static class Composite extends Request { private boolean breakOnError = false;