You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by je...@locus.apache.org on 2000/07/31 19:56:53 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/validators/datatype DecimalDatatypeValidator.java StringDatatypeValidator.java

jeffreyr    00/07/31 10:56:52

  Modified:    java/src/org/apache/xerces/validators/datatype
                        DecimalDatatypeValidator.java
                        StringDatatypeValidator.java
  Log:
  Added Max,Min,Inclusive,Exclusive boundary validatio in Decimal and added Basetype validation
  
  Revision  Changes    Path
  1.9       +95 -54    xml-xerces/java/src/org/apache/xerces/validators/datatype/DecimalDatatypeValidator.java
  
  Index: DecimalDatatypeValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/DecimalDatatypeValidator.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DecimalDatatypeValidator.java	2000/06/23 01:39:20	1.8
  +++ DecimalDatatypeValidator.java	2000/07/31 17:56:52	1.9
  @@ -73,7 +73,7 @@
    *
    * @author Ted Leung
    * @author Jeffrey Rodriguez
  - * @version $Id: DecimalDatatypeValidator.java,v 1.8 2000/06/23 01:39:20 jeffreyr Exp $
  + * @version $Id: DecimalDatatypeValidator.java,v 1.9 2000/07/31 17:56:52 jeffreyr Exp $
    */
   
   public class DecimalDatatypeValidator extends AbstractDatatypeValidator {
  @@ -123,7 +123,7 @@
                               value = ((String) facets.get(key ));
                               fFacetsDefined += DatatypeValidator.FACET_PATTERN;
                               fPattern        = value;
  -                            if( fPattern != null )
  +                            if ( fPattern != null )
                                   fRegex = new RegularExpression(fPattern, "X" );
                           } else if (key.equals(SchemaSymbols.ELT_ENUMERATION)) {
                               fFacetsDefined += DatatypeValidator.FACET_ENUMERATION;
  @@ -177,29 +177,67 @@
   
                   if ( isMaxExclusiveDefined && isMaxInclusiveDefined ) {
                       throw new InvalidDatatypeFacetException(
  -                                                "It is an error for both maxInclusive and maxExclusive to be specified for the same datatype." ); 
  +                                                           "It is an error for both maxInclusive and maxExclusive to be specified for the same datatype." ); 
                   }
                   if ( isMinExclusiveDefined && isMinInclusiveDefined ) {
                       throw new InvalidDatatypeFacetException(
  -                                                "It is an error for both minInclusive and minExclusive to be specified for the same datatype." ); 
  +                                                           "It is an error for both minInclusive and minExclusive to be specified for the same datatype." ); 
                   }
   
  +                if ( isMaxExclusiveDefined && isMinExclusiveDefined ){
  +                    int compareTo = this.fMaxExclusive.compareTo( this.fMinExclusive );
  +                    if ( compareTo != 1)
  +                        throw new InvalidDatatypeFacetException(
  +                                                               "maxExclusive value ='" + this.fMaxExclusive + "'must be > than minExclusive value ='" + 
  +                                                               this.fMinExclusive + "'. " );
  +
  +                }
  +                if ( isMaxInclusiveDefined && isMinInclusiveDefined ){
  +                    int compareTo = this.fMaxInclusive.compareTo( this.fMinInclusive );
  +                    
  +                    if ( compareTo == -1  )
  +                        throw new InvalidDatatypeFacetException(
  +                                                               "maxInclusive value ='" + this.fMaxInclusive + "'must be >= than minInclusive value ='" + 
  +                                                               this.fMinInclusive + "'. " );
  +                }
  +
  +
  +                if ( isMaxExclusiveDefined && isMinInclusiveDefined ){
  +                    int compareTo = this.fMaxExclusive.compareTo( this.fMinInclusive );
  +                    if ( compareTo != 1)
  +                        throw new InvalidDatatypeFacetException(
  +                                                               "maxExclusive value ='" + this.fMaxExclusive + "'must be > than minInclusive value ='" + 
  +                                                               this.fMinInclusive + "'. " );
  +
  +                }
  +                if ( isMaxInclusiveDefined && isMinExclusiveDefined ){
  +                    int compareTo = this.fMaxInclusive.compareTo( this.fMinExclusive );
  +                    if ( compareTo != 1)
  +                        throw new InvalidDatatypeFacetException(
  +                                                               "maxInclusive value ='" + this.fMaxInclusive + "'must be > than minExclusive value ='" + 
  +                                                               this.fMinExclusive + "'. " );
  +                }
  +
  +
  +
  +
  +
                   if ( (fFacetsDefined & DatatypeValidator.FACET_ENUMERATION ) != 0 ) {
                       if (enumeration != null) {
                           fEnumDecimal = new BigDecimal[enumeration.size()];
                           int i = 0;
  -                            try {
  -                                for ( ; i < enumeration.size(); i++) {
  -                                    fEnumDecimal[i] = 
  -                                          new BigDecimal( ((String) enumeration.elementAt(i)));
  -                                    boundsCheck(fEnumDecimal[i]); // Check against max,min Inclusive, Exclusives
  -                                }
  -                            } catch( Exception idve ){
  -                                throw new InvalidDatatypeFacetException(
  -                                      getErrorString(DatatypeMessageProvider.InvalidEnumValue,
  -                                               DatatypeMessageProvider.MSG_NONE,
  -                                                       new Object [] { enumeration.elementAt(i)}));
  +                        try {
  +                            for ( ; i < enumeration.size(); i++) {
  +                                fEnumDecimal[i] = 
  +                                new BigDecimal( ((String) enumeration.elementAt(i)));
  +                                boundsCheck(fEnumDecimal[i]); // Check against max,min Inclusive, Exclusives
                               }
  +                        } catch ( Exception idve ){
  +                            throw new InvalidDatatypeFacetException(
  +                                                                   getErrorString(DatatypeMessageProvider.InvalidEnumValue,
  +                                                                                  DatatypeMessageProvider.MSG_NONE,
  +                                                                                  new Object [] { enumeration.elementAt(i)}));
  +                        }
                       }
                   }
               } else { // Derivation by List
  @@ -225,56 +263,59 @@
   
           if ( fDerivedByList == false ) { //derived by restriction
   
  +            if ( this.fBaseValidator != null ) {//validate against parent type if any
  +                    this.fBaseValidator.validate( content, state );
  +                }
  +
               if ( (fFacetsDefined & DatatypeValidator.FACET_PATTERN ) != 0 ) {
  -              if ( fRegex == null || fRegex.matches( content) == false )
  -                  throw new InvalidDatatypeValueException("Value'"+content+
  -                                                      "does not match regular expression facet" + fPattern );
  +                if ( fRegex == null || fRegex.matches( content) == false )
  +                    throw new InvalidDatatypeValueException("Value'"+content+
  +                                                            "does not match regular expression facet" + fPattern );
               }
   
               BigDecimal d = null; // Is content a Decimal 
               try {
                   d = new BigDecimal(content);
  -            } 
  -            catch (Exception nfe) {
  +            } catch (Exception nfe) {
                   throw new InvalidDatatypeValueException(
  -                   getErrorString(DatatypeMessageProvider.NotDecimal,
  -                  DatatypeMessageProvider.MSG_NONE,
  -                                      new Object[] { "'" + content +"'"}));
  +                                                       getErrorString(DatatypeMessageProvider.NotDecimal,
  +                                                                      DatatypeMessageProvider.MSG_NONE,
  +                                                                      new Object[] { "'" + content +"'"}));
               }
               //} 
               //catch (IOException ex ) {
  -              //  throw new InvalidDatatypeValueException(
  -                //  getErrorString(DatatypeMessageProvider.NotDecimal,
  -                // DatatypeMessageProvider.MSG_NONE,
  -              //                       new Object[] { "'" + content +"'"}));
  +            //  throw new InvalidDatatypeValueException(
  +            //  getErrorString(DatatypeMessageProvider.NotDecimal,
  +            // DatatypeMessageProvider.MSG_NONE,
  +            //                       new Object[] { "'" + content +"'"}));
               //}
   
   
  -            if( isScaleDefined == true ) {
  -                 if (d.scale() > fScale)
  -                      throw new InvalidDatatypeValueException(
  -                                                  getErrorString(DatatypeMessageProvider.ScaleExceeded,
  -                                                          DatatypeMessageProvider.MSG_NONE,
  -                                                          new Object[] { content}));
  +            if ( isScaleDefined == true ) {
  +                if (d.scale() > fScale)
  +                    throw new InvalidDatatypeValueException(
  +                                                           getErrorString(DatatypeMessageProvider.ScaleExceeded,
  +                                                                          DatatypeMessageProvider.MSG_NONE,
  +                                                                          new Object[] { content}));
               }
  -            if( isPrecisionDefined == true ) {
  -                 int precision = d.movePointRight(d.scale()).toString().length() - 
  -                            ((d.signum() < 0) ? 1 : 0); // account for minus sign
  -                 if (precision > fPrecision)
  -                      throw new InvalidDatatypeValueException(
  -                              getErrorString(DatatypeMessageProvider.PrecisionExceeded,
  -                                               DatatypeMessageProvider.MSG_NONE,
  -                                                    new Object[] {content} ));
  +            if ( isPrecisionDefined == true ) {
  +                int precision = d.movePointRight(d.scale()).toString().length() - 
  +                                ((d.signum() < 0) ? 1 : 0); // account for minus sign
  +                if (precision > fPrecision)
  +                    throw new InvalidDatatypeValueException(
  +                                                           getErrorString(DatatypeMessageProvider.PrecisionExceeded,
  +                                                                          DatatypeMessageProvider.MSG_NONE,
  +                                                                          new Object[] {content} ));
               }
               boundsCheck(d);
               if (  fEnumDecimal != null )
  -                 enumCheck(d);
  +                enumCheck(d);
   
   
  -        } else { //derivation by list
  +        } else { //derivation by list Revisit
   
           }
  -    return null;
  +        return null;
       }
   
       /*
  @@ -290,8 +331,8 @@
               maxOk = (d.compareTo(fMaxExclusive) < 0);
           else
               maxOk = (!isMaxInclusiveDefined && ! isMaxExclusiveDefined);
  +
   
  -        
   
           if ( isMinInclusiveDefined)
               minOk = (d.compareTo(fMinInclusive) >= 0);
  @@ -301,9 +342,9 @@
               minOk = (!isMinInclusiveDefined && !isMinExclusiveDefined);
           if (!(minOk && maxOk))
               throw new InvalidDatatypeValueException(
  -                   getErrorString(DatatypeMessageProvider.OutOfBounds,
  -                   DatatypeMessageProvider.MSG_NONE,
  -                                           new Object [] { d}));
  +                                                   getErrorString(DatatypeMessageProvider.OutOfBounds,
  +                                                                  DatatypeMessageProvider.MSG_NONE,
  +                                                                  new Object [] { d}));
   
       }
   
  @@ -316,9 +357,9 @@
   
           }
           throw new InvalidDatatypeValueException(
  -                    getErrorString(DatatypeMessageProvider.NotAnEnumValue,
  -                    DatatypeMessageProvider.MSG_NONE,
  -                                           new Object [] { v}));
  +                                               getErrorString(DatatypeMessageProvider.NotAnEnumValue,
  +                                                              DatatypeMessageProvider.MSG_NONE,
  +                                                              new Object [] { v}));
   
       }
   
  @@ -340,9 +381,9 @@
               return "Illegal Errorcode "+minor;
           }
       }
  -  /**
  -     * Returns a copy of this object.
  -     */
  +    /**
  +       * Returns a copy of this object.
  +       */
       public Object clone() throws CloneNotSupportedException {
           throw new CloneNotSupportedException("clone() is not supported in "+this.getClass().getName());
       }
  
  
  
  1.16      +8 -3      xml-xerces/java/src/org/apache/xerces/validators/datatype/StringDatatypeValidator.java
  
  Index: StringDatatypeValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/StringDatatypeValidator.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- StringDatatypeValidator.java	2000/07/29 02:59:22	1.15
  +++ StringDatatypeValidator.java	2000/07/31 17:56:52	1.16
  @@ -73,7 +73,7 @@
    * @author Ted Leung
    * @author Kito D. Mann, Virtua Communications Corp.
    * @author Jeffrey Rodriguez
  - * @version $Id: StringDatatypeValidator.java,v 1.15 2000/07/29 02:59:22 jeffreyr Exp $
  + * @version $Id: StringDatatypeValidator.java,v 1.16 2000/07/31 17:56:52 jeffreyr Exp $
    */
   public class StringDatatypeValidator extends AbstractDatatypeValidator{
       private Locale     fLocale          = null;
  @@ -280,7 +280,7 @@
       {
           if ( fDerivedByList == false  ) {
               if (fFacetsDefined != 0 )//Any facets to validate
  -                checkContent( content );
  +                checkContent( content, state );
           } else { //derived by list 
               checkContentList( content, state );
           }
  @@ -305,8 +305,13 @@
           return null;
       }
   
  -    private void checkContent( String content )throws InvalidDatatypeValueException
  +    private void checkContent( String content, Object state )throws InvalidDatatypeValueException
       {
  +
  +        if ( this.fBaseValidator != null ) {//validate against parent type if any
  +            this.fBaseValidator.validate( content, state );
  +        }
  +
           if ( (fFacetsDefined & DatatypeValidator.FACET_MAXLENGTH) != 0 ) {
               if ( content.length() > fMaxLength ) {
                   throw new InvalidDatatypeValueException("Value '"+content+