Package org.exolab.castor.xml

Examples of org.exolab.castor.xml.ValidationException


        boolean isThereMinExclusive = (_minExclusive != null);
        boolean isThereMaxInclusive = (_maxInclusive != null);
        boolean isThereMaxExclusive = (_maxExclusive != null);

        if (isThereMinExclusive && isThereMinInclusive) {
            throw new ValidationException("Both minInclusive and minExclusive are defined");
        }

        if (isThereMaxExclusive && isThereMaxInclusive) {
            throw new ValidationException("Both maxInclusive and maxExclusive are defined");
        }

        if (_fixed != null && !duration.equal(_fixed)) {
            String err = "Duration " + duration + " is not equal to the fixed value: " + _fixed;
            throw new ValidationException(err);
        }

        if (isThereMinInclusive && _minInclusive.isGreater(duration)) {
            String err = "Duration " + duration + " is less than the minimum allowed value: "
                    + _minInclusive;
            throw new ValidationException(err);
        }

        if (isThereMinExclusive && (_minExclusive.isGreater(duration)
                                    || duration.equals(_minExclusive))) {
             String err = "Duration " + duration
                     + " is less than or equal to the minimum exclusive value: " + _minExclusive;
             throw new ValidationException(err);
        }

        if (isThereMaxInclusive && duration.isGreater(_maxInclusive)) {
            String err = "Duration " + duration + " is greater than the maximum allowed value "
                    + _maxInclusive;
            throw new ValidationException(err);
        }

        if (isThereMaxExclusive && ((duration.isGreater(_maxExclusive))
                                    || duration.equals(_maxExclusive))) {
            String err = "Duration " + duration
                    + " is greater than or equal to the maximum exclusive value: " + _maxExclusive;
            throw new ValidationException(err);
        }

        if (hasPattern()) {
            super.validate(duration.toString(), context);
        }
View Full Code Here


     */
    public void validate(final Object object, final ValidationContext context)
                                                    throws ValidationException {
        if (object == null) {
            String err = "durationValidator cannot validate a null object.";
            throw new ValidationException(err);
        }

        if (object instanceof String) {
            try {
                Duration duration = Duration.parseDuration((String) object);
                validate(duration, context);
                return;
            } catch (java.text.ParseException pe) {
                String err = "String provided fails to parse into a Duration: " + (String) object;
                throw new ValidationException(err, pe);
            }
        }

        Duration value = null;
        try {
            value = (Duration) object;
        } catch (Exception ex) {
            String err = "Expecting a duration, received instead: " + object.getClass().getName();
            throw new ValidationException(err);
        }

        validate(value, context);
    } //-- validate
