Package org.apache.vxquery.exceptions

Examples of org.apache.vxquery.exceptions.SystemException


    }

    @Override
    public boolean operateYMDurationDuration(IntegerPointable intp1, XSDurationPointable durationp2)
            throws SystemException, IOException {
        throw new SystemException(ErrorCode.XPTY0004);
    }
View Full Code Here


                        return;
                    }
                    sb.finish();
                    result.set(abvs);
                } catch (IOException e) {
                    throw new SystemException(ErrorCode.SYSE0001);
                }
            }

            /**
             * XQuery Specification calls for double value. Integer and Decimal are allowed to cut down on casting.
             *
             * @param tvp
             * @return
             * @throws SystemException
             * @throws IOException
             */
            public long getLongFromArgument(TaggedValuePointable tvp) throws SystemException, IOException {
                if (tvp.getTag() == ValueTag.XS_DOUBLE_TAG) {
                    tvp.getValue(doublep);
                    abvsRound.reset();
                    round.operateDouble(doublep, abvsRound.getDataOutput());
                    doublep.set(abvsRound.getByteArray(), abvsRound.getStartOffset() + 1,
                            DoublePointable.TYPE_TRAITS.getFixedLength());
                    return doublep.longValue();
                } else if (tvp.getTag() == ValueTag.XS_INTEGER_TAG) {
                    tvp.getValue(longp);
                    return longp.longValue();
                } else if (tvp.getTag() == ValueTag.XS_DECIMAL_TAG) {
                    tvp.getValue(decp);
                    return decp.longValue();
                } else {
                    throw new SystemException(ErrorCode.FORG0006);
                }
            }
        };
    }
View Full Code Here

                    tvp1.getValue(seqp);
                    if (seqp.getEntryCount() == 0) {
                        XDMConstants.setEmptyString(tvp);
                        tvp.getValue(stringp);
                    } else {
                        throw new SystemException(ErrorCode.FORG0006);
                    }
                } else {
                    if (!FunctionHelper.isDerivedFromString(tvp1.getTag())) {
                        throw new SystemException(ErrorCode.FORG0006);
                    }
                    tvp1.getValue(stringp);
                }

                // Return the string length of the UTF8 String.
                try {
                    abvs.reset();
                    dOut.write(ValueTag.XS_INTEGER_TAG);
                    dOut.writeLong(stringp.getStringLength());
                    result.set(abvs);
                } catch (Exception e) {
                    throw new SystemException(ErrorCode.SYSE0001, e);
                }
            }
        };
    }
