Search in sources :

Example 51 with ResultBuffer

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

the class OpIntersect method op_intersect.

/**
 * Op-Intersect operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of operation.
 */
public static ResultSequence op_intersect(Collection args) throws DynamicError {
    ResultBuffer rs = new ResultBuffer();
    // convert arguments
    Collection cargs = Function.convert_arguments(args, expected_args());
    // get arguments
    Iterator iter = cargs.iterator();
    ResultSequence one = (ResultSequence) iter.next();
    ResultSequence two = (ResultSequence) iter.next();
    // XXX lame
    for (Iterator i = one.iterator(); i.hasNext(); ) {
        NodeType node = (NodeType) i.next();
        boolean found = false;
        // death
        for (Iterator j = two.iterator(); j.hasNext(); ) {
            NodeType node2 = (NodeType) j.next();
            if (node.node_value() == node2.node_value()) {
                found = true;
                break;
            }
        }
        if (found)
            rs.add(node);
    }
    rs = NodeType.linarize(rs);
    return rs.getSequence();
}
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) Iterator(java.util.Iterator) Collection(java.util.Collection)

Example 52 with ResultBuffer

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

the class FsConvertOperand method convert_operand.

/**
 * Convert-Operand operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fs: operation.
 */
public static ResultSequence convert_operand(Collection args) throws DynamicError {
    assert args.size() == 2;
    Iterator iter = args.iterator();
    ResultSequence actual = (ResultSequence) iter.next();
    ResultSequence expected = (ResultSequence) iter.next();
    if (expected.size() != 1)
        DynamicError.throw_type_error();
    Item at = expected.first();
    if (!(at instanceof AnyAtomicType))
        DynamicError.throw_type_error();
    AnyAtomicType exp_aat = (AnyAtomicType) at;
    ResultBuffer result = new ResultBuffer();
    // 1
    if (actual.empty())
        return result.getSequence();
    // convert sequence
    for (Iterator i = actual.iterator(); i.hasNext(); ) {
        AnyType item = (AnyType) i.next();
        // 2
        if (item instanceof XSUntypedAtomic) {
            // a
            if (exp_aat instanceof XSUntypedAtomic)
                result.add(new XSString(item.getStringValue()));
            else // b
            if (exp_aat instanceof NumericType)
                result.add(new XSDouble(item.getStringValue()));
            else // c
            {
                assert exp_aat instanceof CtrType;
                CtrType cons = (CtrType) exp_aat;
                result.concat(cons.constructor(new XSString(item.getStringValue())));
            }
        } else
            // 4
            result.add(item);
    }
    return result.getSequence();
}
Also used : NumericType(org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType) Item(org.eclipse.wst.xml.xpath2.api.Item) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) XSDouble(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) CtrType(org.eclipse.wst.xml.xpath2.processor.internal.types.CtrType) AnyAtomicType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSUntypedAtomic(org.eclipse.wst.xml.xpath2.processor.internal.types.XSUntypedAtomic) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

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