Package com.volantis.xml.expression.sequence

Examples of com.volantis.xml.expression.sequence.Sequence


     */
    public void testEmptySearch() throws Exception {
        ExpressionContext context = createExpressionContext();
        ExpressionFactory factory = context.getFactory();
        Function indexOf = new IndexOfFunction();
        Sequence sequence = createStringSequence(factory,
                new String[]{"abc", "abc", "abc", "abc", "abc"});
        Value search = factory.createStringValue("");
        Value retVal = indexOf.invoke(context, new Value[]{sequence, search});

        final Sequence retSeq = retVal.getSequence();

        // Should have returned ()
        assertSame(retSeq, Sequence.EMPTY);
    }
View Full Code Here


     */
    public void testEmptySequence() throws Exception {
        ExpressionContext context = createExpressionContext();
        ExpressionFactory factory = context.getFactory();
        Function indexOf = new IndexOfFunction();
        Sequence sequence = createStringSequence(factory, null);
        Value search = factory.createStringValue("peter");
        Value retVal = indexOf.invoke(context, new Value[]{sequence, search});

        final Sequence retSeq = retVal.getSequence();

        // Should have returned ()
        assertSame(retSeq, Sequence.EMPTY);
    }
View Full Code Here

     */
    public void testEmptySequenceEmptySearch() throws Exception {
        ExpressionContext context = createExpressionContext();
        ExpressionFactory factory = context.getFactory();
        Function indexOf = new IndexOfFunction();
        Sequence sequence = createStringSequence(factory, null);
        Value search = factory.createStringValue("");
        Value retVal = indexOf.invoke(context, new Value[]{sequence, search});

        final Sequence retSeq = retVal.getSequence();

        // Should have returned ()
        assertSame(retSeq, Sequence.EMPTY);
    }
View Full Code Here

     */
    public void testIntegerSequence() throws Exception {
        ExpressionContext context = createExpressionContext();
        ExpressionFactory factory = context.getFactory();
        Function indexOf = new IndexOfFunction();
        Sequence sequence = createIntegerSequence(factory,
                new int[]{15, 40, 25, 40, 10});
        Value search = factory.createIntValue(40);
        Value retVal = indexOf.invoke(context, new Value[]{sequence, search});

        final Sequence retSeq = retVal.getSequence();

        // Should have returned (2, 4)
        assertTrue(retSeq.getLength() == 2);
        assertTrue(((IntValue) retSeq.getItem(1)).asJavaInt() == 2);
        assertTrue(((IntValue) retSeq.getItem(2)).asJavaInt() == 4);
    }
View Full Code Here

            // evaluate the current operand
            operandEval = args[i].computeValue(evalContext);

            try {
                // convert the result to a sequence
                Sequence sequence = JXPathExpression.asValue(
                        factory, operandEval).getSequence();

                // convert the sequence to the "effective boolean value"
                eval = PipelineExpressionHelper.fnBoolean(sequence);
            } catch (ExpressionException e) {
View Full Code Here

        // evaluate this functions argument
        Object operand = getArg1().computeValue(context);

        try {
            // convert the operand to a sequence
            Sequence sequence =
                    JXPathExpression.asValue(factory, operand).getSequence();
            return PipelineExpressionHelper.fnNumber(sequence, factory);
        } catch (ExpressionException e) {
            // Tunnel the exception out in a JXPath runtime exception
            throw new JXPathException(
View Full Code Here

        // evaluate this functions argument
        Object operand = getArg1().computeValue(context);

        try {
            // convert the operand to a sequence
            Sequence sequence =
                    JXPathExpression.asValue(factory, operand).getSequence();
            return PipelineExpressionHelper.fnNot(sequence);
        } catch (ExpressionException e) {
            // Tunnel the exception out in a JXPath runtime exception
            throw new JXPathException(
View Full Code Here

        // evaluate this functions argument
        Object operand = getArg1().computeValue(context);

        try {
            // convert the operand to a sequence
            Sequence sequence =
                    JXPathExpression.asValue(factory, operand).getSequence();
            return PipelineExpressionHelper.fnBoolean(sequence);
        } catch (ExpressionException e) {
            // Tunnel the exception out in a JXPath runtime exception
            throw new JXPathException(
View Full Code Here

        }

        // use a string buffer to perform the concatenation
        StringBuffer buffer = new StringBuffer();
        Expression[] operands = getArguments();
        Sequence sequence;
        try {
            for (int i = 0; i < operands.length; i++) {

                // evaluate the operand and convert it to a sequence
                sequence = JXPathExpression.asValue(
                        factory,
                        operands[i].computeValue(context)).getSequence();

                int length = sequence.getLength();
                // 1) If sequence is empty then we append the empty string.
                // 2) If sequence has one item we convert the item to a string
                //    and append to the buffer
                // 3) If sequence contains more that one item we raise an error
                if (length == 1) {
                    buffer.append(
                            sequence.getItem(1).stringValue().asJavaString());
                } else if (length > 1) {
                    throw new JXPathException(
                            "fn:concat cannot accept a sequence operand " +
                            "with more than one item");
                }
View Full Code Here

        // The iterator that is returned.
        EndElementAction action;

        // Evaluate the in expression to a sequence.
        String inExpression = attributes.getValue("in");
        final Sequence sequence = evaluateExpression(expressionContext, inExpression);
        int length = sequence.getLength();
        if (length == 0) {
            // The sequence is empty so there is nothing to do so just skip
            // the body and do not create an iterator.
            context.getFlowControlManager().exitCurrentElement();
            action = EndElementAction.DO_NOTHING;
        } else {

            // Resolve the variable name into an ExpandedName, if the variable
            // name does not have a prefix then it belongs in no namespace,
            // rather than the default namespace.
            String variableName = attributes.getValue("variable");
            QName variableQName = new ImmutableQName(variableName);
            final ExpandedName variableExpandedName =
                    context.getNamespacePrefixTracker()
                    .resolveQName(variableQName, null);

            // If the sequence only has a single value in then it is not
            // necessary to store the body away to be evaluated multiple times.
            if (length == 1) {

                // Create a new block scope to contain the variable.
                expressionContext.pushBlockScope();

                // Create a variable in the current stack frame.
                try {
                    expressionContext.getCurrentScope()
                            .declareVariable(variableExpandedName,
                                    sequence.getItem(1));
                } catch (SequenceIndexOutOfBoundsException e) {
                    throw new ExtendedSAXException(e);
                }

                // Remember to pop the block scope off after the content has
View Full Code Here

TOP

Related Classes of com.volantis.xml.expression.sequence.Sequence

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.