View Full Code Here

                long precision = 0;
                if (args.length > 1) {
                    TaggedValuePointable tvp2 = args[1];
                    if (tvp2.getTag() != ValueTag.XS_INTEGER_TAG) {
                        throw new SystemException(ErrorCode.FORG0006);
                    }
                    tvp2.getValue(longp);
                    precision = longp.getLong();
                }

                // Check special cases.
                try {
                    switch (tid) {
                        case ValueTag.XS_FLOAT_TAG:
                            tvp1.getValue(tp.floatp);
                            if (tp.floatp.getFloat() == 0 || Float.isNaN(tp.floatp.getFloat())
                                    || Float.isInfinite(tp.floatp.getFloat())) {
                                result.set(tvp1.getByteArray(), tvp1.getStartOffset(),
                                        FloatPointable.TYPE_TRAITS.getFixedLength() + 1);
                                return;
                            }
                            break;

                        case ValueTag.XS_DOUBLE_TAG:
                            tvp1.getValue(tp.doublep);
                            if (tp.doublep.getDouble() == 0 || Double.isNaN(tp.doublep.getDouble())
                                    || Double.isInfinite(tp.doublep.getDouble())) {
                                result.set(tvp1.getByteArray(), tvp1.getStartOffset(),
                                        DoublePointable.TYPE_TRAITS.getFixedLength() + 1);
                                return;
                            }
                            break;

                    }
                } catch (Exception e) {
                    throw new SystemException(ErrorCode.SYSE0001, e);
                }

                // Prepare input.
                try {
                    getDecimalPointable(tp, tvp1);
                } catch (IOException e) {
                    throw new SystemException(ErrorCode.SYSE0001, e);
                }

                // Perform rounding on decimal value.
                // TODO round half to the nearest even number.
                long decimalPlace = tp.decp.getDecimalPlace();
                if ((precision - decimalPlace) < 0) {
                    long decimalValue = tp.decp.getDecimalValue();
                    decimalValue = (long) (decimalValue / Math.pow(10, -(precision - decimalPlace)));
                    tp.decp.setDecimal(decimalValue, (byte) precision);
                }

                // Return result.
                try {
                    switch (tvp1.getTag()) {
                        case ValueTag.XS_DECIMAL_TAG:
                            dOut.write(ValueTag.XS_DECIMAL_TAG);
                            dOut.write(tp.decp.getByteArray(), tp.decp.getStartOffset(),
                                    XSDecimalPointable.TYPE_TRAITS.getFixedLength());
                            result.set(abvs.getByteArray(), abvs.getStartOffset(),
                                    XSDecimalPointable.TYPE_TRAITS.getFixedLength() + 1);
                            return;

                        case ValueTag.XS_INTEGER_TAG:
                        case ValueTag.XS_LONG_TAG:
                        case ValueTag.XS_NEGATIVE_INTEGER_TAG:
                        case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
                        case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
                        case ValueTag.XS_POSITIVE_INTEGER_TAG:
                        case ValueTag.XS_UNSIGNED_INT_TAG:
                        case ValueTag.XS_UNSIGNED_LONG_TAG:
                            dOut.write(tvp1.getTag());
                            dOut.writeLong(tp.decp.longValue());
                            result.set(abvs.getByteArray(), abvs.getStartOffset(),
                                    LongPointable.TYPE_TRAITS.getFixedLength() + 1);
                            return;

                        case ValueTag.XS_INT_TAG:
                        case ValueTag.XS_UNSIGNED_SHORT_TAG:
                            dOut.write(tvp1.getTag());
                            dOut.writeInt(tp.decp.intValue());
                            result.set(abvs.getByteArray(), abvs.getStartOffset(),
                                    IntegerPointable.TYPE_TRAITS.getFixedLength() + 1);
                            return;

                        case ValueTag.XS_SHORT_TAG:
                        case ValueTag.XS_UNSIGNED_BYTE_TAG:
                            dOut.write(tvp1.getTag());
                            dOut.writeShort(tp.decp.shortValue());
                            result.set(abvs.getByteArray(), abvs.getStartOffset(),
                                    ShortPointable.TYPE_TRAITS.getFixedLength() + 1);
                            return;

                        case ValueTag.XS_BYTE_TAG:
                            dOut.write(tvp1.getTag());
                            dOut.writeByte(tp.decp.byteValue());
                            result.set(abvs.getByteArray(), abvs.getStartOffset(),
                                    BytePointable.TYPE_TRAITS.getFixedLength() + 1);
                            return;

                        case ValueTag.XS_FLOAT_TAG:
                            dOut.write(ValueTag.XS_FLOAT_TAG);
                            dOut.writeFloat(tp.decp.floatValue());
                            result.set(abvs.getByteArray(), abvs.getStartOffset(),
                                    FloatPointable.TYPE_TRAITS.getFixedLength() + 1);
                            return;

                        case ValueTag.XS_DOUBLE_TAG:
                            dOut.write(ValueTag.XS_DOUBLE_TAG);
                            dOut.writeDouble(tp.decp.doubleValue());
                            result.set(abvs.getByteArray(), abvs.getStartOffset(),
                                    DoublePointable.TYPE_TRAITS.getFixedLength() + 1);
                            return;
                    }
                } catch (Exception e) {
                    throw new SystemException(ErrorCode.SYSE0001, e);
                }
            }

            private void getDecimalPointable(TypedPointables tp, TaggedValuePointable tvp) throws SystemException,
                    IOException {
                abvsInner.reset();
                long value;
                switch (tvp.getTag()) {
                    case ValueTag.XS_DECIMAL_TAG:
                        tvp.getValue(tp.decp);
                        return;

                    case ValueTag.XS_FLOAT_TAG:
                        tvp.getValue(tp.floatp);
                        castToDecimal.convertFloat(tp.floatp, dOutInner);
                        tp.decp.set(abvsInner.getByteArray(), abvsInner.getStartOffset() + 1,
                                XSDecimalPointable.TYPE_TRAITS.getFixedLength());
                        return;

                    case ValueTag.XS_DOUBLE_TAG:
                        tvp.getValue(tp.doublep);
                        castToDecimal.convertDouble(tp.doublep, dOutInner);
                        tp.decp.set(abvsInner.getByteArray(), abvsInner.getStartOffset() + 1,
                                XSDecimalPointable.TYPE_TRAITS.getFixedLength());
                        return;

                    case ValueTag.XS_INTEGER_TAG:
                    case ValueTag.XS_LONG_TAG:
                    case ValueTag.XS_NEGATIVE_INTEGER_TAG:
                    case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
                    case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
                    case ValueTag.XS_POSITIVE_INTEGER_TAG:
                    case ValueTag.XS_UNSIGNED_INT_TAG:
                    case ValueTag.XS_UNSIGNED_LONG_TAG:
                        tvp.getValue(tp.longp);
                        value = tp.longp.longValue();
                        break;

                    case ValueTag.XS_INT_TAG:
                    case ValueTag.XS_UNSIGNED_SHORT_TAG:
                        tvp.getValue(tp.intp);
                        value = tp.intp.longValue();
                        break;

                    case ValueTag.XS_SHORT_TAG:
                    case ValueTag.XS_UNSIGNED_BYTE_TAG:
                        tvp.getValue(tp.shortp);
                        value = tp.shortp.longValue();
                        break;

                    case ValueTag.XS_BYTE_TAG:
                        tvp.getValue(tp.bytep);
                        value = tp.bytep.longValue();
                        break;

                    default:
                        throw new SystemException(ErrorCode.XPTY0004);
                }
                dOutInner.write(ValueTag.XS_DECIMAL_TAG);
                tp.decp.set(abvsInner.getByteArray(), abvsInner.getStartOffset() + 1,
                        XSDecimalPointable.TYPE_TRAITS.getFixedLength());
                tp.decp.setDecimal(value, (byte) 0);
            }

            private int getBaseTypeForArithmetics(int tid) throws SystemException {
                while (true) {
                    switch (tid) {
                        case ValueTag.XS_DECIMAL_TAG:
                        case ValueTag.XS_DOUBLE_TAG:
                        case ValueTag.XS_FLOAT_TAG:
                        case ValueTag.XS_INTEGER_TAG:
                            return tid;

                        case ValueTag.XS_ANY_ATOMIC_TAG:
                            throw new SystemException(ErrorCode.XPTY0004);

                        default:
                            tid = BuiltinTypeRegistry.INSTANCE.getSchemaTypeById(tid).getBaseType().getTypeId();
                    }
                }
View Full Code Here

            @Override
            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
                dCtx.getCurrentDateTime(ctxDatetimep);
                TaggedValuePointable tvp1 = args[0];
                if (tvp1.getTag() != ValueTag.XS_DATE_TAG) {
                    throw new SystemException(ErrorCode.FORG0006);
                }
                tvp1.getValue(datep);

                // Second argument is optional and will used the dynamic context if not supplied.
                long tz;
                if (args.length == 2) {
                    TaggedValuePointable tvp2 = args[1];
                    if (tvp2.getTag() == ValueTag.XS_DAY_TIME_DURATION_TAG) {
                        tvp2.getValue(longp);
                        if (Math.abs(longp.getLong()) > DateTime.CHRONON_OF_HOUR * 14) {
                            throw new SystemException(ErrorCode.FODT0003);
                        }
                        tz = longp.getLong() / DateTime.CHRONON_OF_MINUTE;
                    } else {
                        throw new SystemException(ErrorCode.FORG0006);
                    }
                } else {
                    tz = ctxDatetimep.getTimezoneHour() * 60 + ctxDatetimep.getTimezoneMinute();
                }

                try {
                    abvs.reset();
                    abvsInner.reset();
                    DateTime.adjustDateTimeToTimezone(datep, tz, dOutInner);

                    byte[] bytes = abvsInner.getByteArray();
                    int startOffset = abvsInner.getStartOffset() + 1;
                    // Convert to date.
                    bytes[startOffset + XSDatePointable.TIMEZONE_HOUR_OFFSET] = bytes[startOffset
                            + XSDateTimePointable.TIMEZONE_HOUR_OFFSET];
                    bytes[startOffset + XSDatePointable.TIMEZONE_MINUTE_OFFSET] = bytes[startOffset
                            + XSDateTimePointable.TIMEZONE_MINUTE_OFFSET];
                    dOut.write(ValueTag.XS_DATE_TAG);
                    dOut.write(bytes, startOffset, XSDatePointable.TYPE_TRAITS.getFixedLength());

                    result.set(abvs);
                } catch (IOException e) {
                    throw new SystemException(ErrorCode.SYSE0001, e);
                }
            }
        };
    }
