1    package org.xwt.js;
2    import java.util.*;
3    import org.xwt.util.*;
4    
5    // FEATURE: static slots for four objects?
6    /** A sensible implementation of the abstract methods in the JS class */
7    public class JSObj extends JS {
8        
9        // this gets around a wierd fluke in the Java type checking rules for ?..:
10       public static final Object T = Boolean.TRUE;
11       public static final Object F = Boolean.FALSE;
12   
13       // FEATURE: be smart here; perhaps intern
14       public static final Number N(int i) { return new Integer(i); }
15       public static final Number N(long l) { return new Long(l); }
16       public static final Number N(double d) { return new Double(d); }
17       public static final Boolean B(boolean b) { return b ? Boolean.TRUE : Boolean.FALSE; }
18       
19       private static Enumeration emptyEnumeration = new Enumeration() {
20               public boolean hasMoreElements() { return false; }
21               public Object nextElement() { throw new NoSuchElementException(); }
22           };
23       
24       private Hash entries = null;
25       public JSObj() { }
26       public Enumeration keys() { return entries == null ? emptyEnumeration : entries.keys(); }
27       public Object get(Object key) { return entries == null ? null : entries.get(key, null); }
28       public void put(Object key, Object val) { if (entries == null) entries = new Hash(); entries.put(key, null, val); }
29   
30       // note that we don't actually implement trappable... we just provide these for subclasses which choose to
31       public JSTrap getTrap(Object key) { return entries == null ? null : (JSTrap)entries.get(key, JSTrap.class); }
32       public void putTrap(Object key, JSTrap t) { if (entries == null) entries = new Hash(); entries.put(key, JSTrap.class, t); }
33   }
34