You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2012/01/13 22:16:26 UTC

svn commit: r1231299 - in /cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema: SchemaCollection.java XmlSchemaUtils.java

Author: dkulp
Date: Fri Jan 13 21:16:26 2012
New Revision: 1231299

URL: http://svn.apache.org/viewvc?rev=1231299&view=rev
Log:
[CXF-4017] Update addCrossImportsType to handle other types of particles
Patch from Benoit Lacelle used as a basis

Modified:
    cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java
    cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaUtils.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=1231299&r1=1231298&r2=1231299&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 Fri Jan 13 21:16:26 2012
@@ -31,9 +31,11 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
 import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaAll;
 import org.apache.ws.commons.schema.XmlSchemaAttribute;
 import org.apache.ws.commons.schema.XmlSchemaAttributeGroupRef;
 import org.apache.ws.commons.schema.XmlSchemaAttributeOrGroupRef;
+import org.apache.ws.commons.schema.XmlSchemaChoice;
 import org.apache.ws.commons.schema.XmlSchemaCollection;
 import org.apache.ws.commons.schema.XmlSchemaComplexContentExtension;
 import org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction;
@@ -41,6 +43,7 @@ import org.apache.ws.commons.schema.XmlS
 import org.apache.ws.commons.schema.XmlSchemaContent;
 import org.apache.ws.commons.schema.XmlSchemaContentModel;
 import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaObject;
 import org.apache.ws.commons.schema.XmlSchemaParticle;
 import org.apache.ws.commons.schema.XmlSchemaSequence;
 import org.apache.ws.commons.schema.XmlSchemaSequenceMember;
@@ -295,12 +298,35 @@ public class SchemaCollection {
             addCrossImports(schema, complexType.getContentModel());
             addCrossImportsAttributeList(schema, complexType.getAttributes());
             // could it be a choice or something else?
-            XmlSchemaSequence sequence = XmlSchemaUtils.getSequence(complexType);
-            addCrossImportsSequence(schema, sequence);
+            
+            if (complexType.getParticle() instanceof XmlSchemaChoice) {
+                XmlSchemaChoice choice = XmlSchemaUtils.getChoice(complexType);
+                addCrossImports(schema, choice);
+            } else if (complexType.getParticle() instanceof XmlSchemaAll) {
+                XmlSchemaAll all = XmlSchemaUtils.getAll(complexType);
+                addCrossImports(schema, all);
+            } else {
+                XmlSchemaSequence sequence = XmlSchemaUtils.getSequence(complexType);
+                addCrossImports(schema, sequence);
+            }
+        }
+    }
+    private void addCrossImports(XmlSchema schema, XmlSchemaAll all) {
+        for (XmlSchemaObject seqMember : all.getItems()) {
+            if (seqMember instanceof XmlSchemaElement) {
+                addElementCrossImportsElement(schema, (XmlSchemaElement)seqMember);
+            }
         }
     }
 
-    private void addCrossImportsSequence(XmlSchema schema, XmlSchemaSequence sequence) {
+    private void addCrossImports(XmlSchema schema, XmlSchemaChoice choice) {
+        for (XmlSchemaObject seqMember : choice.getItems()) {
+            if (seqMember instanceof XmlSchemaElement) {
+                addElementCrossImportsElement(schema, (XmlSchemaElement)seqMember);
+            }
+        }
+    }
+    private void addCrossImports(XmlSchema schema, XmlSchemaSequence sequence) {
         for (XmlSchemaSequenceMember seqMember : sequence.getItems()) {
             if (seqMember instanceof XmlSchemaElement) {
                 addElementCrossImportsElement(schema, (XmlSchemaElement)seqMember);
@@ -338,7 +364,11 @@ public class SchemaCollection {
             addCrossImportsAttributeList(schema, extension.getAttributes());
             XmlSchemaParticle particle = extension.getParticle();
             if (particle instanceof XmlSchemaSequence) {
-                addCrossImportsSequence(schema, (XmlSchemaSequence)particle);
+                addCrossImports(schema, (XmlSchemaSequence)particle);
+            } else if (particle instanceof XmlSchemaChoice) {
+                addCrossImports(schema, (XmlSchemaChoice)particle);
+            } else if (particle instanceof XmlSchemaAll) {
+                addCrossImports(schema, (XmlSchemaAll)particle);
             }
         } else if (content instanceof XmlSchemaComplexContentRestriction) {
             XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction)content;

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaUtils.java?rev=1231299&r1=1231298&r2=1231299&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaUtils.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaUtils.java Fri Jan 13 21:16:26 2012
@@ -29,11 +29,13 @@ import org.apache.cxf.common.WSDLConstan
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaAll;
 import org.apache.ws.commons.schema.XmlSchemaAnnotated;
 import org.apache.ws.commons.schema.XmlSchemaAny;
 import org.apache.ws.commons.schema.XmlSchemaAnyAttribute;
 import org.apache.ws.commons.schema.XmlSchemaAttribute;
 import org.apache.ws.commons.schema.XmlSchemaAttributeOrGroupRef;
+import org.apache.ws.commons.schema.XmlSchemaChoice;
 import org.apache.ws.commons.schema.XmlSchemaComplexContentExtension;
 import org.apache.ws.commons.schema.XmlSchemaComplexType;
 import org.apache.ws.commons.schema.XmlSchemaContent;
@@ -64,6 +66,8 @@ public final class XmlSchemaUtils {
 
     private static final Logger LOG = LogUtils.getL7dLogger(XmlSchemaUtils.class);
     private static final XmlSchemaSequence EMPTY_SEQUENCE = new XmlSchemaSequence();
+    private static final XmlSchemaChoice EMPTY_CHOICE = new XmlSchemaChoice();
+    private static final XmlSchemaAll EMPTY_ALL = new XmlSchemaAll();
 
     private XmlSchemaUtils() {
     }
@@ -496,7 +500,42 @@ public final class XmlSchemaUtils {
 
         return sequence;
     }
+    public static XmlSchemaChoice getChoice(XmlSchemaComplexType type) {
+        XmlSchemaParticle particle = type.getParticle();
+        XmlSchemaChoice choice = null;
+
+        if (particle == null) {
+            // the code that uses this wants to iterate. An empty one is more useful than
+            // a null pointer, and certainly an exception.
+            return EMPTY_CHOICE;
+        }
 
+        try {
+            choice = (XmlSchemaChoice) particle;
+        } catch (ClassCastException cce) {
+            unsupportedConstruct("NON_CHOICE_PARTICLE", type);
+        }
+
+        return choice;
+    }
+    public static XmlSchemaAll getAll(XmlSchemaComplexType type) {
+        XmlSchemaParticle particle = type.getParticle();
+        XmlSchemaAll all = null;
+
+        if (particle == null) {
+            // the code that uses this wants to iterate. An empty one is more useful than
+            // a null pointer, and certainly an exception.
+            return EMPTY_ALL;
+        }
+
+        try {
+            all = (XmlSchemaAll) particle;
+        } catch (ClassCastException cce) {
+            unsupportedConstruct("NON_CHOICE_PARTICLE", type);
+        }
+
+        return all;
+    }
     public static boolean isAttributeNameQualified(XmlSchemaAttribute attribute, XmlSchema schema) {
         if (attribute.isRef()) {
             throw new RuntimeException("isElementNameQualified on element with ref=");