cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [02/16] git commit: Update wadl generator to use the prefix that the JAXB implementation chose for the targetNamespace.
Date Fri, 04 Apr 2014 15:01:38 GMT
Update wadl generator to use the prefix that the JAXB implementation chose for the targetNamespace.


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/323863ba
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/323863ba
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/323863ba

Branch: refs/heads/2.7.x-fixes
Commit: 323863ba1b25477e3ae860192939dd480330062b
Parents: 91f47fc
Author: Daniel Kulp <dkulp@apache.org>
Authored: Wed Mar 26 17:00:27 2014 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Fri Apr 4 09:55:37 2014 -0400

----------------------------------------------------------------------
 .../cxf/jaxrs/model/wadl/WadlGenerator.java     | 12 ++++++++----
 .../cxf/jaxrs/model/wadl/WadlGeneratorTest.java | 20 ++++++++++++++------
 2 files changed, 22 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/323863ba/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
index 7807407..dd5d512 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
@@ -1051,10 +1051,14 @@ public class WadlGenerator implements RequestHandler {
                 ElementQNameResolver theResolver = createElementQNameResolver(context);
                 String tns = doc.getDocumentElement().getAttribute("targetNamespace");
                 
-                String tnsDecl = 
-                    doc.getDocumentElement().getAttribute("xmlns:tns");
-                String tnsPrefix = tnsDecl != null && tnsDecl.equals(tns) ? "tns:"
: "";
-                
+                String tnsPrefix = doc.getDocumentElement().lookupPrefix(tns);
+                if (tnsPrefix == null) {
+                    String tnsDecl = doc.getDocumentElement().getAttribute("xmlns:tns");
+                    tnsPrefix = tnsDecl != null && tnsDecl.equals(tns) ? "tns:" :
"";
+                } else {
+                    tnsPrefix += ":";
+                }
+
                 if (supportJaxbXmlType) {
                     for (Class<?> cls : resourceTypes.getAllTypes().keySet()) {
                         if (isXmlRoot(cls)) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/323863ba/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
index 1011d24..abe1bd0 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
@@ -400,14 +400,24 @@ public class WadlGeneratorTest extends Assert {
         return false;
     }
     
+    private boolean checkTypeName(Element el, String typeName, String name) {
+        String pfx = "";
+        String tn = typeName;
+        if (tn.contains(":")) {
+            pfx = tn.substring(0, tn.indexOf(':'));
+            tn = tn.substring(tn.indexOf(':') + 1);
+        }
+        pfx = el.lookupNamespaceURI(pfx);
+        
+        return tn.equals(name) && pfx.length() > 5;
+    }
+    
     private boolean checkElement(List<Element> els, String name, String localTypeName)
{
         for (Element e : els) {
             if (name.equals(e.getAttribute("name"))) {
                 String type = e.getAttribute("type");
                 if (!StringUtils.isEmpty(type)) {
-                    String expectedType1 = "tns:" + localTypeName;
-                    String expectedType2 = "os:" + localTypeName;
-                    if (type.equals(expectedType1) || type.equals(expectedType2)) {
+                    if (checkTypeName(e, type, localTypeName)) {
                         return true;
                     }
                 } else if ("books".equals(name) || "thebook2s".equals(name)) {
@@ -422,9 +432,7 @@ public class WadlGeneratorTest extends Assert {
                         (Element)seqElement.getElementsByTagNameNS(XmlSchemaConstants.XSD_NAMESPACE_URI,

                                                           "element").item(0);
                     String ref = xsElement.getAttribute("ref");
-                    String expectedRef = thebooks2 ? "tns:thebook2" : "tns:thebook";
-                    String expectedRef2 = thebooks2 ? "os:thebook2" : "os:thebook";
-                    if (ref.equals(expectedRef) || ref.equals(expectedRef2)) {
+                    if (checkTypeName(e, ref, thebooks2 ? "thebook2" : "thebook")) {
                         return true;
                     }
                 }


Mime
View raw message