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=8cb2be634b54ee34211cc4944a58f44e785035bb;hp=2f8524791bd4f2d3e53cfa6f19c0d09be37a4ec1;hb=e086a6515bf5d5f1f179240f229056d2bb699a99;hpb=6430dcd3c8bf58a04a370614e375a74f5f2dce8b diff --git a/src/java/org/ibex/xt/shell/Request.java b/src/java/org/ibex/xt/shell/Request.java index 2f85247..8cb2be6 100644 --- a/src/java/org/ibex/xt/shell/Request.java +++ b/src/java/org/ibex/xt/shell/Request.java @@ -45,7 +45,9 @@ public abstract class Request implements Serializable { /** Returns the keys in js that match matcher. */ protected List matches(JS js) throws JSExn { - Pattern pat = Pattern.compile(matcher); + String m = matcher; + + Pattern pat = Pattern.compile(m); List keys = new ArrayList(); Iterator i = js.keys().iterator(); while(i.hasNext()) { @@ -69,6 +71,11 @@ public abstract class Request implements Serializable { public Response process(JSScope root) throws JSExn { JS js = keyed(path(root)); + + // if matcher is exact and a keyed object, return its keys + JS o = keyed(js.get(matcher)); + if (o != null) { js = o; matcher = ".*"; } + return js == null ? new Res() : new Res(matches(js)); } @@ -81,6 +88,22 @@ public abstract class Request implements Serializable { } } + public static class IsKey extends Key { + public IsKey() {} + public IsKey(String c) { super(c); } + public Response process(JSScope root) throws JSExn { + JS js = keyed(path(root)); + return js == null ? new Res(false) : new Res(js.get(matcher) != null); + } + + public static class Res extends Response { + private boolean exists; + public Res() {} + public Res(boolean e) { exists = e; } + public boolean exists() { return exists; } + } + } + public static class RemoveKey extends Key { public RemoveKey(String c) { super(c); } public RemoveKey(String p, String m) { super(p, m); }