use of org.eclipse.wst.xml.xpath2.processor.internal.ast.Expr in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method do_expr.
// basically the comma operator...
private ResultSequence do_expr(Iterator i) {
ResultSequence rs = null;
ResultBuffer buffer = null;
while (i.hasNext()) {
Expr e = (Expr) i.next();
ResultSequence result = (ResultSequence) e.accept(this);
if (rs == null && buffer == null)
rs = result;
else {
if (buffer == null) {
buffer = new ResultBuffer();
buffer.concat(rs);
rs = null;
}
buffer.concat(result);
}
}
if (buffer != null) {
return buffer.getSequence();
} else if (rs != null) {
return rs;
} else
return ResultBuffer.EMPTY;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.ast.Expr in project webservices-axiom by apache.
the class PsychoPathTest method evaluate.
private static ResultSequence evaluate(String xpath) throws Exception {
InputStream is = PsychoPathTest.class.getResourceAsStream("test.xml");
try {
OMFactory factory = OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM).getOMFactory();
Document doc = (Document) OMXMLBuilderFactory.createOMBuilder(factory, is).getDocument();
StaticContextBuilder scb = new StaticContextBuilder();
XPath2Expression expr = new Engine().parseExpression(xpath, scb);
return expr.evaluate(new DynamicContextBuilder(scb), new Object[] { doc });
} finally {
is.close();
}
}
use of org.eclipse.wst.xml.xpath2.processor.internal.ast.Expr in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method do_for_each.
private void do_for_each(ListIterator iter, Expr finalexpr, ResultBuffer destination) {
// we have more vars to bind...
if (iter.hasNext()) {
VarExprPair ve = (VarExprPair) iter.next();
// evaluate binding sequence
ResultSequence rs = (ResultSequence) ve.expr().accept(this);
// XXX
if (rs.empty()) {
iter.previous();
return;
}
QName varname = ve.varname();
for (Iterator i = rs.iterator(); i.hasNext(); ) {
AnyType item = (AnyType) i.next();
pushScope(varname, item);
do_for_each(iter, finalexpr, destination);
popScope();
}
iter.previous();
} else // we finally got to do the "last expression"
{
destination.concat((ResultSequence) finalexpr.accept(this));
}
}
use of org.eclipse.wst.xml.xpath2.processor.internal.ast.Expr in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method visit.
/**
* visit castable expression
*
* @param cexp
* is the castable expression.
* @return a new function
*/
public Object visit(CastableExpr cexp) {
boolean castable = false;
try {
CastExpr ce = new CastExpr((Expr) cexp.left(), (SingleType) cexp.right());
visit(ce);
castable = true;
} catch (Throwable t) {
castable = false;
}
return ResultSequenceFactory.create_new(new XSBoolean(castable));
}
use of org.eclipse.wst.xml.xpath2.processor.internal.ast.Expr in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method do_for_all.
// XXX ugly
// type: 0 = for [return == "correct"]
// 1 = for all [return false, return empty on true]
// 2 = there exists [return true, return empty on false]
private XSBoolean do_for_all(ListIterator iter, Expr finalexpr) {
// we have more vars to bind...
if (iter.hasNext()) {
VarExprPair ve = (VarExprPair) iter.next();
// evaluate binding sequence
ResultSequence rs = (ResultSequence) ve.expr().accept(this);
QName varname = ve.varname();
try {
for (Iterator i = rs.iterator(); i.hasNext(); ) {
AnyType item = (AnyType) i.next();
pushScope(varname, item);
XSBoolean effbool = do_for_all(iter, finalexpr);
popScope();
// out what to do with it
if (!effbool.value())
return XSBoolean.FALSE;
}
} finally {
iter.previous();
}
return XSBoolean.TRUE;
} else // we finally got to do the "last expression"
{
return effective_boolean_value((ResultSequence) finalexpr.accept(this));
}
}
Aggregations