use of org.sirix.service.xml.xpath.types.Type in project sirix by sirixdb.
the class IDivOpAxis 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;
try {
final int op1 = (int) Double.parseDouble(new String(mOperand1.getRawValue()));
final int op2 = (int) Double.parseDouble(new String(mOperand2.getRawValue()));
final int iValue = op1 / op2;
value = TypedValue.getBytes(iValue);
return new AtomicValue(value, typeKey);
} catch (final ArithmeticException e) {
// LOGWRAPPER.error(e);
throw new XPathError(ErrorType.FOAR0001);
}
}
use of org.sirix.service.xml.xpath.types.Type in project sirix by sirixdb.
the class ModOpAxis method getReturnType.
/**
* {@inheritDoc}
*/
@Override
protected Type getReturnType(final int mOp1, final int mOp2) throws SirixXPathException {
Type type1;
Type type2;
try {
type1 = Type.getType(mOp1).getPrimitiveBaseType();
type2 = Type.getType(mOp2).getPrimitiveBaseType();
} catch (IllegalStateException e) {
throw new XPathError(ErrorType.XPTY0004);
}
// only numeric values are valid for the mod operator
if (type1.isNumericType() && type2.isNumericType()) {
// if both have the same numeric type, return it
if (type1 == type2) {
return type1;
}
if (type1 == Type.DOUBLE || type2 == Type.DOUBLE) {
return Type.DOUBLE;
} else if (type1 == Type.FLOAT || type2 == Type.FLOAT) {
return Type.FLOAT;
} else {
assert (type1 == Type.DECIMAL || type2 == Type.DECIMAL);
return Type.DECIMAL;
}
} else {
throw new XPathError(ErrorType.XPTY0004);
}
}
use of org.sirix.service.xml.xpath.types.Type 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;
}
Aggregations