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/06/01 22:37:05 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/validators/schema TraverseSchema.java

ericye      00/06/01 13:37:05

  Modified:    java/src/org/apache/xerces/validators/schema
                        TraverseSchema.java
  Log:
  Fix a bug regarding recursing ComplexType usage pattern, e.g.:
  <complexType name="a" ...>
      <element  name="b" type ="a".... minOccurs="0"....>
   --ericye
  
  Revision  Changes    Path
  1.8       +55 -4     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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TraverseSchema.java	2000/05/27 00:02:09	1.7
  +++ TraverseSchema.java	2000/06/01 20:37:05	1.8
  @@ -376,7 +376,7 @@
    *         Eric Ye
    * @see                  org.apache.xerces.validators.common.Grammar
    *
  - * @version $Id: TraverseSchema.java,v 1.7 2000/05/27 00:02:09 ericye Exp $
  + * @version $Id: TraverseSchema.java,v 1.8 2000/06/01 20:37:05 ericye Exp $
    */
   
   public class TraverseSchema implements 
  @@ -413,6 +413,8 @@
       private int fScopeCount=0;
       private int fCurrentScope=TOP_LEVEL_SCOPE;
       private int fSimpleTypeAnonCount = 0;
  +    private Stack fCurrentTypeNameStack = new Stack();
  +    private Hashtable fElementRecurseComplex = new Hashtable();
   
       private boolean fDefaultQualified = false;
       private int fTargetNSURI;
  @@ -1092,6 +1094,7 @@
           int complexTypeName      =  fStringPool.addSymbol(
                                                            complexTypeDecl.getAttribute( SchemaSymbols.ATT_NAME ));
           String typeName = complexTypeDecl.getAttribute(SchemaSymbols.ATT_NAME); 
  +        boolean isNamedType = false;
   
           if ( DEBUGGING )
               System.out.println("traversing complex Type : " + typeName +","+base+","+content+".");
  @@ -1100,6 +1103,10 @@
               //typeName = "http://www.apache.org/xml/xerces/internalType"+fTypeCount++;
               typeName = "#"+fAnonTypeCount++;
           }
  +        else {
  +            fCurrentTypeNameStack.push(typeName);
  +            isNamedType = true;
  +        }
   
           int scopeDefined = fScopeCount++;
           int previousScope = fCurrentScope;
  @@ -1576,6 +1583,11 @@
   
           // before exit the complex type definition, restore the scope, mainly for nested Anonymous Types
           fCurrentScope = previousScope;
  +        if (isNamedType) {
  +            fCurrentTypeNameStack.pop();
  +            checkRecursingComplexType();
  +            fCurrentTypeNameStack.clear();
  +        }
   
           typeNameIndex = fStringPool.addSymbol(typeName);
           return typeNameIndex;
  @@ -1583,6 +1595,37 @@
   
       } // end of method: traverseComplexTypeDecl
   
  +    private void checkRecursingComplexType() throws Exception {
  +        if ( fCurrentTypeNameStack.empty() ) {
  +            if (! fElementRecurseComplex.isEmpty() ) {
  +                Enumeration e = fElementRecurseComplex.keys();
  +                while( e.hasMoreElements() ) {
  +                    String nameThenScope = (String) e.nextElement();
  +                    String typeName = (String) fElementRecurseComplex.get(nameThenScope);
  +                    int comma = nameThenScope.indexOf(",");
  +                    String eltName = nameThenScope.substring(0, comma);
  +                    int enclosingScope = Integer.parseInt(nameThenScope.substring(comma+1));
  +                    ComplexTypeInfo typeInfo = 
  +                        (ComplexTypeInfo) fComplexTypeRegistry.get(fTargetNSURIString+","+typeName);
  +                    if (typeInfo==null) {
  +                        throw new Exception ( "Internal Error in void checkRecursingComplexType(). " );
  +                    }
  +                    else {
  +                        int nameIndex = fStringPool.addSymbol(eltName);
  +                        int elementIndex = fSchemaGrammar.addElementDecl(new QName(-1, nameIndex, nameIndex, -1), 
  +                                                                         enclosingScope, typeInfo.scopeDefined, 
  +                                                                         typeInfo.contentType, 
  +                                                                         typeInfo.contentSpecHandle, 
  +                                                                         typeInfo.attlistHead, 
  +                                                                         typeInfo.datatypeValidator);
  +                        fSchemaGrammar.setElementComplexTypeInfo(elementIndex, typeInfo);
  +                    }
  +
  +                }
  +            }
  +        }
  +    }
  +
       private void checkParticleDerivationOK(Element derivedTypeNode, Element baseTypeNode) {
           //TO DO: !!!
       }
  @@ -2374,9 +2417,17 @@
                       if (dv == null) {
                           Element topleveltype = getTopLevelComponentByName(SchemaSymbols.ELT_COMPLEXTYPE,localpart);
                           if (topleveltype != null) {
  -                            typeNameIndex = traverseComplexTypeDecl( topleveltype );
  -                            typeInfo = (ComplexTypeInfo)
  -                                fComplexTypeRegistry.get(fStringPool.toString(typeNameIndex));
  +                            if (fCurrentTypeNameStack.search((Object)localpart) > - 1) {
  +                                //then we found a recursive element using complexType.
  +                                // REVISIT: this will be broken when recursing happens between 2 schemas
  +                                fElementRecurseComplex.put(name+","+fCurrentScope, localpart);
  +                                return new QName(-1, fStringPool.addSymbol(name), fStringPool.addSymbol(name), -1);
  +                            }
  +                            else {
  +                                typeNameIndex = traverseComplexTypeDecl( topleveltype );
  +                                typeInfo = (ComplexTypeInfo)
  +                                    fComplexTypeRegistry.get(fStringPool.toString(typeNameIndex));
  +                            }
                           }
                           else {
                               topleveltype = getTopLevelComponentByName(SchemaSymbols.ELT_SIMPLETYPE, localpart);