tns2Type.put(ns, types);
}
types.add(t);
}
for (ServiceInfo si : s.getServiceInfos()) {
SchemaCollection col = si.getXmlSchemaCollection();
if (col.getXmlSchemas().length > 1) {
// someone has already filled in the types
continue;
}
}
Map<String, String> namespaceMap = getDeclaredNamespaceMappings();
for (Map.Entry<String, Set<Type>> entry : tns2Type.entrySet()) {
String xsdPrefix = XmlConstants.XSD_PREFIX;
if (namespaceMap != null && namespaceMap.containsKey(XmlConstants.XSD)) {
xsdPrefix = namespaceMap.get(XmlConstants.XSD);
}
Element e = new Element("schema", xsdPrefix, XmlConstants.XSD);
e.setAttribute(new Attribute(WSDLConstants.ATTR_TNS, entry.getKey()));
if (null != namespaceMap) { // did application hand us some additional namespaces?
for (Map.Entry<String, String> mapping : namespaceMap.entrySet()) {
// user gives us namespace->prefix mapping.
e.addNamespaceDeclaration(Namespace.getNamespace(mapping.getValue(),
mapping.getKey()));
}
}
// if the user didn't pick something else, assign 'tns' as the prefix.
if (namespaceMap == null || !namespaceMap.containsKey(entry.getKey())) {
// Schemas are more readable if there is a specific prefix for the TNS.
e.addNamespaceDeclaration(Namespace.getNamespace(WSDLConstants.CONVENTIONAL_TNS_PREFIX,
entry.getKey()));
}
e.setAttribute(new Attribute("elementFormDefault", "qualified"));
e.setAttribute(new Attribute("attributeFormDefault", "qualified"));
for (Type t : entry.getValue()) {
t.writeSchema(e);
}
if (e.getChildren().size() == 0) {
continue;
}
try {
NamespaceMap nsMap = new NamespaceMap();
nsMap.add(xsdPrefix, XmlConstants.XSD);
// We prefer explicit prefixes over those generated in the types.
// This loop may have intended to support prefixes from individual aegis files,
// but that isn't a good idea.
for (Iterator itr = e.getAdditionalNamespaces().iterator(); itr.hasNext();) {
Namespace n = (Namespace) itr.next();
if (!nsMap.containsValue(n.getURI())) {
nsMap.add(n.getPrefix(), n.getURI());
}
}
org.w3c.dom.Document schema = new DOMOutputter().output(new Document(e));
for (ServiceInfo si : s.getServiceInfos()) {
SchemaCollection col = si.getXmlSchemaCollection();
col.setNamespaceContext(nsMap);
XmlSchema xmlSchema = addSchemaDocument(si, col, schema, entry.getKey());
// Work around bug in JDOM DOMOutputter which fails to correctly
// assign namespaces to attributes. If JDOM worked right,
// the collection object would get the prefixes for itself.
xmlSchema.setNamespaceContext(nsMap);