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) {
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);
}
// 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;
}
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); }
}
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();