Map<Element, Map<String, String>> prefixMaps = new HashMap<Element, Map<String, String>>();
for (Map.Entry<QName, List<ElementInfo>> entry: wrappers.entrySet()) {
String targetNS = entry.getKey().getNamespaceURI();
Document schemaDoc = null;
Element schema = null;
XSDefinition xsDef = wrapperXSDs.get(targetNS);
if (xsDef != null) {
schemaDoc = xsDef.getDocument();
schema = schemaDoc.getDocumentElement();
} else {
schemaDoc = createDocument();
schema = schemaDoc.createElementNS(SCHEMA_NS, "xs:schema");
// The elementFormDefault should be set to unqualified, see TUSCANY-2388
schema.setAttribute("elementFormDefault", "unqualified");
schema.setAttribute("attributeFormDefault", "qualified");
schema.setAttribute("targetNamespace", targetNS);
schema.setAttributeNS(XMLNS_NS, "xmlns:xs", SCHEMA_NS);
schemaDoc.appendChild(schema);
Schema schemaExt = createSchemaExt(definition);
schemaExt.setElement(schema);
prefixMaps.put(schema, new HashMap<String, String>());
xsDef = xsdFactory.createXSDefinition();
xsDef.setUnresolved(true);
xsDef.setNamespace(targetNS);
xsDef.setDocument(schemaDoc);
// TUSCANY-2465: Set the system id to avoid schema conflict
xsDef.setLocation(URI.create("xsd_" + index + ".xsd"));
index++;
wrapperXSDs.put(targetNS, xsDef);
}
Element wrapper = schemaDoc.createElementNS(SCHEMA_NS, "xs:element");
schema.appendChild(wrapper);