Search in sources :

Example 16 with NodeType

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

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

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

the class DefaultEvaluator method node_cmp.

private ResultSequence node_cmp(int type, Collection args) {
    assert args.size() == 2;
    Iterator argsiter = args.iterator();
    ResultSequence one = (ResultSequence) argsiter.next();
    ResultSequence two = (ResultSequence) argsiter.next();
    int size_one = one.size();
    int size_two = two.size();
    if (size_one > 1 || size_two > 1)
        report_error(TypeError.invalid_type(null));
    if (size_one == 0 || size_two == 0)
        return ResultBuffer.EMPTY;
    Item at_one = one.item(0);
    Item at_two = two.item(0);
    if (!(at_one instanceof NodeType) || !(at_two instanceof NodeType))
        report_error(TypeError.invalid_type(null));
    // ok we got the args finally
    NodeType nt_one = (NodeType) at_one;
    NodeType nt_two = (NodeType) at_two;
    // we are pessimistic as usual
    boolean answer = false;
    // do comparison
    switch(type) {
        case CmpExpr.IS:
            answer = nt_one.node_value() == nt_two.node_value();
            break;
        case CmpExpr.LESS_LESS:
            answer = nt_one.before(nt_two);
            break;
        case CmpExpr.GREATER_GREATER:
            answer = nt_one.after(nt_two);
            break;
        default:
            assert false;
    }
    return XSBoolean.valueOf(answer);
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) 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)

Example 19 with NodeType

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

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

the class DefaultEvaluator method derivesFrom.

private boolean derivesFrom(NodeType at, TypeDefinition td) {
    TypeDefinition nodeTd = _sc.getTypeModel().getType(at.node_value());
    short method = TypeDefinition.DERIVATION_EXTENSION | TypeDefinition.DERIVATION_RESTRICTION;
    return nodeTd != null && nodeTd.derivedFromType(td, method);
}
Also used : TypeDefinition(org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition)

Aggregations

NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)39 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)23 Iterator (java.util.Iterator)21 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)15 Collection (java.util.Collection)12 Node (org.w3c.dom.Node)12 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)11 ListIterator (java.util.ListIterator)10 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)9 ElementType (org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType)9 VarExprPair (org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)7 TypeDefinition (org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition)6 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)5 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)5 ArrayList (java.util.ArrayList)4 Attr (org.w3c.dom.Attr)4 ForwardAxis (org.eclipse.wst.xml.xpath2.processor.internal.ForwardAxis)3 ParentAxis (org.eclipse.wst.xml.xpath2.processor.internal.ParentAxis)3 ReverseAxis (org.eclipse.wst.xml.xpath2.processor.internal.ReverseAxis)3 AttrType (org.eclipse.wst.xml.xpath2.processor.internal.types.AttrType)3