xerces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lmar...@apache.org
Subject cvs commit: xml-xerces/java/src/org/apache/xerces/validators/schema TraverseSchema.java
Date Sun, 11 Feb 2001 21:45:35 GMT
lmartin     01/02/11 13:45:35

  Modified:    java/src/org/apache/xerces/validators/schema
                        TraverseSchema.java
  Log:
  Modified patch submitted by Gregoire Pau for a problem to do with recursive types
  
  Revision  Changes    Path
  1.100     +75 -26    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.99
  retrieving revision 1.100
  diff -u -r1.99 -r1.100
  --- TraverseSchema.java	2001/02/09 22:01:26	1.99
  +++ TraverseSchema.java	2001/02/11 21:45:35	1.100
  @@ -124,7 +124,7 @@
    *  
    * @see org.apache.xerces.validators.common.Grammar
    *
  - * @version $Id: TraverseSchema.java,v 1.99 2001/02/09 22:01:26 neilg Exp $
  + * @version $Id: TraverseSchema.java,v 1.100 2001/02/11 21:45:35 lmartin Exp $
    */
   public class TraverseSchema implements 
                               NamespacesScope.NamespacesHandler{
  @@ -1483,21 +1483,18 @@
           String mixed = complexTypeDecl.getAttribute(SchemaSymbols.ATT_MIXED);
           boolean isNamedType = false;
   
  -        if ( DEBUGGING )
  -            System.out.println("traversing complex Type : " + typeName); 
  -
           // ------------------------------------------------------------------
           // Generate a type name, if one wasn't specified
           // ------------------------------------------------------------------
           if (typeName.equals("")) { // gensym a unique name
  -            //typeName = "http://www.apache.org/xml/xerces/internalType"+fTypeCount++;
  -            typeName = "#"+fAnonTypeCount++;
  -        }
  -        else {
  -            fCurrentTypeNameStack.push(typeName);
  -            isNamedType = true;
  +            typeName = genAnonTypeName(complexTypeDecl);
           }
   
  +        if ( DEBUGGING )
  +            System.out.println("traversing complex Type : " + typeName); 
  +
  +        fCurrentTypeNameStack.push(typeName);
  +
           int typeNameIndex = fStringPool.addSymbol(typeName);
   
           // ------------------------------------------------------------------
  @@ -1584,9 +1581,7 @@
           typeInfo.blockSet = parseBlockSet(blockSet); 
           typeInfo.finalSet = parseFinalSet(finalSet); 
           typeInfo.isAbstract = isAbstract.equals(SchemaSymbols.ATTVAL_TRUE) ? true:false
;
  -        if (!typeName.startsWith("#")) {
  -            typeName = fTargetNSURIString + "," + typeName;
  -        }
  +        typeName = fTargetNSURIString + "," + typeName;
           typeInfo.typeName = new String(typeName);
   
           if ( DEBUGGING )
  @@ -1604,10 +1599,8 @@
           // Before exiting, restore the scope, mainly for nested anonymous types
           // ------------------------------------------------------------------
           fCurrentScope = previousScope;
  -        if (isNamedType) {
  -            fCurrentTypeNameStack.pop();
  -            checkRecursingComplexType();
  -        }
  +        fCurrentTypeNameStack.pop();
  +        checkRecursingComplexType();
   
           //set template element's typeInfo
           fSchemaGrammar.setElementComplexTypeInfo(typeInfo.templateElementIndex, typeInfo);
  @@ -2076,6 +2069,41 @@
       }
   
       /**
  +     * Generate a name for an anonymous type                        
  +     *  
  +     * @param Element
  +     * @return String
  +     */
  +    private String genAnonTypeName(Element complexTypeDecl) throws Exception {
  +
  +        String typeName; 
  +
  +        // If the anonymous type is not nested within another type, we can 
  +        // simply assign the type a numbered name
  +        //
  +        if (fCurrentTypeNameStack.empty()) 
  +            typeName = "#"+fAnonTypeCount++;
  +          
  +        // Otherwise, we must generate a name that can be looked up later 
  +        // Do this by concatenating outer type names with the name of the parent
  +        // element
  +        else {
  +            String parentName = ((Element)complexTypeDecl.getParentNode()).getAttribute(
  +                                SchemaSymbols.ATT_NAME);
  +            typeName = parentName + "_AnonType";
  +            int index=fCurrentTypeNameStack.size() -1; 
  +	    for (int i = index; i > -1; i--) {
  +               String parentType = (String)fCurrentTypeNameStack.get(i); 
  +               typeName = parentType + "_" + typeName;
  +               if (!(parentType.startsWith("#"))) 
  +                  break;
  +            }
  +            typeName = "#" + typeName;
  +        }
  +           
  +        return typeName;
  +    }
  +    /**
        * Parse base string                                            
        *  
        * @param base
  @@ -3544,18 +3572,39 @@
                       noErrorSoFar = false;
                       // REVISIT: Localize
                       reportGenericSchemaError("anonymous complexType in element '" + name
+"' has a name attribute"); 
  -                }
  -                else 
  -                    typeNameIndex = traverseComplexTypeDecl(child);
  -                if (typeNameIndex != -1 ) {
  -                    typeInfo = (ComplexTypeInfo)
  -                        fComplexTypeRegistry.get(fStringPool.toString(typeNameIndex));
                   }
  +
                   else {
  -                    noErrorSoFar = false;
  -                    // REVISIT: Localize
  -                    reportGenericSchemaError("traverse complexType error in element '"
+ name +"'"); 
  +                    // Determine what the type name will be 
  +                    String anonTypeName = genAnonTypeName(child);
  +                    if (fCurrentTypeNameStack.search((Object)anonTypeName) > - 1) {
  +                        // A recursing element using an anonymous type
  +
  +                        int uriInd = StringPool.EMPTY_STRING;
  +                        if ( isQName.equals(SchemaSymbols.ATTVAL_QUALIFIED)||
  +                             fElementDefaultQualified) {
  +                             uriInd = fTargetNSURI;
  +                        }
  +                        int nameIndex = fStringPool.addSymbol(name);
  +                        QName tempQName = new QName(fCurrentScope, nameIndex, nameIndex,
uriInd);
  +                        fElementRecurseComplex.put(tempQName, anonTypeName);
  +                        return new QName(-1, nameIndex, nameIndex, uriInd);
  +
  +                    }
  +                    else {
  +                        typeNameIndex = traverseComplexTypeDecl(child);
  +                        if (typeNameIndex != -1 ) {
  +                            typeInfo = (ComplexTypeInfo)
  +                                fComplexTypeRegistry.get(fStringPool.toString(typeNameIndex));
  +                        }
  +                        else {
  +                            noErrorSoFar = false;
  +                            // REVISIT: Localize
  +                            reportGenericSchemaError("traverse complexType error in element
'" + name +"'"); 
  +                        }
  +                    }
                   }
  +
                   haveAnonType = true;
               	child = XUtil.getNextSiblingElement(child);
               } 
  
  
  

Mime
View raw message