use of org.eclipse.wst.xml.xpath2.processor.internal.Focus in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method visit.
/**
* visit XPath expression
*
* @param e
* is the XPath expression.
* @return a new function
*/
public Object visit(XPathExpr e) {
XPathExpr xp = e;
ResultSequence rs = null;
Focus original_focus = focus();
// do all the steps
while (xp != null) {
StepExpr se = xp.expr();
if (se != null) {
// this is not the first step
if (rs != null) {
// results...
if (rs.size() == 0)
break;
// nodes!
for (Iterator i = rs.iterator(); i.hasNext(); ) {
AnyType item = (AnyType) i.next();
if (!(item instanceof NodeType)) {
report_error(TypeError.step_conatins_atoms(null));
// unreach
return null;
}
}
// check if we got a //
if (xp.slashes() == 2) {
rs = descendant_or_self_node(rs);
if (rs.size() == 0)
break;
}
// make result of previous step the new
// focus
set_focus(new Focus(rs));
// do the step for all item in context
rs = do_step(se);
} else // this is first step...
// note... we may be called from upstream...
// like in the expression sorbo/*[2] ... we may
// be called to evaluate the 2... the caller
// will iterate through the whole outer focus
// for us
{
// XXX ???
if (xp.slashes() == 1) {
rs = root_self_node();
set_focus(new Focus(rs));
rs = do_step(se);
} else if (xp.slashes() == 2) {
rs = root_self_node();
rs = descendant_or_self_node(rs);
set_focus(new Focus(rs));
rs = do_step(se);
} else
rs = (ResultSequence) se.accept(this);
}
} else // the expression is "/"
{
assert xp.slashes() == 1;
rs = root_self_node();
}
xp = xp.next();
}
// restore focus
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_step.
// this will evaluate the step expression for the whole focus and return
// the result.
//
// i.e. It will execute the step expression for each item in the focus
// [each time changing the context item].
private ResultSequence do_step(StepExpr se) {
ResultBuffer rs = new ResultBuffer();
ArrayList results = new ArrayList();
// 0: don't know yet
int type = 0;
// 1: atomic
// 2: node
Focus focus = focus();
int original_pos = focus.position();
// execute step for all items in focus
while (true) {
results.add(se.accept(this));
// go to next
if (!focus.advance_cp())
break;
}
// make sure we didn't change focus
focus.set_position(original_pos);
boolean node_types = false;
// check the results
for (Iterator i = results.iterator(); i.hasNext(); ) {
ResultSequence result = (ResultSequence) i.next();
// make sure results are of same type, and add them in
for (Iterator j = result.iterator(); j.hasNext(); ) {
AnyType item = (AnyType) j.next();
// first item
if (type == 0) {
if (item instanceof AnyAtomicType)
type = 1;
else if (item instanceof NodeType)
type = 2;
else
assert false;
}
// make sure we got coherent types
switch(type) {
// atomic... just concat
case 1:
if (!(item instanceof AnyAtomicType))
report_error(TypeError.mixed_vals(null));
rs.add(item);
break;
case 2:
node_types = true;
if (!(item instanceof NodeType))
report_error(TypeError.mixed_vals(null));
rs.add(item);
break;
default:
assert false;
}
}
}
// XXX lame
if (node_types) {
rs = NodeType.linarize(rs);
}
return rs.getSequence();
}
use of org.eclipse.wst.xml.xpath2.processor.internal.Focus in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method visit.
/**
* visit filter expression
*
* @param e
* is the filter expression.
* @return a result sequence
*/
// XXX unify with top ?
public Object visit(FilterExpr e) {
ResultSequence rs = (ResultSequence) e.primary().accept(this);
// the primary expression
if (e.predicate_count() == 0)
return rs;
Focus original_focus = focus();
// go through all predicates
for (Iterator i = e.iterator(); i.hasNext(); ) {
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 visit.
/**
* visit a reverse step expression
*
* @param e
* is the reverse step.
* @return a new function
*/
// XXX unify with top
public Object visit(ReverseStep e) {
// get context node
AnyType ci = focus().context_item();
if (!(ci instanceof NodeType))
report_error(TypeError.ci_not_node(ci.string_type()));
NodeType cn = (NodeType) ci;
// get the nodes on the axis
ReverseAxis axis = e.iterator();
ResultBuffer result = new ResultBuffer();
// short for "gimme da parent"
if (e.axis() == ReverseStep.DOTDOT) {
new ParentAxis().iterate(cn, result, _dc.getLimitNode());
return result.getSequence();
}
assert axis != null;
axis.iterate(cn, result, null);
// get all nodes in the axis, and principal node
Pair arg = new Pair(axis.principal_node_kind().string_type(), result.getSequence());
// do the name test
_param = arg;
ResultSequence rs = (ResultSequence) e.node_test().accept(this);
return rs;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.Focus in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method visit.
/**
* visit a forward step expression
*
* @param e
* is the forward step.
* @return a new function
*/
public Object visit(ForwardStep e) {
// get context node
AnyType ci = focus().context_item();
if (ci == null)
report_error(DynamicError.contextUndefined());
if (!(ci instanceof NodeType))
report_error(TypeError.ci_not_node(ci.string_type()));
NodeType cn = (NodeType) ci;
// get the nodes on the axis
ForwardAxis axis = e.iterator();
ResultBuffer rb = new ResultBuffer();
axis.iterate(cn, rb, _dc.getLimitNode());
// get all nodes in the axis, and principal node
Pair arg = new Pair(axis.principal_node_kind().string_type(), rb.getSequence());
// do the name test
_param = arg;
ResultSequence rs = (ResultSequence) e.node_test().accept(this);
return rs;
}
Aggregations