Search in sources :

Example 51 with QName

use of org.eclipse.wst.xml.xpath2.processor.internal.types.QName in project webtools.sourceediting by eclipse.

the class DefaultEvaluator method visit.

/**
 * visit element test.
 *
 * @param e
 *            is the element test.
 * @return a result sequence
 */
public Object visit(ElementTest e) {
    // filter out all elements
    ResultSequence rs = kind_test((ResultSequence) ((Pair) _param)._two, ElementType.class);
    // match the name if it's not a wild card
    ResultBuffer rb = new ResultBuffer();
    QName nameTest = e.name();
    QName typeTest = e.type();
    for (Iterator i = rs.iterator(); i.hasNext(); ) {
        NodeType node = (NodeType) i.next();
        if (nameTest != null && !e.wild()) {
            // skip if there's a name test and the name does not match
            if (!name_test((ElementType) node, nameTest, "element"))
                continue;
        }
        if (typeTest != null) {
            // check if element derives from
            if (!derivesFrom(node, typeTest))
                continue;
            // nilled may be true or false
            if (!e.qmark()) {
                XSBoolean nilled = (XSBoolean) node.nilled().first();
                if (nilled.value())
                    continue;
            }
        }
        rb.add(node);
    }
    ((Pair) _param)._two = rb.getSequence();
    return ((Pair) _param)._two;
}
Also used : ElementType(org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType) 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) XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean) 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 52 with QName

use of org.eclipse.wst.xml.xpath2.processor.internal.types.QName in project webtools.sourceediting by eclipse.

the class DefaultEvaluator method visit.

/**
 * visit schema attribute test.
 *
 * @param e
 *            is the schema attribute test.
 * @return a result sequence
 */
public Object visit(SchemaAttrTest e) {
    // filter out all attrs
    ResultSequence rs = kind_test((ResultSequence) ((Pair) _param)._two, AttrType.class);
    // match the name
    QName name = e.arg();
    for (Iterator i = rs.iterator(); i.hasNext(); ) {
        if (!name_test((NodeType) i.next(), name, "attribute"))
            i.remove();
    }
    // check the type
    TypeDefinition et = _sc.getTypeModel().lookupAttributeDeclaration(name.namespace(), name.local());
    for (Iterator i = rs.iterator(); i.hasNext(); ) {
        NodeType node = (NodeType) i.next();
        if (!derivesFrom(node, et))
            i.remove();
    }
    return rs;
}
Also used : 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) TypeDefinition(org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition)

Example 53 with QName

use of org.eclipse.wst.xml.xpath2.processor.internal.types.QName in project webtools.sourceediting by eclipse.

the class DefaultEvaluator method do_exists.

private XSBoolean do_exists(ListIterator iter, Expr finalexpr) {
    // we have more vars to bind...
    if (iter.hasNext()) {
        VarExprPair ve = (VarExprPair) iter.next();
        // evaluate binding sequence
        ResultSequence rs = (ResultSequence) ve.expr().accept(this);
        QName varname = ve.varname();
        try {
            for (Iterator i = rs.iterator(); i.hasNext(); ) {
                AnyType item = (AnyType) i.next();
                pushScope(varname, item);
                XSBoolean effbool = do_exists(iter, finalexpr);
                popScope();
                // out what to do with it
                if (effbool.value())
                    return XSBoolean.TRUE;
            }
        } finally {
            iter.previous();
        }
        // since none in this sequence evaluated to true, return false
        return XSBoolean.FALSE;
    } else // we finally got to do the "last expression"
    {
        return effective_boolean_value((ResultSequence) finalexpr.accept(this));
    }
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean) 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 54 with QName

use of org.eclipse.wst.xml.xpath2.processor.internal.types.QName 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 55 with QName

use of org.eclipse.wst.xml.xpath2.processor.internal.types.QName in project webtools.sourceediting by eclipse.

the class DefaultEvaluator method visit.

/**
 * visit cast expression
 *
 * @param cexp
 *            is the cast expression.
 * @return a new function
 */
public Object visit(CastExpr cexp) {
    ResultSequence rs = (ResultSequence) cexp.left().accept(this);
    SingleType st = (SingleType) cexp.right();
    rs = FnData.atomize(rs);
    if (rs.size() > 1)
        report_error(TypeError.invalid_type(null));
    if (rs.empty()) {
        if (st.qmark())
            return rs;
        else
            report_error(TypeError.invalid_type(null));
    }
    AnyType at = (AnyType) rs.item(0);
    if (!(at instanceof AnyAtomicType))
        report_error(TypeError.invalid_type(null));
    AnyAtomicType aat = (AnyAtomicType) at;
    QName type = st.type();
    // prepare args from function
    Collection args = new ArrayList();
    args.add(ResultSequenceFactory.create_new(aat));
    try {
        Function function = cexp.function();
        if (function == null) {
            function = _sc.resolveFunction(type.asQName(), args.size());
            cexp.set_function(function);
        }
        if (function == null)
            report_error(TypeError.invalid_type(null));
        return function.evaluate(args, _ec);
    } catch (DynamicError err) {
        report_error(err);
        // unreach
        return null;
    }
}
Also used : Function(org.eclipse.wst.xml.xpath2.api.Function) SingleType(org.eclipse.wst.xml.xpath2.processor.internal.ast.SingleType) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) ArrayList(java.util.ArrayList) Collection(java.util.Collection) AnyAtomicType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Aggregations

DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)77 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)77 URL (java.net.URL)76 XSModel (org.apache.xerces.xs.XSModel)76 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)76 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)76 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)42 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)21 Iterator (java.util.Iterator)18 Collection (java.util.Collection)17 ArrayList (java.util.ArrayList)13 VarExprPair (org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)11 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)10 NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)10 ListIterator (java.util.ListIterator)9 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)9 XPathExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr)6 TypeDefinition (org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition)5 SeqType (org.eclipse.wst.xml.xpath2.processor.internal.SeqType)5 Schema (javax.xml.validation.Schema)4