sandygao    2002/08/26 23:11:08

  Modified:    java/src/org/apache/xerces/impl/xs/models XSAllCM.java
  Log:
  Improving the error-handling code in XSAllCM.
  In the old code, we go through the whole list of candidate elements to find
  the one that matches the current element, even if some of those elements
  were already matched.
  The new code only looks at those elements that are not matched yet. This
  will improve the performance for valid documents, because checking whether
  2 elements match is an expensive operation (which involves substitution
  group checking). Of course, the performance would suffer a little bit for invalid
  documents (because we might need to go through the list twice), but the
  performance for valid documents is our primary concern.
  
  Revision  Changes    Path
  1.6       +22 -33    
xml-xerces/java/src/org/apache/xerces/impl/xs/models/XSAllCM.java
  
  Index: XSAllCM.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/models/XSAllCM.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XSAllCM.java      27 Aug 2002 05:34:09 -0000      1.5
  +++ XSAllCM.java      27 Aug 2002 06:11:08 -0000      1.6
  @@ -150,6 +150,17 @@
           return state;
       }
   
  +    // convinient method: when error occurs, to find a matching decl
  +    // from the candidate elements.
  +    Object findMatchingDecl(QName elementName, SubstitutionGroupHandler 
subGroupHandler) {
  +        Object matchingDecl = null;
  +        for (int i = 0; i < fNumElements; i++) {
  +            matchingDecl = subGroupHandler.getMatchingElemDecl(elementName, 
fAllElements[i]);
  +            if (matchingDecl != null)
  +                break;
  +        }
  +        return matchingDecl;
  +    }
   
       /**
        * The method corresponds to one transition in the content model.
  @@ -163,49 +174,27 @@
           // error state
           if (currentState[0] < 0) {
               currentState[0] = XSCMValidator.SUBSEQUENT_ERROR;
  -            Object matchingDecl = null;
  -            for (int i = 0; i < fNumElements; i++) {
  -                matchingDecl = subGroupHandler.getMatchingElemDecl(elementName, 
fAllElements[i]);
  -                if (matchingDecl != null)
  -                    break;
  -            }
  -            return matchingDecl;
  +            return findMatchingDecl(elementName, subGroupHandler);
           }
   
           Object matchingDecl = null;
   
           for (int i = 0; i < fNumElements; i++) {
  -
  +            // we only try to look for a matching decl if we have not seen
  +            // this element yet.
  +            if (currentState[i+1] != STATE_START)
  +                continue;
               matchingDecl = subGroupHandler.getMatchingElemDecl(elementName, 
fAllElements[i]);
               if (matchingDecl != null) {
  -
  -                if (currentState[i+1] == STATE_START) {
  -                    currentState[i+1] = STATE_VALID;
  -                }
  -                else if (currentState[i+1] == STATE_VALID) {
  -                    // duplicate element
  -                    currentState[i+1] = XSCMValidator.FIRST_ERROR;
  -                    currentState[0] = XSCMValidator.FIRST_ERROR;
  -                }
  -                else if (currentState[i+1] == XSCMValidator.FIRST_ERROR) {
  -                    currentState[i+1] = XSCMValidator.SUBSEQUENT_ERROR;
  -                    currentState[0] = XSCMValidator.SUBSEQUENT_ERROR;
  -                }
  -
  -                if (currentState[0] == STATE_START) {
  -                    currentState[0] = STATE_VALID;
  -                }
  -
  +                // found the decl, mark this element as "seen".
  +                currentState[i+1] = STATE_VALID;
                   return matchingDecl;
               }
           }
   
  -        if (currentState[0] == XSCMValidator.FIRST_ERROR)
  -            currentState[0] = XSCMValidator.SUBSEQUENT_ERROR;
  -        else if (currentState[0] == STATE_START || currentState[0] == STATE_VALID)
  -            currentState[0] = XSCMValidator.FIRST_ERROR;
  -
  -        return null;
  +        // couldn't find the decl, change to error state.
  +        currentState[0] = XSCMValidator.FIRST_ERROR;
  +        return findMatchingDecl(elementName, subGroupHandler);
       }
   
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to