cloneable is an interface
authorbrian <brian@brianweb.net>
Sat, 3 Jul 2004 15:31:34 +0000 (15:31 +0000)
committerbrian <brian@brianweb.net>
Sat, 3 Jul 2004 15:31:34 +0000 (15:31 +0000)
darcs-hash:20040703153134-24bed-f877e80580384798dcb895394d01bef227a79593.gz

src/org/ibex/core/Box.java
src/org/ibex/core/Ibex.java
src/org/ibex/js/JS.java
src/org/ibex/js/Stream.java

index 0e95a7e..e39e201 100644 (file)
@@ -518,7 +518,7 @@ public final class Box extends JSScope implements Task {
         throw new Error("unreachable"); // unreachable
     }
 
-    private class Mouse extends JS.Cloneable {
+    private class Mouse extends JS implements JS.Cloneable {
         public Object get(Object key) {
             //#switch(key)
             case "x": return N(globalToLocalX(getSurface()._mousex));
index 0a48c5f..7b5f8b5 100644 (file)
@@ -10,12 +10,12 @@ import org.ibex.net.*;
 import org.ibex.crypto.*;
 
 /** Singleton class that provides all functionality in the ibex.* namespace */
-public final class Ibex extends JS.Cloneable {
+public final class Ibex extends JS implements JS.Cloneable {
 
     // FIXME remove this
     private final JS rr;
 
-    public Ibex(Stream rr) { this.rr = bless(rr); }
+    public Ibex(Stream rr) { try { this.rr = bless(rr);} catch(JSExn e) { throw new Error("should never happen"); } }
 
     public JS resolveString(String str, boolean permitAbsolute) throws JSExn {
         if (str.indexOf("://") != -1) {
@@ -161,8 +161,8 @@ public final class Ibex extends JS.Cloneable {
                 case 1:
                     //#switch(name)
                     case "clone":
-                        if (!(a instanceof JS.Cloneable)) throw new JSExn("cannot clone a " + a.getClass().getName());
-                        return ((JS.Cloneable)a).jsclone();
+                        if(a == null) throw new JSExn("can't clone the null value");
+                        return ((JS)a).jsclone();
                     case "bless": return bless((JS)a);
                     case "ui.browser": Platform.newBrowserWindow((String)a); return null;
                     case "stream.unzip": return new Stream.Zip((Stream)a);
@@ -341,19 +341,20 @@ public final class Ibex extends JS.Cloneable {
     }
 
     // FEATURE: move this into builtin.xwar
-    public Blessing bless(JS b) { return new Ibex.Blessing((JS.Cloneable)b, this, null, null); }
+    public Blessing bless(JS b) throws JSExn { return new Ibex.Blessing(b, this, null, null); }
+    // FIXME: Does this really need to extends JS.Clone?
     public static class Blessing extends JS.Clone {
         private Ibex ibex;
         private Template t = null;
         public Object parentkey = null;
         public Blessing parent = null;
         private Hash cache = new Hash();
-        public Blessing(JS.Cloneable clonee, Ibex ibex, Blessing parent, Object parentkey) {
+        public Blessing(JS clonee, Ibex ibex, Blessing parent, Object parentkey) throws JSExn {
             super(clonee); this.ibex = ibex; this.parentkey = parentkey; this.parent = parent; }
         public Object get(Object key) throws JSExn {
             if (key.equals("")) return ((Object)getStatic());
             if (cache.get(key) != null) return cache.get(key);
-            Object ret = new Blessing((JS.Cloneable)clonee.get(key), ibex, this, key);
+            Object ret = new Blessing((JS)clonee.get(key), ibex, this, key);
             cache.put(key, ret);
             return ret;
         }
index 65f624e..0290e46 100644 (file)
@@ -12,6 +12,7 @@ public class JS extends org.ibex.util.BalancedTree {
 
     public static final Object METHOD = new Object() { public String toString() { return "JS.METHOD"; } };
     public final JS unclone() { return _unclone(); }
+    public final JS jsclone() throws JSExn { return new Clone(this); }
     public Enumeration keys() throws JSExn { return entries == null ? emptyEnumeration : entries.keys(); }
     public Object get(Object key) throws JSExn { return entries == null ? null : entries.get(key, null); }
     public void put(Object key, Object val) throws JSExn { (entries==null?entries=new Hash():entries).put(key,null,val); }
@@ -24,17 +25,17 @@ public class JS extends org.ibex.util.BalancedTree {
     }
 
     JS _unclone() { return this; }
-    public static class Cloneable extends JS {
-        public Object jsclone() throws JSExn {
-            return new Clone(this);
-        }
-    }
-
-    public static class Clone extends JS.Cloneable {
-        protected JS.Cloneable clonee = null;
+    
+    public interface Cloneable { }
+    
+    public static class Clone extends JS implements Cloneable {
+        protected JS clonee;
         JS _unclone() { return clonee.unclone(); }
-        public JS.Cloneable getClonee() { return clonee; }
-        public Clone(JS.Cloneable clonee) { this.clonee = clonee; }
+        public JS getClonee() { return clonee; }
+        public Clone(JS clonee) throws JSExn {
+            if(!(clonee instanceof Cloneable)) throw new JSExn("this object isn't cloneable");
+            this.clonee = clonee;
+        }
         public boolean equals(Object o) {
             if (!(o instanceof JS)) return false;
             return unclone() == ((JS)o).unclone();
index 05045e9..72ee0a0 100644 (file)
@@ -13,7 +13,7 @@ import org.ibex.net.*;
  *   be totally independent of the others (ie separate stream position
  *   and state) although they draw from the same data source.
  */
-public abstract class Stream extends JS.Cloneable {
+public abstract class Stream extends JS implements JS.Cloneable {
 
     // Public Interface //////////////////////////////////////////////////////////////////////////////