sandygao    2004/02/03 09:27:46

  Modified:    java/src/org/apache/xerces/impl/xs XSConstraints.java
               java/src/org/apache/xerces/impl/xs/models CMBuilder.java
               java/src/org/apache/xerces/impl/xs/traversers
                        XSDAbstractParticleTraverser.java
                        XSDElementTraverser.java XSDGroupTraverser.java
                        XSDHandler.java
  Log:
  Fixing a potential NPE.
  When there exist empty particles, it's possible for other parts to get NPE when
  they try to access such particles. Now all empty particles are removed from
  the model group that contains it.
  
  Revision  Changes    Path
  1.37      +2 -2      xml-xerces/java/src/org/apache/xerces/impl/xs/XSConstraints.java
  
  Index: XSConstraints.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/XSConstraints.java,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- XSConstraints.java        3 Feb 2004 17:10:38 -0000       1.36
  +++ XSConstraints.java        3 Feb 2004 17:27:45 -0000       1.37
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 1999-2004 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  
  
  
  1.21      +5 -8      
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.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- CMBuilder.java    18 Jun 2003 13:40:11 -0000      1.20
  +++ CMBuilder.java    3 Feb 2004 17:27:45 -0000       1.21
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2004 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -153,12 +153,9 @@
           // 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 &&
  -                group.fParticles[i].fMaxOccurs != 0)
  -                // add the element decl to the all content model
  -                allContent.addElement((XSElementDecl)group.fParticles[i].fValue,
  -                                      group.fParticles[i].fMinOccurs == 0);
  +            // add the element decl to the all content model
  +            allContent.addElement((XSElementDecl)group.fParticles[i].fValue,
  +            group.fParticles[i].fMinOccurs == 0);
           }
           return allContent;
       }
  
  
  
  1.15      +13 -12    
xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDAbstractParticleTraverser.java
  
  Index: XSDAbstractParticleTraverser.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDAbstractParticleTraverser.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- XSDAbstractParticleTraverser.java 23 Jun 2003 16:35:22 -0000      1.14
  +++ XSDAbstractParticleTraverser.java 3 Feb 2004 17:27:45 -0000       1.15
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2004 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -65,6 +65,7 @@
   import org.apache.xerces.impl.xs.XSComplexTypeDecl;
   import org.apache.xerces.util.DOMUtil;
   import org.apache.xerces.impl.xs.util.XInt;
  +import org.apache.xerces.xs.XSObject;
   import org.w3c.dom.Element;
   
   /**
  @@ -94,7 +95,7 @@
                                  XSDocumentInfo schemaDoc,
                                  SchemaGrammar grammar,
                                  int allContextFlags,
  -                               XSComplexTypeDecl enclosingCT) {
  +                               XSObject parent) {
   
           // General Attribute Checking
   
  @@ -121,7 +122,7 @@
   
               // Only elements are allowed in <all>
               if (childName.equals(SchemaSymbols.ELT_ELEMENT)) {
  -                particle = fSchemaHandler.fElementTraverser.traverseLocal(child, 
schemaDoc, grammar, PROCESSING_ALL_EL, enclosingCT);
  +                particle = fSchemaHandler.fElementTraverser.traverseLocal(child, 
schemaDoc, grammar, PROCESSING_ALL_EL, parent);
               }
               else {
                   Object[] args = {"all", "(annotation?, element*)", 
DOMUtil.getLocalName(child)};
  @@ -177,9 +178,9 @@
                                       XSDocumentInfo schemaDoc,
                                       SchemaGrammar grammar,
                                       int allContextFlags,
  -                                    XSComplexTypeDecl enclosingCT) {
  +                                    XSObject parent) {
   
  -        return traverseSeqChoice(seqDecl, schemaDoc, grammar, allContextFlags, 
false, enclosingCT);
  +        return traverseSeqChoice(seqDecl, schemaDoc, grammar, allContextFlags, 
false, parent);
       }
   
       /**
  @@ -201,9 +202,9 @@
                                     XSDocumentInfo schemaDoc,
                                     SchemaGrammar grammar,
                                     int allContextFlags,
  -                                  XSComplexTypeDecl enclosingCT) {
  +                                  XSObject parent) {
   
  -        return traverseSeqChoice (choiceDecl, schemaDoc, grammar, allContextFlags, 
true, enclosingCT);
  +        return traverseSeqChoice (choiceDecl, schemaDoc, grammar, allContextFlags, 
true, parent);
       }
   
       /**
  @@ -220,7 +221,7 @@
                                                SchemaGrammar grammar,
                                                int allContextFlags,
                                                boolean choice,
  -                                             XSComplexTypeDecl enclosingCT) {
  +                                             XSObject parent) {
   
           // General Attribute Checking
           Object[] attrValues = fAttrChecker.checkAttributes(decl, false, schemaDoc);
  @@ -245,7 +246,7 @@
   
               childName = DOMUtil.getLocalName(child);
               if (childName.equals(SchemaSymbols.ELT_ELEMENT)) {
  -                particle = fSchemaHandler.fElementTraverser.traverseLocal(child, 
schemaDoc, grammar, NOT_ALL_CONTEXT, enclosingCT);
  +                particle = fSchemaHandler.fElementTraverser.traverseLocal(child, 
schemaDoc, grammar, NOT_ALL_CONTEXT, parent);
               }
               else if (childName.equals(SchemaSymbols.ELT_GROUP)) {
                   particle = fSchemaHandler.fGroupTraverser.traverseLocal(child, 
schemaDoc, grammar);
  @@ -261,10 +262,10 @@
   
               }
               else if (childName.equals(SchemaSymbols.ELT_CHOICE)) {
  -                particle = traverseChoice(child, schemaDoc, grammar, 
NOT_ALL_CONTEXT, enclosingCT);
  +                particle = traverseChoice(child, schemaDoc, grammar, 
NOT_ALL_CONTEXT, parent);
               }
               else if (childName.equals(SchemaSymbols.ELT_SEQUENCE)) {
  -                particle = traverseSequence(child, schemaDoc, grammar, 
NOT_ALL_CONTEXT, enclosingCT);
  +                particle = traverseSequence(child, schemaDoc, grammar, 
NOT_ALL_CONTEXT, parent);
               }
               else if (childName.equals(SchemaSymbols.ELT_ANY)) {
                   particle = fSchemaHandler.fWildCardTraverser.traverseAny(child, 
schemaDoc, grammar);
  
  
  
  1.29      +14 -11    
xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java
  
  Index: XSDElementTraverser.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- XSDElementTraverser.java  11 Nov 2003 20:15:00 -0000      1.28
  +++ XSDElementTraverser.java  3 Feb 2004 17:27:45 -0000       1.29
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2004 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -67,6 +67,7 @@
   import org.apache.xerces.impl.xs.XSElementDecl;
   import org.apache.xerces.impl.xs.XSParticleDecl;
   import org.apache.xerces.xs.XSConstants;
  +import org.apache.xerces.xs.XSObject;
   import org.apache.xerces.xs.XSTypeDefinition;
   import org.apache.xerces.impl.xs.util.XInt;
   import org.apache.xerces.util.DOMUtil;
  @@ -103,7 +104,6 @@
   class XSDElementTraverser extends XSDAbstractTraverser {
   
       protected final XSElementDecl  fTempElementDecl  = new XSElementDecl();
  -    protected final XSParticleDecl fTempParticleDecl = new XSParticleDecl();
   
       // this controls what happens when a local element is encountered.
       // We may not encounter all local elements when first parsing.
  @@ -131,7 +131,7 @@
                                    XSDocumentInfo schemaDoc,
                                    SchemaGrammar grammar,
                                    int allContextFlags,
  -                                 XSComplexTypeDecl enclosingCT) {
  +                                 XSObject parent) {
   
           XSParticleDecl particle = null;
           if (fSchemaHandler.fDeclPool !=null) {
  @@ -155,9 +155,12 @@
                   catch (NumberFormatException ex) {
                   }
               }
  -            fSchemaHandler.fillInLocalElemInfo(elmDecl, schemaDoc, allContextFlags, 
enclosingCT, particle);
  +            fSchemaHandler.fillInLocalElemInfo(elmDecl, schemaDoc, allContextFlags, 
parent, particle);
           } else {
  -            traverseLocal(particle, elmDecl, schemaDoc, grammar, allContextFlags, 
enclosingCT);
  +            traverseLocal(particle, elmDecl, schemaDoc, grammar, allContextFlags, 
parent);
  +            // If it's an empty particle, return null.
  +            if (particle.fType == XSParticleDecl.PARTICLE_EMPTY)
  +                particle = null;
           }
   
           return particle;
  @@ -176,7 +179,7 @@
                                    XSDocumentInfo schemaDoc,
                                    SchemaGrammar grammar,
                                    int allContextFlags,
  -                                 XSComplexTypeDecl enclosingCT) {
  +                                 XSObject parent) {
   
           // General Attribute Checking
           Object[] attrValues = fAttrChecker.checkAttributes(elmDecl, false, 
schemaDoc);
  @@ -208,7 +211,7 @@
                   element = null;
               }
           } else {
  -            element = traverseNamedElement(elmDecl, attrValues, schemaDoc, grammar, 
false, enclosingCT);
  +            element = traverseNamedElement(elmDecl, attrValues, schemaDoc, grammar, 
false, parent);
           }
   
           particle.fMinOccurs = minAtt.intValue();
  @@ -263,7 +266,7 @@
                                          XSDocumentInfo schemaDoc,
                                          SchemaGrammar grammar,
                                          boolean isGlobal,
  -                                       XSComplexTypeDecl enclosingCT) {
  +                                       XSObject parent) {
   
           Boolean abstractAtt  = (Boolean) 
attrValues[XSAttributeChecker.ATTIDX_ABSTRACT];
           XInt    blockAtt     = (XInt)    
attrValues[XSAttributeChecker.ATTIDX_BLOCK];
  @@ -294,8 +297,8 @@
               element.setIsGlobal();
           }
           else {
  -            if (enclosingCT != null)
  -                element.setIsLocal(enclosingCT);
  +            if (parent instanceof XSComplexTypeDecl)
  +                element.setIsLocal((XSComplexTypeDecl)parent);
   
               if (formAtt != null) {
                   if (formAtt.intValue() == SchemaSymbols.FORM_QUALIFIED)
  
  
  
  1.19      +17 -10    
xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDGroupTraverser.java
  
  Index: XSDGroupTraverser.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDGroupTraverser.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- XSDGroupTraverser.java    23 Jun 2003 16:35:22 -0000      1.18
  +++ XSDGroupTraverser.java    3 Feb 2004 17:27:45 -0000       1.19
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2004 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -169,10 +169,14 @@
           Element l_elmChild = DOMUtil.getFirstChildElement(elmNode);
           XSAnnotationImpl annotation = null;
           if (l_elmChild == null) {
  -             reportSchemaError("s4s-elt-must-match.2",
  +            reportSchemaError("s4s-elt-must-match.2",
                                 new Object[]{"group (global)", "(annotation?, (all | 
choice | sequence))"},
                                 elmNode);
           } else {
  +            // Create the group defi up-front, so it can be passed
  +            // to the traversal methods
  +            group = new XSGroupDecl();
  +
               String childName = l_elmChild.getLocalName();
               if (childName.equals(SchemaSymbols.ELT_ANNOTATION)) {
                   annotation = traverseAnnotationDecl(l_elmChild, attrValues, true, 
schemaDoc);
  @@ -182,24 +186,24 @@
               }
   
               if (l_elmChild == null) {
  -                             reportSchemaError("s4s-elt-must-match.2",
  +                reportSchemaError("s4s-elt-must-match.2",
                                     new Object[]{"group (global)", "(annotation?, 
(all | choice | sequence))"},
                                     elmNode);
               } else if (childName.equals(SchemaSymbols.ELT_ALL)) {
  -                particle = traverseAll(l_elmChild, schemaDoc, grammar, 
CHILD_OF_GROUP, null);
  +                particle = traverseAll(l_elmChild, schemaDoc, grammar, 
CHILD_OF_GROUP, group);
               } else if (childName.equals(SchemaSymbols.ELT_CHOICE)) {
  -                particle = traverseChoice(l_elmChild, schemaDoc, grammar, 
CHILD_OF_GROUP, null);
  +                particle = traverseChoice(l_elmChild, schemaDoc, grammar, 
CHILD_OF_GROUP, group);
               } else if (childName.equals(SchemaSymbols.ELT_SEQUENCE)) {
  -                particle = traverseSequence(l_elmChild, schemaDoc, grammar, 
CHILD_OF_GROUP, null);
  +                particle = traverseSequence(l_elmChild, schemaDoc, grammar, 
CHILD_OF_GROUP, group);
               } else {
  -                             reportSchemaError("s4s-elt-must-match.1",
  +                reportSchemaError("s4s-elt-must-match.1",
                                     new Object[]{"group (global)", "(annotation?, 
(all | choice | sequence))", DOMUtil.getLocalName(l_elmChild)},
                                     l_elmChild);
               }
   
               if (l_elmChild != null &&
                   DOMUtil.getNextSiblingElement(l_elmChild) != null) {
  -                             reportSchemaError("s4s-elt-must-match.1",
  +                reportSchemaError("s4s-elt-must-match.1",
                                     new Object[]{"group (global)", "(annotation?, 
(all | choice | sequence))",
                                                  
DOMUtil.getLocalName(DOMUtil.getNextSiblingElement(l_elmChild))},
                                     DOMUtil.getNextSiblingElement(l_elmChild));
  @@ -207,13 +211,16 @@
   
               // add global group declaration to the grammar
               if (strNameAttr != null) {
  -                group = new XSGroupDecl();
                   group.fName = strNameAttr;
                   group.fTargetNamespace = schemaDoc.fTargetNamespace;
                   if (particle != null)
                       group.fModelGroup = (XSModelGroupImpl)particle.fValue;
                   group.fAnnotation = annotation;
                   grammar.addGlobalGroupDecl(group);
  +            }
  +            else {
  +                // name attribute is not there, don't return this group.
  +                group = null;
               }
           }
           if(group != null) { 
  
  
  
  1.75      +39 -9     
xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java
  
  Index: XSDHandler.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java,v
  retrieving revision 1.74
  retrieving revision 1.75
  diff -u -r1.74 -r1.75
  --- XSDHandler.java   21 Jan 2004 23:08:33 -0000      1.74
  +++ XSDHandler.java   3 Feb 2004 17:27:45 -0000       1.75
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
  + * Copyright (c) 1999-2004 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -75,7 +75,9 @@
   import org.apache.xerces.impl.xs.XSDeclarationPool;
   import org.apache.xerces.impl.xs.XSElementDecl;
   import org.apache.xerces.impl.xs.XSGrammarBucket;
  +import org.apache.xerces.impl.xs.XSGroupDecl;
   import org.apache.xerces.impl.xs.XSMessageFormatter;
  +import org.apache.xerces.impl.xs.XSModelGroupImpl;
   import org.apache.xerces.impl.xs.XSParticleDecl;
   import org.apache.xerces.impl.xs.opti.ElementImpl;
   import org.apache.xerces.impl.xs.opti.SchemaParsingConfig;
  @@ -90,6 +92,7 @@
   import org.apache.xerces.xni.parser.XMLEntityResolver;
   import org.apache.xerces.xni.parser.XMLErrorHandler;
   import org.apache.xerces.xni.parser.XMLInputSource;
  +import org.apache.xerces.xs.XSObject;
   import org.w3c.dom.Document;
   import org.w3c.dom.Element;
   
  @@ -311,7 +314,7 @@
       private XSParticleDecl[] fParticle = new XSParticleDecl[INIT_STACK_SIZE];
       private Element[] fLocalElementDecl = new Element[INIT_STACK_SIZE];
       private int[] fAllContext = new int[INIT_STACK_SIZE];
  -    private XSComplexTypeDecl[] fEnclosingCT = new 
XSComplexTypeDecl[INIT_STACK_SIZE];
  +    private XSObject[] fParent = new XSObject[INIT_STACK_SIZE];
       private String [][] fLocalElemNamespaceContext = new String 
[INIT_STACK_SIZE][1];
   
       // these data members are needed for the deferred traversal
  @@ -1675,8 +1678,35 @@
               Element currElem = fLocalElementDecl[i];
               XSDocumentInfo currSchema = 
(XSDocumentInfo)fDoc2XSDocumentMap.get(DOMUtil.getDocument(currElem));
               SchemaGrammar currGrammar = 
fGrammarBucket.getGrammar(currSchema.fTargetNamespace);
  -            fElementTraverser.traverseLocal (fParticle[i], currElem, currSchema, 
currGrammar, fAllContext[i], fEnclosingCT[i]);
  +            fElementTraverser.traverseLocal (fParticle[i], currElem, currSchema, 
currGrammar, fAllContext[i], fParent[i]);
  +            // If it's an empty particle, remove it from the containing component.
  +            if (fParticle[i].fType == XSParticleDecl.PARTICLE_EMPTY) {
  +                XSModelGroupImpl group;
  +                if (fParent[i] instanceof XSComplexTypeDecl)
  +                    group = 
(XSModelGroupImpl)((XSComplexTypeDecl)fParent[i]).getParticle().getTerm();
  +                else
  +                    group = ((XSGroupDecl)fParent[i]).fModelGroup;
  +                removeParticle(group, fParticle[i]);
  +            }
  +        }
  +    }
  +
  +    private boolean removeParticle(XSModelGroupImpl group, XSParticleDecl particle) 
{
  +        XSParticleDecl member;
  +        for (int i = 0; i < group.fParticleCount; i++) {
  +            member = group.fParticles[i];
  +            if (member == particle) {
  +                for (int j = i; j < group.fParticleCount-1; j++)
  +                    group.fParticles[j] = group.fParticles[j+1];
  +                group.fParticleCount--;
  +                return true;
  +            }
  +            if (member.fType == XSParticleDecl.PARTICLE_MODELGROUP) {
  +                if (removeParticle((XSModelGroupImpl)member.fValue, particle))
  +                    return true;
  +            }
           }
  +        return false;
       }
   
       // the purpose of this method is to keep up-to-date structures
  @@ -1684,7 +1714,7 @@
       void fillInLocalElemInfo(Element elmDecl,
                                XSDocumentInfo schemaDoc,
                                int allContextFlags,
  -                             XSComplexTypeDecl enclosingCT,
  +                             XSObject parent,
                                XSParticleDecl particle) {
   
           // if the stack is full, increase the size
  @@ -1699,9 +1729,9 @@
               int[] newStackI = new int[fLocalElemStackPos+INC_STACK_SIZE];
               System.arraycopy(fAllContext, 0, newStackI, 0, fLocalElemStackPos);
               fAllContext = newStackI;
  -            XSComplexTypeDecl[] newStackC = new 
XSComplexTypeDecl[fLocalElemStackPos+INC_STACK_SIZE];
  -            System.arraycopy(fEnclosingCT, 0, newStackC, 0, fLocalElemStackPos);
  -            fEnclosingCT = newStackC;
  +            XSObject[] newStackC = new XSObject[fLocalElemStackPos+INC_STACK_SIZE];
  +            System.arraycopy(fParent, 0, newStackC, 0, fLocalElemStackPos);
  +            fParent = newStackC;
               String [][] newStackN = new String 
[fLocalElemStackPos+INC_STACK_SIZE][];
               System.arraycopy(fLocalElemNamespaceContext, 0, newStackN, 0, 
fLocalElemStackPos);
               fLocalElemNamespaceContext = newStackN;
  @@ -1710,7 +1740,7 @@
           fParticle[fLocalElemStackPos] = particle;
           fLocalElementDecl[fLocalElemStackPos] = elmDecl;
           fAllContext[fLocalElemStackPos] = allContextFlags;
  -        fEnclosingCT[fLocalElemStackPos] = enclosingCT;
  +        fParent[fLocalElemStackPos] = parent;
           fLocalElemNamespaceContext[fLocalElemStackPos++] = 
schemaDoc.fNamespaceSupport.getEffectiveLocalContext();
       } // end fillInLocalElemInfo(...)
   
  
  
  

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

Reply via email to