You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by el...@apache.org on 2001/02/21 23:24:42 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/validators/datatype AbstractDatatypeValidator.java DecimalDatatypeValidator.java DoubleDatatypeValidator.java FloatDatatypeValidator.java ListDatatypeValidator.java StringDatatypeValidator.java UnionDatatypeValidator.java

elena       01/02/21 14:24:41

  Modified:    java/src/org/apache/xerces/validators/datatype
                        AbstractDatatypeValidator.java
                        DecimalDatatypeValidator.java
                        DoubleDatatypeValidator.java
                        FloatDatatypeValidator.java
                        ListDatatypeValidator.java
                        StringDatatypeValidator.java
                        UnionDatatypeValidator.java
  Log:
  Implemented compare() methods on *main* datatypes.
  More work needs to be done..
  
  Revision  Changes    Path
  1.5       +6 -4      xml-xerces/java/src/org/apache/xerces/validators/datatype/AbstractDatatypeValidator.java
  
  Index: AbstractDatatypeValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/AbstractDatatypeValidator.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractDatatypeValidator.java	2001/02/14 21:28:29	1.4
  +++ AbstractDatatypeValidator.java	2001/02/21 22:24:35	1.5
  @@ -57,7 +57,8 @@
   
   
   /**
  - * @version $Id: AbstractDatatypeValidator.java,v 1.4 2001/02/14 21:28:29 elena Exp $
  + * @version $Id: AbstractDatatypeValidator.java,v 1.5 2001/02/21 22:24:35 elena Exp $
  + * @author  Elena Litani
    * @author  Jeffrey Rodriguez
   */
   
  @@ -101,7 +102,8 @@
        * @return
        */
       public Hashtable getFacets() {
  -        return null;  // Not implemented yet
  +        //REVISIT: do we really need getFacets? 
  +        return fFacets;  
       }
       
       /**
  @@ -121,8 +123,8 @@
        * @param valu2
        * @return
        */
  -    public int compare(String value1, String valu2) {
  -        return 0;     //Not implemented yet 
  +    public int compare(String value1, String value2) {
  +        return value1.compareTo(value2);
       }
   
   
  
  
  
  1.17      +11 -26    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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- DecimalDatatypeValidator.java	2001/01/17 20:46:02	1.16
  +++ DecimalDatatypeValidator.java	2001/02/21 22:24:35	1.17
  @@ -71,10 +71,11 @@
    *
    * DecimalValidator validates that content satisfies the W3C XML Datatype for decimal
    *
  + * @author  Elena Litani
    * @author Ted Leung
    * @author Jeffrey Rodriguez
    * @author Mark Swinkles - List Validation refactoring
  - * @version $Id: DecimalDatatypeValidator.java,v 1.16 2001/01/17 20:46:02 elena Exp $
  + * @version $Id: DecimalDatatypeValidator.java,v 1.17 2001/02/21 22:24:35 elena Exp $
    */
   
   public class DecimalDatatypeValidator extends AbstractDatatypeValidator {
  @@ -427,9 +428,6 @@
           fLocale = locale;
       }
   
  -    public Hashtable getFacets(){
  -        return fFacets;
  -    }
   
       private String getErrorString(int major, int minor, Object args[]) {
           try {
  @@ -444,31 +442,18 @@
       public Object clone() throws CloneNotSupportedException {
           throw new CloneNotSupportedException("clone() is not supported in "+this.getClass().getName());
       }
  -
   
  -    /*
  -    public static void main(String args[]) {
  -        // simple unit test
  +        
  +    public int compare( String value1, String value2){
           try {
  -            DatatypeValidator v = new DecimalValidator();
  -            Hashtable facets = new Hashtable();
  -            facets.put("minInclusive","0");
  -            DatatypeValidator nonneg = new DecimalValidator();
  -            nonneg.setBasetype(v);
  -            nonneg.setFacets(facets);
  -            facets = new Hashtable();
  -            facets.put("minInclusive","-1");
  -            DatatypeValidator bad = new DecimalValidator();
  -            bad.setBasetype(nonneg);
  -            bad.setFacets(facets);
  -        } catch (Exception e) {
  -            e.printStackTrace();
  +            //REVISIT: datatypes create lots of *new* objects..
  +            BigDecimal d1 = new BigDecimal(stripPlusIfPresent(value1));
  +            BigDecimal d2 = new BigDecimal(stripPlusIfPresent(value2));
  +            return d1.compareTo(d2);
  +        } catch (NumberFormatException e){
  +            //REVISIT: should we throw exception??
  +            return -1;
           }
  -    }
  -    */
  -
  -    public int compare( String content1, String content2){
  -        return 0;
       }
   
   
  
  
  
  1.12      +14 -20    xml-xerces/java/src/org/apache/xerces/validators/datatype/DoubleDatatypeValidator.java
  
  Index: DoubleDatatypeValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/DoubleDatatypeValidator.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DoubleDatatypeValidator.java	2001/01/17 20:46:03	1.11
  +++ DoubleDatatypeValidator.java	2001/02/21 22:24:35	1.12
  @@ -65,11 +65,11 @@
   import org.apache.xerces.utils.regex.RegularExpression;
   
   /**
  - *
  + * @author Elena Litani
    * @author Ted Leung
    * @author Jeffrey Rodriguez
    * @author Mark Swinkles - List Validation refactoring
  - * @version $Id: DoubleDatatypeValidator.java,v 1.11 2001/01/17 20:46:03 elena Exp $
  + * @version $Id: DoubleDatatypeValidator.java,v 1.12 2001/02/21 22:24:35 elena Exp $
    */
   
   public class DoubleDatatypeValidator extends AbstractDatatypeValidator {
  @@ -380,27 +380,21 @@
                                                                 new Object [] { new Double(v)}));
       }
   
  -    /**
  -     * Compare two Double datatype. Comparison is
  -     * in Space value.
  -     * 
  -     * @param content1
  -     * @param content2
  -     * @return 
  -     */
  -    public int compare( String content1, String content2){
  -        return 0;
  +    
  +   public int compare( String value1, String value2){
  +        try {
  +            //REVISIT: datatypes create lots of *new* objects..
  +            Double d1 = Double.valueOf(value1);
  +            Double d2 = Double.valueOf(value2);
  +            return d1.compareTo(d2);
  +        } catch (NumberFormatException e){
  +            //REVISIT: should we throw exception??
  +            return -1;
  +        }
       }
   
   
  -    /**
  -     * Returns a Hashtable containing facet information.
  -     * 
  -     * @return 
  -     */
  -    public Hashtable getFacets(){
  -        return null;
  -    }
  +
       /**
          * Returns a copy of this object.
          */
  
  
  
  1.13      +15 -13    xml-xerces/java/src/org/apache/xerces/validators/datatype/FloatDatatypeValidator.java
  
  Index: FloatDatatypeValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/FloatDatatypeValidator.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- FloatDatatypeValidator.java	2001/01/17 20:46:04	1.12
  +++ FloatDatatypeValidator.java	2001/02/21 22:24:36	1.13
  @@ -68,10 +68,11 @@
   
   /**
    *
  + * @author  Elena Litani
    * @author Ted Leung
    * @author Jeffrey Rodriguez
    * @author Mark Swinkles - List Validation refactoring
  - * @version  $Id: FloatDatatypeValidator.java,v 1.12 2001/01/17 20:46:04 elena Exp $
  + * @version  $Id: FloatDatatypeValidator.java,v 1.13 2001/02/21 22:24:36 elena Exp $
    */
   
   public class FloatDatatypeValidator extends AbstractDatatypeValidator {
  @@ -395,21 +396,22 @@
           fLocale = locale;
       }
   
  -    public int compare( String content1, String content2){
  -        return 0;
  -    }
  -
  -
  -    
  -
  -
  +    public int compare( String value1, String value2){
  +        try {
  +           //REVISIT: datatypes create lots of *new* objects..
  +           Float f1 = Float.valueOf(value1);
  +           Float f2 = Float.valueOf(value2);
  +           return f1.compareTo(f2);
  +       } catch (NumberFormatException e){
  +           //REVISIT: should we throw exception??
  +           return -1;
  +       }
   
  -    public Hashtable getFacets(){
  -        return null;
       }
  +
       /**
  -       * 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.6       +31 -13    xml-xerces/java/src/org/apache/xerces/validators/datatype/ListDatatypeValidator.java
  
  Index: ListDatatypeValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/ListDatatypeValidator.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ListDatatypeValidator.java	2001/01/17 20:46:05	1.5
  +++ ListDatatypeValidator.java	2001/02/21 22:24:37	1.6
  @@ -70,9 +70,10 @@
   
   /**
    * StringValidator validates that XML content is a W3C string type.
  + * @author  Elena Litani
    * @author Jeffrey Rodriguez
    * @author Mark Swinkles - List Validation refactoring
  - * @version $Id: ListDatatypeValidator.java,v 1.5 2001/01/17 20:46:05 elena Exp $
  + * @version $Id: ListDatatypeValidator.java,v 1.6 2001/02/21 22:24:37 elena Exp $
    */
   public class ListDatatypeValidator extends AbstractDatatypeValidator{
       private Locale     fLocale          = null;
  @@ -200,13 +201,33 @@
           return null;
       }
   
  -    public int compare( String content, String facetValue ){
  -        // if derive by list then this should iterate through
  -        // the tokens in each string and compare using the base type
  -        // compare function.
  -        // if not derived by list just pass the compare down to the
  -        // base type.
  -        return 0;
  +    public int compare( String value1, String value2 ){
  +        if (!fDerivedByList) { //derived by restriction
  +          return ((ListDatatypeValidator)this.fBaseValidator).compare( value1, value2 );
  +        }
  +        // <list> datatype
  +        StringTokenizer pList1 = new StringTokenizer( value1 );
  +        StringTokenizer pList2 = new StringTokenizer( value2 );
  +        int numberOfTokens = pList1.countTokens();         
  +        if (numberOfTokens < pList2.countTokens()) {
  +            return -1; 
  +        }
  +        else if (numberOfTokens > pList2.countTokens()) {
  +            return 1;
  +        }
  +        else { //compare each token
  +            int i=0;
  +            while(i++<numberOfTokens) {
  +                if ( this.fBaseValidator != null ) {
  +                    int returnValue = this.fBaseValidator.compare( pList1.nextToken(), pList2.nextToken());
  +                    if (returnValue!=0) {
  +                        return returnValue; //REVISIT: does it make sense to return -1 or +1..?
  +                    }
  +                }
  +                
  +            }
  +            return 0;
  +        }
       }
   
       /**
  @@ -246,11 +267,8 @@
               
               //REVISIT: attemt to make enumeration to be validated against value space.
               //a redesign of Datatypes might help to reduce complexity of this validation
  -        StringTokenizer parsedList = null;
  -        int numberOfTokens = 0;
  -        parsedList= new StringTokenizer( content );
  -        numberOfTokens =  parsedList.countTokens();
  -        
  +        StringTokenizer parsedList = new StringTokenizer( content );
  +        int numberOfTokens = parsedList.countTokens();         
           if (!this.fDerivedByList) { 
               //<simpleType name="fRestriction"><restriction base="fList">...</restriction></simpleType>
               try {
  
  
  
  1.20      +5 -12     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.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- StringDatatypeValidator.java	2001/02/15 23:14:29	1.19
  +++ StringDatatypeValidator.java	2001/02/21 22:24:37	1.20
  @@ -74,7 +74,7 @@
    * @author Kito D. Mann, Virtua Communications Corp.
    * @author Jeffrey Rodriguez
    * @author Mark Swinkles - List Validation refactoring
  - * @version $Id: StringDatatypeValidator.java,v 1.19 2001/02/15 23:14:29 elena Exp $
  + * @version $Id: StringDatatypeValidator.java,v 1.20 2001/02/21 22:24:37 elena Exp $
    */
   public class StringDatatypeValidator extends AbstractDatatypeValidator{
       private Locale     fLocale          = null;
  @@ -211,15 +211,6 @@
       }
   
   
  -    /**
  -     * 
  -     * @return   A Hashtable containing the facets
  -     *         for this datatype.
  -     */
  -    public Hashtable getFacets(){
  -        return null;
  -    }
  -
       private void checkContent( String content, Object state )throws InvalidDatatypeValueException
       {
   
  @@ -263,10 +254,12 @@
           }
   
       }
  -    public int compare( String content, String facetValue ){
  +
  +
  +    public int compare( String value1, String value2 ){
           Locale    loc       = Locale.getDefault();
           Collator  collator  = Collator.getInstance( loc );
  -        return collator.compare( content, facetValue );
  +        return collator.compare( value1, value2 );
       }
   
       /**
  
  
  
  1.4       +16 -9     xml-xerces/java/src/org/apache/xerces/validators/datatype/UnionDatatypeValidator.java
  
  Index: UnionDatatypeValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/UnionDatatypeValidator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- UnionDatatypeValidator.java	2001/01/17 20:46:07	1.3
  +++ UnionDatatypeValidator.java	2001/02/21 22:24:37	1.4
  @@ -173,13 +173,21 @@
           return(null);
       }
   
  -    public int compare( String content, String facetValue ){
  -        // if derive by list then this should iterate through
  -        // the tokens in each string and compare using the base type
  -        // compare function.
  -        // if not derived by list just pass the compare down to the
  -        // base type.
  -        return(0);
  +    public int compare( String value1, String value2 ){
  +        if (fBaseValidator != null) {
  +            return this.fBaseValidator.compare(value1, value2);
  +        }
  +        //union datatype
  +        int index=-1;
  +        DatatypeValidator currentDV;
  +        while ( ++index < fValidatorsSize ) {  
  +            currentDV =  (DatatypeValidator)this.fBaseValidators.elementAt(index);
  +            if (currentDV.compare(value1, value2) == 0) {
  +                return  0;
  +            }
  +        }
  +        //REVISIT: what does it mean for UNION1 to be <less than> or <greater than> UNION2 ?
  +        return -1;
       }
   
       /**
  @@ -263,8 +271,7 @@
               return;
           }
           // native union type
  -        while ( (fValidatorsSize-1) > index++ ) {  
  -
  +        while ( ++index < fValidatorsSize) {  
               // check content against each base validator in Union
               // report an error only in case content is not valid against all base datatypes.
               currentDV =  (DatatypeValidator)this.fBaseValidators.elementAt(index);