cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1213421 - /cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java
Date Mon, 12 Dec 2011 20:30:18 GMT
Author: dkulp
Date: Mon Dec 12 20:30:18 2011
New Revision: 1213421

URL: http://svn.apache.org/viewvc?rev=1213421&view=rev
Log:
[CXF-3968] If a schema is imported from multiple places via different
paths, make some attempt to rationalize all the various imports into
a single import url.

Modified:
    cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java

Modified: cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java?rev=1213421&r1=1213420&r2=1213421&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java (original)
+++ cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java Mon
Dec 12 20:30:18 2011
@@ -56,10 +56,10 @@ import org.apache.cxf.catalog.OASISCatal
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.DOMUtils;
-import org.apache.cxf.helpers.XMLUtils;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageUtils;
 import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.cxf.wsdl.WSDLManager;
 import org.apache.cxf.wsdl11.ResourceManagerWSDLLocator;
 import org.apache.cxf.wsdl11.ServiceWSDLBuilder;
@@ -236,7 +236,7 @@ public class WSDLGetUtils {
                                                                                 bus);
                 
                 InputSource src = rml.getBaseInputSource();
-                doc = XMLUtils.getParser().parse(src);
+                doc = StaxUtils.read(src);
             }
             
             updateDoc(doc, base, mp, smp, message);
@@ -251,6 +251,15 @@ public class WSDLGetUtils {
         }
     }
     
+    protected String mapUri(String base, Map<String, SchemaReference> smp, String loc)
+        throws UnsupportedEncodingException {
+        SchemaReference ref = smp.get(URLDecoder.decode(loc, "utf-8"));
+        if (ref != null) {
+            return base + "?xsd=" + ref.getSchemaLocationURI().replace(" ", "%20");
+        }
+        return null;
+    }
+    
     protected void updateDoc(Document doc, 
                            String base,
                            Map<String, Definition> mp,
@@ -265,8 +274,9 @@ public class WSDLGetUtils {
                                                                            "import");
             for (Element el : elementList) {
                 String sl = el.getAttribute("schemaLocation");
-                if (smp.containsKey(URLDecoder.decode(sl, "utf-8"))) {
-                    el.setAttribute("schemaLocation", base + "?xsd=" + sl.replace(" ", "%20"));
+                sl = mapUri(base, smp, sl);
+                if (sl != null) {
+                    el.setAttribute("schemaLocation", sl);
                 }
             }
             
@@ -451,7 +461,7 @@ public class WSDLGetUtils {
         for (List<?> lst : imports) {
             List<SchemaImport> impLst = CastUtils.cast(lst);
             for (SchemaImport imp : impLst) {
-                String start = imp.getSchemaLocationURI();
+                String start = findSchemaLocation(doneSchemas, imp);
                 
                 if (start != null) {
                     String decodedStart = null;
@@ -490,7 +500,7 @@ public class WSDLGetUtils {
         
         List<SchemaReference> includes = CastUtils.cast(schema.getIncludes());
         for (SchemaReference included : includes) {
-            String start = included.getSchemaLocationURI();
+            String start = findSchemaLocation(doneSchemas, included);
 
             if (start != null) {
                 String decodedStart = null;
@@ -527,7 +537,7 @@ public class WSDLGetUtils {
         }
         List<SchemaReference> redefines = CastUtils.cast(schema.getRedefines());
         for (SchemaReference included : redefines) {
-            String start = included.getSchemaLocationURI();
+            String start = findSchemaLocation(doneSchemas, included);
 
             if (start != null) {
                 String decodedStart = null;
@@ -564,4 +574,16 @@ public class WSDLGetUtils {
         }
     }
 
+    private String findSchemaLocation(Map<String, SchemaReference> doneSchemas, SchemaReference
imp) {
+        for (Map.Entry<String, SchemaReference> e : doneSchemas.entrySet()) {
+            if (e.getValue().getReferencedSchema().getElement() 
+                == imp.getReferencedSchema().getElement()) {
+                doneSchemas.put(imp.getSchemaLocationURI(), imp);
+                imp.setSchemaLocationURI(e.getKey());
+                return e.getKey();
+            }
+        }
+        return imp.getSchemaLocationURI();
+    }
+
 }



Mime
View raw message