You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by mm...@apache.org on 2007/12/07 11:19:00 UTC

svn commit: r602058 - in /incubator/cxf/trunk: api/src/main/java/org/apache/cxf/ api/src/main/java/org/apache/cxf/ws/addressing/ api/src/main/java/org/apache/cxf/wsdl/ api/src/test/java/org/apache/cxf/ rt/core/src/main/java/org/apache/cxf/wsdl11/ tools...

Author: mmao
Date: Fri Dec  7 02:18:59 2007
New Revision: 602058

URL: http://svn.apache.org/viewvc?rev=602058&view=rev
Log:
* Easy to handle the prefix from the namespace


Added:
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/NSManager.java
    incubator/cxf/trunk/api/src/test/java/org/apache/cxf/NSManagerTest.java
Modified:
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/addressing/JAXWSAConstants.java
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/WSDLConstants.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java
    incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/expected/add_numbers_expected.wsdl

Added: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/NSManager.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/NSManager.java?rev=602058&view=auto
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/NSManager.java (added)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/NSManager.java Fri Dec  7 02:18:59 2007
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.cxf.ws.addressing.JAXWSAConstants;
+import org.apache.cxf.wsdl.WSDLConstants;
+
+/***
+ * Only public/static/final fields can be resolved
+ * The prefix MUST ends with _PREFIX
+ * Namespace MUST starts with NS_
+ * The value of the _PREFIX is the suffix of NS_
+ 
+ e.g
+    public static final String WSAW_PREFIX = "wsaw";
+    public static final String NS_WSAW = "http://www.w3.org/2006/05/addressing/wsdl"; 
+***/
+
+public final class NSManager {
+    private final Map<String, String> cache = new HashMap<String, String>();
+
+
+    public NSManager() {
+        resolveConstants(JAXWSAConstants.class);
+        resolveConstants(WSDLConstants.class);
+    }
+
+    private void resolveConstants(final Class clz) {
+        for (Field field : clz.getFields()) {
+            if (field.getName().endsWith("_PREFIX") && isPulicStaticFinal(field)) {
+                try {
+                    String prefix = (String) field.get(clz);
+                    Field nsField = clz.getField("NS_" + prefix.toUpperCase());
+                    if (nsField != null) {
+                        cache.put((String)nsField.get(clz), prefix);
+                    }
+                } catch (Exception e) {
+                    // ignore
+                }
+            }
+        }
+    }
+
+    public String getPrefixFromNS(String namespace) {
+        return cache.get(namespace);
+    }
+
+    private boolean isPulicStaticFinal(final Field field) {
+        return field.getModifiers() == (Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL);
+    }
+
+    public Set<String> getNamespaces() {
+        return this.cache.keySet();
+    }
+}
\ No newline at end of file

Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/addressing/JAXWSAConstants.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/addressing/JAXWSAConstants.java?rev=602058&r1=602057&r2=602058&view=diff
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/addressing/JAXWSAConstants.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/addressing/JAXWSAConstants.java Fri Dec  7 02:18:59 2007
@@ -28,11 +28,12 @@
  */
 public final class JAXWSAConstants {
     
-    public static final String WSAW = "http://www.w3.org/2006/05/addressing/wsdl"; 
+    public static final String WSAW_PREFIX = "wsaw";
+    public static final String NS_WSAW = "http://www.w3.org/2006/05/addressing/wsdl";
 
-    public static final QName WSAW_ACTION_QNAME = new QName(WSAW,  "Action");
+    public static final QName WSAW_ACTION_QNAME = new QName(NS_WSAW,  "Action");
     
-    public static final QName WSAW_USINGADDRESSING_QNAME = new QName(WSAW, "UsingAddressing");
+    public static final QName WSAW_USINGADDRESSING_QNAME = new QName(NS_WSAW, "UsingAddressing");
 
     /**
      * Well-known Property names for AddressingProperties in BindingProvider

Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/WSDLConstants.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/WSDLConstants.java?rev=602058&r1=602057&r2=602058&view=diff
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/WSDLConstants.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/WSDLConstants.java Fri Dec  7 02:18:59 2007
@@ -19,8 +19,6 @@
 
 package org.apache.cxf.wsdl;
 
-import java.util.HashMap;
-import java.util.Map;
 import javax.xml.namespace.QName;
 
 public final class WSDLConstants {
@@ -50,24 +48,18 @@
 
 
 
-    public static final String NS_SOAP11 = "http://schemas.xmlsoap.org/wsdl/soap/";
+    public static final String NS_SOAP = "http://schemas.xmlsoap.org/wsdl/soap/";
     public static final String NS_SOAP12 = "http://schemas.xmlsoap.org/wsdl/soap12/";
-    public static final String NP_SOAP11 = "soap";
-    public static final String NP_SOAP12 = "soap12";
+    public static final String SOAP11_PREFIX = "soap";
+    public static final String SOAP12_PREFIX = "soap12";
     
-    public static final Map<String, String> NS_PREFIX_PAIR = new HashMap<String, String>(2);
-    static {
-        NS_PREFIX_PAIR.put(NS_SOAP11, NP_SOAP11);
-        NS_PREFIX_PAIR.put(NS_SOAP12, NP_SOAP12);
-    }
-
     public static final String NS_SOAP11_HTTP_TRANSPORT = "http://schemas.xmlsoap.org/soap/http";
     
-    public static final QName QNAME_SOAP_BINDING = new QName(NS_SOAP11, "binding");
-    public static final QName QNAME_SOAP_OPERATION = new QName(NS_SOAP11, "operation");
-    public static final QName QNAME_SOAP_BODY = new QName(NS_SOAP11, "body");
-    public static final QName QNAME_SOAP_FAULT = new QName(NS_SOAP11, "fault");
-    public static final QName QNAME_SOAP_BINDING_ADDRESS = new QName(NS_SOAP11, "address");
+    public static final QName QNAME_SOAP_BINDING = new QName(NS_SOAP, "binding");
+    public static final QName QNAME_SOAP_OPERATION = new QName(NS_SOAP, "operation");
+    public static final QName QNAME_SOAP_BODY = new QName(NS_SOAP, "body");
+    public static final QName QNAME_SOAP_FAULT = new QName(NS_SOAP, "fault");
+    public static final QName QNAME_SOAP_BINDING_ADDRESS = new QName(NS_SOAP, "address");
 
 
     public static final String NS_SOAP12_HTTP_TRANSPORT = "http://www.w3.org/2003/05/soap/bindings/HTTP/";

Added: incubator/cxf/trunk/api/src/test/java/org/apache/cxf/NSManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/test/java/org/apache/cxf/NSManagerTest.java?rev=602058&view=auto
==============================================================================
--- incubator/cxf/trunk/api/src/test/java/org/apache/cxf/NSManagerTest.java (added)
+++ incubator/cxf/trunk/api/src/test/java/org/apache/cxf/NSManagerTest.java Fri Dec  7 02:18:59 2007
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf;
+
+import org.apache.cxf.ws.addressing.JAXWSAConstants;
+import org.apache.cxf.wsdl.WSDLConstants;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class NSManagerTest extends Assert {
+    @Test
+    public void testGetPrefix() {
+        NSManager nsMan = new NSManager();
+        assertEquals("wsaw", nsMan.getPrefixFromNS(JAXWSAConstants.NS_WSAW));
+
+        assertEquals("soap", nsMan.getPrefixFromNS(WSDLConstants.NS_SOAP));
+        assertEquals("soap12", nsMan.getPrefixFromNS(WSDLConstants.NS_SOAP12));
+    }
+}
\ No newline at end of file

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java?rev=602058&r1=602057&r2=602058&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java Fri Dec  7 02:18:59 2007
@@ -58,6 +58,7 @@
 
 import com.ibm.wsdl.extensions.schema.SchemaImpl;
 import org.apache.cxf.Bus;
+import org.apache.cxf.NSManager;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.XMLUtils;
 import org.apache.cxf.helpers.XPathUtils;
@@ -96,6 +97,7 @@
     private String baseFileName;
     private int xsdCount;
     private final Bus bus;
+    private final NSManager nsMan;
     
     /**
      * Sets up the builder on a bus with a list of services.
@@ -106,6 +108,7 @@
         this.services = services;
         bus = b;
         ns2prefix = new HashMap<String, String>();
+        nsMan = new NSManager();
     }
     
     /**
@@ -520,9 +523,9 @@
     }
 
     private String getPrefix(String ns) {
-        for (String namespace : WSDLConstants.NS_PREFIX_PAIR.keySet()) {
+        for (String namespace : nsMan.getNamespaces()) {
             if (namespace.equals(ns)) {
-                return WSDLConstants.NS_PREFIX_PAIR.get(namespace);
+                return nsMan.getPrefixFromNS(namespace);
             }
         }
         String prefix = ns2prefix.get(ns);

Modified: incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/expected/add_numbers_expected.wsdl
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/expected/add_numbers_expected.wsdl?rev=602058&r1=602057&r2=602058&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/expected/add_numbers_expected.wsdl (original)
+++ incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/expected/add_numbers_expected.wsdl Fri Dec  7 02:18:59 2007
@@ -17,7 +17,7 @@
   specific language governing permissions and limitations
   under the License.
 -->
-<wsdl:definitions name="AddNumbersImplService" targetNamespace="http://fortest.tools.cxf.apache.org/" xmlns:tns="http://fortest.tools.cxf.apache.org/" xmlns:ns1="http://www.w3.org/2006/05/addressing/wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
+<wsdl:definitions name="AddNumbersImplService" targetNamespace="http://fortest.tools.cxf.apache.org/" xmlns:tns="http://fortest.tools.cxf.apache.org/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
   <wsdl:types>
 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://fortest.tools.cxf.apache.org/" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://fortest.tools.cxf.apache.org/">
     <xsd:element name="AddNumbersException" type="tns:AddNumbersException"/>
@@ -101,17 +101,17 @@
     </wsdl:output>
     </wsdl:operation>
     <wsdl:operation name="addNumbers3">
-      <wsdl:input name="addNumbers3" message="tns:addNumbers3" ns1:Action="tns:http://cxf.apache.org/input3">
+      <wsdl:input name="addNumbers3" message="tns:addNumbers3" wsaw:Action="tns:http://cxf.apache.org/input3">
     </wsdl:input>
-      <wsdl:output name="addNumbers3Response" message="tns:addNumbers3Response" ns1:Action="tns:http://cxf.apache.org/output3">
+      <wsdl:output name="addNumbers3Response" message="tns:addNumbers3Response" wsaw:Action="tns:http://cxf.apache.org/output3">
     </wsdl:output>
-      <wsdl:fault name="AddNumbersException" message="tns:AddNumbersException" ns1:Action="tns:http://cxf.apache.org/fault3">
+      <wsdl:fault name="AddNumbersException" message="tns:AddNumbersException" wsaw:Action="tns:http://cxf.apache.org/fault3">
     </wsdl:fault>
     </wsdl:operation>
     <wsdl:operation name="addNumbers">
-      <wsdl:input name="addNumbers" message="tns:addNumbers" ns1:Action="tns:http://cxf.apache.org/input">
+      <wsdl:input name="addNumbers" message="tns:addNumbers" wsaw:Action="tns:http://cxf.apache.org/input">
     </wsdl:input>
-      <wsdl:output name="addNumbersResponse" message="tns:addNumbersResponse" ns1:Action="tns:http://cxf.apache.org/output">
+      <wsdl:output name="addNumbersResponse" message="tns:addNumbersResponse" wsaw:Action="tns:http://cxf.apache.org/output">
     </wsdl:output>
       <wsdl:fault name="AddNumbersException" message="tns:AddNumbersException">
     </wsdl:fault>
@@ -119,7 +119,7 @@
   </wsdl:portType>
   <wsdl:binding name="AddNumbersImplServiceSoapBinding" type="tns:AddNumbersImpl">
     <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
-    <ns1:UsingAddressing />
+    <wsaw:UsingAddressing />
     <wsdl:operation name="addNumbers2">
       <soap:operation soapAction="" style="document"/>
       <wsdl:input name="addNumbers2">