sandygao    2002/11/08 07:55:31

  Modified:    java/src/org/apache/xerces/impl/xs/models CMBuilder.java
                        XSAllCM.java
  Log:
  According to an errata (E1-2), <all minOccurs="0"> is allowed.
  
  Revision  Changes    Path
  1.14      +4 -5      
xml-xerces/java/src/org/apache/xerces/impl/xs/models/CMBuilder.java
  
  Index: CMBuilder.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/models/CMBuilder.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- CMBuilder.java    26 Jul 2002 18:59:18 -0000      1.13
  +++ CMBuilder.java    8 Nov 2002 15:55:31 -0000       1.14
  @@ -146,12 +146,11 @@
           if (particle.fMaxOccurs == 0)
               return null;
   
  -        // create an all content model. the parameter indicates whether
  -        // the <all> itself is optional        
  -        XSAllCM allContent = new XSAllCM(particle.fMinOccurs == 0);
  -        
           // get the model group, and add all children of it to the content model
           XSModelGroupImpl group = (XSModelGroupImpl)particle.fValue;
  +        // create an all content model. the parameter indicates whether
  +        // the <all> itself is optional        
  +        XSAllCM allContent = new XSAllCM(particle.fMinOccurs == 0, 
group.fParticleCount);
           for (int i = 0; i < group.fParticleCount; i++) {
               // for all non-empty particles
               if (group.fParticles[i].fType != XSParticleDecl.PARTICLE_EMPTY &&
  
  
  
  1.7       +15 -40    
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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XSAllCM.java      27 Aug 2002 06:11:08 -0000      1.6
  +++ XSAllCM.java      8 Nov 2002 15:55:31 -0000       1.7
  @@ -78,54 +78,32 @@
       // start the content model: did not see any children
       private static final short STATE_START = 0;
       private static final short STATE_VALID = 1;
  +    private static final short STATE_CHILD = 1;
   
   
       //
       // Data
       //
   
  -    private XSElementDecl fAllElements[] = new XSElementDecl[10];
  -    private boolean fIsOptionalElement[] = new boolean[10];
  +    private XSElementDecl fAllElements[];
  +    private boolean fIsOptionalElement[];
       private boolean fHasOptionalContent = false;
  -    // private boolean fIsMixed = false;
  -
       private int fNumElements = 0;
  -    private int fNumRequired = 0;
   
       //
       // Constructors
       //
   
  -    public XSAllCM (boolean hasOptionalContent) {
  +    public XSAllCM (boolean hasOptionalContent, int size) {
           fHasOptionalContent = hasOptionalContent;
  +        fAllElements = new XSElementDecl[size];
  +        fIsOptionalElement = new boolean[size];
       }
   
       public void addElement (XSElementDecl element, boolean isOptional) {
  -
  -        // resize arrays if necessary
  -        if (fNumElements >= fAllElements.length) {
  -            XSElementDecl newAllElements[] = new XSElementDecl 
[2*fAllElements.length];
  -            boolean newIsOptionalElements[] =
  -                                      new boolean[2*fIsOptionalElement.length];
  -            System.arraycopy(fAllElements, 0, newAllElements, 0,
  -                             fAllElements.length);
  -            System.arraycopy(fIsOptionalElement, 0, newIsOptionalElements, 0,
  -                             fIsOptionalElement.length);
  -
  -            fAllElements = newAllElements;
  -            fIsOptionalElement = newIsOptionalElements;
  -        }
  -
           fAllElements[fNumElements] = element;
           fIsOptionalElement[fNumElements] = isOptional;
  -
           fNumElements++;
  -
  -        // keeping track of the number of elements that are required
  -        if (!isOptional) {
  -            fNumRequired++;
  -        }
  -
       }
   
   
  @@ -177,6 +155,9 @@
               return findMatchingDecl(elementName, subGroupHandler);
           }
   
  +        // seen child
  +        currentState[0] = STATE_CHILD;
  +        
           Object matchingDecl = null;
   
           for (int i = 0; i < fNumElements; i++) {
  @@ -214,23 +195,17 @@
   
           // If <all> has minOccurs of zero and there are
           // no children to validate, it is trivially valid
  -
  -        if (fHasOptionalContent && fNumElements == 0) {
  +        if (fHasOptionalContent && state == STATE_START) {
               return true;
           }
   
  -        int numRequiredSeen = 0;
  -
           for (int i = 0; i < fNumElements; i++) {
  -            if (!fIsOptionalElement[i] && currentState[i+1] != STATE_START)
  -                numRequiredSeen++;
  -        }
  -
  -        if (fNumRequired == numRequiredSeen ) {
  -            return true;
  +            // if one element is required, but not present, then error
  +            if (!fIsOptionalElement[i] && currentState[i+1] == STATE_START)
  +                return false;
           }
   
  -        return false;
  +        return true;
       }
   
       /**
  
  
  

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

Reply via email to