View Full Code Here

                    tvp1.getValue(seqp);
                    if (seqp.getEntryCount() == 0) {
                        XDMConstants.setEmptyString(tvp);
                        tvp.getValue(stringp1);
                    } else {
                        throw new SystemException(ErrorCode.FORG0006);
                    }
                } else {
                    if (!FunctionHelper.isDerivedFromString(tvp1.getTag())) {
                        throw new SystemException(ErrorCode.FORG0006);
                    }
                    tvp1.getValue(stringp1);
                }
                if (tvp2.getTag() == ValueTag.SEQUENCE_TAG) {
                    tvp2.getValue(seqp);
                    if (seqp.getEntryCount() == 0) {
                        XDMConstants.setEmptyString(tvp);
                        tvp.getValue(stringp2);
                    } else {
                        throw new SystemException(ErrorCode.FORG0006);
                    }
                } else {
                    if (!FunctionHelper.isDerivedFromString(tvp2.getTag())) {
                        throw new SystemException(ErrorCode.FORG0006);
                    }
                    tvp2.getValue(stringp2);
                }
                stringIterator.reset();
                searchIterator.reset();

                // Third parameter is optional.
                if (args.length > 2) {
                    TaggedValuePointable tvp3 = args[2];
                    if (!FunctionHelper.isDerivedFromString(tvp3.getTag())) {
                        throw new SystemException(ErrorCode.FORG0006);
                    }
                    tvp3.getValue(stringp3);
                }

                stringIterator.setSearch(searchIterator);
