Index: src/main/java/org/exolab/castor/xml/validators/IntegerValidator.java =================================================================== --- src/main/java/org/exolab/castor/xml/validators/IntegerValidator.java (Revision 6993) +++ src/main/java/org/exolab/castor/xml/validators/IntegerValidator.java (Arbeitskopie) @@ -44,6 +44,8 @@ */ package org.exolab.castor.xml.validators; +import org.exolab.castor.util.Configuration; +import org.exolab.castor.util.LocalConfiguration; import org.exolab.castor.xml.TypeValidator; import org.exolab.castor.xml.ValidationContext; import org.exolab.castor.xml.ValidationException; @@ -182,6 +184,25 @@ } // -- setFixed /** + * Sets the fixed value that integers validated with this validated must be + * equal to. + *

+ * NOTE: Using Fixed values takes preceedence over using max and mins, and + * is really the same as setting both max-inclusive and min-inclusive to the + * same value + * + * Added for backward compatibility with old <xs:integer> implementation. + * + * @param fixedValue + * the fixed value an integer validated with this validator must + * be equal to. + */ + public void setFixed(final int fixedValue) { + _useFixed = true; + this._fixed = fixedValue; + } // -- setFixed + + /** * Sets the fixed value for xsd:Integer validation. *

* NOTE: If maximum and/or minimum values have been set and the fixed value @@ -210,6 +231,20 @@ } // -- setMinExclusive /** + * Sets the minimum (exclusive) value for xsd:integer validation. To pass + * validation, an xsd:Integer must be greater than this value. + * + * Added for backward compatibility with old <xs:integer> implementation. + * + * @param minValue + * the minimum (exclusive) value for xsd:Integer validation. + */ + public void setMinExclusive(final int minValue) { + _useMin = true; + _min = minValue + 1; + } // -- setMinExclusive + + /** * Sets the minimum (inclusive) value for xsd:integer validation. To pass * validation, an xsd:integer must be greater than or equal to this value. * @@ -222,6 +257,20 @@ } // -- setMinInclusive /** + * Sets the minimum (inclusive) value for xsd:integer validation. To pass + * validation, an xsd:integer must be greater than or equal to this value. + * + * Added for backward compatibility with old <xs:integer> implementation. + * + * @param minValue + * the minimum (inclusive) value for xsd:integer validation. + */ + public void setMinInclusive(final int minValue) { + _useMin = true; + _min = minValue; + } // -- setMinInclusive + + /** * Sets the maximum (exclusive) value for xsd:integer validation. To pass * validation, a xsd:integer must be less than this value. * @@ -234,6 +283,21 @@ } // -- setMaxExclusive /** + * Sets the maximum (exclusive) value for xsd:integer validation. To pass + * validation, a xsd:integer must be less than this value. + * + * Added for backward compatibility with old <xs:integer> implementation. + * + * @param maxValue + * the maximum (exclusive) value for xsd:integer validation. + */ + public void setMaxExclusive(final int maxValue) { + _useMax = true; + _max = maxValue - 1; + } // -- setMaxExclusive + + + /** * Sets the maximum (inclusive) value for xsd:integer validation. To pass * validation, a xsd:integer must be less than or equal to this value. * @@ -246,6 +310,20 @@ } // -- setMaxInclusive /** + * Sets the maximum (inclusive) value for xsd:integer validation. To pass + * validation, a xsd:integer must be less than or equal to this value. + * + * Added for backward compatibility with old <xs:integer> implementation. + * + * @param maxValue + * the maximum (inclusive) value for xsd:integer validation. + */ + public void setMaxInclusive(final int maxValue) { + _useMax = true; + _max = maxValue; + } // -- setMaxInclusive + + /** * Sets the maximum number of digits for xsd:integer validation. To pass * validation, a xsd:integer must have this many digits or fewer. Leading * zeros are not counted. @@ -336,9 +414,21 @@ try { value = ((Long) object).longValue(); } catch (Exception ex) { - String err = "Expecting an Long, received instead: "; - err += object.getClass().getName(); - throw new ValidationException(err); + String lenientProperty = + LocalConfiguration.getInstance().getProperty(Configuration.Property.LENIENT_INTEGER_VALIDATION, "false"); + if (Boolean.valueOf(lenientProperty).booleanValue()) { + try { + value = ((Integer) object).longValue(); + } catch (Exception e) { + String err = "Expecting a Long/Integer, received instead: "; + err += object.getClass().getName(); + throw new ValidationException(err); + } + } else { + String err = "Expecting an Long, received instead: "; + err += object.getClass().getName(); + throw new ValidationException(err); + } } validate(value, context); } //-- validate Index: src/main/java/org/exolab/castor/util/Configuration.java =================================================================== --- src/main/java/org/exolab/castor/util/Configuration.java (Revision 6993) +++ src/main/java/org/exolab/castor/util/Configuration.java (Arbeitskopie) @@ -282,6 +282,15 @@ public static final String SqlServerAnsiCompliant = "org.exolab.castor.jdo.sqlserver.ansi-compliant"; /** + * Property that allows to specify whether the validation for should accept + * the old 'int/Integer' members as well. + *

+         * org.exolab.castor.xml.lenientIntegerValidation= false
+         * 
+ */ + public static final String LENIENT_INTEGER_VALIDATION = "org.exolab.castor.xml.lenientIntegerValidation"; + + /** * Property specifying whether sequence order validation should be lenient *
          * org.exolab.castor.xml.lenient.sequence.order=false
Index: src/main/resources/org/exolab/castor/castor.properties
===================================================================
--- src/main/resources/org/exolab/castor/castor.properties	(Revision 6993)
+++ src/main/resources/org/exolab/castor/castor.properties	(Arbeitskopie)
@@ -235,6 +235,11 @@
 #
 #org.exolab.castor.xml.loadPackageMappings=false
 
+# Property that allows to specify whether the validation for  should accept
+# the old 'int/Integer' members as well.
+org.exolab.castor.xml.lenientIntegerValidation=false
+
+
 #
 # Property specifying whether sequence order validation should be lenient;
 # defaults to false