Author: dkulp Date: Fri Jan 13 21:27:25 2012 New Revision: 1231309 URL: http://svn.apache.org/viewvc?rev=1231309&view=rev Log: Merged revisions 1231304 via svnmerge from https://svn.apache.org/repos/asf/cxf/branches/2.5.x-fixes
................ r1231304 | dkulp | 2012-01-13 16:20:44 -0500 (Fri, 13 Jan 2012) | 10 lines Merged revisions 1231299 via svnmerge from https://svn.apache.org/repos/asf/cxf/trunk ........ r1231299 | dkulp | 2012-01-13 16:16:26 -0500 (Fri, 13 Jan 2012) | 2 lines [CXF-4017] Update addCrossImportsType to handle other types of particles Patch from Benoit Lacelle used as a basis ........ ................ Modified: cxf/branches/2.4.x-fixes/ (props changed) cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaUtils.java Propchange: cxf/branches/2.4.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java?rev=1231309&r1=1231308&r2=1231309&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java (original) +++ cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java Fri Jan 13 21:27:25 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/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaUtils.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaUtils.java?rev=1231309&r1=1231308&r2=1231309&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaUtils.java (original) +++ cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaUtils.java Fri Jan 13 21:27:25 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=");
