SWS-575 - CommonsXsdSchemaCollection: Combination of xs:includes and xs:imports in a schema result in incorrect/overcomplete schema in wsdl generated by DefaultWsdl11Definition
This commit is contained in:
@@ -183,23 +183,24 @@ public class CommonsXsdSchemaCollection implements XsdSchemaCollection, Initiali
|
||||
|
||||
private void inlineIncludes(XmlSchema schema, Set processedIncludes, Set processedImports) {
|
||||
processedIncludes.add(schema);
|
||||
XmlSchemaObjectCollection includes = schema.getIncludes();
|
||||
for (int i = 0; i < includes.getCount(); i++) {
|
||||
XmlSchemaExternal external = (XmlSchemaExternal) includes.getItem(i);
|
||||
if (external instanceof XmlSchemaInclude) {
|
||||
XmlSchema includedSchema = external.getSchema();
|
||||
XmlSchemaObjectCollection items = schema.getItems();
|
||||
|
||||
XmlSchemaObjectCollection schemaItems = schema.getItems();
|
||||
for (int i = 0; i < schemaItems.getCount(); i++) {
|
||||
XmlSchemaObject schemaObject = schemaItems.getItem(i);
|
||||
if (schemaObject instanceof XmlSchemaInclude) {
|
||||
XmlSchema includedSchema = ((XmlSchemaInclude) schemaObject).getSchema();
|
||||
if (!processedIncludes.contains(includedSchema)) {
|
||||
inlineIncludes(includedSchema, processedIncludes, processedImports);
|
||||
findImports(includedSchema, processedImports, processedIncludes);
|
||||
XmlSchemaObjectCollection includeItems = includedSchema.getItems();
|
||||
for (int j = 0; j < includeItems.getCount(); j++) {
|
||||
XmlSchemaObject includedItem = includeItems.getItem(j);
|
||||
items.add(includedItem);
|
||||
schemaItems.add(includedItem);
|
||||
}
|
||||
}
|
||||
// remove the <include/>
|
||||
items.remove(external);
|
||||
schemaItems.removeAt(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,4 +120,29 @@ public class CommonsXsdSchemaCollectionTest extends XMLTestCase {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testIncludesAndImports() throws Exception {
|
||||
Resource hr = new ClassPathResource("hr.xsd", getClass());
|
||||
collection.setXsds(new Resource[]{hr});
|
||||
collection.setInline(true);
|
||||
collection.afterPropertiesSet();
|
||||
|
||||
XsdSchema[] schemas = collection.getXsdSchemas();
|
||||
assertEquals("Invalid amount of XSDs loaded", 2, schemas.length);
|
||||
|
||||
assertEquals("Invalid target namespace", "http://mycompany.com/hr/schemas", schemas[0].getTargetNamespace());
|
||||
Resource hr_employee = new ClassPathResource("hr_employee.xsd", getClass());
|
||||
Document expected = documentBuilder.parse(SaxUtils.createInputSource(hr_employee));
|
||||
DOMResult domResult = new DOMResult();
|
||||
transformer.transform(schemas[0].getSource(), domResult);
|
||||
assertXMLEqual("Invalid XSD generated", expected, (Document) domResult.getNode());
|
||||
|
||||
assertEquals("Invalid target namespace", "http://mycompany.com/hr/schemas/holiday", schemas[1].getTargetNamespace());
|
||||
Resource holiday = new ClassPathResource("holiday.xsd", getClass());
|
||||
expected = documentBuilder.parse(SaxUtils.createInputSource(holiday));
|
||||
domResult = new DOMResult();
|
||||
transformer.transform(schemas[1].getSource(), domResult);
|
||||
assertXMLEqual("Invalid XSD generated", expected, (Document) domResult.getNode());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:hr="http://mycompany.com/hr/schemas"
|
||||
elementFormDefault="qualified"
|
||||
targetNamespace="http://mycompany.com/hr/schemas">
|
||||
<xs:complexType name="EmployeeType">
|
||||
<xs:sequence>
|
||||
<xs:element name="Number" type="xs:integer"/>
|
||||
<xs:element name="FirstName" type="xs:string"/>
|
||||
<xs:element name="LastName" type="xs:string"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:schema>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:hrh="http://mycompany.com/hr/schemas/holiday"
|
||||
attributeFormDefault="unqualified"
|
||||
elementFormDefault="qualified"
|
||||
targetNamespace="http://mycompany.com/hr/schemas/holiday">
|
||||
<xs:complexType name="HolidayType">
|
||||
<xs:sequence>
|
||||
<xs:element name="StartDate" type="xs:date"/>
|
||||
<xs:element name="EndDate" type="xs:date"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:schema>
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:hr="http://mycompany.com/hr/schemas"
|
||||
xmlns:hrh="http://mycompany.com/hr/schemas/holiday"
|
||||
elementFormDefault="qualified"
|
||||
targetNamespace="http://mycompany.com/hr/schemas">
|
||||
|
||||
<xs:import namespace="http://mycompany.com/hr/schemas/holiday" schemaLocation="holiday.xsd"/>
|
||||
<xs:include schemaLocation="employee.xsd"/>
|
||||
<xs:element name="HolidayRequest">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="Holiday" type="hrh:HolidayType"/>
|
||||
<xs:element name="Employee" type="hr:EmployeeType"/>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:hr="http://mycompany.com/hr/schemas"
|
||||
xmlns:hrh="http://mycompany.com/hr/schemas/holiday"
|
||||
attributeFormDefault="unqualified"
|
||||
elementFormDefault="qualified"
|
||||
targetNamespace="http://mycompany.com/hr/schemas">
|
||||
|
||||
<xs:import namespace="http://mycompany.com/hr/schemas/holiday"/>
|
||||
<xs:element name="HolidayRequest">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="Holiday" type="hrh:HolidayType"/>
|
||||
<xs:element name="Employee" type="hr:EmployeeType"/>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:complexType name="EmployeeType">
|
||||
<xs:sequence>
|
||||
<xs:element name="Number" type="xs:integer"/>
|
||||
<xs:element name="FirstName" type="xs:string"/>
|
||||
<xs:element name="LastName" type="xs:string"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:schema>
|
||||
Reference in New Issue
Block a user