View Full Code Here

     */
    public void validate(final BigDecimal bd, final ValidationContext context)
                                                    throws ValidationException {
        if (_fixed != null && !bd.equals(_fixed)) {
            String err = "BigDecimal " + bd + " is not equal to the fixed value: " + _fixed;
            throw new ValidationException(err);
        }

        if (_min != null) {
            if (bd.compareTo(_min) == -1) {
                String err = "BigDecimal " + bd + " is less than the minimum allowed value: "
                        + _min;
                throw new ValidationException(err);
            } else if ((bd.compareTo(_min) == 0) && (_hasMinExclusive)) {
                String err = "BigDecimal " + bd
                        + " cannot be equal to the minimum exclusive value: " + _min;
                throw new ValidationException(err);
            }
        }

        if (_max != null) {
            if (bd.compareTo(_max) == 1) {
                String err = "BigDecimal " + bd + " is greater than the maximum allowed value: "
                        + _max;
                throw new ValidationException(err);
            } else if ((bd.compareTo(_max) == 0) && (_hasMaxExclusive)) {
                String err = "BigDecimal " + bd
                        + " cannot be equal to the maximum exclusive value: " + _max;
                throw new ValidationException(err);
            }
        }

        // For digit counting, we are not supposed to count leading or trailing zeros
        BigDecimal clean = stripTrailingZeros(bd);

        if (_totalDigits != -1) {
            String temp = toStringForBigDecimal(clean);
            int length = temp.length();
            if (temp.indexOf('-') == 0) {
                --length;
            }
            if (temp.indexOf('.') != -1) {
                --length;
            }
            if (length > _totalDigits) {
                String err = "BigDecimal " + bd + " has too many significant digits -- must have "
                        + _totalDigits + " or fewer";
                throw new ValidationException(err);
            }
            temp = null;
        }

        if (_fractionDigits != -1 && clean.scale() > _fractionDigits) {
            String err = "BigDecimal " + bd + " has too many fraction digits -- must have "
                    + _fractionDigits + " fraction digits or fewer";
            throw new ValidationException(err);
        }

        if (hasPattern()) {
            super.validate(toStringForBigDecimal(bd), context);
        }
View Full Code Here

     */
    public void validate(final Object object, final ValidationContext context)
                                                    throws ValidationException {
        if (object == null) {
            String err = "decimalValidator cannot validate a null object.";
            throw new ValidationException(err);
        }

        BigDecimal value = null;
        if (object instanceof BigDecimal) {
            value = (BigDecimal) object;
        } else {
            try {
                value = new java.math.BigDecimal(object.toString());
            } catch (Exception ex) {
                String err = "Expecting a decimal, received instead: "
                        + object.getClass().getName();
                throw new ValidationException(err);
            }
        }
        validate(value, context);
    } //-- validate
View Full Code Here

        boolean isThereMinExclusive = (_minExclusive != null);
        boolean isThereMaxInclusive = (_maxInclusive != null);
        boolean isThereMaxExclusive = (_maxExclusive != null);

        if (isThereMinExclusive && isThereMinInclusive) {
            throw new ValidationException("Both minInclusive and minExclusive are defined");
        }

        if (isThereMaxExclusive && isThereMaxInclusive) {
            throw new ValidationException("Both maxInclusive and maxExclusive are defined");
        }

        if (_fixed != null) {
            int comparison = dateTime.compareTo(_fixed);
            if (comparison == DateTimeBase.INDETERMINATE) {
                String err = dateTime.getClass().getName() + " " + dateTime
                        + " comparison to the fixed value " + _fixed
                        + " is indeterminate";
                throw new ValidationException(err);
            } else if (comparison != DateTimeBase.EQUALS) {
                String err = dateTime.getClass().getName() + " " + dateTime
                        + " is not equal to the fixed value: " + _fixed;
                throw new ValidationException(err);
            }
        }

        if (isThereMinInclusive && dateTime.compareTo(_minInclusive) != DateTimeBase.GREATER_THAN
                && !dateTime.equals(_minInclusive)) {
            String err = dateTime.getClass().getName() + " " + dateTime
                    + " is less than the minimum allowed value: " + _minInclusive;
            throw new ValidationException(err);
        }

        if (isThereMinExclusive && dateTime.compareTo(_minExclusive) != DateTimeBase.GREATER_THAN) {
            String err =  dateTime.getClass().getName() + " " + dateTime
                    + " is less than or equal to the minimum (exclusive) value: " + _minExclusive;
            throw new ValidationException(err);
        }

        if (isThereMaxInclusive && dateTime.compareTo(_maxInclusive) != DateTimeBase.LESS_THAN
                && !dateTime.equals(_maxInclusive)) {
            String err = dateTime.getClass().getName() + " " + dateTime
                    + " is greater than the maximum allowed value: " + _maxInclusive;
            throw new ValidationException(err);
        }

        if (isThereMaxExclusive && dateTime.compareTo(_maxExclusive) != DateTimeBase.LESS_THAN) {
            String err =  dateTime.getClass().getName() + " " + dateTime
                    + " is greater than or equal to the maximum (exclusive) value: "
                    + _maxExclusive;
            throw new ValidationException(err);
        }

        if (hasPattern()) {
            super.validate(dateTime.toString(), context);
        }
View Full Code Here

     */
    public void validate(final Object object, final ValidationContext context)
                                                    throws ValidationException {
        if (object == null) {
            String err = "DateTimeValidator cannot validate a null object.";
            throw new ValidationException(err);
        }

        if (object instanceof String) {
            try {
                DateTime dateTime = new DateTime((String) object);
                validate(dateTime, context);
                return;
            } catch (java.text.ParseException pe) {
                String err = "String provided fails to parse into a DateTime: " + (String) object;
                throw new ValidationException(err, pe);
            }
        }

        DateTimeBase value = null;

        try {
            value = (DateTimeBase) object;
        } catch (Exception ex) {
            String err = ex.toString() + "\nExpecting a DateTime, received instead: "
                         + object.getClass().getName();
            throw new ValidationException(err);
        }

        validate(value, context);
    } //-- validate
View Full Code Here

     */
    public void validate(final Object object, final ValidationContext context)
                                                    throws ValidationException {
        if (object == null) {
             String err = "The object of type IDREFS is null!";
             throw new ValidationException(err);
        }

        Object[] objects = (Object[]) object;
        for (int i = 0; i < objects.length; i++) {
            _idRefValidator.validate(objects[i], context);
View Full Code Here

     */
    public void validate(final float d, final ValidationContext context)
                                                    throws ValidationException {
        if (_useFixed && d != _fixed) {
            String err = "float " + d + " is not equal to the fixed value of " + _fixed;
            throw new ValidationException(err);
        }

        if (_useMinInclusive && d < _minInclusive) {
            String err = "float " + d + " is less than the minimum allowed value: " + _minInclusive;
            throw new ValidationException(err);
        }

        if (_useMinExclusive && d <= _minExclusive) {
            String err = "float " + d
                    + " is less than or equal to the minimum exclusive value: " + _minExclusive;
            throw new ValidationException(err);
        }

        if (_useMaxInclusive && d > _maxInclusive) {
            String err = "float " + d + " is greater than the maximum allowed value: "
                    + _maxInclusive;
            throw new ValidationException(err);
        }

        if (_useMaxExclusive && d >= _maxExclusive) {
            String err = "float " + d
                    + " is greater than or equal to the maximum exclusive value: " + _maxExclusive;
            throw new ValidationException(err);
        }

        if (hasPattern()) {
            super.validate(Float.toString(d), context);
        }
View Full Code Here

     */
    public void validate(final Object object, final ValidationContext context)
                                                    throws ValidationException {
        if (object == null) {
            String err = "floatValidator cannot validate a null object.";
            throw new ValidationException(err);
        }

        float value = 0;
        try {
            value = new java.lang.Float(object.toString()).floatValue();
        } catch (Exception ex) {
            String err = "Expecting a float, received instead: ";
            err += object.getClass().getName();
            throw new ValidationException(err);
        }
        validate(value, context);
    } //-- validate
View Full Code Here

    public void validate(final Object object, final ValidationContext context)
    throws ValidationException {
        // we need a target Object
        if (object == null) {
            String err = "The object associated with IDREF \"" + object + "\" is null!";
            throw new ValidationException(err);
        }

        // get the id of the target object
        String id = null;
        try {
            ClassDescriptorResolver classDescriptorResolver = context.getClassDescriptorResolver();
            ClassDescriptor classDescriptor = classDescriptorResolver.resolve(object.getClass());
            FieldDescriptor fieldDescriptor = classDescriptor.getIdentity();
            FieldHandler fieldHandler = fieldDescriptor.getHandler();
            id = (String) fieldHandler.getValue(object);
        } catch (Exception e) {
            String err = "The object associated with IDREF \"" + object
            + "\" of type " + object.getClass() + " has no ID!";
            throw new ValidationException(err);
        }

        if (id == null) {
            String err = "The object associated with IDREF \"" + object + "\" has no ID!";
            throw new ValidationException(err);
        }

        // check if referenced id exists, otherwise put it into "currently unresolved" queue
        context.checkIdRef(id);
View Full Code Here

TOP

Related Classes of org.exolab.castor.xml.ValidationException

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.