added JSSubProperties
authoradam <adam@megacz.com>
Sun, 27 Feb 2005 20:34:38 +0000 (20:34 +0000)
committeradam <adam@megacz.com>
Sun, 27 Feb 2005 20:34:38 +0000 (20:34 +0000)
darcs-hash:20050227203438-5007d-b58880a1d27f1f4b3712cd48047d9b9e74d4654e.gz

src/org/ibex/js/JSSubProperties.java [new file with mode: 0644]

diff --git a/src/org/ibex/js/JSSubProperties.java b/src/org/ibex/js/JSSubProperties.java
new file mode 100644 (file)
index 0000000..dcf8042
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright 2000-2005 the Contributors, as shown in the revision logs.
+// Licensed under the Apache Public Source License 2.0 ("the License").
+// You may not use this file except in compliance with the License.
+
+package org.ibex.js;
+
+// FEATURE: cache JSSubProperties.Sub
+public abstract class JSSubProperties extends JS.Immutable {
+    protected static final JS SUBPROPERTY = new JS.Immutable();
+    public abstract JS _get(JS key) throws JSExn;
+    public final JS get(JS key) throws JSExn {
+        JS ret = _get(key);
+        return ret==SUBPROPERTY ? new Sub(key) : ret;
+    }
+    private class Sub extends JS.Immutable {
+        final JS key;
+        Sub(JS key) { this.key = key; }
+        public void put(JS key, JS val) throws JSExn {
+            JSSubProperties.this.put(JSU.S(JSU.toString(this.key) + "." + JSU.toString(key)), val); }
+        public JS get(JS key) throws JSExn {
+            return JSSubProperties.this.get(JSU.S(JSU.toString(this.key) + "." + JSU.toString(key))); }
+        public JS call(JS method, JS[] args) throws JSExn {
+            return JSSubProperties.this.call(JSU.S(JSU.toString(this.key) + "." + JSU.toString(method)), args); }
+    }
+}