Search in sources :

Example 26 with ResultBuffer

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

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

the class DefaultEvaluator method visit.

/**
 * visit for expression
 *
 * @param fex
 *            is the for expression.
 * @return a new function.
 */
public Object visit(ForExpr fex) {
    // XXX
    List pairs = new ArrayList(fex.ve_pairs());
    ResultBuffer rb = new ResultBuffer();
    do_for_each(pairs.listIterator(), fex.expr(), rb);
    return rb.getSequence();
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) NodeList(org.w3c.dom.NodeList)

Example 28 with ResultBuffer

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

the class DefaultEvaluator method visit.

/**
 * visit attribute test.
 *
 * @param e
 *            is the attribute test.
 * @return a result sequence
 */
public Object visit(AttributeTest e) {
    // filter out all attrs
    ResultSequence rs = kind_test((ResultSequence) ((Pair) _param)._two, AttrType.class);
    ResultBuffer rb = new ResultBuffer();
    QName name = e.name();
    QName type = e.type();
    for (Iterator i = rs.iterator(); i.hasNext(); ) {
        NodeType node = (NodeType) i.next();
        // match the name if it's not a wild card
        if (name != null && !e.wild()) {
            if (!name_test(node, name, "attribute"))
                continue;
        }
        // match the type
        if (type != null) {
            // check if element derives from
            if (!derivesFrom(node, type))
                continue;
        }
        rb.add(node);
    }
    ((Pair) _param)._two = rb.getSequence();
    return ((Pair) _param)._two;
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) 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 29 with ResultBuffer

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

the class DefaultEvaluator method visit.

/**
 * visit PI test.
 *
 * @param e
 *            is the PI test.
 * @return a argument
 */
public Object visit(PITest e) {
    ResultSequence arg = (ResultSequence) ((Pair) _param)._two;
    String pit_arg = e.arg();
    // match any pi
    if (pit_arg == null)
        return kind_test(arg, PIType.class);
    ResultBuffer rb = new ResultBuffer();
    for (Iterator i = arg.iterator(); i.hasNext(); ) {
        AnyType item = (AnyType) i.next();
        // match PI
        if (item instanceof PIType) {
            PIType pi = (PIType) item;
            // match target
            if (pit_arg.equals(pi.value().getTarget()))
                rb.add(pi);
        }
    }
    arg = rb.getSequence();
    ((Pair) _param)._two = arg;
    return arg;
}
Also used : PIType(org.eclipse.wst.xml.xpath2.processor.internal.types.PIType) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 30 with ResultBuffer

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

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