Search in sources :

Example 21 with ResultBuffer

use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.

the class DefaultEvaluator method descendant_or_self_node.

private ResultSequence descendant_or_self_node(ResultSequence rs) {
    ResultBuffer res = new ResultBuffer();
    Axis axis = new DescendantOrSelfAxis();
    // for all nodes, get descendant or self nodes
    for (Iterator i = rs.iterator(); i.hasNext(); ) {
        NodeType item = (NodeType) i.next();
        axis.iterate(item, res, _dc.getLimitNode());
    }
    return res.getSequence();
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) ParentAxis(org.eclipse.wst.xml.xpath2.processor.internal.ParentAxis) SelfAxis(org.eclipse.wst.xml.xpath2.processor.internal.SelfAxis) ReverseAxis(org.eclipse.wst.xml.xpath2.processor.internal.ReverseAxis) DescendantOrSelfAxis(org.eclipse.wst.xml.xpath2.processor.internal.DescendantOrSelfAxis) ForwardAxis(org.eclipse.wst.xml.xpath2.processor.internal.ForwardAxis) Axis(org.eclipse.wst.xml.xpath2.processor.internal.Axis) DescendantOrSelfAxis(org.eclipse.wst.xml.xpath2.processor.internal.DescendantOrSelfAxis)

Example 22 with ResultBuffer

use of org.eclipse.wst.xml.xpath2.api.ResultBuffer 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;
}
Also used : QuantifiedExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.QuantifiedExpr) IfExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.IfExpr) OrExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.OrExpr) TreatAsExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.TreatAsExpr) ForExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ForExpr) ParExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ParExpr) DivExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.DivExpr) SubExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.SubExpr) CastExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CastExpr) RangeExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.RangeExpr) InstOfExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.InstOfExpr) IntersectExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.IntersectExpr) IDivExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.IDivExpr) AddExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.AddExpr) CmpExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CmpExpr) PipeExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.PipeExpr) BinExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.BinExpr) MulExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.MulExpr) XPathExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr) Expr(org.eclipse.wst.xml.xpath2.processor.internal.ast.Expr) MinusExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.MinusExpr) FilterExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.FilterExpr) CastableExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CastableExpr) PlusExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.PlusExpr) AndExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.AndExpr) StepExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.StepExpr) CntxItemExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CntxItemExpr) ExceptExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ExceptExpr) UnionExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.UnionExpr) ModExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ModExpr) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence)

Example 23 with ResultBuffer

use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.

the class DefaultEvaluator method visit.

/**
 * visit a name test expression
 *
 * @param e
 *            is thename test.
 * @return a result sequence
 */
public Object visit(NameTest e) {
    QName name = e.name();
    // get the arguments
    Pair arg = (Pair) _param;
    String type = (String) arg._one;
    ResultSequence rs = (ResultSequence) arg._two;
    ResultBuffer rb = new ResultBuffer();
    for (Iterator i = rs.iterator(); i.hasNext(); ) {
        NodeType nt = (NodeType) i.next();
        // check if node passes name test
        if (name_test(nt, name, type))
            rb.add(nt);
    }
    rs = rb.getSequence();
    arg._two = rs;
    return rs;
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) VarExprPair(org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)

Example 24 with ResultBuffer

use of org.eclipse.wst.xml.xpath2.api.ResultBuffer 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 25 with ResultBuffer

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

Aggregations

ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)40 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)31 Iterator (java.util.Iterator)26 NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)20 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)12 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)11 ElementType (org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType)10 ArrayList (java.util.ArrayList)9 Collection (java.util.Collection)9 Item (org.eclipse.wst.xml.xpath2.api.Item)8 Node (org.w3c.dom.Node)8 ListIterator (java.util.ListIterator)7 VarExprPair (org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)6 AnyAtomicType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType)5 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)5 NodeList (org.w3c.dom.NodeList)5 List (java.util.List)4 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)4 NumericType (org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType)4 XSInteger (org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger)4