xmlbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kkro...@apache.org
Subject svn commit: r149446 - in xmlbeans/branches/1.x: src/typeimpl/org/apache/xmlbeans/impl/schema/ src/xmlcomp/org/apache/xmlbeans/impl/tool/ test/src/drt/drtcases/
Date Tue, 01 Feb 2005 20:41:34 GMT
Author: kkrouse
Date: Tue Feb  1 12:41:31 2005
New Revision: 149446

URL: http://svn.apache.org/viewcvs?view=rev&rev=149446
Log:
merge radu's change r149295 from trunk to 1.x branch
Fix for http://issues.apache.org/jira/browse/XMLBEANS-35

Modified:
    xmlbeans/branches/1.x/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeImpl.java
    xmlbeans/branches/1.x/src/typeimpl/org/apache/xmlbeans/impl/schema/StscState.java
    xmlbeans/branches/1.x/src/typeimpl/org/apache/xmlbeans/impl/schema/StscTranslator.java
    xmlbeans/branches/1.x/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCodeGenerator.java
    xmlbeans/branches/1.x/test/src/drt/drtcases/ValidationTests.java

Modified: xmlbeans/branches/1.x/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeImpl.java
URL: http://svn.apache.org/viewcvs/xmlbeans/branches/1.x/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeImpl.java?view=diff&r1=149445&r2=149446
==============================================================================
--- xmlbeans/branches/1.x/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeImpl.java
(original)
+++ xmlbeans/branches/1.x/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeImpl.java
Tue Feb  1 12:41:31 2005
@@ -65,6 +65,7 @@
     private volatile SchemaField _containerField;
     private volatile int _containerFieldCode;
     private volatile int _containerFieldIndex;
+    private volatile QName[] _groupReferenceContext;
     private SchemaType.Ref[] _anonymousTyperefs;
     private boolean _isDocumentType;
     private boolean _isAttributeType;
@@ -475,6 +476,15 @@
         _containerFieldCode = code;
         _containerFieldIndex = index;
     }
+
+    /* package */ void setGroupReferenceContext(QName[] groupNames)
+    {
+        assertUnresolved();
+        _groupReferenceContext = groupNames;
+    }
+
+    /* package */ QName[] getGroupReferenceContext()
+    { return _groupReferenceContext; }
 
     public SchemaType getOuterType()
         { return _outerSchemaTypeRef == null ? null : _outerSchemaTypeRef.get(); }

Modified: xmlbeans/branches/1.x/src/typeimpl/org/apache/xmlbeans/impl/schema/StscState.java
URL: http://svn.apache.org/viewcvs/xmlbeans/branches/1.x/src/typeimpl/org/apache/xmlbeans/impl/schema/StscState.java?view=diff&r1=149445&r2=149446
==============================================================================
--- xmlbeans/branches/1.x/src/typeimpl/org/apache/xmlbeans/impl/schema/StscState.java (original)
+++ xmlbeans/branches/1.x/src/typeimpl/org/apache/xmlbeans/impl/schema/StscState.java Tue
Feb  1 12:41:31 2005
@@ -75,7 +75,7 @@
     private Map _attributeTypes     = new LinkedHashMap();
     private Map _typesByClassname   = new LinkedHashMap();
     private Map _misspelledNames    = new HashMap();
-    private Set _processingGroups   = new HashSet();
+    private Set _processingGroups   = new LinkedHashSet();
     private Map _idConstraints      = new LinkedHashMap();
     private Set _namespaces         = new HashSet();
     private boolean _noUpa;
@@ -752,6 +752,11 @@
     {
         assert(_processingGroups.contains(obj));
         _processingGroups.remove(obj);
+    }
+
+    Object[] getCurrentProcessing()
+    {
+        return _processingGroups.toArray();
     }
 
     /* JAVAIZATION ====================================================*/