View Full Code Here

                    tvp1.getValue(seqp);
                    if (seqp.getEntryCount() == 0) {
                        XDMConstants.setEmptySequence(result);
                        return;
                    } else {
                        throw new SystemException(ErrorCode.XPTY0004);
                    }
                } else {
                    if (!FunctionHelper.isDerivedFromString(tvp1.getTag())) {
                        throw new SystemException(ErrorCode.XPTY0004);
                    }
                    tvp1.getValue(stringp1);
                }
                if (tvp2.getTag() == ValueTag.SEQUENCE_TAG) {
                    tvp2.getValue(seqp);
                    if (seqp.getEntryCount() == 0) {
                        XDMConstants.setEmptySequence(result);
                        return;
                    } else {
                        throw new SystemException(ErrorCode.XPTY0004);
                    }
                } else {
                    if (!FunctionHelper.isDerivedFromString(tvp2.getTag())) {
                        throw new SystemException(ErrorCode.XPTY0004);
                    }
                    tvp2.getValue(stringp2);
                }

                if (stringp1.compareTo(stringp2) == 0) {
View Full Code Here

                        }
                    }
                    sb.finish();
                    result.set(abvs);
                } catch (IOException e) {
                    throw new SystemException(ErrorCode.SYSE0001);
                }
            }
        };
    }
View Full Code Here

            @Override
            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
                dCtx.getCurrentDateTime(ctxDatetimep);
                TaggedValuePointable tvp1 = args[0];
                if (tvp1.getTag() != ValueTag.XS_TIME_TAG) {
                    throw new SystemException(ErrorCode.FORG0006);
                }
                tvp1.getValue(timep);

                // Second argument is optional and will used the dynamic context if not supplied.
                long tz;
                if (args.length == 2) {
                    TaggedValuePointable tvp2 = args[1];
                    if (tvp2.getTag() == ValueTag.XS_DAY_TIME_DURATION_TAG) {
                        tvp2.getValue(longp);
                        if (Math.abs(longp.getLong()) > DateTime.CHRONON_OF_HOUR * 14) {
                            throw new SystemException(ErrorCode.FODT0003);
                        }
                        tz = longp.getLong() / DateTime.CHRONON_OF_MINUTE;
                    } else {
                        throw new SystemException(ErrorCode.FORG0006);
                    }
                } else {
                    tz = ctxDatetimep.getTimezoneHour() * 60 + ctxDatetimep.getTimezoneMinute();
                }

                try {
                    abvs.reset();
                    abvsInner.reset();
                    // Convert to DateTime to help have a good date.
                    datetimep.set(abvsInner.getByteArray(), abvsInner.getStartOffset(),
                            XSDateTimePointable.TYPE_TRAITS.getFixedLength());
                    datetimep.setDateTime(1970, 1, 1, timep.getHour(), timep.getMinute(), timep.getMilliSecond(),
                            timep.getTimezoneHour(), timep.getTimezoneMinute());

                    DateTime.adjustDateTimeToTimezone(datetimep, tz, dOutInner);

                    byte[] bytes = abvsInner.getByteArray();
                    int startOffset = abvsInner.getStartOffset() + 1;
                    // Convert to time.
                    dOut.write(ValueTag.XS_TIME_TAG);
                    dOut.write(bytes, startOffset + XSDateTimePointable.HOUR_OFFSET,
                            XSTimePointable.TYPE_TRAITS.getFixedLength());

                    result.set(abvs);
                } catch (IOException e) {
                    throw new SystemException(ErrorCode.SYSE0001, e);
                }
            }
        };
    }
View Full Code Here

            value1 *= 10;
            ++count1;
        }
        // Add
        if (count1 > XSDecimalPointable.PRECISION || count2 > XSDecimalPointable.PRECISION) {
            throw new SystemException(ErrorCode.XPDY0002);
        }
        value1 -= value2;
        // Save
        dOut.write(ValueTag.XS_DECIMAL_TAG);
        dOut.writeByte(place1);
View Full Code Here

TOP

Related Classes of org.apache.vxquery.exceptions.SystemException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.