From 95c5a8f2287c2869f100995b7e2bcf749bb097c8 Mon Sep 17 00:00:00 2001 From: adam Date: Sun, 27 Feb 2005 20:34:38 +0000 Subject: [PATCH] added JSSubProperties darcs-hash:20050227203438-5007d-b58880a1d27f1f4b3712cd48047d9b9e74d4654e.gz --- src/org/ibex/js/JSSubProperties.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/org/ibex/js/JSSubProperties.java diff --git a/src/org/ibex/js/JSSubProperties.java b/src/org/ibex/js/JSSubProperties.java new file mode 100644 index 0000000..dcf8042 --- /dev/null +++ b/src/org/ibex/js/JSSubProperties.java @@ -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); } + } +} -- 1.7.10.4