Package org.exolab.castor.xml

Examples of org.exolab.castor.xml.ValidationException


    public void validate(final Object object, final ValidationContext context) throws ValidationException {
        boolean required = (_minOccurs > 0);

        if (object == null && required) {
            String err = "This field is required and cannot be null.";
            throw new ValidationException(err);
        }

        if (object != null) {
            Class type = object.getClass();

            int size = 1;
            boolean byteArray = false;
            if (type.isArray()) {
                byteArray = (type.getComponentType() == Byte.TYPE);
                if (!byteArray) {
                    size = Array.getLength(object);
                }
            }

            //-- check minimum
            if (size < _minOccurs) {
                String err = "A minimum of " + _minOccurs
                             + " instance(s) of this field is required.";
                throw new ValidationException(err);
            }

            //-- check maximum
            if (_maxOccurs >= 0 && size > _maxOccurs) {
                String err = "A maximum of " + _maxOccurs
                             + " instance(s) of this field are allowed.";
                throw new ValidationException(err);
            }

            if (_validator == null) {
                return;
            }
View Full Code Here


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

        if (_useMin && value < _min) {
            String err = "long " + value + " is less than the minimum allowed value: " + _min;
            throw new ValidationException(err);
        }

        if (_useMax && value > _max) {
            String err = "long " + value + " is greater than the maximum allowed value: " + _max;
            throw new ValidationException(err);
        }

        if (_totalDigits != -1) {
            int length = Long.toString(value).length();
            if (value < 0) {
                length--;
            }
            if (length > _totalDigits) {
                String err = "long " + value + " has too many digits -- must be " + _totalDigits
                        + " digits or fewer.";
                throw new ValidationException(err);
            }
        }

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

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

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

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

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

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

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

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

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

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

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

        if ( !(this.getPeriod().equals(reccD.getPeriod())) ||
             !(this.getDuration().equals(reccD.getDuration())) )
        {
                String err = " Recurring Duration which have different values "
                            +"for the duration and period can not be compared";
                throw new ValidationException(err);
        }
        result = this.getCentury() == reccD.getCentury();
        result = result && (this.getYear() == reccD.getYear());
        result = result && (this.getMonth() == reccD.getMonth());
        result = result && (this.getDay() == reccD.getDay());
View Full Code Here

        if ( !(this.getPeriod().equals(reccD.getPeriod())) ||
             !(this.getDuration().equals(reccD.getDuration())) )
        {
                String err = " Recurring Duration which have different values "
                            +"for the duration and period can not be compared";
                throw new ValidationException(err);
        }
        short[] val_this = this.getValues();
        short[] val_reccD = reccD.getValues();
        int i = 0;
        while ( (result != true) && (i< (val_this.length-1)) ) {
View Full Code Here

        boolean result = false;
        if (!(this.getPeriod().equals(reccD.getPeriod()))
            || !(this.getDuration().equals(reccD.getDuration()))) {
            String err = "Recurring Duration which have different values "
                         + "for the duration and period can not be compared";
            throw new ValidationException(err);
        }

        result = (this.getHour() == reccD.getHour());
        result = result && (this.getMinute() == reccD.getMinute());
        result = result && (this.getSeconds() == reccD.getSeconds());
View Full Code Here

    public boolean isGreater(RecurringDurationBase reccD) throws ValidationException {
        if (!(this.getPeriod().equals(reccD.getPeriod()))
            || !(this.getDuration().equals(reccD.getDuration()))) {
            String err = "Recurring Duration which have different values "
                         + "for the duration and period can not be compared";
            throw new ValidationException(err);
        }

        boolean result = false;
        short[] val_this = this.getValues();
        short[] val_reccD = reccD.getValues();
View Full Code Here

                    baseFacets = datatype.getFacets();
                }
                try {
                    facet.checkConstraints(getLocalFacets(), baseFacets);
                } catch (SchemaException e) {
                    throw new ValidationException(
                            "Facet validation failed for type '" + getName() + "'", e);
                }
            }
        }
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.