Search in sources :

Example 6 with AtomicValue

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

the class OrExpr method evaluate.

/**
 * {@inheritDoc}
 *
 * @throws SirixXPathException
 */
@Override
public void evaluate() throws SirixXPathException {
    // first find the effective boolean values of the two operands, then
    // determine value of the and-expression and store it in am item
    final boolean result = Function.ebv(mOp1) || Function.ebv(mOp2);
    // note: the error handling is implicitly done by the fnBoolean()
    // function.
    // add result item to list and set the item as the current item
    final int itemKey = getTrx().getItemList().addItem(new AtomicValue(TypedValue.getBytes(Boolean.toString(result)), getTrx().keyForName("xs:boolean")));
    mKey = itemKey;
}
Also used : AtomicValue(org.sirix.service.xml.xpath.AtomicValue)

Example 7 with AtomicValue

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

the class XPathParser method parseStringLiteral.

/**
 * Parses the the rule StringLiteral according to the following production rule:
 * <p>
 * [73] StringLiteral ::= ('"' (('"' '"') | [^"])* '"') | ("'" (("'" "'") | [^'])* "'" .
 * </p>
 *
 * @return parseStringLiteral
 */
private int parseStringLiteral() {
    final StringBuilder mValue = new StringBuilder();
    if (is(TokenType.DBL_QUOTE, true)) {
        do {
            while (mToken.getType() != TokenType.DBL_QUOTE) {
                mValue.append(mToken.getContent());
                // consume(Token.TEXT, false); // TODO: does not need to be
                // a text
                // could also be a value
                mToken = mScanner.nextToken();
            }
            consume(TokenType.DBL_QUOTE, true);
        } while (is(TokenType.DBL_QUOTE, true));
    } else {
        consume(TokenType.SINGLE_QUOTE, true);
        do {
            while (mToken.getType() != TokenType.SINGLE_QUOTE) {
                mValue.append(mToken.getContent());
                // consume(Token.TEXT, false);
                mToken = mScanner.nextToken();
            }
            consume(TokenType.SINGLE_QUOTE, true);
        } while (is(TokenType.SINGLE_QUOTE, true));
    }
    final AtomicValue mStringLiteral = new AtomicValue(TypedValue.getBytes(mValue.toString()), getTransaction().keyForName("xs:string"));
    return (getTransaction().getItemList().addItem(mStringLiteral));
}
Also used : AtomicValue(org.sirix.service.xml.xpath.AtomicValue)

Example 8 with AtomicValue

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

the class AddOpAxis method operate.

/**
 * {@inheritDoc}
 */
@Override
public Node operate(final AtomicValue mOperand1, final AtomicValue mOperand2) throws SirixXPathException {
    final Type returnType = getReturnType(mOperand1.getTypeKey(), mOperand2.getTypeKey());
    final int typeKey = getTrx().keyForName(returnType.getStringRepr());
    final byte[] value;
    switch(returnType) {
        case DOUBLE:
        case FLOAT:
        case DECIMAL:
        case INTEGER:
            final double dOp1 = Double.parseDouble(new String(mOperand1.getRawValue()));
            final double dOp2 = Double.parseDouble(new String(mOperand2.getRawValue()));
            value = TypedValue.getBytes(dOp1 + dOp2);
            break;
        case DATE:
        case TIME:
        case DATE_TIME:
        case YEAR_MONTH_DURATION:
        case DAY_TIME_DURATION:
            throw new IllegalStateException("Add operator is not implemented for the type " + returnType.getStringRepr() + " yet.");
        default:
            throw EXPathError.XPTY0004.getEncapsulatedException();
    }
    return new AtomicValue(value, typeKey);
}
Also used : Type(org.sirix.service.xml.xpath.types.Type) AtomicValue(org.sirix.service.xml.xpath.AtomicValue)

Example 9 with AtomicValue

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

the class ModOpAxis method operate.

/**
 * {@inheritDoc}
 */
@Override
public Node operate(final AtomicValue mOperand1, final AtomicValue mOperand2) throws SirixXPathException {
    final Type returnType = getReturnType(mOperand1.getTypeKey(), mOperand2.getTypeKey());
    final int typeKey = getTrx().keyForName(returnType.getStringRepr());
    final byte[] value;
    switch(returnType) {
        case DOUBLE:
        case FLOAT:
        case DECIMAL:
            final double dOp1 = Double.parseDouble(new String(mOperand1.getRawValue()));
            final double dOp2 = Double.parseDouble(new String(mOperand2.getRawValue()));
            value = TypedValue.getBytes(dOp1 % dOp2);
            break;
        case INTEGER:
            try {
                final int iOp1 = (int) Double.parseDouble(new String(mOperand1.getRawValue()));
                final int iOp2 = (int) Double.parseDouble(new String(mOperand2.getRawValue()));
                value = TypedValue.getBytes(iOp1 % iOp2);
            } catch (final ArithmeticException e) {
                throw new XPathError(ErrorType.FOAR0001);
            }
            break;
        default:
            throw new XPathError(ErrorType.XPTY0004);
    }
    return new AtomicValue(value, typeKey);
}
Also used : Type(org.sirix.service.xml.xpath.types.Type) ErrorType(org.sirix.service.xml.xpath.XPathError.ErrorType) AtomicValue(org.sirix.service.xml.xpath.AtomicValue) XPathError(org.sirix.service.xml.xpath.XPathError)

Example 10 with AtomicValue

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

the class MulOpAxis method operate.

/**
 * {@inheritDoc}
 */
@Override
public Node operate(final AtomicValue mOperand1, final AtomicValue mOperand2) throws SirixXPathException {
    final Type returnType = getReturnType(mOperand1.getTypeKey(), mOperand2.getTypeKey());
    final int typeKey = getTrx().keyForName(returnType.getStringRepr());
    final byte[] value;
    switch(returnType) {
        case DOUBLE:
        case FLOAT:
        case DECIMAL:
        case INTEGER:
            final double dOp1 = Double.parseDouble(new String(mOperand1.getRawValue()));
            final double dOp2 = Double.parseDouble(new String(mOperand2.getRawValue()));
            value = TypedValue.getBytes(dOp1 * dOp2);
            break;
        case YEAR_MONTH_DURATION:
        case DAY_TIME_DURATION:
            throw new IllegalStateException("Add operator is not implemented for the type " + returnType.getStringRepr() + " yet.");
        default:
            throw new XPathError(ErrorType.XPTY0004);
    }
    return new AtomicValue(value, typeKey);
}
Also used : Type(org.sirix.service.xml.xpath.types.Type) ErrorType(org.sirix.service.xml.xpath.XPathError.ErrorType) AtomicValue(org.sirix.service.xml.xpath.AtomicValue) XPathError(org.sirix.service.xml.xpath.XPathError)

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