Search in sources :

Example 11 with SirixXPathException

use of org.sirix.exception.SirixXPathException in project sirix by sirixdb.

the class ConXPathAxisTest method testDescendant.

@Test
public void testDescendant() {
    try {
        // Find descendants starting from nodeKey 0L (root).
        holder.getReader().moveToDocumentRoot();
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "/p:a//b"), new long[] { 5L, 9L });
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "//p:a"), new long[] { 1L });
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "descendant-or-self::p:a"), new long[] { 1L });
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "/p:a/descendant-or-self::b"), new long[] { 5L, 9L });
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "p:a/descendant::b"), new long[] { 5L, 9L });
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "p:a/descendant::p:a"), new long[] {});
    } catch (final SirixXPathException mExp) {
        mExp.getStackTrace();
    }
}
Also used : SirixXPathException(org.sirix.exception.SirixXPathException) XPathAxis(org.sirix.service.xml.xpath.XPathAxis) Test(org.junit.Test) AbsAxisTest(org.sirix.axis.AbsAxisTest)

Example 12 with SirixXPathException

use of org.sirix.exception.SirixXPathException in project sirix by sirixdb.

the class ConXPathAxisTest method testDupElemination.

// 
@Test
public void testDupElemination() {
    try {
        // Find descendants starting from nodeKey 0L (root).
        holder.getReader().moveTo(1L);
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "child::node()/parent::node()"), new long[] { 1L });
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "b/c"), new long[] { 7L, 11L });
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "b/text()"), new long[] { 6L, 12L });
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "/p:a/b/c"), new long[] { 7L, 11L });
    } catch (final SirixXPathException mExp) {
        mExp.getStackTrace();
    }
}
Also used : SirixXPathException(org.sirix.exception.SirixXPathException) XPathAxis(org.sirix.service.xml.xpath.XPathAxis) Test(org.junit.Test) AbsAxisTest(org.sirix.axis.AbsAxisTest)

Example 13 with SirixXPathException

use of org.sirix.exception.SirixXPathException in project sirix by sirixdb.

the class ConXPathAxisTest method testSelf.

@Test
public void testSelf() {
    try {
        // Find ancestor starting from nodeKey 8L.
        holder.getReader().moveTo(1L);
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "self::p:a"), new long[] { 1L });
        holder.getReader().moveTo(9L);
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "self::b"), new long[] { 9L });
        holder.getReader().moveTo(11L);
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "./node()"), new long[] {});
        holder.getReader().moveTo(11L);
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "self::node()"), new long[] { 11L });
        holder.getReader().moveTo(1L);
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "./b/node()"), new long[] { 6L, 7L, 11L, 12L });
    } catch (final SirixXPathException mExp) {
        mExp.getStackTrace();
    }
}
Also used : SirixXPathException(org.sirix.exception.SirixXPathException) XPathAxis(org.sirix.service.xml.xpath.XPathAxis) Test(org.junit.Test) AbsAxisTest(org.sirix.axis.AbsAxisTest)

Example 14 with SirixXPathException

use of org.sirix.exception.SirixXPathException in project sirix by sirixdb.

the class AbstractObAxis method hasNext.

/**
 * {@inheritDoc}
 */
@Override
public boolean hasNext() {
    resetToLastKey();
    if (mIsFirst) {
        mIsFirst = false;
        if (mOperand1.hasNext()) {
            mKey = mOperand1.next();
            // atomize operand
            final AtomicValue mItem1 = atomize(mOperand1);
            if (mOperand2.hasNext()) {
                mKey = mOperand2.next();
                // atomize operand
                final AtomicValue mItem2 = atomize(mOperand2);
                try {
                    final AtomicValue result = (AtomicValue) operate(mItem1, mItem2);
                    // add retrieved AtomicValue to item list
                    final int itemKey = getTrx().getItemList().addItem(result);
                    mKey = itemKey;
                    return true;
                } catch (SirixXPathException e) {
                    throw new RuntimeException(e);
                }
            }
        }
        if (XPATH_10_COMP) {
            // and empty sequence, return NaN
            final AtomicValue result = new AtomicValue(Double.NaN, Type.DOUBLE);
            final int itemKey = getTrx().getItemList().addItem(result);
            mKey = itemKey;
            return true;
        }
    }
    // either not the first call, or empty sequence
    resetToStartKey();
    return false;
}
Also used : SirixXPathException(org.sirix.exception.SirixXPathException) AtomicValue(org.sirix.service.xml.xpath.AtomicValue)

Example 15 with SirixXPathException

use of org.sirix.exception.SirixXPathException in project sirix by sirixdb.

the class NodeCompTest method testAtomize.

@Test
public void testAtomize() throws SirixXPathException {
    Axis axis = new LiteralExpr(holder.getReader(), -2);
    axis.hasNext();
    axis.next();
    AtomicValue[] value = comparator.atomize(axis);
    assertEquals(value.length, 1);
    assertEquals(holder.getReader().getNodeKey(), value[0].getNodeKey());
    assertEquals("xs:integer", value[0].getType());
    try {
        axis = new DescendantAxis(holder.getReader());
        axis.hasNext();
        comparator.atomize(axis);
    } catch (SirixXPathException e) {
        assertEquals("err:XPTY0004 The type is not appropriate the expression or" + " the typedoes not match a required type as specified by the " + "matching rules.", e.getMessage());
    }
}
Also used : SirixXPathException(org.sirix.exception.SirixXPathException) LiteralExpr(org.sirix.service.xml.xpath.expr.LiteralExpr) AtomicValue(org.sirix.service.xml.xpath.AtomicValue) DescendantAxis(org.sirix.axis.DescendantAxis) Axis(org.sirix.api.Axis) DescendantAxis(org.sirix.axis.DescendantAxis) Test(org.junit.Test)

Aggregations

SirixXPathException (org.sirix.exception.SirixXPathException)16 Test (org.junit.Test)14 AbsAxisTest (org.sirix.axis.AbsAxisTest)12 XPathAxis (org.sirix.service.xml.xpath.XPathAxis)12 AtomicValue (org.sirix.service.xml.xpath.AtomicValue)3 LiteralExpr (org.sirix.service.xml.xpath.expr.LiteralExpr)2 Axis (org.sirix.api.Axis)1 DescendantAxis (org.sirix.axis.DescendantAxis)1 AbstractAxis (org.sirix.service.xml.xpath.AbstractAxis)1 SequenceAxis (org.sirix.service.xml.xpath.expr.SequenceAxis)1