added xt.scope (forgotten earlier)
[org.ibex.xt.git] / src / org / ibex / xt / Scope.java
1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
4
5 package org.ibex.xt;
6 import org.ibex.js.*;
7 import org.ibex.util.*;
8 import org.ibex.io.*;
9 import java.io.*;
10 import java.net.*;
11 import java.util.*;
12 import javax.servlet.*;
13 import javax.servlet.http.*;
14
15 public class Scope extends JS.Obj {
16     private final JS parent;
17     private final Hash declared = new Hash();
18     public Scope(JS parent) { this.parent = parent; }
19     public JS get(JS key) throws JSExn { if (declared.get(key)!=null) return super.get(key); return parent.get(key); }
20     public void put(JS key, JS val) throws JSExn { if (declared.get(key)!=null) super.put(key,val); else parent.put(key,val); }
21     public void declare(JS key) { declared.put(key, Boolean.TRUE); }
22     public void declare(String key) { declare(JSU.S(key)); }
23     public void undeclare(JS key) { declared.remove(key); }
24     public void undeclare(String key) { undeclare(JSU.S(key)); }
25 }