Search in sources :

Example 1 with Type

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

the class GeneralComp method getType.

/**
 * {@inheritDoc}
 */
@Override
protected Type getType(final int mKey1, final int mKey2) throws SirixXPathException {
    final Type mType1 = Type.getType(mKey1).getPrimitiveBaseType();
    final Type mType2 = Type.getType(mKey2).getPrimitiveBaseType();
    if (XPATH_10_COMP) {
        if (mType1.isNumericType() || mType2.isNumericType()) {
            return Type.DOUBLE;
        }
        if (mType1 == Type.STRING || mType2 == Type.STRING || (mType1 == Type.UNTYPED_ATOMIC && mType2 == Type.UNTYPED_ATOMIC)) {
            return Type.STRING;
        }
        if (mType1 == Type.UNTYPED_ATOMIC || mType2 == Type.UNTYPED_ATOMIC) {
            return Type.UNTYPED_ATOMIC;
        }
    } else {
        if (mType1 == Type.UNTYPED_ATOMIC) {
            switch(mType2) {
                case UNTYPED_ATOMIC:
                case STRING:
                    return Type.STRING;
                case INTEGER:
                case DECIMAL:
                case FLOAT:
                case DOUBLE:
                    return Type.DOUBLE;
                default:
                    return mType2;
            }
        }
        if (mType2 == Type.UNTYPED_ATOMIC) {
            switch(mType1) {
                case UNTYPED_ATOMIC:
                case STRING:
                    return Type.STRING;
                case INTEGER:
                case DECIMAL:
                case FLOAT:
                case DOUBLE:
                    return Type.DOUBLE;
                default:
                    return mType1;
            }
        }
    }
    return Type.getLeastCommonType(mType1, mType2);
}
Also used : Type(org.sirix.service.xml.xpath.types.Type)

Example 2 with Type

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

the class ValueComp method compare.

@Override
protected boolean compare(final AtomicValue[] mOperand1, final AtomicValue[] mOperand2) throws SirixXPathException {
    final Type type = getType(mOperand1[0].getTypeKey(), mOperand2[0].getTypeKey());
    final String op1 = new String(mOperand1[0].getRawValue());
    final String op2 = new String(mOperand2[0].getRawValue());
    return getCompKind().compare(op1, op2, type);
}
Also used : Type(org.sirix.service.xml.xpath.types.Type)

Example 3 with Type

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

the class ValueComp method getType.

/**
 * {@inheritDoc}
 *
 * @throws SirixXPathException
 */
@Override
protected Type getType(final int mKey1, final int mKey2) throws SirixXPathException {
    Type type1 = Type.getType(mKey1).getPrimitiveBaseType();
    Type type2 = Type.getType(mKey2).getPrimitiveBaseType();
    return Type.getLeastCommonType(type1, type2);
}
Also used : Type(org.sirix.service.xml.xpath.types.Type)

Example 4 with Type

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

the class CastExpr method evaluate.

/**
 * {@inheritDoc}
 */
@Override
public void evaluate() throws SirixXPathException {
    // 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()) {
        mSourceExpr.next();
        final Type sourceType = Type.getType(getTrx().getTypeKey());
        final String sourceValue = getTrx().getValue();
        // cast source to target type, if possible
        if (sourceType.isCastableTo(mTargetType, sourceValue)) {
            throw new IllegalStateException("casts not implemented yet.");
        // ((XPathReadTransaction)
        // getTransaction()).castTo(mTargetType);
        }
        // items, a type error is raised.
        if (mSourceExpr.hasNext()) {
            throw new XPathError(ErrorType.XPTY0004);
        }
    } else {
        // 3. if is empty sequence:
        if (!mPermitEmptySeq) {
            // otherwise an error is raised.
            throw new XPathError(ErrorType.XPTY0004);
        }
    }
}
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) XPathError(org.sirix.service.xml.xpath.XPathError)

Example 5 with Type

use of org.sirix.service.xml.xpath.types.Type 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)

Aggregations

Type (org.sirix.service.xml.xpath.types.Type)18 XPathError (org.sirix.service.xml.xpath.XPathError)12 ErrorType (org.sirix.service.xml.xpath.XPathError.ErrorType)12 AtomicValue (org.sirix.service.xml.xpath.AtomicValue)7 SingleType (org.sirix.service.xml.xpath.SingleType)2 Axis (org.sirix.api.Axis)1 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)1