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;
}
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));
}
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);
}
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);
}
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);
}
Aggregations