Search in sources :

Example 81 with Item

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

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

Example 83 with Item

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

the class DefaultEvaluator method visit.

/**
 * visit item type.
 *
 * @param e
 *            is the item type.
 * @return null
 */
public Object visit(ItemType e) {
    switch(e.type()) {
        case ItemType.ITEM:
            break;
        case ItemType.QNAME:
            boolean ok = false;
            TypeModel model = _sc.getTypeModel();
            if (model != null) {
                ok = _sc.getTypeModel().lookupType(e.qname().namespace(), e.qname().local()) != null;
            }
            if (!ok) {
                ok = BuiltinTypeLibrary.BUILTIN_TYPES.lookupType(e.qname().namespace(), e.qname().local()) != null;
            }
            if (!ok)
                report_error(new StaticTypeNameError("Type not defined: " + e.qname().string()));
            ResultSequence arg = (ResultSequence) ((Pair) _param)._two;
            ((Pair) _param)._two = item_test(arg, e.qname());
            break;
        case ItemType.KINDTEST:
            ((Pair) _param)._two = e.kind_test().accept(this);
            break;
    }
    return null;
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) TypeModel(org.eclipse.wst.xml.xpath2.api.typesystem.TypeModel) StaticTypeNameError(org.eclipse.wst.xml.xpath2.processor.internal.StaticTypeNameError)

Example 84 with Item

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

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

Aggregations

DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)71 Item (org.eclipse.wst.xml.xpath2.api.Item)69 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)66 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)65 URL (java.net.URL)64 XSModel (org.apache.xerces.xs.XSModel)64 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)64 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)46 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)34 Iterator (java.util.Iterator)26 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)14 BigInteger (java.math.BigInteger)13 Collection (java.util.Collection)13 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)11 ListIterator (java.util.ListIterator)8 NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)8 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)6 NumericType (org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType)5 ArrayList (java.util.ArrayList)4 GregorianCalendar (java.util.GregorianCalendar)4