You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by er...@locus.apache.org on 2000/11/06 21:32:35 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/validators/common DFAContentModel.java

ericye      00/11/06 12:32:33

  Modified:    java/src/org/apache/xerces/validators/common
                        DFAContentModel.java
  Log:
  1. fix bug in validateContent() when there is (#any, a, b) and child sequence [d,a,b], by lmartin@ca.ibm.com
  2. do the same for validateContentSpecial
  3. fix the conditional logic when DTD validation, should not check the type of leaf in case of DTD.
  
  Revision  Changes    Path
  1.15      +72 -52    xml-xerces/java/src/org/apache/xerces/validators/common/DFAContentModel.java
  
  Index: DFAContentModel.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/common/DFAContentModel.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- DFAContentModel.java	2000/10/26 19:49:11	1.14
  +++ DFAContentModel.java	2000/11/06 20:32:29	1.15
  @@ -75,7 +75,7 @@
    * are very constrained in form and easily handled via a special case. 
    * This also makes implementation of this class much easier.
    *
  - * @version $Id: DFAContentModel.java,v 1.14 2000/10/26 19:49:11 ericye Exp $
  + * @version $Id: DFAContentModel.java,v 1.15 2000/11/06 20:32:29 ericye Exp $
    */
   public class DFAContentModel 
       implements XMLContentModel {
  @@ -371,6 +371,7 @@
           //  an element index to a state index.
           //
           int curState = 0;
  +        int nextState = 0;
           for (int childIndex = 0; childIndex < length; childIndex++)
           {
               // Get the current element index out
  @@ -381,38 +382,56 @@
               int elemIndex = 0;
               for (; elemIndex < fElemMapSize; elemIndex++)
               {
  -                int type = fElemMapType[elemIndex] & 0x0f ;
  -                if (type == XMLContentSpec.CONTENTSPECNODE_LEAF) {
  -                    //System.out.println("fElemMap["+elemIndex+"]: "+fElemMap[elemIndex]);
  -                    if (fDTD) {
  -                        if (fElemMap[elemIndex].rawname == curElem.rawname) {
  -                            break;
  -                        }
  +                if (fDTD) {
  +                    if (fElemMap[elemIndex].rawname == curElem.rawname) {
  +                        nextState = fTransTable[curState][elemIndex];
  +                        if (nextState != -1) 
  +                          break;
                       }
  -                    else {
  +                }
  +                else {
  +                    int type = fElemMapType[elemIndex] & 0x0f ;
  +                    if (type == XMLContentSpec.CONTENTSPECNODE_LEAF) {
                           if (fElemMap[elemIndex].uri==curElem.uri
  -                             && fElemMap[elemIndex].localpart == curElem.localpart)
  -                            break;
  +                            && fElemMap[elemIndex].localpart == curElem.localpart)
  +                            {
  +                            nextState = fTransTable[curState][elemIndex];
  +                            if (nextState != -1) 
  +                                break;
  +                        }
                       }
  -                }
  -                else if (type == XMLContentSpec.CONTENTSPECNODE_ANY) {
  -                    int uri = fElemMap[elemIndex].uri;
  -                    if (uri == -1 || uri == curElem.uri) {
  -                        break;
  +                    else if (type == XMLContentSpec.CONTENTSPECNODE_ANY) {
  +                        int uri = fElemMap[elemIndex].uri;
  +                        if (uri == -1 || uri == curElem.uri) {
  +                            nextState = fTransTable[curState][elemIndex];
  +                            if (nextState != -1) 
  +                              break;
  +                        }
                       }
  -                }
  -                else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL) {
  -                    if (curElem.uri == -1) {
  -                        break;
  +                    else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL) {
  +                        if (curElem.uri == -1) {
  +                            nextState = fTransTable[curState][elemIndex];
  +                            if (nextState != -1) 
  +                              break;
  +                        }
                       }
  -                }
  -                else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER) {
  -                    if (fElemMap[elemIndex].uri != curElem.uri) {
  -                        break;
  +                    else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER) {
  +                        if (fElemMap[elemIndex].uri != curElem.uri) {
  +                            nextState = fTransTable[curState][elemIndex];
  +                            if (nextState != -1) 
  +                              break;
  +                        }
                       }
                   }
               }
   
  +            // If "nextState" is -1, we found a match, but the transition is invalid 
  +            if (nextState == -1) {
  +                if (DEBUG_VALIDATE_CONTENT) 
  +                    System.out.println("!!! not a legal transition");
  +                return childIndex;
  +            }
  +
               // If we didn't find it, then obviously not valid
               if (elemIndex == fElemMapSize) {
                   if (DEBUG_VALIDATE_CONTENT) {
  @@ -428,18 +447,9 @@
                   return childIndex;
               }
   
  -            //
  -            //  Look up the next state for this input symbol when in the
  -            //  current state.
  -            //
  -            curState = fTransTable[curState][elemIndex];
  +            curState = nextState;                              
  +            nextState = 0;
   
  -            // If its not a legal transition, then invalid
  -            if (curState == -1) {
  -                if (DEBUG_VALIDATE_CONTENT) 
  -                    System.out.println("!!! not a legal transition");
  -                return childIndex;
  -            }
           }
   
           //
  @@ -456,6 +466,7 @@
           return -1;
       }
   
  +
       private boolean isEqual(QName name1, QName name2) {
               return name1.localpart == name2.localpart &&
                   name1.uri == name2.uri;
  @@ -491,6 +502,7 @@
           //  an element index to a state index.
           //
           int curState = 0;
  +        int nextState = 0;
           for (int childIndex = 0; childIndex < length; childIndex++)
           {
               // Get the current element index out
  @@ -500,27 +512,44 @@
               int elemIndex = 0;
               for (; elemIndex < fElemMapSize; elemIndex++)
               {
  -                int type = fElemMapType[elemIndex] & 0x0f;
  +                int type = fElemMapType[elemIndex] & 0x0f ;
                   if (type == XMLContentSpec.CONTENTSPECNODE_LEAF) {
  -                    if (comparator.isEquivalentTo(curElem,fElemMap[elemIndex] ) )
  -                        break;
  +                    if (comparator.isEquivalentTo(curElem,fElemMap[elemIndex]) ) {
  +                        nextState = fTransTable[curState][elemIndex];
  +                        if (nextState != -1) 
  +                            break;
  +                    }
                   }
                   else if (type == XMLContentSpec.CONTENTSPECNODE_ANY) {
                       int uri = fElemMap[elemIndex].uri;
                       if (uri == -1 || uri == curElem.uri) {
  -                        break;
  +                        nextState = fTransTable[curState][elemIndex];
  +                        if (nextState != -1) 
  +                          break;
                       }
                   }
                   else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL) {
                       if (curElem.uri == -1) {
  -                        break;
  +                        nextState = fTransTable[curState][elemIndex];
  +                        if (nextState != -1) 
  +                          break;
                       }
                   }
                   else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER) {
                       if (fElemMap[elemIndex].uri != curElem.uri) {
  -                        break;
  +                        nextState = fTransTable[curState][elemIndex];
  +                        if (nextState != -1) 
  +                          break;
                       }
                   }
  +            
  +            }
  +
  +            // If "nextState" is -1, we found a match, but the transition is invalid 
  +            if (nextState == -1) {
  +                if (DEBUG_VALIDATE_CONTENT) 
  +                    System.out.println("!!! not a legal transition");
  +                return childIndex;
               }
   
               // If we didn't find it, then obviously not valid
  @@ -538,18 +567,9 @@
                   return childIndex;
               }
   
  -            //
  -            //  Look up the next state for this input symbol when in the
  -            //  current state.
  -            //
  -            curState = fTransTable[curState][elemIndex];
  +            curState = nextState;                              
  +            nextState = 0;
   
  -            // If its not a legal transition, then invalid
  -            if (curState == -1) {
  -                if (DEBUG_VALIDATE_CONTENT) 
  -                    System.out.println("!!! not a legal transition");
  -                return childIndex;
  -            }
           }
   
           //