projects
/
org.ibex.xt-crawshaw.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
introduce a signalling exception and improve error messages
[org.ibex.xt-crawshaw.git]
/
src
/
java
/
org
/
ibex
/
xt
/
JSElement.java
diff --git
a/src/java/org/ibex/xt/JSElement.java
b/src/java/org/ibex/xt/JSElement.java
index
1f07af2
..
c6eee6e
100644
(file)
--- a/
src/java/org/ibex/xt/JSElement.java
+++ b/
src/java/org/ibex/xt/JSElement.java
@@
-9,6
+9,7
@@
import java.util.*;
import org.ibex.util.*;
import org.ibex.js.JS;
import org.ibex.js.JSScope;
import org.ibex.util.*;
import org.ibex.js.JS;
import org.ibex.js.JSScope;
+import org.ibex.js.JSExn;
public class JSElement extends JSScope implements XML.Element {
protected XML.Element wrapped;
public class JSElement extends JSScope implements XML.Element {
protected XML.Element wrapped;
@@
-35,12
+36,14
@@
public class JSElement extends JSScope implements XML.Element {
protected void loadAttr() {
try {
XML.Attributes a = getAttributes();
protected void loadAttr() {
try {
XML.Attributes a = getAttributes();
+ // FIXME: questionable abuse of XML namespaces here
+ boolean xturi = "http://xt.ibex.org/".equals(getUri());
for(int i=0; i < a.attrSize(); i++) {
for(int i=0; i < a.attrSize(); i++) {
- if (!"http://xt.ibex.org/".equals(a.getUri(i))) continue;
+ if (!xturi && !"http://xt.ibex.org/".equals(a.getUri(i))) continue;
declare(a.getKey(i));
put(a.getKey(i), eval(a.getVal(i)));
}
declare(a.getKey(i));
put(a.getKey(i), eval(a.getVal(i)));
}
- } catch (Exception e) { throw new RuntimeException(e); }
+ } catch (JSExn e) { throw new Exn(e); }
}
private Object eval(String s) {
}
private Object eval(String s) {
@@
-56,9
+59,9
@@
public class JSElement extends JSScope implements XML.Element {
app instanceof String ||
app instanceof Number ||
app instanceof Boolean))
app instanceof String ||
app instanceof Number ||
app instanceof Boolean))
- throw new RuntimeException("javascripts within ${...} can only return " +
- "strings, numbers, and booleans; not a " +
- app.getClass().getName());
+ throw new Exn("javascripts within ${...} can only return " +
+ "strings, numbers, and booleans; not a " +
+ app.getClass().getName());
ret.append(app == null ? "null" : app.toString());
}
ret.append(app == null ? "null" : app.toString());
}
@@
-70,9
+73,11
@@
public class JSElement extends JSScope implements XML.Element {
try {
return JS.eval(JS.cloneWithNewParentScope(
JS.fromReader("input", 0, new StringReader(s)), this));
try {
return JS.eval(JS.cloneWithNewParentScope(
JS.fromReader("input", 0, new StringReader(s)), this));
- } catch (Exception e) {
+ } catch (IOException e) {
e.printStackTrace();
e.printStackTrace();
- throw new RuntimeException(e);
+ throw new Exn("impossible IOException, reading from StringReader");
+ } catch (JSExn e) {
+ throw new Exn(e);
}
}
}
}
@@
-145,4
+150,10
@@
public class JSElement extends JSScope implements XML.Element {
return i >= a.attrSize() ? b.getUri(i-a.attrSize()) : a.getUri(i); }
public int attrSize() { return a.attrSize() + b.attrSize(); }
}
return i >= a.attrSize() ? b.getUri(i-a.attrSize()) : a.getUri(i); }
public int attrSize() { return a.attrSize() + b.attrSize(); }
}
+
+ public static class Exn extends RuntimeException {
+ public Exn(String cause) { super(cause); }
+ public Exn(JSExn e) { super(e); }
+ public String toString() { return "JSElement.Exn: "+getMessage(); }
+ }
}
}