}
}
+ private static final JS[] callempty = new JS[0];
private void apply(Box b, PerInstantiationScope parentPis) throws JSExn, IOException {
if (prev != null) prev.apply(b, null);
if (prev2 != null) prev2.apply(b, null);
b.putAndTriggerTraps(b.get(JSU.S("numchildren")), kid);
}
- if (script != null) JS.cloneWithNewGlobalScope(script, pis).call(null, null, null, null, 0);
+ if (script != null) JSU.cloneWithNewGlobalScope(script, pis).call(callempty);
for(int i=0; keys != null && i < keys.length; i++) {
if (keys[i] == null) continue;
if ("null".equals(val)) val = null;
- if (JS.isString(val) && (JS.toString(val).length() > 0)) {
- switch (JS.toString(val).charAt(0)) {
+ if (JSU.isString(val) && (JSU.toString(val).length() > 0)) {
+ switch (JSU.toString(val).charAt(0)) {
case '$':
val = pis.get(val);
- if (val == null) throw new JSExn("unknown box id '"+JS.toString(vals[i])+"' referenced in XML attribute");
+ if (val == null) throw new JSExn("unknown box id '"+JSU.str(vals[i])+"' referenced in XML attribute");
break;
case '.':
- val = ibex.resolveString(JS.toString(val).substring(1), false);
+ val = ibex.resolveString(JSU.toString(val).substring(1), false);
// FIXME: url case
// FIXME: should we be resolving all of these in the XML-parsing code?
}
/** handles XML parsing; builds a Template tree as it goes */
static final class TemplateHelper extends XML {
- String sourceName;
+ String sourceName;
private int state = STATE_INITIAL;
private static final int STATE_INITIAL = 0;
private static final int STATE_IN_ROOT_NODE = 1;
private static final int STATE_IN_TEMPLATE_NODE = 2;
private static final int STATE_IN_META_NODE = 3;
+ private static final JS[] callempty = new JS[0];
StringBuffer static_content = null;
int static_content_start = 0;
String initial_uri = "";
- public TemplateHelper(String sourceName, JS s, Ibex ibex) throws XML.Exn, IOException, JSExn {
+ public TemplateHelper(String sourceName, JS s, Ibex ibex) throws XML.Exn, IOException, JSExn {
this.sourceName = sourceName;
this.ibex = ibex;
InputStream is = s.getInputStream();
Ibex.Blessing b = Ibex.Blessing.getBlessing(s).parent;
while(b != null) {
- if(b.parentkey != null) initial_uri = JS.toString(b.parentkey) + (initial_uri.equals("") ? "" : "." + initial_uri);
+ if(b.parentkey != null) initial_uri = JSU.toString(b.parentkey) + (initial_uri.equals("") ? "" : "." + initial_uri);
b = b.parent;
}
initial_uri = "";
parse(new InputStreamReader(is));
JS staticScript = parseScript(static_content, static_content_start);
- t.staticObject = new JS.O();
+ t.staticObject = new JS.Obj();
JS staticScope = new PerInstantiationScope(null, ibex, null, t.staticObject);
- if (staticScript != null) JS.cloneWithNewGlobalScope(staticScript, staticScope).call(null, null, null, null, 0);
+ if (staticScript != null) JSU.cloneWithNewGlobalScope(staticScript, staticScope).call(callempty);
}
private JS parseScript(StringBuffer content, int content_start) throws IOException {
if (content == null) return null;
String contentString = content.toString();
- if (contentString.trim().length() > 0) return JS.fromReader(sourceName, content_start, new StringReader(contentString));
+ if (contentString.trim().length() > 0) return JSU.fromReader(sourceName, content_start, new StringReader(contentString));
return null;
}
- public void startElement(XML.Element c) throws XML.Exn {
+ public void startElement(Tree.Element c) throws XML.Exn {
+ Tree.Attributes a = c.getAttributes();
switch(state) {
case STATE_IN_META_NODE: { meta++; return; }
case STATE_INITIAL:
if (!"ibex".equals(c.getLocalName()))
throw new XML.Exn("root element was not <ibex>", XML.Exn.SCHEMA, getLine(), getCol());
- if (c.getAttrLen() != 0)
+ if (a.attrSize() != 0)
throw new XML.Exn("root element must not have attributes", XML.Exn.SCHEMA, getLine(), getCol());
- if (c.getUri("ui") == null || "".equals(c.getUri("ui"))) c.addUri("ui", "ibex://ui");
- if (c.getUri("meta") == null || "".equals(c.getUri("meta"))) c.addUri("meta", "ibex://meta");
- if (c.getUri("") == null || "".equals(c.getUri(""))) c.addUri("", initial_uri);
state = STATE_IN_ROOT_NODE;
return;
case STATE_IN_ROOT_NODE:
Log.error(Template.class, e);
}
}
-
- Hash urimap = c.getUriMap();
- t.urikeys = new String[urimap.size()];
- t.urivals = new String[urimap.size()];
- Enumeration uriEnumeration = urimap.keys();
+
+ Tree.Prefixes prefixes = c.getPrefixes();
+ t.urikeys = new String[prefixes.pfxSize()];
+ t.urivals = new String[prefixes.pfxSize()];
+
int ii = 0;
- while(uriEnumeration.hasMoreElements()) {
- String key = (String)uriEnumeration.nextElement();
- String val = (String)urimap.get(key);
+ for (int i=0; i < prefixes.pfxSize(); i++) {
+ String key = prefixes.getPrefixKey(i);
+ String val = prefixes.getPrefixVal(i);
if (val.equals("ibex://ui")) continue;
if (val.equals("ibex://meta")) continue;
t.urikeys[ii] = key;
t.urivals[ii] = val;
ii++;
}
-
- Vec keys = new Vec(c.getAttrLen());
- Vec vals = new Vec(c.getAttrLen());
+
+ // FIXME: 2-value Array
+ Basket.Array keys = new Basket.Array(a.attrSize());
+ Basket.Array vals = new Basket.Array(a.attrSize());
// process attributes into Vecs, dealing with any XML Namespaces in the process
- ATTR: for (int i=0; i < c.getAttrLen(); i++) {
- if (c.getAttrKey(i).equals("id")) {
- t.id = c.getAttrVal(i).toString().intern();
+ ATTR: for (int i=0; i < a.attrSize(); i++) {
+ if (a.getKey(i).equals("id")) {
+ t.id = a.getVal(i).toString().intern();
continue ATTR;
}
// treat value starting with '.' as resource reference
- String uri = c.getAttrUri(i); if (!uri.equals("")) uri = '.' + uri;
- keys.addElement(c.getAttrKey(i));
- vals.addElement((c.getAttrVal(i).startsWith(".") ? uri : "") + c.getAttrVal(i));
+ String uri = a.getUri(i); if (!uri.equals("")) uri = '.' + uri;
+ keys.add(a.getKey(i));
+ vals.add((a.getVal(i).startsWith(".") ? uri : "") + a.getVal(i));
}
if (keys.size() == 0) return;
// sort the attributes lexicographically
- Vec.sort(keys, vals, new Vec.CompareFunc() { public int compare(Object a, Object b) {
- return ((String)a).compareTo((String)b);
- } });
+ Basket.Array.sort(keys, vals, new Basket.CompareFunc() {
+ public int compare(Object a, Object b) { return ((String)a).compareTo((String)b); }
+ }, 0, keys.size());
t.keys = new JS[keys.size()];
t.vals = new JS[vals.size()];
// convert attributes to appropriate types and intern strings
for(int i=0; i<t.keys.length; i++) {
// FEATURE: Intern
- t.keys[i] = JSU.S((String)keys.elementAt(i));
- String valString = (String) vals.elementAt(i);
+ t.keys[i] = JSU.S((String)keys.get(i));
+ String valString = (String) vals.get(i);
if (valString.equals("true")) t.vals[i] = JSU.T;
else if (valString.equals("false")) t.vals[i] = JSU.F;
}
}
- public void endElement(XML.Element c) throws XML.Exn, IOException {
+ public void endElement(Tree.Element c) throws XML.Exn, IOException {
switch(state) {
case STATE_IN_META_NODE: if (--meta < 0) state = STATE_IN_ROOT_NODE; return;
case STATE_IN_ROOT_NODE: return;
public void whitespace(char[] ch, int start, int length) throws XML.Exn { }
}
- private static class PerInstantiationScope extends JS.O {
+ // FIXME: david, get to work
+ private static class PerInstantiationScope extends JS.Obj {
Ibex ibex = null;
PerInstantiationScope parentBoxPis = null;
JS myStatic = null;
this.box = box;
}
public JS get(JS key) throws JSExn {
- if(JS.isString(key)) {
- String s = JS.toString(key);
+ if(JSU.isString(key)) {
+ String s = JSU.toString(key);
// JS:FIXME This is a hack
if (super.get(key) != null) return super.get(key);
if (s.equals("ibex")) return ibex;
}
// JS:FIXME: Everything below here should come from js.scope or something
public void put(JS key, JS val) throws JSExn { if(box != null) box.putAndTriggerTraps(key,val); else super.put(key,val); }
- public void addTrap(JS key, JSFunction f) throws JSExn { box.addTrap(key,f); }
- public void delTrap(JS key, JSFunction f) throws JSExn { box.delTrap(key,f); }
+ public void addTrap(JS key, JS f) throws JSExn { box.addTrap(key,f); }
+ public void delTrap(JS key, JS f) throws JSExn { box.delTrap(key,f); }
}
}