Search in sources :

Example 36 with AtomicValue

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

the class Function method fnNilled.

/**
 * <p>
 * fn:nilled($arg as node()?) as xs:boolean?
 * </p>
 * <p>
 * Returns an xs:boolean indicating whether the argument node is "nilled". If the argument is not
 * an element node, returns the empty sequence. If the argument is the empty sequence, returns the
 * empty sequence.
 * </p>
 *
 * @param rtx the transaction to operate on
 * @param axis The sequence containing the node to test its nilled property
 * @return true, if current item is a node that has the nilled property (only elements)
 */
public static boolean fnNilled(final XdmNodeReadTrx rtx, final AbstractAxis axis) {
    if (axis.hasNext() && rtx.getKind() == Kind.ELEMENT) {
        // TODO how is the nilled property
        final boolean nilled = false;
        // defined?
        final int itemKey = rtx.getItemList().addItem(new AtomicValue(nilled));
        rtx.moveTo(itemKey);
        return true;
    }
    // empty sequence
    return false;
}
Also used : AtomicValue(org.sirix.service.xml.xpath.AtomicValue)

Example 37 with AtomicValue

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

the class Function method zeroOrOne.

public static boolean zeroOrOne(final XdmNodeReadTrx rtx, final AbstractAxis axis) throws SirixXPathException {
    final boolean result = true;
    if (axis.hasNext() && axis.hasNext()) {
        // more than one result
        throw EXPathError.FORG0003.getEncapsulatedException();
    }
    final int itemKey = rtx.getItemList().addItem(new AtomicValue(result));
    rtx.moveTo(itemKey);
    return true;
}
Also used : AtomicValue(org.sirix.service.xml.xpath.AtomicValue)

Example 38 with AtomicValue

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

the class Function method fnnot.

public static boolean fnnot(final XdmNodeReadTrx rtx, final AbstractAxis axis) {
    if (axis.hasNext()) {
        axis.next();
        final AtomicValue item = new AtomicValue(rtx.getRawValue()[0] == 0);
        final int itemKey = rtx.getItemList().addItem(item);
        rtx.moveTo(itemKey);
        return true;
    } else {
        return false;
    }
}
Also used : AtomicValue(org.sirix.service.xml.xpath.AtomicValue)

Example 39 with AtomicValue

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

the class CastableExpr method evaluate.

/**
 * {@inheritDoc}
 */
@Override
public void evaluate() throws SirixXPathException {
    // defines if current item is castable to the target type, or not
    boolean isCastable;
    // atomic type must not be xs:anyAtomicType or xs:NOTATION
    if (mTargetType == Type.ANY_ATOMIC_TYPE || mTargetType == Type.NOTATION) {
        throw new XPathError(ErrorType.XPST0080);
    }
    if (mSourceExpr.hasNext()) {
        // result sequence > 0
        mKey = mSourceExpr.next();
        final Type sourceType = Type.getType(getTrx().getTypeKey());
        final String sourceValue = getTrx().getValue();
        // determine castability
        isCastable = sourceType.isCastableTo(mTargetType, sourceValue);
        // item, a type error is raised.
        if (mSourceExpr.hasNext()) {
            // result sequence > 1
            throw new XPathError(ErrorType.XPTY0004);
        }
    } else {
        // result sequence = 0 (empty sequence)
        // empty sequence is allowed.
        isCastable = mPermitEmptySeq;
    }
    // create result item and move transaction to it.
    final int mItemKey = getTrx().getItemList().addItem(new AtomicValue(TypedValue.getBytes(Boolean.toString(isCastable)), getTrx().keyForName("xs:boolean")));
    mKey = mItemKey;
}
Also used : Type(org.sirix.service.xml.xpath.types.Type) ErrorType(org.sirix.service.xml.xpath.XPathError.ErrorType) SingleType(org.sirix.service.xml.xpath.SingleType) AtomicValue(org.sirix.service.xml.xpath.AtomicValue) XPathError(org.sirix.service.xml.xpath.XPathError)

Example 40 with AtomicValue

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

the class EveryExpr method evaluate.

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

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