Modified: xmlbeans/branches/1.x/src/typeimpl/org/apache/xmlbeans/impl/schema/StscTranslator.java
URL: http://svn.apache.org/viewcvs/xmlbeans/branches/1.x/src/typeimpl/org/apache/xmlbeans/impl/schema/StscTranslator.java?view=diff&r1=149445&r2=149446
==============================================================================
--- xmlbeans/branches/1.x/src/typeimpl/org/apache/xmlbeans/impl/schema/StscTranslator.java
(original)
+++ xmlbeans/branches/1.x/src/typeimpl/org/apache/xmlbeans/impl/schema/StscTranslator.java
Tue Feb  1 12:41:31 2005
@@ -617,14 +617,26 @@
 
         if (typedef != null)
         {
+            Object[] grps = state.getCurrentProcessing();
+            QName[] context = new QName[grps.length];
+            for (int i = 0; i < context.length; i++)
+                if (grps[i] instanceof SchemaModelGroupImpl)
+                    context[i] = ((SchemaModelGroupImpl ) grps[i]).getName();
+            SchemaType repeat = checkRecursiveGroupReference(context, qname, (SchemaTypeImpl)outerType);
+            if (repeat != null)
+                sType = repeat;
+            else
+            {
             SchemaTypeImpl sTypeImpl = new SchemaTypeImpl(state.sts());
             sType = sTypeImpl;
             sTypeImpl.setContainerField(impl);
             sTypeImpl.setOuterSchemaTypeRef(outerType == null ? null : outerType.getRef());
+            sTypeImpl.setGroupReferenceContext(context);
             // leave the anonymous type unresolved: it will be resolved later.
             anonymousTypes.add(sType);
             sTypeImpl.setSimpleType(simpleTypedef);
             sTypeImpl.setParseContext(typedef, targetNamespace, chameleon, false);
+            }
         }
 
         if (sType == null)
@@ -744,6 +756,62 @@
         return impl;
     }
     
