cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r702547 - in /cxf/trunk/api/src: main/java/org/apache/cxf/wsdl/JAXBExtensionHelper.java test/java/org/apache/cxf/wsdl/JAXBExtensionHelperTest.java
Date Tue, 07 Oct 2008 17:06:08 GMT
Author: dkulp
Date: Tue Oct  7 10:06:08 2008
New Revision: 702547

URL: http://svn.apache.org/viewvc?rev=702547&view=rev
Log:
[CXF-1834] Fix for writing extensor objects that have been namespace mapped

Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/JAXBExtensionHelper.java
    cxf/trunk/api/src/test/java/org/apache/cxf/wsdl/JAXBExtensionHelperTest.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/JAXBExtensionHelper.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/JAXBExtensionHelper.java?rev=702547&r1=702546&r2=702547&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/JAXBExtensionHelper.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/JAXBExtensionHelper.java Tue Oct  7 10:06:08
2008
@@ -87,7 +87,18 @@
                 .asSubclass(TExtensibilityElementImpl.class);
         addExtensions(registry, parentTypeClass, elementTypeClass, null);
     }
-    
+    public static void addExtensions(ExtensionRegistry registry,
+                                     String parentType, 
+                                     String elementType,
+                                     String namespace)
+        throws JAXBException, ClassNotFoundException {
+        Class<?> parentTypeClass = ClassLoaderUtils.loadClass(parentType, JAXBExtensionHelper.class);
+
+        Class<? extends TExtensibilityElementImpl> elementTypeClass = 
+            ClassLoaderUtils.loadClass(elementType, JAXBExtensionHelper.class)
+                .asSubclass(TExtensibilityElementImpl.class);
+        addExtensions(registry, parentTypeClass, elementTypeClass, namespace);
+    }
     public static void addExtensions(ExtensionRegistry registry,
                                      Class<?> parentType,
                                      Class<? extends TExtensibilityElementImpl> cls)
@@ -224,6 +235,10 @@
                 }
                                 
                 public String getPrefix(String arg) {
+                    if (arg.equals(jaxbNamespace)) {
+                        arg = namespace;
+                    }
+                    
                     for (Object ent : wsdl.getNamespaces().entrySet()) {
                         Map.Entry entry = (Map.Entry)ent;
                         if (arg.equals(entry.getValue())) {
@@ -234,6 +249,9 @@
                 }
                 
                 public Iterator getPrefixes(String arg) {
+                    if (arg.equals(jaxbNamespace)) {
+                        arg = namespace;
+                    }
                     return wsdl.getNamespaces().keySet().iterator();
                 }
             });

Modified: cxf/trunk/api/src/test/java/org/apache/cxf/wsdl/JAXBExtensionHelperTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/wsdl/JAXBExtensionHelperTest.java?rev=702547&r1=702546&r2=702547&view=diff
==============================================================================
--- cxf/trunk/api/src/test/java/org/apache/cxf/wsdl/JAXBExtensionHelperTest.java (original)
+++ cxf/trunk/api/src/test/java/org/apache/cxf/wsdl/JAXBExtensionHelperTest.java Tue Oct 
7 10:06:08 2008
@@ -23,6 +23,7 @@
 import java.io.ByteArrayOutputStream;
 import java.io.PrintWriter;
 import java.io.StringReader;
+import java.io.StringWriter;
 import java.util.List;
 
 import javax.wsdl.Definition;
@@ -33,6 +34,8 @@
 import javax.wsdl.xml.WSDLReader;
 import javax.xml.namespace.QName;
 
+import org.xml.sax.InputSource;
+
 import org.apache.cxf.abc.test.AnotherPolicyType;
 import org.apache.cxf.abc.test.NewServiceType;
 import org.apache.cxf.abc.test.TestPolicyType;
@@ -79,28 +82,7 @@
         wsdlReader.setExtensionRegistry(registry);
 
         wsdlDefinition = wsdlReader.readWSDL(file);
