Search in sources :

Example 6 with Step

use of org.eclipse.wst.xml.xpath2.processor.internal.ast.Step 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();
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) Focus(org.eclipse.wst.xml.xpath2.processor.internal.Focus) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) ArrayList(java.util.ArrayList) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) AnyAtomicType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 7 with Step

use of org.eclipse.wst.xml.xpath2.processor.internal.ast.Step 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;
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) ParentAxis(org.eclipse.wst.xml.xpath2.processor.internal.ParentAxis) ReverseAxis(org.eclipse.wst.xml.xpath2.processor.internal.ReverseAxis) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType) VarExprPair(org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)

Example 8 with Step

use of org.eclipse.wst.xml.xpath2.processor.internal.ast.Step 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;
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType) ForwardAxis(org.eclipse.wst.xml.xpath2.processor.internal.ForwardAxis) VarExprPair(org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)

Example 9 with Step

use of org.eclipse.wst.xml.xpath2.processor.internal.ast.Step 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;
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Focus(org.eclipse.wst.xml.xpath2.processor.internal.Focus) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) Collection(java.util.Collection)

Example 10 with Step

use of org.eclipse.wst.xml.xpath2.processor.internal.ast.Step in project webtools.sourceediting by eclipse.

the class StaticNameResolver method visit.

/**
 * Validate a reverse step.
 *
 * @param e
 *            is the expression.
 * @return null.
 */
public Object visit(ReverseStep e) {
    NodeTest nt = e.node_test();
    if (nt != null)
        nt.accept(this);
    ReverseAxis iterator = e.iterator();
    if (iterator != null)
        _axes.add(iterator.name());
    return null;
}
Also used : ReverseAxis(org.eclipse.wst.xml.xpath2.processor.internal.ReverseAxis) NodeTest(org.eclipse.wst.xml.xpath2.processor.internal.ast.NodeTest)

Aggregations

ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)5 AxisStep (org.eclipse.wst.xml.xpath2.processor.internal.ast.AxisStep)4 ForwardStep (org.eclipse.wst.xml.xpath2.processor.internal.ast.ForwardStep)4 ReverseStep (org.eclipse.wst.xml.xpath2.processor.internal.ast.ReverseStep)4 Step (org.eclipse.wst.xml.xpath2.processor.internal.ast.Step)4 XPathExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr)4 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)4 NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)4 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3 ListIterator (java.util.ListIterator)3 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)3 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)3 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)3 Focus (org.eclipse.wst.xml.xpath2.processor.internal.Focus)3 AnyKindTest (org.eclipse.wst.xml.xpath2.processor.internal.ast.AnyKindTest)3 StepExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.StepExpr)3 URL (java.net.URL)2 Collection (java.util.Collection)2 XSModel (org.apache.xerces.xs.XSModel)2