diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-07-13 17:02:55 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-07-13 17:02:55 +0000 |
commit | 70ff746f64113f137bdd3ea2af9f77205b5b4e0a (patch) | |
tree | 96fe41d9c33ad713054267109fe5178a226cd5d4 /java/sca/modules/binding-ws-wsdlgen | |
parent | f055db88f952b39ba2a90c1781c77985bb3af4bd (diff) |
Avoid duplicate xs:import elements
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@793627 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/binding-ws-wsdlgen')
-rw-r--r-- | java/sca/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/java/sca/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java b/java/sca/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java index e98534b6ff..93c393914f 100644 --- a/java/sca/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java +++ b/java/sca/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java @@ -437,17 +437,30 @@ public class Interface2WSDLGenerator { if (!"".equals(nsURI)) { imp.setAttribute("namespace", nsURI); } - NodeList childNodes = schema.getChildNodes(); + // Scan all xs:import elements to match namespace + NodeList childNodes = schema.getElementsByTagNameNS(SCHEMA_NS, "import"); for (int i = 0; i < childNodes.getLength(); i++) { Node childNode = childNodes.item(i); if (childNode instanceof Element) { - schema.insertBefore(imp, childNode); - imp = null; - break; + String ns = ((Element)childNode).getAttributeNS(SCHEMA_NS, "namespace"); + if (nsURI.equals(ns)) { + // The xs:import with the same namespace has been declared + return; + } } } - if (imp != null) { + // Try to find the first node after the import elements + Node firstNodeAfterImport = null; + if (childNodes.getLength() > 0) { + firstNodeAfterImport = childNodes.item(childNodes.getLength() - 1).getNextSibling(); + } else { + firstNodeAfterImport = schema.getFirstChild(); + } + + if (firstNodeAfterImport == null) { schema.appendChild(imp); + } else { + schema.insertBefore(imp, firstNodeAfterImport); } } |