From: brian Date: Tue, 6 Jul 2004 06:07:12 +0000 (+0000) Subject: ibex.core updates for new api X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=commitdiff_plain;h=b0ec2e1d6c3bd35205dfffc6893f01157aef2ced ibex.core updates for new api darcs-hash:20040706060712-24bed-785fec5551b41417ce8f1f13f1b3d13c8b011188.gz --- diff --git a/src/org/ibex/core/Box.java b/src/org/ibex/core/Box.java index 29cd9bc..151654b 100644 --- a/src/org/ibex/core/Box.java +++ b/src/org/ibex/core/Box.java @@ -57,7 +57,11 @@ public final class Box extends JSScope implements Task { // FIXME memory leak static Hash boxToCursor = new Hash(500, 3); - static final Font DEFAULT_FONT = Font.getFont((Stream)Main.builtin.get(JS.S("fonts/vera/Vera.ttf")), 10); + static final Font DEFAULT_FONT; + static { + try { DEFAULT_FONT = Font.getFont(Main.builtin.get(JS.S("fonts/vera/Vera.ttf")), 10); } + catch(JSExn e) { throw new Error("Error loading default font: " + e); } + } // Flags ////////////////////////////////////////////////////////////////////// diff --git a/src/org/ibex/core/Ibex.java b/src/org/ibex/core/Ibex.java index 6492ed2..58969ae 100644 --- a/src/org/ibex/core/Ibex.java +++ b/src/org/ibex/core/Ibex.java @@ -152,10 +152,10 @@ public final class Ibex extends JS implements JS.Cloneable { case "date": return new JSDate(a, b, c, rest, nargs); case "net.rpc.soap": return new SOAP(JS.toString(a), "", JS.toString(b), JS.toString(c)); // FIXME support object dumping - case "log.debug": JS.debug(a== null ? "**null**" : a.toString()); return null; - case "log.info": JS.info(a== null ? "**null**" : a.toString()); return null; - case "log.warn": JS.warn(a== null ? "**null**" : a.toString()); return null; - case "log.error": JS.error(a== null ? "**null**" : a.toString()); return null; + case "log.debug": JS.debug(a== null ? "**null**" : JS.debugToString(a)); return null; + case "log.info": JS.info(a== null ? "**null**" : JS.debugToString(a)); return null; + case "log.warn": JS.warn(a== null ? "**null**" : JS.debugToString(a)); return null; + case "log.error": JS.error(a== null ? "**null**" : JS.debugToString(a)); return null; //#end switch (nargs) { @@ -349,6 +349,7 @@ public final class Ibex extends JS implements JS.Cloneable { // FEATURE: move this into builtin.xwar public Blessing bless(JS b) throws JSExn { return new Ibex.Blessing(b, this, null, null); } // FIXME: Does this really need to extends JS.Clone? + // FEATURE: Mandate that Blessings use only String keys? public static class Blessing extends JS.Clone { private Ibex ibex; private Template t = null; @@ -382,28 +383,34 @@ public final class Ibex extends JS implements JS.Cloneable { } catch (IOException f) { /* DELIBERATE */ } return null; } - public JSScope getStatic() { + public JSScope getStatic() throws JSExn { try { if (t == null) { + // FEATURE: Might want to handle the ".t" part better JS res = (JS) parent.get(JS.S(JS.toString(parentkey) + ".t")); - t = Template.buildTemplate(res.unclone().toString(), res, ibex); + // FIXME: need a better description (Stream.toString()) + t = Template.buildTemplate(JS.toString(parentkey), res, ibex); } - return t.staticScope; + return t != null ? t.staticScope : null; } catch (Exception e) { Log.error(this, e); return null; } } public JS call(JS a, JS b, JS c, JS[] rest, int nargs) throws JSExn { - // GROSS hack - if (nargs != 1 && nargs != 9999) throw new JSExn("FIXME can only call with one arg"); + if (nargs != 1) throw new JSExn("can only call a template with one arg"); getStatic(); if (t == null) throw new JSExn("No such template " + parentkey); - if (nargs == 9999) /*return t;*/ throw new Error("FIXME"); // FIXME: 9999 stuff if(!(a instanceof Box)) throw new JSExn("can only apply templates to boxes"); t.apply((Box)a); return a; } + // FEATURE: This is a gross hack + Template getTemplate() throws JSExn { + getStatic(); + if (t == null) throw new JSExn("No such template " + JS.debugToString(parentkey)); + return t; + } } } diff --git a/src/org/ibex/core/Main.java b/src/org/ibex/core/Main.java index 7d1f62a..3a0ec17 100644 --- a/src/org/ibex/core/Main.java +++ b/src/org/ibex/core/Main.java @@ -93,7 +93,7 @@ public class Main { final Ibex ibex = new Ibex(rr); org.ibex.graphics.Surface.scarImage = - Picture.load((Stream)Main.builtin.get(JS.S("org/ibex/core/builtin/scar.png")), + Picture.load(Main.builtin.get(JS.S("org/ibex/core/builtin/scar.png")), new Task() { public void perform() throws JSExn, UnknownHostException { if (Log.on) Log.info(Main.class, "invoking initial template"); ibex.resolveString(startupTemplate, false).call(new Box(), null, null, null, 1); diff --git a/src/org/ibex/core/Template.java b/src/org/ibex/core/Template.java index ddbf5b0..7f342dd 100644 --- a/src/org/ibex/core/Template.java +++ b/src/org/ibex/core/Template.java @@ -25,7 +25,7 @@ public class Template { String id = null; ///< the id of this box String redirect = null; ///< the id of the redirect target; only meaningful on a root node - private String[] keys; ///< keys to be "put" to instances of this template; elements correspond to those of vals + private JS[] keys; ///< keys to be "put" to instances of this template; elements correspond to those of vals private JS[] vals; ///< values to be "put" to instances of this template; elements correspond to those of keys private String[] urikeys; private String[] urivals; @@ -101,7 +101,7 @@ public class Template { for(int i=0; keys != null && i < keys.length; i++) { if (keys[i] == null) continue; - String key = keys[i]; + JS key = keys[i]; JS val = vals[i]; if ("null".equals(val)) val = null; @@ -118,7 +118,7 @@ public class Template { // FIXME: should we be resolving all of these in the XML-parsing code? } } - b.putAndTriggerTraps(JS.S(key), val); + b.putAndTriggerTraps(key, val); } } @@ -160,7 +160,7 @@ public class Template { InputStream is = Stream.getInputStream(s); Ibex.Blessing b = Ibex.Blessing.getBlessing(s).parent; while(b != null) { - if(b.parentkey != null) initial_uri = b.parentkey + (initial_uri.equals("") ? "" : "." + initial_uri); + if(b.parentkey != null) initial_uri = JS.toString(b.parentkey) + (initial_uri.equals("") ? "" : "." + initial_uri); b = b.parent; } initial_uri = ""; @@ -202,13 +202,15 @@ public class Template { break; } + // FIXME: This is all wrong if (!("ibex://ui".equals(c.getUri()) && "box".equals(c.getLocalName()))) { String tagname = (c.getUri().equals("") ? "" : (c.getUri() + ".")) + c.getLocalName(); // GROSS hack try { // GROSSER hack // t.prev2 = (Template)t.ibex.resolveString(tagname, false).call(null, null, null, null, 9999); - throw new Error("FIXME - 9999 thing"); // FIXME:9999 thing + if(t.prev2 != null) throw new Error("FIXME: t.prev2 != null"); + t.prev2 = ((Ibex.Blessing)t.ibex.resolveString(tagname, false)).getTemplate(); } catch (Exception e) { Log.error(Template.class, e); } @@ -253,16 +255,14 @@ public class Template { return ((String)a).compareTo((String)b); } }); - t.keys = new String[keys.size()]; + t.keys = new JS[keys.size()]; t.vals = new JS[vals.size()]; - keys.copyInto(t.keys); - vals.copyInto(t.vals); - + // convert attributes to appropriate types and intern strings for(int i=0; i