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/08/12 04:30:16 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/validators/datatype IDDatatypeValidator.java IDREFDatatypeValidator.java StateMessageDatatype.java

jeffreyr    00/08/11 19:30:16

  Modified:    java/src/org/apache/xerces/validators/datatype
                        IDDatatypeValidator.java
                        IDREFDatatypeValidator.java
                        StateMessageDatatype.java
  Log:
  ID, IDs connection
  
  Revision  Changes    Path
  1.8       +20 -14    xml-xerces/java/src/org/apache/xerces/validators/datatype/IDDatatypeValidator.java
  
  Index: IDDatatypeValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/IDDatatypeValidator.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- IDDatatypeValidator.java	2000/08/11 02:12:01	1.7
  +++ IDDatatypeValidator.java	2000/08/12 02:30:15	1.8
  @@ -67,7 +67,7 @@
    * These validators can be supplied by the application writer and may be useful as
    * standalone code as well as plugins to the validator architecture.
    * @author Jeffrey Rodriguez
  - * @version $Id: IDDatatypeValidator.java,v 1.7 2000/08/11 02:12:01 jeffreyr Exp $
  + * @version $Id: IDDatatypeValidator.java,v 1.8 2000/08/12 02:30:15 jeffreyr Exp $
    */
   public class IDDatatypeValidator extends AbstractDatatypeValidator {
       private DatatypeValidator         fBaseValidator = null;
  @@ -75,7 +75,8 @@
       private Object                        fNullValue = null;
       private DatatypeMessageProvider fMessageProvider = new DatatypeMessageProvider();
       private Hashtable                     fTableOfId;
  -    private Locale            fLocale           = null;
  +    private Locale                 fLocale           = null;
  +    public static final  int          IDREF_STORE    = 0;
   
   
   
  @@ -104,7 +105,7 @@
        * @exception InvalidDatatypeValueException
        * @see org.apache.xerces.validators.datatype.InvalidDatatypeValueException
        */
  -    public Object validate(String content, Object state ) throws InvalidDatatypeValueException{
  +    public Object validate(String content, Object IDStorage ) throws InvalidDatatypeValueException{
           //Pass content as a String
   
           if (!XMLCharacterProperties.validName(content)) {//Check if is valid key-[81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
  @@ -114,15 +115,16 @@
               error.setMinorCode(XMLMessages.VC_ID);
               throw error;
           }
  -        if(!addId( content, state) ){
  +        if(!addId( content, IDStorage) ){
  +            //System.out.println("Should not be here" );
               InvalidDatatypeValueException error = 
  -                   new InvalidDatatypeValueException( "ID" + content +"has to be unique" );
  +                   new InvalidDatatypeValueException( "ID" + content +" has to be unique" );
               error.setMajorCode(XMLMessages.MSG_ID_NOT_UNIQUE);
               error.setMinorCode(XMLMessages.VC_ID);
               throw error;
  -
           }
  -        return null;
  +        //System.out.println("IDStorage = " + IDStorage );
  +        return fTableOfId;//Return the table of Id
       }
   
       /**
  @@ -161,21 +163,25 @@
       }
   
       /** addId. */
  -    private boolean addId(String content, Object state) {
  +    private boolean addId(String content, Object idTable) {
   
  -        if ( state == null ) {
  -            if ( this.fTableOfId == null ){
  -                this.fTableOfId = new Hashtable();
  +        //System.out.println("state = " + state );
  +            if ( this.fTableOfId == null ) {
  +               this.fTableOfId = new Hashtable();//Gain reference to table
               } else if ( this.fTableOfId.containsKey( content ) ){ 
  +               //System.out.println("ID - it already has this key =" + content );
  +
                   return false;
               }
               if ( this.fNullValue == null ){
                   fNullValue = new Object();
               }
  +            //System.out.println("Before putting content" + content );
  +            try {
               this.fTableOfId.put( content, fNullValue ); 
  -        } else {
  -            ;
  -        }
  +            } catch( Exception ex ){
  +                ex.printStackTrace();
  +            }
           return true;
       } // addId(int):boolean
   
  
  
  
  1.9       +40 -31    xml-xerces/java/src/org/apache/xerces/validators/datatype/IDREFDatatypeValidator.java
  
  Index: IDREFDatatypeValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/IDREFDatatypeValidator.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- IDREFDatatypeValidator.java	2000/08/11 22:09:48	1.8
  +++ IDREFDatatypeValidator.java	2000/08/12 02:30:15	1.9
  @@ -60,6 +60,7 @@
   import java.util.Hashtable;
   import java.util.Locale;
   import java.util.Enumeration;
  +import java.util.StringTokenizer;
   import org.apache.xerces.utils.XMLCharacterProperties;
   import org.apache.xerces.utils.XMLMessages;
   
  @@ -73,7 +74,7 @@
    * standalone code as well as plugins to the validator architecture.
    * 
    * @author Jeffrey Rodriguez-
  - * @version $Id: IDREFDatatypeValidator.java,v 1.8 2000/08/11 22:09:48 jeffreyr Exp $
  + * @version $Id: IDREFDatatypeValidator.java,v 1.9 2000/08/12 02:30:15 jeffreyr Exp $
    */
   public class IDREFDatatypeValidator extends AbstractDatatypeValidator {
       private DatatypeValidator fBaseValidator    = null;
  @@ -100,8 +101,6 @@
           fDerivedByList = derivedByList;
           setBasetype( base ); // Set base type 
   
  -
  -
       }
   
   
  @@ -129,6 +128,7 @@
               if (state!= null){
                   message = (StateMessageDatatype) state;    
                   if (message.getDatatypeState() == IDREFDatatypeValidator.IDREF_CLEAR ){
  +                    //System.out.println("Received a IDREF Clear" );
                       if ( this.fTableOfId != null ){
                           fTableOfId.clear(); //This is pass to us through the state object
                       }
  @@ -137,6 +137,7 @@
                       }
                       return null;
                   } else if ( message.getDatatypeState() == IDREFDatatypeValidator.IDREF_VALIDATE ){
  +                    //System.out.println("Call to Validate" );
                       this.checkIdRefs();//Validate that all keyRef is a keyIds
                   } else if ( message.getDatatypeState() == IDREFDatatypeValidator.IDREF_STORE ) {
                       this.fTableOfId = (Hashtable) message.getDatatypeObject();
  @@ -148,10 +149,11 @@
                           error.setMinorCode(XMLMessages.VC_IDREF);
                           throw error;//Need Message
                       }
  +                    //System.out.println("Content = " + content );
                       addIdRef( content, state);// We are storing IDs 
                   }
               }
  -        } else {
  +         } else {
   
               if (state!= null){
                   message = (StateMessageDatatype) state;    
  @@ -164,8 +166,21 @@
                       }
                       return null;
   
  +                } else if ( message.getDatatypeState() == IDREFDatatypeValidator.IDREF_VALIDATE ){
  +                    ////System.out.println("Call to Validate" );
  +                    this.checkIdRefs();//Validate that all keyRef is a keyIds
  +                } else if ( message.getDatatypeState() == IDREFDatatypeValidator.IDREF_STORE ) {
  +                    //System.out.println("IDREFS = " + content );
  +                    StringTokenizer   tokenizer = new StringTokenizer( content );
  +                    this.fTableOfId = (Hashtable) message.getDatatypeObject();
  +                    while ( tokenizer.hasMoreTokens() ) {
  +                        String idName = tokenizer.nextToken(); 
  +                        addIdRef( idName, state);// We are storing IDs 
  +                    }
                   }
  +
               }
  +
           }
           return null;
       }
  @@ -207,48 +222,42 @@
   
       /** addId. */
       private void addIdRef(String content, Object state) {
  +        //System.out.println("this.fTableOfId = " + this.fTableOfId );
  +        //System.out.println("this =  " + this );
   
  -        if ( state == null ) {
  -            if (content != null &&  this.fTableOfId.containsKey( content ) ){
  -                return;
  -            }
  -            if ( this.fTableIDRefs == null ){
  -                this.fTableIDRefs = new Hashtable();
  -            } else if ( fTableIDRefs.containsKey( content ) ){
  -                return;
  -            }
  +        if ( this.fTableOfId != null &&  this.fTableOfId.containsKey( content ) ){
  +            //System.out.println("It already contains key = " + content );
  +            return;
  +        }
  +        if ( this.fTableIDRefs == null ){
  +            this.fTableIDRefs = new Hashtable();
  +        } else if ( fTableIDRefs.containsKey( content ) ){
  +            return;
  +        }
   
  -            if ( this.fNullValue == null ){
  -                fNullValue = new Object();
  -            }
  -            this.fTableIDRefs.put( content, fNullValue ); 
  -        } else {
  -            ;
  +        if ( this.fNullValue == null ){
  +            fNullValue = new Object();
           }
  +        //System.out.println("tabl IDREFs = " + this.fTableIDRefs );
  +        this.fTableIDRefs.put( content, fNullValue ); 
       } // addId(int):boolean
   
   
       private void checkIdRefs() throws InvalidDatatypeValueException {
           if ( this.fTableIDRefs == null)
               return;
  +        
           Enumeration en = this.fTableIDRefs.keys();
           while (en.hasMoreElements()) {
  -            Integer key = (Integer)en.nextElement();
  +            String key = (String)en.nextElement();
  +
               if ( this.fTableOfId == null || ! this.fTableOfId.containsKey(key)) {
                   InvalidDatatypeValueException error =  new
  -                                                       InvalidDatatypeValueException( "ID is not valid: " );
  -                error.setMajorCode(XMLMessages.MSG_ELEMENT_WITH_ID_REQUIRED);
  -                error.setMinorCode(XMLMessages.VC_IDREF);
  +                            InvalidDatatypeValueException( key );
  +                error.setMinorCode(XMLMessages.MSG_ELEMENT_WITH_ID_REQUIRED);
  +                error.setMajorCode(XMLMessages.VC_IDREF);
                   throw error;
               }
  -            //    Object[] args = { key.intValue() };
  -
  -            //  fErrorReporter.reportError(fErrorReporter.getLocator(),
  -            //                           XMLMessages.XML_DOMAIN,
  -            //                         XMLMessages.MSG_ELEMENT_WITH_ID_REQUIRED,
  -            //                       XMLMessages.VC_IDREF,
  -            //                     args,
  -            //                   XMLErrorReporter.ERRORTYPE_RECOVERABLE_ERROR);
           }
   
       } // checkIdRefs()
  
  
  
  1.2       +1 -0      xml-xerces/java/src/org/apache/xerces/validators/datatype/StateMessageDatatype.java
  
  Index: StateMessageDatatype.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/StateMessageDatatype.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StateMessageDatatype.java	2000/08/11 02:12:02	1.1
  +++ StateMessageDatatype.java	2000/08/12 02:30:15	1.2
  @@ -59,6 +59,7 @@
   
   public interface StateMessageDatatype{
       public Object getDatatypeObject();
  +    public void   setDatatypeObject( Object data );
       public int    getDatatypeState();
   
   }