cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r811149 - /cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java
Date Thu, 03 Sep 2009 21:56:17 GMT
Author: dkulp
Date: Thu Sep  3 21:56:16 2009
New Revision: 811149

URL: http://svn.apache.org/viewvc?rev=811149&view=rev
Log:
[CXF-2418] Fix for stackOverlow in SchemaCollection
Patch from Fried Hoeben applied

Modified:
    cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java?rev=811149&r1=811148&r2=811149&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java
(original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java
Thu Sep  3 21:56:16 2009
@@ -21,6 +21,10 @@
 
 import java.io.Reader;
 import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
 
 import javax.xml.namespace.QName;
 import javax.xml.transform.Source;
@@ -72,6 +76,9 @@
     }
 
     private XmlSchemaCollection schemaCollection;
+    private Map<XmlSchema, Set<XmlSchemaType>> xmlTypesCheckedForCrossImportsPerSchema

+        = new HashMap<XmlSchema, Set<XmlSchemaType>>();
+
 
     public SchemaCollection() {
         this(new XmlSchemaCollection());
@@ -346,7 +353,35 @@
         XmlSchemaUtils.addImportIfNeeded(schema, element.getSchemaTypeName());
         // if there's an anonymous type, it might have element refs in it.
         XmlSchemaType schemaType = element.getSchemaType();
-        addCrossImportsType(schema, schemaType);
+        if (!crossImportsAdded(schema, schemaType)) {
+            addCrossImportsType(schema, schemaType);
+        }
+    }
+
+    /**
+     * Determines whether the schema has already received (cross) imports for
+     * the schemaType
+     * @param schema
+     * @param schemaType
+     * @return false if cross imports for schemaType must still be added to schema
+     */
+    private boolean crossImportsAdded(XmlSchema schema, XmlSchemaType schemaType) {
+        boolean result = true;
+        if (schemaType != null) {
+            Set<XmlSchemaType> xmlTypesCheckedForCrossImports;
+            if (!xmlTypesCheckedForCrossImportsPerSchema.containsKey(schema)) {
+                xmlTypesCheckedForCrossImports = new HashSet<XmlSchemaType>();
+                xmlTypesCheckedForCrossImportsPerSchema.put(schema, xmlTypesCheckedForCrossImports);
+            } else {
+                xmlTypesCheckedForCrossImports = xmlTypesCheckedForCrossImportsPerSchema.get(schema);
+            }
+            if (!xmlTypesCheckedForCrossImports.contains(schemaType)) {
+                // cross imports for this schemaType have not yet been added
+                xmlTypesCheckedForCrossImports.add(schemaType);
+                result = false;
+            }
+        }
+        return result;
     }
 
     private void addCrossImportsType(XmlSchema schema, XmlSchemaType schemaType) {
@@ -426,4 +461,4 @@
             schema.addType(type);
         }
     }
-}
+}
\ No newline at end of file



Mime
View raw message