Package com.volantis.xml.expression.sequence

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


            // items
            int size = values.size();
            int i;
            int j;
            ArrayList resultValues = new ArrayList(size);
            Sequence sequence;
            Item[] items;

            for (i = 0;
                 i < size;
                 i++) {
                // Each value could feasibly be a multi-value sequence.
                // Atomic values can always provide a sequence containing just
                // themselves. Thus, it is easiest to get the sequence each
                // time and process its values later
                sequence = asValue(factory, values.get(i)).getSequence();

                // Sequences are not allowed to contain nested sequences, so
                // this must be avoided by "flattening" the sequence of
                // sequences into a single sequence of atomic values. Thus the
                // sequence (atomic) items are individually added to the
                // current resultValues array for later addition into the
                // resulting sequence
                //
                // Sequence indices are in the range [1..n] and not the
                // normal java range of [0..(n - 1)]
                for (j = 1;
                     j <= sequence.getLength();
                     j++) {
                    resultValues.add(sequence.getItem(j));
                }
            }

            // Generate the item array needed to create a sequence from the
            // resultValues
View Full Code Here


    /**
     * Tests that the less than operator works with 2 sequences
     * @throws Exception if an error occurs
     */
    public void testLessThanWithSequencesTrue() throws Exception {
        Sequence first = factory.createSequence(new Item[] {
            factory.createIntValue(1000),
            factory.createIntValue(100),
            factory.createIntValue(1)
        });

        Sequence second = factory.createSequence(new Item[] {
            factory.createIntValue(1),
            factory.createIntValue(2)
        });

        context.getCurrentScope().declareVariable(
View Full Code Here

    /**
     * Test the boolean function with a sequence (of one numeric) argument.
     * @throws Exception if an error occurs
     */
    public void testBooleanNumericSequenceArg() throws Exception {
        Sequence seq = factory.createDoubleValue(1.0).getSequence();
        context.getCurrentScope().declareVariable(
                        new ImmutableExpandedName("", "myVar"),
                        seq);

        Expression exp = compileExpression("boolean($myVar)");
View Full Code Here

                        return factory.createStringValue(buffer.toString());
                    }
                   
                    private void addTo(final StringBuffer buffer, final Value value) {
                      try {
                            Sequence s = value.getSequence();

                            if (s.getLength() != 1) {
                                buffer.append('(');

                                for (int i = 0; i < s.getLength(); i++) {
                                   Item item = s.getItem(i+1);

                                   addTo(buffer, item);
                                   if (i<s.getLength()-1) {
                                       buffer.append(", ");
                                   }
                                }
                                buffer.append(')');
                            } else {
View Full Code Here

        Value result = exp.evaluate(context);
        // result should be an empty sequence
        assertTrue("Result is not a Sequence instance",
                   result instanceof Sequence);

        Sequence sequence = (Sequence) result;

        assertEquals("Sequence is not empty", 0, sequence.getLength());
    }
View Full Code Here

        Value result = exp.evaluate(context);
        // result should be an empty sequence
        assertTrue("Result is not a Sequence instance",
                   result instanceof Sequence);

        Sequence sequence = (Sequence) result;

        assertEquals("Sequence is not empty", 0, sequence.getLength());
    }
View Full Code Here

        Expression exp = compileExpression("('a', (), 'b')");
        Value result = exp.evaluate(context);
        assertTrue("Result is not a Sequence instance",
                   result instanceof Sequence);

        Sequence sequence = (Sequence) result;

        assertEquals("Sequence length is not 2", 2, sequence.getLength());
        assertTrue("First item is not a string", sequence.getItem(1) instanceof StringValue);
        assertTrue("Second item is not a string", sequence.getItem(2) instanceof StringValue);
        assertEquals("First item is not \"a\"", "a", ((StringValue) sequence.getItem(1)).asJavaString());
        assertEquals("Second item is not \"b\"", "b", ((StringValue) sequence.getItem(2)).asJavaString());
    }
View Full Code Here

                " return the empty sequence",
                Sequence.EMPTY,
                intersectFunction.invoke(expressionContextMock, new Value[] {
                        Sequence.EMPTY, Sequence.EMPTY
                }));
        final Sequence firstSequence =
                expressionContextMock.getFactory().createSequence(
                        new Item[] {
                                expressionContextMock.getFactory()
                                        .createStringValue("value0"),
                                expressionContextMock.getFactory()
                                        .createStringValue("value1"),
                                expressionContextMock.getFactory()
                                        .createStringValue("value2"),
                                expressionContextMock.getFactory()
                                        .createBooleanValue(true)});
        final Sequence secondSequence =
                expressionContextMock.getFactory().createSequence(
                        new Item[] {
                                expressionContextMock.getFactory()
                                        .createStringValue("value2"),
                                expressionContextMock.getFactory()
                                        .createStringValue("value2"),
                                expressionContextMock.getFactory()
                                        .createStringValue("value3"),
                                expressionContextMock.getFactory()
                                        .createBooleanValue(false),
                                expressionContextMock.getFactory()
                                        .createBooleanValue(true)});
        final Sequence result = (Sequence) intersectFunction.invoke(
                expressionContextMock, new Value[] {firstSequence,
                        secondSequence});
        assertEquals("number of elements in returned sequence is incorrect",
                2, result.getLength());
        assertEquals("incorrect element in returned sequence",
                "value2", result.getItem(1).stringValue().asJavaString());
        assertEquals("incorrect element in returned sequence",
                "true", result.getItem(2).stringValue().asJavaString());
    }
View Full Code Here

     * Test that the function returns false for an empty sequence.
     */
    public void testEmptySequence() throws Exception {

        // Create an empty sequence.
        Sequence sequence = Sequence.EMPTY;

        Function function = new ExistsFunction();
        Value result =
                function.invoke(expressionContextMock, new Value[] {sequence});
        assertSame(result, BooleanValue.FALSE);
View Full Code Here

     * Test that the function returns true for a non-empty sequence.
     */
    public void testNonEmptySequence() throws Exception {

        // Create a non empty sequence.
        Sequence sequence = factory.createSequence(new Item[] {
            BooleanValue.TRUE
        });

        Function function = new ExistsFunction();
        Value result =
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.