-        Service s = wsdlDefinition.getService(new QName("http://cxf.apache.org/test/hello_world",
-                        "HelloWorldService"));
-        Port p = s.getPort("HelloWorldPort");
-        List extPortList = p.getExtensibilityElements();
-
-        TestPolicyType tp = null;
-        AnotherPolicyType ap = null;
-        for (Object ext : extPortList) {
-            if (ext instanceof TestPolicyType) {
-                tp = (TestPolicyType) ext;
-            }
-            if (ext instanceof AnotherPolicyType) {
-                ap = (AnotherPolicyType) ext;
-            }
-        }
-        assertNotNull("Could not find extension element TestPolicyType", tp);
-        assertNotNull("Could not find extension element AnotherPolicyType", ap);
-
-        assertEquals("Unexpected value for TestPolicyType intAttr", 30, tp.getIntAttr());
-        assertEquals("Unexpected value for TestPolicyType stringAttr", "hello", tp.getStringAttr());
-        assertTrue("Unexpected value for AnotherPolicyType floatAttr",
-            Math.abs(0.1F - ap.getFloatAttr()) < 0.5E-5);
+        checkTestExt();
     }
 
     @Test
@@ -149,6 +131,57 @@
             actual = reader.readLine();
         }
     }
+    
+    @Test
+    public void testMappedNamespace() throws Exception {
+        JAXBExtensionHelper.addExtensions(registry, "javax.wsdl.Port",
+            "org.apache.cxf.abc.test.TestPolicyType",
+            "http://cxf.apache.org/abc/test/remapped");
+
+        JAXBExtensionHelper.addExtensions(registry, "javax.wsdl.Port",
+            "org.apache.cxf.abc.test.AnotherPolicyType",
+            "http://cxf.apache.org/abc/test/remapped");
+
+        JAXBExtensionHelper.addExtensions(registry, "javax.wsdl.Definition",
+            "org.apache.cxf.abc.test.NewServiceType",
+            "http://cxf.apache.org/abc/test/remapped");
+
+        String file = this.getClass().getResource("/wsdl/test_ext_remapped.wsdl").toURI().toString();
+        wsdlReader.setExtensionRegistry(registry);
+
+        wsdlDefinition = wsdlReader.readWSDL(file);
+        checkTestExt();
+        StringWriter out = new StringWriter();
+        wsdlFactory.newWSDLWriter().writeWSDL(wsdlDefinition, out);
+        wsdlDefinition = wsdlReader.readWSDL(null,
+                                             new InputSource(new StringReader(out.toString())));
+        checkTestExt();
+    }
+    
+    private void checkTestExt() throws Exception {
+        Service s = wsdlDefinition.getService(new QName("http://cxf.apache.org/test/hello_world",
+            "HelloWorldService"));
+        Port p = s.getPort("HelloWorldPort");
+        List extPortList = p.getExtensibilityElements();
+    
+        TestPolicyType tp = null;
+        AnotherPolicyType ap = null;
+        for (Object ext : extPortList) {
+            if (ext instanceof TestPolicyType) {
+                tp = (TestPolicyType) ext;
+            }
+            if (ext instanceof AnotherPolicyType) {
+                ap = (AnotherPolicyType) ext;
+            }
+        }
+        assertNotNull("Could not find extension element TestPolicyType", tp);
+        assertNotNull("Could not find extension element AnotherPolicyType", ap);
+    
+        assertEquals("Unexpected value for TestPolicyType intAttr", 30, tp.getIntAttr());
+        assertEquals("Unexpected value for TestPolicyType stringAttr", "hello", tp.getStringAttr());
+        assertTrue("Unexpected value for AnotherPolicyType floatAttr",
+                   Math.abs(0.1F - ap.getFloatAttr()) < 0.5E-5);        
+    }
 
     private void checkSpaces(String actual, int spaces) {
         String space = "";



Mime
View raw message