geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r541126 - in /geronimo/server/trunk/modules: geronimo-axis2-builder/src/main/java/org/apache/geronimo/axis2/builder/Axis2Builder.java geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/JAXWSUtils.java
Date Thu, 24 May 2007 01:13:43 GMT
Author: gawor
Date: Wed May 23 18:13:42 2007
New Revision: 541126

URL: http://svn.apache.org/viewvc?view=rev&rev=541126
Log:
set proper service and port name

Modified:
    geronimo/server/trunk/modules/geronimo-axis2-builder/src/main/java/org/apache/geronimo/axis2/builder/Axis2Builder.java
    geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/JAXWSUtils.java

Modified: geronimo/server/trunk/modules/geronimo-axis2-builder/src/main/java/org/apache/geronimo/axis2/builder/Axis2Builder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-axis2-builder/src/main/java/org/apache/geronimo/axis2/builder/Axis2Builder.java?view=diff&rev=541126&r1=541125&r2=541126
==============================================================================
--- geronimo/server/trunk/modules/geronimo-axis2-builder/src/main/java/org/apache/geronimo/axis2/builder/Axis2Builder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-axis2-builder/src/main/java/org/apache/geronimo/axis2/builder/Axis2Builder.java
Wed May 23 18:13:42 2007
@@ -303,14 +303,14 @@
         
         // set wsdl service
         if (portInfo.getWsdlService() == null) {
-            generator.setWsdlService(new QName(JAXWSUtils.getServiceName(serviceClass)));
+            generator.setWsdlService(JAXWSUtils.getServiceQName(serviceClass));
         } else {
             generator.setWsdlService(portInfo.getWsdlService());
         }
         
         // set wsdl port
         if (portInfo.getWsdlPort() == null) {
-            // TODO: get it from the class
+            generator.setWsdlPort(JAXWSUtils.getPortQName(serviceClass));
         } else {
             generator.setWsdlPort(portInfo.getWsdlPort());
         }

Modified: geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/JAXWSUtils.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/JAXWSUtils.java?view=diff&rev=541126&r1=541125&r2=541126
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/JAXWSUtils.java
(original)
+++ geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/JAXWSUtils.java
Wed May 23 18:13:42 2007
@@ -19,6 +19,7 @@
 import java.lang.reflect.Modifier;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.StringTokenizer;
 
 import javax.jws.WebService;
 import javax.xml.namespace.QName;
@@ -48,7 +49,7 @@
                 localName = seiClass.getName();
             }
             String namespace = webService.targetNamespace();
-            return new QName(namespace, localName);
+            return new QName(getNamespace(seiClass, namespace), localName);
         }
         return null;
     }
@@ -82,6 +83,73 @@
     }
     
     public static String getServiceName(Class clazz) {
+        return getServiceQName(clazz).getLocalPart();
+    }
+    
+    private static String getServiceName(Class clazz, String name) {
+        if (name == null || name.trim().length() == 0) {
+            return clazz.getSimpleName() + "Service";
+        } else {
+            return name.trim();
+        }       
+    }
+    
+    private static String getPortName(Class clazz, String name, String portName) {
+        if (portName == null || portName.trim().length() == 0) {
+            if (name == null || name.trim().length() == 0) {
+                return clazz.getSimpleName() + "Port";
+            } else {
+                return name + "Port";
+            }
+        } else {
+            return portName.trim();
+        }
+    }
+    
+    private static String getNamespace(Class clazz, String namespace) {
+        if (namespace == null || namespace.trim().length() == 0) {
+            Package pkg = clazz.getPackage();
+            if (pkg == null) {
+                return null;
+            } else {
+                return getNamespace(pkg.getName());
+            }
+        } else {
+            return namespace.trim();
+        }
+    }
+    
+    private static String getNamespace(String packageName) {
+        if (packageName == null || packageName.length() == 0) {
+            return null;
+        }
+        StringTokenizer tokenizer = new StringTokenizer(packageName, ".");
+        String[] tokens;
+        if (tokenizer.countTokens() == 0) {
+            tokens = new String[0];
+        } else {
+            tokens = new String[tokenizer.countTokens()];
+            for (int i = tokenizer.countTokens() - 1; i >= 0; i--) {
+                tokens[i] = tokenizer.nextToken();
+            }
+        }
+        StringBuffer namespace = new StringBuffer("http://");
+        String dot = "";
+        for (int i = 0; i < tokens.length; i++) {
+            if (i == 1) {
+                dot = ".";
+            }
+            namespace.append(dot + tokens[i]);
+        }
+        namespace.append('/');
+        return namespace.toString();
+    }
+    
+    private static QName getServiceQName(Class clazz, String namespace, String name) {
+        return new QName(getNamespace(clazz, namespace), getServiceName(clazz, name));  
      
+    }
+    
+    public static QName getServiceQName(Class clazz) {
         WebService webService = 
             (WebService)clazz.getAnnotation(WebService.class);
         if (webService == null) {
@@ -90,20 +158,31 @@
             if (webServiceProvider == null) {
                 throw new IllegalArgumentException("The " + clazz.getName() + " is not annotated");
             }
-            return getServiceName(clazz, webServiceProvider.serviceName());
+            return getServiceQName(clazz, webServiceProvider.targetNamespace(), webServiceProvider.serviceName());
         } else {
-            return getServiceName(clazz, webService.serviceName());
+            return getServiceQName(clazz, webService.targetNamespace(), webService.serviceName());
         }
     }
     
-    private static String getServiceName(Class clazz, String name) {
-        if (name == null || name.trim().length() == 0) {
-            return clazz.getSimpleName() + "Service";
-        } else {
-            return name.trim();
-        }       
+    private static QName getPortQName(Class clazz, String namespace, String name, String
portName) {
+        return new QName(getNamespace(clazz, namespace), getPortName(clazz, name, portName));
        
     }
     
+    public static QName getPortQName(Class clazz) {
+        WebService webService = 
+            (WebService)clazz.getAnnotation(WebService.class);
+        if (webService == null) {
+            WebServiceProvider webServiceProvider = 
+                (WebServiceProvider)clazz.getAnnotation(WebServiceProvider.class);
+            if (webServiceProvider == null) {
+                throw new IllegalArgumentException("The " + clazz.getName() + " is not annotated");
+            }
+            return getPortQName(clazz, webServiceProvider.targetNamespace(), null, webServiceProvider.portName());
+        } else {
+            return getPortQName(clazz, webService.targetNamespace(), webService.name(), webService.serviceName());
+        }
+    }
+        
     public static String getName(Class clazz) {
         WebService webService = 
             (WebService)clazz.getAnnotation(WebService.class);
@@ -126,8 +205,7 @@
                     throw new RuntimeException("Unable to load SEI class: " + sei);
                 }
             }
-        }
-        
+        }        
     }
         
     private static String getNameFromSEI(Class seiClass) {



Mime
View raw message