+    /**
+     * We need to do this because of the following kind of Schemas:
+     * <xs:group name="e">
+     *     <xs:sequence>
+     *         <xs:element name="error">
+     *             <xs:complexType>
+     *                 <xs:group ref="e"/>
+     *             </xs:complexType>
+     *         </xs:element>
+     *     </xs:sequence>
+     * </xs:group>
+     * (see JIRA bug XMLBEANS-35)
+     * Even though this should not be allowed because it produces an infinite
+     * number of anonymous types and local elements nested within each other,
+     * the de facto consensus among Schema processors is that this should be
+     * valid, therefore we have to detect this situation and "patch up" the
+     * Schema object model so that instead of creating a new anonymous type,
+     * we refer to the one that was already created earlier.
+     * In order to accomplish that, we store inside every anonymous type the
+     * list of groups that were dereferenced at the moment the type was created
+     * and if the same pattern is about to repeat, it means that we are in a
+     * case similar to the above.
+     */
+    private static SchemaType checkRecursiveGroupReference(QName[] context, QName containingElement,
SchemaTypeImpl outerType)
+    {
+        if (context.length < 1)
+            return null;
+        SchemaTypeImpl type = outerType;
+
+        while (type != null)
+        {
+            if (type.getName() != null || type.isDocumentType())
+                return null; // not anonymous
+            if (containingElement.equals(type.getContainerField().getName()))
+            {
+                QName[] outerContext = type.getGroupReferenceContext();
+                if (outerContext != null && outerContext.length == context.length)
+                {
+                    // Smells like trouble
+                    boolean equal = true;
+                    for (int i = 0; i < context.length; i++)
+                        if (!(context[i] == null && outerContext[i] == null ||
+                              context[i] != null && context[i].equals(outerContext[i])))
+                        {
+                            equal = false;
+                            break;
+                        }
+                    if (equal)
+                        return type;
+                }
+            }
+            type = (SchemaTypeImpl) type.getOuterType();
+        }
+        return null;
+    }
+
     private static String removeWhitespace(String xpath)
     {
         StringBuffer sb = new StringBuffer();

Modified: xmlbeans/branches/1.x/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCodeGenerator.java
URL: http://svn.apache.org/viewcvs/xmlbeans/branches/1.x/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCodeGenerator.java?view=diff&r1=149445&r2=149446
==============================================================================
--- xmlbeans/branches/1.x/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCodeGenerator.java
(original)
+++ xmlbeans/branches/1.x/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCodeGenerator.java
Tue Feb  1 12:41:31 2005
@@ -292,9 +292,10 @@
         {
             if (dir.isDirectory())
             {
-                String[] list = dir.list();
-                for (int i = 0; i < list.length; i++)
-                    tryToDelete(new File(dir, list[i]));
+                String[] list = dir.list(); // can return null if I/O error
+                if (list != null)
+                    for (int i = 0; i < list.length; i++)
+                        tryToDelete(new File(dir, list[i]));
             }
             if (!dir.delete())
                 return; // don't try very hard, because we're just deleting tmp

Modified: xmlbeans/branches/1.x/test/src/drt/drtcases/ValidationTests.java
URL: http://svn.apache.org/viewcvs/xmlbeans/branches/1.x/test/src/drt/drtcases/ValidationTests.java?view=diff&r1=149445&r2=149446
==============================================================================
--- xmlbeans/branches/1.x/test/src/drt/drtcases/ValidationTests.java (original)
+++ xmlbeans/branches/1.x/test/src/drt/drtcases/ValidationTests.java Tue Feb  1 12:41:31 2005
@@ -1599,4 +1599,60 @@
         doTest(schemas, null, valid, invalid);
     }
 
+    public void testValidateNestedGroups ( )
+        throws Exception
+    {
+        // This is a weird Schema, inspired from JIRA bug XMLBEANS-35
+        // Make sure we compile it and then validate correctly
+        String schemas[] = {
+            "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://tempuri.org/f_up_groups\"
xmlns:tns=\"http://tempuri.org/f_up_groups\">\n" +
+            "\n" +
+            "<xs:group name=\"d\">\n" +
+            "  <xs:sequence>\n" +
+            "      <xs:element name=\"error\">\n" +
+            "          <xs:complexType>\n" +
+            "                  <xs:group ref=\"tns:e\"/>\n" +
+            "          </xs:complexType>\n" +
+            "      </xs:element>\n" +
+            "  </xs:sequence>\n" +
+            "</xs:group>\n" +
+            "\n" +
+            "<xs:group name=\"e\">\n" +
+            "  <xs:sequence>\n" +
+            "          <xs:element name=\"error\" minOccurs=\"0\">\n" +
+            "                  <xs:complexType>\n" +
+            "                          <xs:group ref=\"tns:d\"/>\n" +
+            "                  </xs:complexType>\n" +
+            "          </xs:element>\n" +
+            "  </xs:sequence>\n" +
+            "</xs:group>\n" +
+            "\n" +
+            "<xs:element name=\"root\">\n" +
+            "  <xs:complexType>\n" +
+            "  <xs:group ref=\"tns:d\"/>\n" +
+            "  </xs:complexType>\n" +
+            "</xs:element>\n" +
+            "\n" +
+            "</xs:schema>\n"};
+
+        String valid[] = {
+            "<ns:root xmlns:ns=\"http://tempuri.org/f_up_groups\">\n" +
+            "   <error>\n" +
+            "      <error>\n" +
+            "         <error/>" +
+           "      </error>\n" +
+            "    </error>\n" +
+            "</ns:root>\n"};
+
+        String invalid[] = {
+            "<ns:root xmlns:ns=\"http://tempuri.org/f_up_groups\">\n" +
+            "   <error>\n" +
+            "      <error>\n" +
+           "      </error>\n" +
+            "    </error>\n" +
+            "</ns:root>\n"};
+
+        doTest(schemas, null, valid, invalid);
+    }
+
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: commits-help@xmlbeans.apache.org


Mime
View raw message