use of org.eclipse.wst.xml.xpath2.processor.internal.Focus in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method visit.
/**
* visit context item expression.
*
* @param e
* is the context item expression.
* @return a result sequence
*/
public Object visit(CntxItemExpr e) {
ResultBuffer rs = new ResultBuffer();
AnyType contextItem = focus().context_item();
if (contextItem == null) {
report_error(DynamicError.contextUndefined());
}
rs.add(contextItem);
return rs.getSequence();
}
use of org.eclipse.wst.xml.xpath2.processor.internal.Focus in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method root_self_node.
private ResultSequence root_self_node() {
Axis axis = new SelfAxis();
ResultBuffer buffer = new ResultBuffer();
// XXX the cast!!!
axis.iterate((NodeType) focus().context_item(), buffer, _dc.getLimitNode());
ResultSequence rs = kind_test(buffer.getSequence(), NodeType.class);
List records = new ArrayList();
records.add(rs);
rs = FnRoot.fn_root(records, _ec);
return rs;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.Focus in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method visit.
/**
* visit axis step.
*
* @param e
* is the axis step.
* @return a result sequence
*/
public Object visit(AxisStep e) {
ResultSequence rs = (ResultSequence) e.step().accept(this);
if (e.predicate_count() == 0)
return rs;
// I take it predicates are logical ANDS...
Focus original_focus = focus();
// go through all predicates
for (Iterator i = e.iterator(); i.hasNext(); ) {
// empty results... get out of here ? XXX
if (rs.size() == 0)
break;
set_focus(new Focus(rs));
rs = do_predicate((Collection) i.next());
}
// restore focus [context switching ;D ]
set_focus(original_focus);
return rs;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.Focus in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method do_predicate.
// do the predicate for all items in focus
private ResultSequence do_predicate(Collection exprs) {
ResultBuffer rs = new ResultBuffer();
Focus focus = focus();
int original_cp = focus.position();
// check if predicate is single numeric constant
if (exprs.size() == 1) {
Expr expr = (Expr) exprs.iterator().next();
if (expr instanceof XPathExpr) {
XPathExpr xpe = (XPathExpr) expr;
if (xpe.next() == null && xpe.slashes() == 0 && xpe.expr() instanceof FilterExpr) {
FilterExpr fex = (FilterExpr) xpe.expr();
if (fex.primary() instanceof IntegerLiteral) {
int pos = (((IntegerLiteral) fex.primary()).value().int_value()).intValue();
if (pos <= focus.last() && pos > 0) {
focus.set_position(pos);
rs.add(focus.context_item());
}
focus.set_position(original_cp);
return rs.getSequence();
}
}
}
}
// go through all elements
while (true) {
// do the predicate
// XXX saxon doesn't allow for predicates to have
// commas... but XPath 2.0 spec seems to do
ResultSequence res = do_expr(exprs.iterator());
// in the sequence
if (predicate_truth(res))
rs.add(focus().context_item());
if (!focus.advance_cp())
break;
}
// restore
focus.set_position(original_cp);
return rs.getSequence();
}
Aggregations