public void evalAsEvents(XMLPushStreamBase output, Focus focus, EvalContext context) throws EvaluationException { context.at(this); QName qname = evalName(output, focus, context); try { output.putElementStart(qname); for (int a = 0; a < attributes.size(); a++) { try { getAttribute(a).evalAsEvents(output, focus, context); } catch (EvaluationException e) { if ((getFlags() & DIRECT) != 0) e.substituteCode("XQDY0025", "XQST0040"); throw e; } } for (int c = 0; c < contents.length; c++) { contents[c].evalAsEvents(output, focus, context); output.noSpace(); } output.putElementEnd(qname); } catch (DataModelException e) { dmError(context, e); } }
public XQValue eval(Focus focus, EvalContext context) throws EvaluationException { context.at(this); try { XQValue res = caught.eval(focus, context); // it is crucial to expand the sequence here, so that // eval errors are actually caught ArraySequence expanded = new ArraySequence(4, res); for (; res.next(); ) expanded.addItem(res.getItem()); return expanded; } catch (EvaluationException e) { Catch catcher = null; for (int i = 0; i < catches.length; i++) { if (catches[i].catches(e.getErrorCode())) { catcher = catches[i]; break; } } if (catcher == null) throw e; if (compatibility) { // feature: show error as a node whose name is the error code // and whose content the message CorePushBuilder builder = new CorePushBuilder(""); QName errName = IQName.get(e.getErrorCode()); try { builder.putElementStart(errName); // cant be attr value builder.putText(e.getMessage()); builder.putElementEnd(errName); } catch (QizxException e1) {; } context.storeLocal( catcher.valueVar.address, new SingleNode(builder.harvest()), false /* current */, null); } else { // 1.1 if (catcher.codeVar != null) { context.storeLocal( catcher.codeVar.address, new SingleQName(e.getErrorCode()), false /* current */, null); } if (catcher.descVar != null) { context.storeLocal( catcher.descVar.address, new SingleString(e.getMessage()), false /* current */, null); } if (catcher.valueVar != null) { XQValue v = e.getValue(); if (v == null) v = XQValue.empty; context.storeLocal(catcher.valueVar.address, v, false /* current */, null); } } // execute the handler with bound variables (if any) return catcher.handler.eval(focus, context); } }