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/01 15:56:11 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/validators/schema/identity IDValue.java Field.java Selector.java XPathMatcher.java ValueStore.java

neilg       01/05/01 06:56:11

  Modified:    java/src/org/apache/xerces/validators/common
                        XMLValidator.java
               java/src/org/apache/xerces/validators/schema
                        TraverseSchema.java
               java/src/org/apache/xerces/validators/schema/identity
                        Field.java Selector.java XPathMatcher.java
                        ValueStore.java
  Added:       java/src/org/apache/xerces/validators/schema/identity
                        IDValue.java
  Log:
  More fixes for identity constraint support.
  Since we cannot statically determine the datatype validator corresponding
  to a certain field (because of wildcards, both in content models
  and in ID constraints), these need to be tied to the value the
  identity constraint matches to.  This fix implements this support.
  This involved a bit of a rework of AndyC's careful XPathMatcher
  interface.
  
  Still to come:
  
  - full support for descendant and union operator in selectors;
  - making sure we can survive grammar switches;
  - lots more error checking.
  
  Revision  Changes    Path
  1.139     +20 -36    xml-xerces/java/src/org/apache/xerces/validators/common/XMLValidator.java
  
  Index: XMLValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/common/XMLValidator.java,v
  retrieving revision 1.138
  retrieving revision 1.139
  diff -u -r1.138 -r1.139
  --- XMLValidator.java	2001/04/26 17:44:59	1.138
  +++ XMLValidator.java	2001/05/01 13:56:09	1.139
  @@ -103,6 +103,7 @@
   import org.apache.xerces.validators.schema.identity.Field;
   import org.apache.xerces.validators.schema.identity.FieldActivator;
   import org.apache.xerces.validators.schema.identity.IdentityConstraint;
  +import org.apache.xerces.validators.schema.identity.IDValue;
   import org.apache.xerces.validators.schema.identity.Key;
   import org.apache.xerces.validators.schema.identity.KeyRef;
   import org.apache.xerces.validators.schema.identity.Selector;
  @@ -122,7 +123,7 @@
   /**
    * This class is the super all-in-one validator used by the parser.
    *
  - * @version $Id: XMLValidator.java,v 1.138 2001/04/26 17:44:59 lmartin Exp $
  + * @version $Id: XMLValidator.java,v 1.139 2001/05/01 13:56:09 neilg Exp $
    */
   public final class XMLValidator
       implements DefaultEntityHandler.EventHandler,
  @@ -638,7 +639,7 @@
           ValueStore valueStore = fValueStoreCache.getValueStoreFor(field);
           XPathMatcher matcher = field.createMatcher(valueStore);
           fMatcherStack.addMatcher(matcher);
  -        matcher.startDocumentFragment(fStringPool, fNamespacesScope);
  +        matcher.startDocumentFragment(fStringPool, (SchemaGrammar)fGrammar);
           return matcher;
       } // activateField(Field):XPathMatcher
   
  @@ -1165,7 +1166,7 @@
                 if (DEBUG_IDENTITY_CONSTRAINTS) {
                     System.out.println("<IC>: "+matcher.toString()+"#startElement("+fStringPool.toString(element.rawname)+")");
                 }
  -              matcher.startElement(element, fAttrList, fAttrListHandle);
  +              matcher.startElement(element, fAttrList, fAttrListHandle, fCurrentScope);
             }
         }
         
  @@ -1245,7 +1246,7 @@
           if (DEBUG_IDENTITY_CONSTRAINTS) {
               System.out.println("<IC>: "+matcher+"#startDocumentFragment()");
           }
  -        matcher.startDocumentFragment(fStringPool, null);
  +        matcher.startDocumentFragment(fStringPool, (SchemaGrammar)fGrammar);
       }
   
      private void pushContentLeafStack() throws Exception {
  @@ -1369,7 +1370,7 @@
                if (DEBUG_IDENTITY_CONSTRAINTS) {
                    System.out.println("<IC>: "+matcher+"#endElement("+fStringPool.toString(fCurrentElement.rawname)+")");
                }
  -             matcher.endElement(fCurrentElement);
  +             matcher.endElement(fCurrentElement, fCurrentScope);
            }
            if (DEBUG_IDENTITY_CONSTRAINTS) {
                System.out.println("<IC>: popping context - element: "+fStringPool.toString(fCurrentElement.rawname));
  @@ -3174,7 +3175,7 @@
                               // WARNING!!!  Comparison by reference. 
                               if(tempVal == ancestorValidator) break;
                           if(tempVal == null) { 
  -                            // now if ancestorValidator is a union, then wemust
  +                            // now if ancestorValidator is a union, then we must
                               // look through its members to see whether we derive from any of them.
   			                if(ancestorValidator instanceof UnionDatatypeValidator) {
   			                    // fXsiTypeValidator must derive from one of its members...
  @@ -4436,7 +4437,7 @@
           //
   
           /** Not a value (Unicode: #FFFF). */
  -        protected final String NOT_A_VALUE = "\uFFFF";
  +        protected IDValue NOT_AN_IDVALUE = new IDValue("\uFFFF", null);
   
           //
           // Data
  @@ -4475,7 +4476,7 @@
               fValuesCount = 0;
               int count = fIdentityConstraint.getFieldCount();
               for (int i = 0; i < count; i++) {
  -                fValues.put(fIdentityConstraint.getFieldAt(i), NOT_A_VALUE);
  +                fValues.put(fIdentityConstraint.getFieldAt(i), NOT_AN_IDVALUE);
               }
           } // startValueScope()
   
  @@ -4552,7 +4553,7 @@
            *              is used to ensure that each field only adds a value
            *              once within a selection scope.
            */
  -        public void addValue(Field field, String value) throws Exception {
  +        public void addValue(Field field, IDValue value) throws Exception {
               if (DEBUG_VALUE_STORES) {
                   System.out.println("<VS>: "+toString()+"#addValue("+
                                      "field="+field+','+
  @@ -4569,8 +4570,8 @@
               }    
   
               // store value
  -            String storedValue = fValues.valueAt(index);
  -            if (storedValue.equals(NOT_A_VALUE)) {
  +            IDValue storedValue = fValues.valueAt(index);
  +            if (storedValue.isDuplicateOf(NOT_AN_IDVALUE)) {
                   fValuesCount++;
               }
               fValues.put(field, value);
  @@ -4598,36 +4599,19 @@
               }
              
               // do sizes match?
  -            int vcount = fValues.size();
               int tcount = tuple.size();
  -            if (vcount != tcount) {
  -                return false;
  -            }
   
               // iterate over tuples to find it
               int count = fValueTuples.size();
               LOOP: for (int i = 0; i < count; i++) {
                   OrderedHashtable vtuple = (OrderedHashtable)fValueTuples.elementAt(i);
                   // compare values
  -                for (int j = 0; j < vcount; j++) {
  -                    String value1 = vtuple.valueAt(j);
  -                    String value2 = tuple.valueAt(j);
  -                    Field field = fValues.keyAt(j);
  -                    DatatypeValidator validator = field.getDatatypeValidator();
  -                    // REVISIT: THIS DOESN'T WORK RIGHT BECAUSE THE
  -                    //          COMPARE METHOD OF ALL OF THE DATATYPE
  -                    //          VALIDATORS WERE NEVER IMPLEMENTED!
  -                    //          Once those methods are implemented,
  -                    //          then this code can be swapped out. -Ac
  -                    /***
  -                    if (validator.compare(value1, value2) != 0) {
  -                        continue LOOP;
  -                    }
  -                    /***/
  -                    if (!value1.equals(value2)) {
  +                for (int j = 0; j < tcount; j++) {
  +                    IDValue value1 = vtuple.valueAt(j);
  +                    IDValue value2 = tuple.valueAt(j);
  +                    if(!(value1.isDuplicateOf(value2))) {
                           continue LOOP;
                       }
  -                    /***/
                   }
   
                   // found it
  @@ -5029,7 +5013,7 @@
           } // size():int
   
           /** Puts an entry into the hashtable. */
  -        public void put(Field key, String value) {
  +        public void put(Field key, IDValue value) {
               int index = indexOf(key);
               if (index == -1) {
                   ensureCapacity(fSize);
  @@ -5040,7 +5024,7 @@
           } // put(Field,String)
   
           /** Returns the value associated to the specified key. */
  -        public String get(Field key) {
  +        public IDValue get(Field key) {
               return fEntries[indexOf(key)].value;
           } // get(Field):String
   
  @@ -5072,7 +5056,7 @@
           } // keyAt(int):Field
   
           /** Returns the value at the specified index. */
  -        public String valueAt(int index) {
  +        public IDValue valueAt(int index) {
               return fEntries[index].value;
           } // valueAt(int):String
   
  @@ -5172,7 +5156,7 @@
               public Field key;
   
               /** Value. */
  -            public String value;
  +            public IDValue value;
   
           } // class Entry
   
  
  
  
  1.135     +41 -31    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.134
  retrieving revision 1.135
  diff -u -r1.134 -r1.135
  --- TraverseSchema.java	2001/04/26 17:44:06	1.134
  +++ TraverseSchema.java	2001/05/01 13:56:10	1.135
  @@ -127,7 +127,7 @@
    *  
    * @see org.apache.xerces.validators.common.Grammar
    *
  - * @version $Id: TraverseSchema.java,v 1.134 2001/04/26 17:44:06 lmartin Exp $
  + * @version $Id: TraverseSchema.java,v 1.135 2001/05/01 13:56:10 neilg Exp $
    */
   public class TraverseSchema implements 
                               NamespacesScope.NamespacesHandler{
  @@ -156,8 +156,6 @@
        */
       private static final boolean DEBUG_IC_DATATYPES = false;
   
  -    //CR Implementation
  -    private static final boolean CR_IMPL = true;
       //private data members
   
   
  @@ -4793,26 +4791,30 @@
       } // traverseKeyRef(Element,XMLElementDecl)
   
       private void traverseIdentityConstraint(IdentityConstraint ic, 
  -                                            Element icelem) throws Exception {
  +                                            Element icElem) throws Exception {
           
  -        // get selector
  -        Element selem = XUtil.getFirstChildElementNS(icelem, 
  -                                                     SchemaSymbols.URI_SCHEMAFORSCHEMA,
  -                                                     SchemaSymbols.ELT_SELECTOR);
  -        String stext = CR_IMPL
  -                     ? selem.getAttribute(SchemaSymbols.ATT_XPATH) 
  -                     : XUtil.getChildText(selem);
  -        stext = stext.trim();
  -        Selector.XPath sxpath = null;
  +        // check for <annotation> and get selector
  +        Element sElem = XUtil.getFirstChildElement(icElem);
  +        sElem = checkContent( icElem, sElem, false);
  +        if(!sElem.getLocalName().equals(SchemaSymbols.ELT_SELECTOR)) {
  +            // REVISIT: localize
  +            reportGenericSchemaError("The content of an identity constraint must match (annotation?, selector, field+)");
  +        }
  +        // and make sure <selector>'s content is fine:
  +        checkContent(icElem, XUtil.getFirstChildElement(sElem), true);
  +
  +        String sText = sElem.getAttribute(SchemaSymbols.ATT_XPATH);
  +        sText = sText.trim();
  +        Selector.XPath sXpath = null;
           try {
               // REVISIT: Must get ruling from XML Schema working group
               //          regarding whether steps in the XPath must be
               //          fully qualified if the grammar has a target
               //          namespace. -Ac
               //          RESOLUTION: Yes.
  -            sxpath = new Selector.XPath(stext, fStringPool, 
  +            sXpath = new Selector.XPath(sText, fStringPool, 
                                           fNamespacesScope);
  -            Selector selector = new Selector(sxpath, ic);
  +            Selector selector = new Selector(sXpath, ic);
               if (DEBUG_IDENTITY_CONSTRAINTS) {
                   System.out.println("<IC>:   selector: "+selector);
               }
  @@ -4825,29 +4827,33 @@
           }
   
           // get fields
  -        Element parent = (Element)icelem.getParentNode();
  -        Element felem = XUtil.getNextSiblingElementNS(selem, 
  -                                                      SchemaSymbols.URI_SCHEMAFORSCHEMA,
  -                                                      SchemaSymbols.ELT_FIELD);
  -        while (felem != null) {
  -            String ftext = CR_IMPL
  -                         ? felem.getAttribute(SchemaSymbols.ATT_XPATH) 
  -                         : XUtil.getChildText(felem);
  -            ftext = ftext.trim();
  +        Element fElem = XUtil.getNextSiblingElement(sElem);
  +
  +        while (fElem != null) {
  +            if(!fElem.getLocalName().equals(SchemaSymbols.ELT_FIELD))
  +                // REVISIT: localize
  +                reportGenericSchemaError("The content of an identity constraint must match (annotation?, selector, field+)");
  +            // and make sure <field>'s content is fine:
  +            checkContent(icElem, XUtil.getFirstChildElement(fElem), true);
  +            String fText = fElem.getAttribute(SchemaSymbols.ATT_XPATH);
  +            fText = fText.trim();
               try {
                   // REVISIT: Must get ruling from XML Schema working group
                   //          regarding whether steps in the XPath must be
                   //          fully qualified if the grammar has a target
                   //          namespace. -Ac
                   //          RESOLUTION: Yes.
  -                Field.XPath fxpath = new Field.XPath(ftext, fStringPool, 
  +                Field.XPath fXpath = new Field.XPath(fText, fStringPool, 
                                                        fNamespacesScope);
                   // REVISIT: Get datatype validator. -Ac
  -                DatatypeValidator validator = getDatatypeValidatorFor(parent, sxpath, fxpath);
  -                if (DEBUG_IC_DATATYPES) {
  -                    System.out.println("<ICD>: datatype validator: "+validator);
  -                }
  -                Field field = new Field(fxpath, validator, ic);
  +                // cannot statically determine type of field; not just because of descendant/union
  +                // but because of <any> and <anyAttribute>.  - NG
  +                // DatatypeValidator validator = getDatatypeValidatorFor(parent, sXpath, fXpath);
  +                // if (DEBUG_IC_DATATYPES) {
  +                //  System.out.println("<ICD>: datatype validator: "+validator);
  +                // }
  +                // must find DatatypeValidator in the Validator...
  +                Field field = new Field(fXpath, ic);
                   if (DEBUG_IDENTITY_CONSTRAINTS) {
                       System.out.println("<IC>:   field:    "+field);
                   }
  @@ -4858,11 +4864,12 @@
                   reportGenericSchemaError(e.getMessage());
                   return;
               }
  -            felem = XUtil.getNextSiblingElement(felem, SchemaSymbols.ELT_FIELD);
  +            fElem = XUtil.getNextSiblingElement(fElem);
           }
   
       } // traverseIdentityConstraint(IdentityConstraint,Element)
   
  +    /* This code is no longer used because datatypes can't be found statically for ID constraints.
       private DatatypeValidator getDatatypeValidatorFor(Element element, 
                                                         Selector.XPath sxpath, 
                                                         Field.XPath fxpath)
  @@ -4971,6 +4978,8 @@
                               return null;
                           }
                           DatatypeValidator validator = edecl.datatypeValidator;
  +                        if (validator == null) validator = new StringDatatypeValidator();
  +                        System.err.println(validator);
                           return validator;
                       }
                       break;
  @@ -4990,6 +4999,7 @@
           return null;
   
       } // getDatatypeValidatorFor(XPath):DatatypeValidator
  +    */ // back in to live code...
   
       private String getElementNameFor(Element icnode) {
           Element enode = (Element)icnode.getParentNode();
  
  
  
  1.7       +11 -14    xml-xerces/java/src/org/apache/xerces/validators/schema/identity/Field.java
  
  Index: Field.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/identity/Field.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Field.java	2001/04/23 20:41:28	1.6
  +++ Field.java	2001/05/01 13:56:10	1.7
  @@ -59,6 +59,7 @@
   
   import org.apache.xerces.utils.NamespacesScope;
   import org.apache.xerces.utils.StringPool;
  +
   import org.apache.xerces.validators.datatype.DatatypeValidator;
   
   import org.xml.sax.SAXException;
  @@ -67,7 +68,7 @@
    * Schema identity constraint field.
    *
    * @author Andy Clark, IBM
  - * @version $Id: Field.java,v 1.6 2001/04/23 20:41:28 neilg Exp $
  + * @version $Id: Field.java,v 1.7 2001/05/01 13:56:10 neilg Exp $
    */
   public class Field {
   
  @@ -79,7 +80,9 @@
       protected Field.XPath fXPath;
   
       /** Datatype. */
  -    protected DatatypeValidator fDatatypeValidator;
  +    // Unfortunately, a Field may conceivably match values of varying
  +    // datatypes.  Hence, this member no longer makes sense; see the IDValue class.
  +    // protected DatatypeValidator fDatatypeValidator;
   
       /** Identity constraint. */
       protected IdentityConstraint fIdentityConstraint;
  @@ -88,13 +91,12 @@
       // Constructors
       //
   
  -    /** Constructs a selector. */
  -    public Field(Field.XPath xpath, DatatypeValidator datatypeValidator,
  +    /** Constructs a field. */
  +    public Field(Field.XPath xpath, 
                    IdentityConstraint identityConstraint) {
           fXPath = xpath;
  -        fDatatypeValidator = datatypeValidator;
           fIdentityConstraint = identityConstraint;
  -    } // <init>(Field.XPath,DatatypeValidator,IdentityConstraint)
  +    } // <init>(Field.XPath,IdentityConstraint)
   
       //
       // Public methods
  @@ -105,11 +107,6 @@
           return fXPath;
       } // getXPath():org.apache.xerces.validators.schema.identity.XPath
   
  -    /** Returns the datatype validator. */
  -    public DatatypeValidator getDatatypeValidator() {
  -        return fDatatypeValidator;
  -    } // getDatatypeValidator():DatatypeValidator
  -
       /** Returns the identity constraint. */
       public IdentityConstraint getIdentityConstraint() {
           return fIdentityConstraint;
  @@ -195,9 +192,9 @@
            * This method is called when the XPath handler matches the
            * XPath expression.
            */
  -        protected void matched(String content) throws Exception {
  -            super.matched(content);
  -            fStore.addValue(Field.this, content);
  +        protected void matched(String content, DatatypeValidator val) throws Exception {
  +            super.matched(content, val);
  +            fStore.addValue(Field.this, new IDValue(content, val));
           } // matched(String)
   
       } // class Matcher
  
  
  
  1.8       +11 -10    xml-xerces/java/src/org/apache/xerces/validators/schema/identity/Selector.java
  
  Index: Selector.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/identity/Selector.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Selector.java	2001/04/23 20:41:27	1.7
  +++ Selector.java	2001/05/01 13:56:10	1.8
  @@ -58,8 +58,9 @@
   package org.apache.xerces.validators.schema.identity;
   
   import org.apache.xerces.framework.XMLAttrList;
  -import org.apache.xerces.utils.NamespacesScope;
  +import org.apache.xerces.validators.schema.SchemaGrammar;
   import org.apache.xerces.utils.QName;
  +import org.apache.xerces.utils.NamespacesScope;
   import org.apache.xerces.utils.StringPool;
   
   import org.xml.sax.SAXException;
  @@ -68,7 +69,7 @@
    * Schema identity constraint selector.
    *
    * @author Andy Clark, IBM
  - * @version $Id: Selector.java,v 1.7 2001/04/23 20:41:27 neilg Exp $
  + * @version $Id: Selector.java,v 1.8 2001/05/01 13:56:10 neilg Exp $
    */
   public class Selector {
   
  @@ -131,7 +132,7 @@
        * Schema identity constraint selector XPath expression.
        *
        * @author Andy Clark, IBM
  -     * @version $Id: Selector.java,v 1.7 2001/04/23 20:41:27 neilg Exp $
  +     * @version $Id: Selector.java,v 1.8 2001/05/01 13:56:10 neilg Exp $
        */
       public static class XPath
           extends org.apache.xerces.validators.schema.identity.XPath {
  @@ -200,9 +201,9 @@
           //
       
           public void startDocumentFragment(StringPool stringPool,
  -                                          NamespacesScope namespacesScope)
  +                                          SchemaGrammar grammar)
               throws Exception {
  -            super.startDocumentFragment(stringPool,namespacesScope);
  +            super.startDocumentFragment(stringPool,grammar);
               fElementDepth = 0;
               fMatchedDepth = -1;
           } // startDocumentFragment(StringPool,NamespacesScope)
  @@ -218,8 +219,8 @@
            * @throws SAXException Thrown by handler to signal an error.
            */
           public void startElement(QName element, XMLAttrList attributes, 
  -                                 int handle) throws Exception {
  -            super.startElement(element, attributes, handle);
  +                                 int handle, int scope) throws Exception {
  +            super.startElement(element, attributes, handle, scope);
               fElementDepth++;
       
               // activate the fields, if selector is matched
  @@ -230,14 +231,14 @@
                   for (int i = 0; i < count; i++) {
                       Field field = fIdentityConstraint.getFieldAt(i);
                       XPathMatcher matcher = fFieldActivator.activateField(field);
  -                    matcher.startElement(element, attributes, handle);
  +                    matcher.startElement(element, attributes, handle, scope);
                   }
               }
       
           } // startElement(QName,XMLAttrList,int)
       
  -        public void endElement(QName element) throws Exception {
  -            super.endElement(element);
  +        public void endElement(QName element, int scope) throws Exception {
  +            super.endElement(element, scope);
               if (fElementDepth-- == fMatchedDepth) {
                   fMatchedDepth = -1;
                   fFieldActivator.endValueScopeFor(fIdentityConstraint);
  
  
  
  1.8       +33 -17    xml-xerces/java/src/org/apache/xerces/validators/schema/identity/XPathMatcher.java
  
  Index: XPathMatcher.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/identity/XPathMatcher.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XPathMatcher.java	2001/02/20 06:12:29	1.7
  +++ XPathMatcher.java	2001/05/01 13:56:11	1.8
  @@ -58,6 +58,10 @@
   package org.apache.xerces.validators.schema.identity;
   
   import org.apache.xerces.framework.XMLAttrList;
  +import org.apache.xerces.validators.common.XMLAttributeDecl;
  +import org.apache.xerces.validators.common.XMLElementDecl;
  +import org.apache.xerces.validators.schema.SchemaGrammar;
  +import org.apache.xerces.validators.datatype.DatatypeValidator;
   
   import org.apache.xerces.utils.IntStack;
   import org.apache.xerces.utils.QName;
  @@ -75,7 +79,7 @@
    *
    * @author Andy Clark, IBM
    *
  - * @version $Id: XPathMatcher.java,v 1.7 2001/02/20 06:12:29 andyc Exp $
  + * @version $Id: XPathMatcher.java,v 1.8 2001/05/01 13:56:11 neilg Exp $
    */
   public class XPathMatcher {
   
  @@ -149,6 +153,9 @@
       /** String pool. */
       protected StringPool fStringPool;
   
  +    // the Schema grammar that we're validating against.
  +    protected SchemaGrammar fGrammar;
  +
       /** Namespace scope. */
       protected NamespacesScope fNamespacesScope;
   
  @@ -161,7 +168,6 @@
        * handler. 
        *
        * @param xpath   The xpath.
  -     * @param symbols The symbol table.
        */
       public XPathMatcher(XPath xpath) {
           this(xpath, false);
  @@ -172,7 +178,6 @@
        * handler. 
        *
        * @param xpath   The xpath.
  -     * @param symbols The symbol table.
        * @param shouldBufferContent True if the matcher should buffer the
        *                            matched content.
        */
  @@ -207,11 +212,11 @@
        * XPath expression. Subclasses can override this method to
        * provide default handling upon a match.
        */
  -    protected void matched(String content) throws Exception {
  +    protected void matched(String content, DatatypeValidator val) throws Exception {
           if (DEBUG_METHODS3) {
               System.out.println(toString()+"#matched(\""+normalize(content)+"\")");
           }
  -    } // matched(String content)
  +    } // matched(String content, DatatypeValidator val)
   
       //
       // XMLDocumentFragmentHandler methods
  @@ -222,16 +227,17 @@
        *
        * @param namespaceScope The namespace scope in effect at the
        *                       start of this document fragment.
  +     * @param grammar:  the schema grammar we're validating against.
        *
        * @throws SAXException Thrown by handler to signal an error.
        */
       public void startDocumentFragment(StringPool stringPool,
  -                                      NamespacesScope namespacesScope) 
  +                                      SchemaGrammar grammar) 
           throws Exception {
           if (DEBUG_METHODS) {
               System.out.println(toString()+"#startDocumentFragment("+
                                  "stringPool="+stringPool+','+
  -                               "namespacesScope="+namespacesScope+
  +                               "grammar="+fGrammar+
                                  ")");
           }
   
  @@ -244,12 +250,9 @@
   
           // keep values
           fStringPool = stringPool;
  -        fNamespacesScope = namespacesScope;
  -        if (namespacesScope == null) {
  -            fNamespacesScope = new NamespacesScope();
  -        }
  +        fGrammar = grammar;
   
  -    } // startDocumentFragment(StringPool,NamespacesScope)
  +    } // startDocumentFragment(StringPool,SchemaGrammar)
   
       /**
        * The start of an element. If the document specifies the start element
  @@ -258,10 +261,11 @@
        * 
        * @param element    The name of the element.
        * @param attributes The element attributes.
  +     * @param scope:  the scope of the current element
        *
        * @throws SAXException Thrown by handler to signal an error.
        */
  -    public void startElement(QName element, XMLAttrList attributes, int handle)
  +    public void startElement(QName element, XMLAttrList attributes, int handle, int scope)
           throws Exception {
           if (DEBUG_METHODS2) {
               System.out.println(toString()+"#startElement("+
  @@ -281,7 +285,6 @@
           if (DEBUG_STACK) {
               System.out.println(toString()+": "+fStepIndexes);
           }
  -        //fNamespacesScope.increaseDepth();
   
           // return, if not matching
           if (fMatched || fNoMatchDepth > 0) {
  @@ -357,7 +360,14 @@
                               fMatched = true;
                               int avalue = attributes.getAttValue(aindex);
                               fMatchedString = fStringPool.toString(avalue);
  -                            matched(fMatchedString);
  +                            // now, we have to go on the hunt for 
  +                            // datatype validator; not an easy or pleasant task...
  +                            int eIndex = fGrammar.getElementDeclIndex(element, scope);
  +                            int attIndex = fGrammar.getAttributeDeclIndex(eIndex, aname);
  +                            XMLAttributeDecl tempAttDecl = new XMLAttributeDecl();
  +                            fGrammar.getAttributeDecl(attIndex, tempAttDecl);
  +                            DatatypeValidator aValidator = tempAttDecl.datatypeValidator;
  +                            matched(fMatchedString, aValidator);
                           }
                           break;
                       }
  @@ -403,10 +413,12 @@
        * The end of an element.
        * 
        * @param element The name of the element.
  +     * @param scope:  the scope of the element.  Needed so that we can look 
  +     *      up its datatypeValidator.
        *
        * @throws SAXException Thrown by handler to signal an error.
        */
  -    public void endElement(QName element) throws Exception {
  +    public void endElement(QName element, int scope) throws Exception {
           if (DEBUG_METHODS2) {
               System.out.println(toString()+"#endElement("+
                                  "element={"+
  @@ -427,7 +439,11 @@
               if (fBufferContent) {
                   fBufferContent = false;
                   fMatchedString = fMatchedBuffer.toString();
  -                matched(fMatchedString);
  +                int eIndex = fGrammar.getElementDeclIndex(element, scope);
  +                XMLElementDecl temp = new XMLElementDecl();
  +                fGrammar.getElementDecl(eIndex, temp);
  +                DatatypeValidator val = temp.datatypeValidator;
  +                matched(fMatchedString, val);
               }
               clear();
           }
  
  
  
  1.3       +2 -2      xml-xerces/java/src/org/apache/xerces/validators/schema/identity/ValueStore.java
  
  Index: ValueStore.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/identity/ValueStore.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ValueStore.java	2001/01/25 07:18:59	1.2
  +++ ValueStore.java	2001/05/01 13:56:11	1.3
  @@ -75,7 +75,7 @@
    *
    * @author Andy Clark, IBM
    *
  - * @version $Id: ValueStore.java,v 1.2 2001/01/25 07:18:59 andyc Exp $
  + * @version $Id: ValueStore.java,v 1.3 2001/05/01 13:56:11 neilg Exp $
    */
   public interface ValueStore {
       
  @@ -91,6 +91,6 @@
        *              is used to ensure that each field only adds a value
        *              once within a selection scope.
        */
  -    public void addValue(Field field, String value) throws Exception;
  +    public void addValue(Field field, IDValue value) throws Exception;
   
   } // interface ValueStore
  
  
  
  1.1                  xml-xerces/java/src/org/apache/xerces/validators/schema/identity/IDValue.java
  
  Index: IDValue.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  
   * All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xerces" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.xerces.validators.schema.identity;
  
  import org.apache.xerces.validators.datatype.DatatypeValidator;
  
  /**
   * Stores a value associated with a particular field of an identity constraint that
   * has successfully matched some string in an instance document.  
   * This class also stores the DatatypeValidator associated
   * with the element or attribute whose content is the string
   * in question; this must be done here because type determination is
   * dynamic.  
   * <p> This class also makes it its business to provide
   * functionality to determine whether two instances are duplicates.</p>
   *
   * @author Neil Graham, IBM
   *
   */
  public class IDValue {
  
      // data
  
      protected String fValue;
      protected DatatypeValidator fValidator;
      
      // constructor
      
      public IDValue(String value, DatatypeValidator val) {
          fValue = value;
          fValidator = val;
      }
  
      //
      // IDValue methods
      //
  
      /** 
       * Returns whether the supplied IDValue is a duplicate of this IDValue.  
       * It is a duplicate only if either of these conditions are true:
       * - The Datatypes are the same or related by derivation and
       * the values are in the same valuespace.
       * - The datatypes are unrelated and the values are Stringwise identical.
       *
       * @param value The value to compare.
       *              once within a selection scope.
       */
      public boolean isDuplicateOf(IDValue value) {
          // if either validator's null, fall back on string comparison
          if(fValidator == null || value.fValidator == null)
              return(fValue.equals(value.fValue));
          // are the validators equal?
          // As always we are obliged to compare by reference...
          if (fValidator == value.fValidator) {
              return ((fValidator.compare(fValue, value.fValue)) == 0);
          } 
          // see if this.fValidator is derived from value.fValidator:
          DatatypeValidator tempVal;
          for(tempVal = fValidator; tempVal == null || tempVal == value.fValidator; tempVal = tempVal.getBaseValidator());
          if(tempVal != null) { // was derived!
              return ((value.fValidator.compare(fValue, value.fValue)) == 0);
          }
          // see if value.fValidator is derived from this.fValidator:
          for(tempVal = value.fValidator; tempVal == null || tempVal == fValidator; tempVal = tempVal.getBaseValidator());
          if(tempVal != null) { // was derived!
              return ((fValidator.compare(fValue, value.fValue)) == 0);
          }
          // if we're here it means the types weren't related.  Must fall back to strings:
          return(fValue.equals(value.fValue)); 
      } // end compare(IDValue):boolean
  
      // Object methods:
      public String toString() {
          return ("ID Value:  " + fValue );
      }
  } // class IDValue
  
  
  

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