You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ne...@apache.org on 2001/05/17 22:59:05 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/validators/schema/identity IdentityConstraint.java

neilg       01/05/17 13:59:04

  Modified:    java/src/org/apache/xerces/validators/schema
                        TraverseSchema.java
               java/src/org/apache/xerces/validators/schema/identity
                        IdentityConstraint.java
  Log:
  rcase-nameAndTypeOK.5 support
  
  Revision  Changes    Path
  1.159     +95 -2     xml-xerces/java/src/org/apache/xerces/validators/schema/TraverseSchema.java
  
  Index: TraverseSchema.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/TraverseSchema.java,v
  retrieving revision 1.158
  retrieving revision 1.159
  diff -u -r1.158 -r1.159
  --- TraverseSchema.java	2001/05/17 17:18:52	1.158
  +++ TraverseSchema.java	2001/05/17 20:58:48	1.159
  @@ -128,7 +128,7 @@
    *  
    * @see org.apache.xerces.validators.common.Grammar
    *
  - * @version $Id: TraverseSchema.java,v 1.158 2001/05/17 17:18:52 lmartin Exp $
  + * @version $Id: TraverseSchema.java,v 1.159 2001/05/17 20:58:48 neilg Exp $
    */
   public class TraverseSchema implements 
                               NamespacesScope.NamespacesHandler{
  @@ -4403,13 +4403,106 @@
           throw new ParticleRecoverableError("rcase-nameAndTypeOK.4:  Element " +fStringPool.toString(localpart1) + "is either not fixed, or is not fixed with the same value as in the base");
         }
            
  -      // check identity constraints - TO BE DONE
  +      // check identity constraints 
  +      checkIDConstraintRestriction(eltndx1, eltndx2, aGrammar, localpart1, localpart2);
   
         // check disallowed substitutions - TO BE DONE
   
         // check that the derived element's type is derived from the base's. - TO BE DONE
     
       }
  +
  +    private void checkIDConstraintRestriction(int derivedElemIndex, int baseElemIndex, 
  +                SchemaGrammar grammar, int derivedElemName, int baseElemName) throws Exception {
  +        // this method throws no errors if the ID constraints on
  +        // the derived element are a logical subset of those on the
  +        // base element--that is, those that are present are
  +        // identical to ones in the base element.  
  +        XMLElementDecl derivedElemDecl = new XMLElementDecl();
  +        grammar.getElementDecl(derivedElemIndex, derivedElemDecl);
  +        XMLElementDecl baseElemDecl = new XMLElementDecl();
  +        grammar.getElementDecl(baseElemIndex, baseElemDecl);
  +        Vector derivedUnique = derivedElemDecl.unique;
  +        Vector baseUnique = baseElemDecl.unique;
  +        if(derivedUnique.size() > baseUnique.size()) {
  +            throw new ParticleRecoverableError("rcase-nameAndTypeOK.5:  derived element " + 
  +                    fStringPool.toString(derivedElemName) + 
  +                    " has fewer <unique> Identity Constraints than the base element"+
  +                    fStringPool.toString(baseElemName));
  +        } else {
  +            boolean found = true;
  +            for(int i=0; i<derivedUnique.size() && found; i++) {
  +                Unique id = (Unique)derivedUnique.elementAt(i);
  +                found = false;
  +                for(int j=0; j<baseUnique.size(); j++) {
  +                    if(id.equals((Unique)baseUnique.elementAt(j))) {
  +                        found = true;
  +                        break;
  +                    }
  +                }
  +            }
  +            if(!found) {
  +                throw new ParticleRecoverableError("rcase-nameAndTypeOK.5:  derived element " + 
  +                    fStringPool.toString(derivedElemName) + 
  +                    " has a <unique> Identity Constraint that does not appear on the base element"+
  +                    fStringPool.toString(baseElemName));
  +            }
  +        }
  +
  +        Vector derivedKey = derivedElemDecl.key;
  +        Vector baseKey = baseElemDecl.key;
  +        if(derivedKey.size() > baseKey.size()) {
  +            throw new ParticleRecoverableError("rcase-nameAndTypeOK.5:  derived element " + 
  +                    fStringPool.toString(derivedElemName) + 
  +                    " has fewer <key> Identity Constraints than the base element"+
  +                    fStringPool.toString(baseElemName));
  +        } else {
  +            boolean found = true;
  +            for(int i=0; i<derivedKey.size() && found; i++) {
  +                Key id = (Key)derivedKey.elementAt(i);
  +                found = false;
  +                for(int j=0; j<baseKey.size(); j++) {
  +                    if(id.equals((Key)baseKey.elementAt(j))) {
  +                        found = true;
  +                        break;
  +                    }
  +                }
  +            }
  +            if(!found) {
  +                throw new ParticleRecoverableError("rcase-nameAndTypeOK.5:  derived element " + 
  +                    fStringPool.toString(derivedElemName) + 
  +                    " has a <key> Identity Constraint that does not appear on the base element"+
  +                    fStringPool.toString(baseElemName));
  +            }
  +        }
  +
  +        Vector derivedKeyRef = derivedElemDecl.keyRef;
  +        Vector baseKeyRef = baseElemDecl.keyRef;
  +        if(derivedKeyRef.size() > baseKeyRef.size()) {
  +            throw new ParticleRecoverableError("rcase-nameAndTypeOK.5:  derived element " + 
  +                    fStringPool.toString(derivedElemName) + 
  +                    " has fewer <keyref> Identity Constraints than the base element"+
  +                    fStringPool.toString(baseElemName));
  +        } else {
  +            boolean found = true;
  +            for(int i=0; i<derivedKeyRef.size() && found; i++) {
  +                KeyRef id = (KeyRef)derivedKeyRef.elementAt(i);
  +                found = false;
  +                for(int j=0; j<baseKeyRef.size(); j++) {
  +                    if(id.equals((KeyRef)baseKeyRef.elementAt(j))) {
  +                        found = true;
  +                        break;
  +                    }
  +                }
  +            }
  +            if(!found) {
  +                throw new ParticleRecoverableError("rcase-nameAndTypeOK.5:  derived element " + 
  +                    fStringPool.toString(derivedElemName) + 
  +                    " has a <keyref> Identity Constraint that does not appear on the base element"+
  +                    fStringPool.toString(baseElemName));
  +            }
  +        }
  +    } // checkIDConstraintRestriction
   
       private boolean checkOccurrenceRange(int min1, int max1, int min2, int max2) {
   
  
  
  
  1.4       +16 -1     xml-xerces/java/src/org/apache/xerces/validators/schema/identity/IdentityConstraint.java
  
  Index: IdentityConstraint.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/identity/IdentityConstraint.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- IdentityConstraint.java	2001/02/20 06:12:28	1.3
  +++ IdentityConstraint.java	2001/05/17 20:58:59	1.4
  @@ -61,7 +61,7 @@
    * Base class of Schema identity constraint.
    *
    * @author Andy Clark, IBM
  - * @version $Id: IdentityConstraint.java,v 1.3 2001/02/20 06:12:28 andyc Exp $
  + * @version $Id: IdentityConstraint.java,v 1.4 2001/05/17 20:58:59 neilg Exp $
    */
   public abstract class IdentityConstraint {
   
  @@ -178,5 +178,20 @@
           }
           return s;
       } // toString():String
  +
  +    // equals:  returns true if and only if the String
  +    // representations of all members of both objects (except for
  +    // the elenemtName field) are equal.
  +    public boolean equals(IdentityConstraint id) {
  +        boolean areEqual = fIdentityConstraintName.equals(id.fIdentityConstraintName);
  +        if(!areEqual) return false;
  +        areEqual = fSelector.toString().equals(id.fSelector.toString());
  +        if(!areEqual) return false;
  +        areEqual = (fFieldCount == id.fFieldCount);
  +        if(!areEqual) return false;
  +        for(int i=0; i<fFieldCount; i++) 
  +            if(!fFields[i].toString().equals(id.fFields[i].toString())) return false;
  +        return true;
  +    } // equals
   
   } // class IdentityConstraint
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org