use of org.sirix.service.xml.xpath.AtomicValue in project sirix by sirixdb.
the class NodeComp method atomize.
@Override
protected AtomicValue[] atomize(final Axis mOperand) throws SirixXPathException {
final XdmNodeReadTrx rtx = getTrx();
// store item key as atomic value
final AtomicValue mAtomized = new AtomicValue(TypedValue.getBytes(((Long) rtx.getNodeKey()).toString()), rtx.keyForName("xs:integer"));
final AtomicValue[] op = { mAtomized };
// the operands must be singletons in case of a node comparison
if (mOperand.hasNext()) {
throw EXPathError.XPTY0004.getEncapsulatedException();
} else {
return op;
}
}
use of org.sirix.service.xml.xpath.AtomicValue in project sirix by sirixdb.
the class ValueComp method atomize.
@Override
protected AtomicValue[] atomize(final Axis mOperand) throws SirixXPathException {
final XdmNodeReadTrx trx = getTrx();
int type = trx.getTypeKey();
// (3.) if type is untypedAtomic, cast to string
if (type == trx.keyForName("xs:unytpedAtomic")) {
type = trx.keyForName("xs:string");
}
final AtomicValue atomized = new AtomicValue(mOperand.getTrx().getValue().getBytes(), type);
final AtomicValue[] op = { atomized };
// (4.) the operands must be singletons in case of a value comparison
if (mOperand.hasNext()) {
throw EXPathError.XPTY0004.getEncapsulatedException();
} else {
return op;
}
}
use of org.sirix.service.xml.xpath.AtomicValue in project sirix by sirixdb.
the class SubOpAxis 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 new XPathError(ErrorType.XPTY0004);
}
return new AtomicValue(value, typeKey);
}
use of org.sirix.service.xml.xpath.AtomicValue in project sirix by sirixdb.
the class XPathParser method parseIntegerLiteral.
/**
* Parses the the rule IntegerLiteral according to the following production rule:
* <p>
* [70] IntegerLiteral ::= Digits => IntergerLiteral : Token.Value .
* </p>
*
* @return parseItem
*/
private int parseIntegerLiteral() {
String value = mToken.getContent();
String type = "xs:integer";
if (is(TokenType.VALUE, false)) {
// is at least decimal literal (could also be a double literal)
if (mToken.getType() == TokenType.POINT) {
// TODO: not so nice, try to find a better solution
final boolean isDouble = mScanner.lookUpTokens(2).getType() == TokenType.E_NUMBER;
value = parseDecimalLiteral(value);
type = isDouble ? "xs:double" : "xs:decimal";
}
// values containing an 'e' are double literals
if (mToken.getType() == TokenType.E_NUMBER) {
value = parseDoubleLiteral(value);
type = "xs:double";
}
} else {
// decimal literal that starts with a "."
final boolean isDouble = mScanner.lookUpTokens(2).getType() == TokenType.E_NUMBER;
value = parseDecimalLiteral("");
type = isDouble ? "xs:double" : "xs:decimal";
}
is(TokenType.SPACE, true);
final AtomicValue intLiteral = new AtomicValue(TypedValue.getBytes(value), getTransaction().keyForName(type));
return getTransaction().getItemList().addItem(intLiteral);
}
use of org.sirix.service.xml.xpath.AtomicValue 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;
}
Aggregations