Search in sources :

Example 16 with AtomicValue

use of org.sirix.service.xml.xpath.AtomicValue in project sirix by sirixdb.

the class Function method fnNodeName.

/**
 * <p>
 * fn:node-name($arg as node()?) as xs:QName?
 * </p>
 * <p>
 * Returns an expanded-QName for node kinds that can have names. For other kinds of nodes it
 * returns the empty sequence. If $arg is the empty sequence, the empty sequence is returned.
 * <p>
 *
 * @param rtx the transaction to operate on
 * @param axis The sequence, containing the node, to return its QName
 * @return true, if node has a name
 */
public static boolean fnNodeName(final XdmNodeReadTrx rtx, final AbstractAxis axis) {
    if (axis.hasNext()) {
        final String name = rtx.getName().getLocalName();
        if (!name.equals("-1")) {
            final int itemKey = rtx.getItemList().addItem(new AtomicValue(name, Type.STRING));
            rtx.moveTo(itemKey);
            return true;
        }
    }
    // TODO: check if -1 really is the null-name-key
    return false;
}
Also used : AtomicValue(org.sirix.service.xml.xpath.AtomicValue)

Example 17 with AtomicValue

use of org.sirix.service.xml.xpath.AtomicValue in project sirix by sirixdb.

the class Function method fnBoolean.

/**
 * <p>
 * The effective boolean value of a value is defined as the result of applying the fn:boolean
 * function to the value, as defined in [XQuery 1.0 and XPath 2.0 Functions and Operators].]
 * </p>
 * <p>
 * <li>If its operand is an empty sequence, fn:boolean returns false.</li>
 * <li>If its operand is a sequence whose first item is a node, fn:boolean returns true.</li>
 * <li>If its operand is a singleton value of type xs:boolean or derived from xs:boolean,
 * fn:boolean returns the value of its operand unchanged.</li>
 * <li>If its operand is a singleton value of type xs:string, xs:anyURI, xs:untypedAtomic, or a
 * type derived from one of these, fn:boolean returns false if the operand value has zero length;
 * otherwise it returns true.</li>
 * <li>If its operand is a singleton value of any numeric type or derived from a numeric type,
 * fn:boolean returns false if the operand value is NaN or is numerically equal to zero; otherwise
 * it returns true.</li>
 * <li>In all other cases, fn:boolean raises a type error [err:FORG0006].</li>
 * </p>
 *
 * @param rtx the transaction to operate on.
 * @param axis Expression to get the effective boolean value for
 * @return true if sucessfull, false otherwise
 * @throws SirixXPathException
 */
public static boolean fnBoolean(final XdmNodeReadTrx rtx, final AbstractAxis axis) throws SirixXPathException {
    final boolean ebv = ebv(axis);
    final int itemKey = rtx.getItemList().addItem(new AtomicValue(ebv));
    rtx.moveTo(itemKey);
    return true;
}
Also used : AtomicValue(org.sirix.service.xml.xpath.AtomicValue)

Example 18 with AtomicValue

use of org.sirix.service.xml.xpath.AtomicValue in project sirix by sirixdb.

the class RangeAxis method hasNext.

/**
 * {@inheritDoc}
 */
@Override
public boolean hasNext() {
    resetToLastKey();
    if (mFirst) {
        mFirst = false;
        if (mFrom.hasNext() && Type.getType(mFrom.getTrx().getTypeKey()).derivesFrom(Type.INTEGER)) {
            mStart = Integer.parseInt(mFrom.getTrx().getValue());
            if (mTo.hasNext() && Type.getType(mTo.getTrx().getTypeKey()).derivesFrom(Type.INTEGER)) {
                mEnd = Integer.parseInt(mTo.getTrx().getValue());
            } else {
                // at least one operand is the empty sequence
                resetToStartKey();
                return false;
            }
        } else {
            // at least one operand is the empty sequence
            resetToStartKey();
            return false;
        }
    }
    if (mStart <= mEnd) {
        final int itemKey = getTrx().getItemList().addItem(new AtomicValue(TypedValue.getBytes(Integer.toString(mStart)), getTrx().keyForName("xs:integer")));
        mKey = itemKey;
        mStart++;
        return true;
    } else {
        resetToStartKey();
        return false;
    }
}
Also used : AtomicValue(org.sirix.service.xml.xpath.AtomicValue)

Example 19 with AtomicValue

use of org.sirix.service.xml.xpath.AtomicValue in project sirix by sirixdb.

the class SomeExpr method evaluate.

@Override
public void evaluate() {
    boolean satisfiesCond = false;
    for (final Axis axis : mVars) {
        while (axis.hasNext()) {
            mKey = axis.next();
            mSatisfy.reset(mKey);
            if (mSatisfy.hasNext()) {
                mKey = mSatisfy.next();
                // condition is satisfied for this item -> expression is
                // true
                satisfiesCond = true;
                break;
            }
        }
    }
    final int itemKey = getTrx().getItemList().addItem(new AtomicValue(TypedValue.getBytes(Boolean.toString(satisfiesCond)), getTrx().keyForName("xs:boolean")));
    mKey = itemKey;
}
Also used : AtomicValue(org.sirix.service.xml.xpath.AtomicValue) Axis(org.sirix.api.Axis)

Example 20 with AtomicValue

use of org.sirix.service.xml.xpath.AtomicValue in project sirix by sirixdb.

the class LiteralExprTest method testLiteralExpr.

@Test
public void testLiteralExpr() throws SirixException {
    // Build simple test tree.
    final AtomicValue item1 = new AtomicValue(false);
    final AtomicValue item2 = new AtomicValue(14, Type.INTEGER);
    final int key1 = holder.getReader().getItemList().addItem(item1);
    final int key2 = holder.getReader().getItemList().addItem(item2);
    final AbstractAxis axis1 = new LiteralExpr(holder.getReader(), key1);
    assertEquals(true, axis1.hasNext());
    axis1.next();
    assertEquals(key1, holder.getReader().getNodeKey());
    assertEquals(holder.getReader().keyForName("xs:boolean"), holder.getReader().getTypeKey());
    assertEquals(false, Boolean.parseBoolean(holder.getReader().getValue()));
    assertEquals(false, axis1.hasNext());
    final AbstractAxis axis2 = new LiteralExpr(holder.getReader(), key2);
    assertEquals(true, axis2.hasNext());
    axis2.next();
    assertEquals(key2, holder.getReader().getNodeKey());
    assertEquals(holder.getReader().keyForName("xs:integer"), holder.getReader().getTypeKey());
    assertEquals(14, Integer.parseInt(holder.getReader().getValue()));
    assertEquals(false, axis2.hasNext());
}
Also used : AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) AtomicValue(org.sirix.service.xml.xpath.AtomicValue) Test(org.junit.Test)

Aggregations

AtomicValue (org.sirix.service.xml.xpath.AtomicValue)47 Test (org.junit.Test)12 AbstractAxis (org.sirix.service.xml.xpath.AbstractAxis)10 LiteralExpr (org.sirix.service.xml.xpath.expr.LiteralExpr)10 Type (org.sirix.service.xml.xpath.types.Type)7 XPathError (org.sirix.service.xml.xpath.XPathError)6 ErrorType (org.sirix.service.xml.xpath.XPathError.ErrorType)6 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)4 Axis (org.sirix.api.Axis)3 SirixXPathException (org.sirix.exception.SirixXPathException)3 ArrayList (java.util.ArrayList)1 DescendantAxis (org.sirix.axis.DescendantAxis)1 SingleType (org.sirix.service.xml.xpath.SingleType)1