axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r463395 - in /webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl: ./ utils/
Date Thu, 12 Oct 2006 19:49:55 GMT
Author: dims
Date: Thu Oct 12 12:49:54 2006
New Revision: 463395

URL: http://svn.apache.org/viewvc?view=rev&rev=463395
Log:
Fix for AXIS2-1252 - java2wsdl generates unknown namespace

Added:
    webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/DefaultNamespaceGenerator.java
    webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/NamespaceGenerator.java
Modified:
    webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDL.java
    webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLBuilder.java
    webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLCodegenEngine.java
    webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLConstants.java
    webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLUtils.java
    webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/SchemaGenerator.java
    webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/utils/Java2WSDLOptionsValidator.java

Added: webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/DefaultNamespaceGenerator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/DefaultNamespaceGenerator.java?view=auto&rev=463395
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/DefaultNamespaceGenerator.java
(added)
+++ webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/DefaultNamespaceGenerator.java
Thu Oct 12 12:49:54 2006
@@ -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.ws.java2wsdl;
+
+/**
+ * This class provides the default implementatoin for mapping java classes to namespaces
+ *
+ */
+public class DefaultNamespaceGenerator implements NamespaceGenerator {
+    public static final String HTTP = "http://";
+    public static final char PACKAGE_CLASS_DELIMITER = '.';
+    public static final String SCHEMA_NAMESPACE_EXTN = "/xsd";
+
+    /* (non-Javadoc)
+     * @see org.apache.ws.java2wsdl.NamespaceGenerator#namespaceFromPackageName(java.lang.String)
+     */
+    public StringBuffer namespaceFromPackageName(String packageName) {
+
+        StringBuffer strBuf = new StringBuffer();
+        int prevIndex = packageName.length();
+        int currentIndex = packageName.lastIndexOf(PACKAGE_CLASS_DELIMITER);
+        if (currentIndex > 0) {
+            strBuf.append(HTTP);
+        } else if (prevIndex > 0) {
+            strBuf.append(HTTP);
+            strBuf.append(packageName);
+            return strBuf;
+        } else if (currentIndex == -1) {
+//            strBuf.append(HTTP);
+//            strBuf.append(packageName);
+            return strBuf;
+        }
+        while (currentIndex != -1) {
+            strBuf.append(packageName.substring(currentIndex + 1, prevIndex));
+            prevIndex = currentIndex;
+            currentIndex = packageName.lastIndexOf(PACKAGE_CLASS_DELIMITER, prevIndex - 1);
+            strBuf.append(PACKAGE_CLASS_DELIMITER);
+
+            if (currentIndex == -1) {
+                strBuf.append(packageName.substring(0, prevIndex));
+            }
+        }
+        return strBuf;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ws.java2wsdl.NamespaceGenerator#schemaNamespaceFromPackageName(java.lang.String)
+     */
+    public StringBuffer schemaNamespaceFromPackageName(String packageName) {
+        if (packageName.length() > 0) {
+            return namespaceFromPackageName(packageName).append(SCHEMA_NAMESPACE_EXTN);
+        } else {
+            StringBuffer buffer = new StringBuffer();
+            buffer.append(Java2WSDLConstants.DEFAULT_TARGET_NAMESPACE);
+            buffer.append(SCHEMA_NAMESPACE_EXTN);
+            return buffer;
+        }
+    }
+    
+    
+
+}

Modified: webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDL.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDL.java?view=diff&rev=463395&r1=463394&r2=463395
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDL.java
(original)
+++ webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDL.java
Thu Oct 12 12:49:54 2006
@@ -1,68 +1,71 @@
-package org.apache.ws.java2wsdl;
-
-import org.apache.ws.java2wsdl.utils.Java2WSDLCommandLineOptionParser;
-import org.apache.ws.java2wsdl.utils.Java2WSDLOptionsValidator;
-/*
-* Copyright 2004,2005 The Apache Software Foundation.
-*
-* Licensed 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.
-*
-*/
-
-public class Java2WSDL {
-    public static void main(String[] args) {
-        Java2WSDLCommandLineOptionParser commandLineOptionParser = new Java2WSDLCommandLineOptionParser(
-                args);
-        //  validate the arguments
-        validateCommandLineOptions(commandLineOptionParser);
-        try {
-            new Java2WSDLCodegenEngine(commandLineOptionParser.getAllOptions()).generate();
-        } catch (Exception e) {
-            System.out.println("An error occured while generating code" + e.getMessage());
-        }
-    }
-
-    public static void printUsage() {
-        System.out.println("Usage java2wsdl -cn <fully qualified class name> : class
file name");
-        System.out.println("-o <output Location> : output file location");
-        System.out.println("-cp <class path uri> : list of classpath entries - (urls)");
-        System.out.println("-tn <target namespace> : target namespace");
-        System.out.println("-tp <target namespace prefix> : target namespace prefix");
-        System.out.println("-stn <schema target namespace> : target namespace for schema");
-        System.out.println("-stp <schema target namespace prefix> : target namespace
prefix for schema");
-        System.out.println("-sn <service name> : service name");
-        System.out.println("-of <output file name> : output file name for the WSDL");
-        System.out.println("-st <binding style> : style for the WSDL");
-        System.out.println("-u <binding use> : use for the WSDL");
-        System.out.println("-l <soap address> : address of the port for the WSDL");
-        System.out.println("-efd <qualified/unqualified> : Setting for elementFormDefault
(defaults to qualified)");
-        System.out.println("-afd <qualified/unqualified> : Setting for attributeFormDefault
(defaults to qualified)");
-        System.out.println("-xc <extra class> : Extra class for which schematype must
be generated.  " +
-                           "\t\tUse as : -xc class1 -xc class2 ...");
-        
-        System.exit(0);
-    }
-
-
-    private static void validateCommandLineOptions(
-            Java2WSDLCommandLineOptionParser parser) {
-        if (parser.getAllOptions().size() == 0) {
-            printUsage();
-        } else if (parser.getInvalidOptions(new Java2WSDLOptionsValidator()).size() >
0) {
-            printUsage();
-        }
-
-    }
-
-}
-
+package org.apache.ws.java2wsdl;
+
+import org.apache.ws.java2wsdl.utils.Java2WSDLCommandLineOptionParser;
+import org.apache.ws.java2wsdl.utils.Java2WSDLOptionsValidator;
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.
+*
+*/
+
+public class Java2WSDL {
+    public static void main(String[] args) {
+        Java2WSDLCommandLineOptionParser commandLineOptionParser = new Java2WSDLCommandLineOptionParser(
+                args);
+        //  validate the arguments
+        validateCommandLineOptions(commandLineOptionParser);
+        try {
+            new Java2WSDLCodegenEngine(commandLineOptionParser.getAllOptions()).generate();
+        } catch (Exception e) {
+            System.out.println("An error occured while generating code" + e.getMessage());
+        }
+    }
+
+    public static void printUsage() {
+        System.out.println("Usage java2wsdl -cn <fully qualified class name> : class
file name");
+        System.out.println("-o <output Location> : output file location");
+        System.out.println("-cp <class path uri> : list of classpath entries - (urls)");
+        System.out.println("-tn <target namespace> : target namespace");
+        System.out.println("-tp <target namespace prefix> : target namespace prefix");
+        System.out.println("-stn <schema target namespace> : target namespace for schema");
+        System.out.println("-stp <schema target namespace prefix> : target namespace
prefix for schema");
+        System.out.println("-sn <service name> : service name");
+        System.out.println("-of <output file name> : output file name for the WSDL");
+        System.out.println("-st <binding style> : style for the WSDL");
+        System.out.println("-u <binding use> : use for the WSDL");
+        System.out.println("-l <soap address> : address of the port for the WSDL");
+        System.out.println("-nsg <generator class name> : fully qualified name of the
class that implements NamespaceGenerator");
+        System.out.println("-p2n [<java package>,<namespace] [<java package>,<namespace]...
: java package to namespace mapping for argument and return types..." +
+                                "\t\t to assign all types to a single namespace : -p2n [all
, <namespace>] ...");
+        System.out.println("-efd <qualified/unqualified> : Setting for elementFormDefault
(defaults to qualified)");
+        System.out.println("-afd <qualified/unqualified> : Setting for attributeFormDefault
(defaults to qualified)");
+        System.out.println("-xc <extra class> : Extra class for which schematype must
be generated.  " +
+                           "\t\tUse as : -xc class1 -xc class2 ...");
+        
+        System.exit(0);
+    }
+
+
+    private static void validateCommandLineOptions(
+            Java2WSDLCommandLineOptionParser parser) {
+        if (parser.getAllOptions().size() == 0) {
+            printUsage();
+        } else if (parser.getInvalidOptions(new Java2WSDLOptionsValidator()).size() >
0) {
+            printUsage();
+        }
+
+    }
+
+}
+

Modified: webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLBuilder.java?view=diff&rev=463395&r1=463394&r2=463395
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLBuilder.java
(original)
+++ webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLBuilder.java
Thu Oct 12 12:49:54 2006
@@ -5,6 +5,8 @@
 import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Hashtable;
+import java.util.Map;
 /*
 * Copyright 2004,2005 The Apache Software Foundation.
 *
@@ -25,6 +27,7 @@
 
 public class Java2WSDLBuilder {
 
+    public static final String ALL = "all";
     private OutputStream out;
     private String className;
     private ClassLoader classLoader;
@@ -44,6 +47,9 @@
     private String use = Java2WSDLConstants.LITERAL;
     private String locationUri = Java2WSDLConstants.DEFAULT_LOCATION_URL;
     private ArrayList extraClasses;
+    
+    private String nsGenClassName = null;
+    private Map pkg2nsMap = null;
 
     public String getSchemaTargetNamespace() {
         return schemaTargetNamespace;
@@ -148,12 +154,20 @@
         schemaGenerator.setAttrFormDefault(getAttrFormDefault());
         schemaGenerator.setElementFormDefault(getElementFormDefault());
         schemaGenerator.setExtraClasses(getExtraClasses());
+        schemaGenerator.setNsGenClassName(getNsGenClassName());
+        schemaGenerator.setPkg2nsmap(getPkg2nsMap());
+        if ( getPkg2nsMap() != null && !getPkg2nsMap().isEmpty() && 
+                (getPkg2nsMap().containsKey(ALL) || getPkg2nsMap().containsKey(ALL.toUpperCase()))
) {
+            schemaGenerator.setUseWSDLTypesNamespace(true);
+        } 
+        
         Collection schemaCollection = schemaGenerator.generateSchema();
+        
         Java2OMBuilder java2OMBuilder = new Java2OMBuilder(schemaGenerator.getMethods(),
                 schemaCollection,
                 schemaGenerator.getTypeTable(),
                 serviceName == null ? Java2WSDLUtils.getSimpleClassName(className) : serviceName,
-                targetNamespace == null ? Java2WSDLUtils.namespaceFromClassName(className,classLoader).toString()
: targetNamespace,
+                targetNamespace == null ? Java2WSDLUtils.namespaceFromClassName(className,classLoader,
resolveNSGen()).toString() : targetNamespace,
                 targetNamespacePrefix,
                 style,
                 use,
@@ -187,5 +201,33 @@
     public void setExtraClasses(ArrayList extraClasses) {
         this.extraClasses = extraClasses;
     }
+
+    public String getNsGenClassName() {
+        return nsGenClassName;
+    }
+
+    public void setNsGenClassName(String nsGenClassName) {
+        this.nsGenClassName = nsGenClassName;
+    }
+
+    public Map getPkg2nsMap() {
+        return pkg2nsMap;
+    }
+
+    public void setPkg2nsMap(Map pkg2nsMap) {
+        this.pkg2nsMap = pkg2nsMap;
+    }
+    
+    private NamespaceGenerator resolveNSGen() {
+        NamespaceGenerator nsGen = null;
+        try {
+            nsGen = (NamespaceGenerator)Class.forName(this.nsGenClassName).newInstance();
+        } catch ( Exception e ) {
+            nsGen = new DefaultNamespaceGenerator();
+        }
+        
+        return nsGen;
+    }
+    
 }
 

Modified: webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLCodegenEngine.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLCodegenEngine.java?view=diff&rev=463395&r1=463394&r2=463395
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLCodegenEngine.java
(original)
+++ webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLCodegenEngine.java
Thu Oct 12 12:49:54 2006
@@ -9,6 +9,7 @@
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.ArrayList;
+import java.util.Hashtable;
 import java.util.Map;
 import java.util.Vector;
 /*
@@ -31,6 +32,7 @@
 public class Java2WSDLCodegenEngine implements Java2WSDLConstants {
     private Java2WSDLBuilder java2WsdlBuilder;
     public static final String WSDL_FILENAME_SUFFIX = ".wsdl";
+    public static final String COMMA = ",";
 
     public Java2WSDLCodegenEngine(Map optionsMap) throws Exception {
         //create a new  Java2WSDLBuilder and populate it
@@ -183,6 +185,16 @@
         option = loadOption(Java2WSDLConstants.EXTRA_CLASSES_DEFAULT_OPTION,
                             Java2WSDLConstants.EXTRA_CLASSES_DEFAULT_OPTION_LONG, optionsMap);
         java2WsdlBuilder.setExtraClasses(option == null ? new ArrayList() : option.getOptionValues());
+        
+        option = loadOption(Java2WSDLConstants.NAMESPACE_GENERATOR_OPTION,
+                            Java2WSDLConstants.NAMESPACE_GENERATOR_OPTION_LONG, optionsMap);
+        if ( option != null ) {
+            java2WsdlBuilder.setNsGenClassName(option.getOptionValue());
+        }
+        
+        option = loadOption(Java2WSDLConstants.JAVA_PKG_2_NSMAP_OPTION,
+                            Java2WSDLConstants.JAVA_PKG_2_NSMAP_OPTION_LONG, optionsMap);
+        java2WsdlBuilder.setPkg2nsMap(loadJavaPkg2NamespaceMap(option));
     }
     
      /**
@@ -204,5 +216,33 @@
         }
 
         return option;
+    }
+    
+    protected void addToSchemaLocationMap(String optionValue) throws Exception
+    {
+        
+        
+        
+    }
+    
+    protected Map loadJavaPkg2NamespaceMap(Java2WSDLCommandLineOption option) 
+    { 
+        Map pkg2nsMap = new Hashtable();
+        if (option != null) 
+        {
+            ArrayList optionValues = option.getOptionValues();
+            String anOptionValue = "";
+            for ( int count = 0 ; count < optionValues.size() ; ++count )
+            {
+                anOptionValue = ((String)optionValues.get(count)).trim();
+                
+                //an option value will be of the form [java package, namespace]
+                //hence we take the two substrings starting after '[' and upto ',' and
+                //starting after ',' and upto ']'
+                pkg2nsMap.put(anOptionValue.substring(1, anOptionValue.indexOf(COMMA)).trim(),
+                                        anOptionValue.substring(anOptionValue.indexOf(COMMA)
+ 1, anOptionValue.length() - 1).trim()); 
+            }
+        }
+        return pkg2nsMap;
     }
 }

Modified: webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLConstants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLConstants.java?view=diff&rev=463395&r1=463394&r2=463395
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLConstants.java
(original)
+++ webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLConstants.java
Thu Oct 12 12:49:54 2006
@@ -101,6 +101,8 @@
     String ATTR_FORM_DEFAULT_OPTION = "afd";
     String ELEMENT_FORM_DEFAULT_OPTION = "efd";
     String EXTRA_CLASSES_DEFAULT_OPTION = "xc";
+    String NAMESPACE_GENERATOR_OPTION = "nsg";
+    String JAVA_PKG_2_NSMAP_OPTION = "p2n";
 
     //long option constants
     String OUTPUT_LOCATION_OPTION_LONG = "output";
@@ -119,6 +121,8 @@
     String ATTR_FORM_DEFAULT_OPTION_LONG = "attributeFormDefault";
     String ELEMENT_FORM_DEFAULT_OPTION_LONG = "elementFormDefault";
     String EXTRA_CLASSES_DEFAULT_OPTION_LONG = "extraClasses";
+    String NAMESPACE_GENERATOR_OPTION_LONG = "namespaceGenerator";
+    String JAVA_PKG_2_NSMAP_OPTION_LONG = "package2Namespace";
 
     public static final String SOLE_INPUT = "SOLE_INPUT";
 

Modified: webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLUtils.java?view=diff&rev=463395&r1=463394&r2=463395
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLUtils.java
(original)
+++ webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/Java2WSDLUtils.java
Thu Oct 12 12:49:54 2006
@@ -1,31 +1,35 @@
 package org.apache.ws.java2wsdl;
 
 /*
-* Copyright 2004,2005 The Apache Software Foundation.
-*
-* Licensed 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.
-*
-*/
-
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ */
 
 public class Java2WSDLUtils {
+    
     public static final String HTTP = "http://";
+
     public static final char PACKAGE_CLASS_DELIMITER = '.';
+
     public static final String SCHEMA_NAMESPACE_EXTN = "/xsd";
+    
+    private static NamespaceGenerator defaultNsGenerator = new DefaultNamespaceGenerator();
 
     /**
      * check the entry for a URL. This is a simple check and need to be improved
-     *
+     * 
      * @param entry
      */
 
@@ -35,48 +39,49 @@
 
     /**
      * A method to strip the fully qualified className to a simple classname
-     *
+     * 
      * @param qualifiedName
      */
     public static String getSimpleClassName(String qualifiedName) {
         int index = qualifiedName.lastIndexOf(".");
         if (index > 0) {
-            return qualifiedName.substring(index + 1, qualifiedName.length());
+            return qualifiedName.substring(index + 1,
+                                           qualifiedName.length());
         }
         return qualifiedName;
     }
 
-    public static StringBuffer namespaceFromPackageName(String packageName) {
+    public static StringBuffer namespaceFromClassName(String className,
+                                                      ClassLoader classLoader) throws Exception
{
+        return namespaceFromClassName(className, classLoader, defaultNsGenerator);
+    }
+    
+    
+    public static StringBuffer namespaceFromClassName(String className,
+                                                      ClassLoader classLoader,
+                                                      NamespaceGenerator nsGen) throws Exception
{
+        Class clazz = Class.forName(className,
+                                    true,
+                                    classLoader);
+        Package pkg = clazz.getPackage();
+        String name;
 
-        StringBuffer strBuf = new StringBuffer();
-        int prevIndex = packageName.length();
-        int currentIndex = packageName.lastIndexOf(PACKAGE_CLASS_DELIMITER);
-        if (currentIndex > 0) {
-            strBuf.append(HTTP);
-        } else if (prevIndex > 0) {
-            strBuf.append(HTTP);
-            strBuf.append(packageName);
-            return strBuf;
-        } else if (currentIndex == -1) {
-//            strBuf.append(HTTP);
-//            strBuf.append(packageName);
-            return strBuf;
-        }
-        while (currentIndex != -1) {
-            strBuf.append(packageName.substring(currentIndex + 1, prevIndex));
-            prevIndex = currentIndex;
-            currentIndex = packageName.lastIndexOf(PACKAGE_CLASS_DELIMITER, prevIndex - 1);
-            strBuf.append(PACKAGE_CLASS_DELIMITER);
-
-            if (currentIndex == -1) {
-                strBuf.append(packageName.substring(0, prevIndex));
-            }
-        }
-        return strBuf;
+        if (pkg != null)
+            name = pkg.getName();
+        else
+            name = packageNameFromClass(clazz.getName());
+
+        return nsGen.namespaceFromPackageName(name);
     }
 
     public static StringBuffer schemaNamespaceFromClassName(String packageName, ClassLoader
loader) throws Exception {
-        StringBuffer stringBuffer = namespaceFromClassName(packageName, loader);
+        return schemaNamespaceFromClassName(packageName, loader, defaultNsGenerator);
+    }
+    
+    public static StringBuffer schemaNamespaceFromClassName(String packageName, ClassLoader
loader, NamespaceGenerator nsGen) throws Exception {
+        StringBuffer stringBuffer = namespaceFromClassName(packageName,
+                                                           loader,
+                                                           nsGen);
         if (stringBuffer.length() == 0) {
             stringBuffer.append(Java2WSDLConstants.DEFAULT_TARGET_NAMESPACE);
         }
@@ -84,21 +89,10 @@
         return stringBuffer;
     }
 
-    public static StringBuffer namespaceFromClassName(String className, ClassLoader classLoader)
throws Exception {
-        Class clazz = Class.forName(className, true, classLoader);
-        Package pkg = clazz.getPackage();
-        String name;
-
-        if (pkg != null)
-            name = pkg.getName();
-        else
-            name = packageNameFromClass(clazz.getName());
-
-        return namespaceFromPackageName(name);
-    }
-
     public static String getPackageName(String className, ClassLoader classLoader) throws
Exception {
-        Class clazz = Class.forName(className, true, classLoader);
+        Class clazz = Class.forName(className,
+                                    true,
+                                    classLoader);
         Package pkg = clazz.getPackage();
         String name;
 
@@ -116,16 +110,5 @@
         if (lastDot != -1)
             ret = name.substring(lastDot + 1);
         return ret;
-    }
-
-    public static StringBuffer schemaNamespaceFromPackageName(String packageName) {
-        if (packageName.length() > 0) {
-            return namespaceFromPackageName(packageName).append(SCHEMA_NAMESPACE_EXTN);
-        } else {
-            StringBuffer buffer = new StringBuffer();
-            buffer.append(Java2WSDLConstants.DEFAULT_TARGET_NAMESPACE);
-            buffer.append(SCHEMA_NAMESPACE_EXTN);
-            return buffer;
-        }
     }
 }

Added: webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/NamespaceGenerator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/NamespaceGenerator.java?view=auto&rev=463395
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/NamespaceGenerator.java
(added)
+++ webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/NamespaceGenerator.java
Thu Oct 12 12:49:54 2006
@@ -0,0 +1,30 @@
+/*
+ * 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.ws.java2wsdl;
+
+/**
+ * This interface must be implemented to provide custom implemtations for, 
+ * java package name to namespace mapping.  An instance of this class is used by the schema
generator
+ * for generation namespaces
+ *
+ */
+public interface NamespaceGenerator {
+    public StringBuffer namespaceFromPackageName(String packageName);
+    public StringBuffer schemaNamespaceFromPackageName(String packageName);
+}

Modified: webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/SchemaGenerator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/SchemaGenerator.java?view=diff&rev=463395&r1=463394&r2=463395
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/SchemaGenerator.java
(original)
+++ webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/SchemaGenerator.java
Thu Oct 12 12:49:54 2006
@@ -63,7 +63,24 @@
 
     private ArrayList extraClasses = null;
 
-    private boolean useScheamNameSpace = false;
+    private boolean useWSDLTypesNamespace = false;
+    
+    private Map pkg2nsmap = null;
+    
+    private String nsGenClassName = null;
+    
+    private NamespaceGenerator nsGen = null;
+
+    public NamespaceGenerator getNsGen() {
+        if ( nsGen == null ) {
+            nsGen = new DefaultNamespaceGenerator();
+        }
+        return nsGen;
+    }
+
+    public void setNsGen(NamespaceGenerator nsGen) {
+        this.nsGen = nsGen;
+    }
 
     public SchemaGenerator(ClassLoader loader, String className,
                            String schematargetNamespace, String schematargetNamespacePrefix)
@@ -77,10 +94,9 @@
         if (schematargetNamespace != null
                 && schematargetNamespace.trim().length() != 0) {
             this.schemaTargetNameSpace = schematargetNamespace;
-            useScheamNameSpace = true;
         } else {
-            this.schemaTargetNameSpace = Java2WSDLUtils
-                    .schemaNamespaceFromClassName(className, loader).toString();
+            this.schemaTargetNameSpace =
+                Java2WSDLUtils.schemaNamespaceFromClassName(className, loader, getNsGen()).toString();
         }
         if (schematargetNamespacePrefix != null
                 && schematargetNamespacePrefix.trim().length() != 0) {
@@ -233,12 +249,8 @@
             String simpleName = javaType.getSimpleName();
 
             String packageName = javaType.getContainingPackage().getQualifiedName();
-            String targetNameSpace;
-            if (useScheamNameSpace) {
-                targetNameSpace = this.schemaTargetNameSpace;
-            } else {
-                targetNameSpace = Java2WSDLUtils.schemaNamespaceFromPackageName(packageName).toString();
-            }
+            String targetNameSpace = resolveSchemaNamespace(packageName).toString();
+            
             XmlSchema xmlSchema = getXmlSchema(targetNameSpace);
             String targetNamespacePrefix = (String) targetNamespacePrefixMap.get(targetNameSpace);
 
@@ -330,12 +342,8 @@
                     isArrayType);
             //addImport((XmlSchema)schemaMap.get(schemaTargetNameSpace), schemaTypeName);
             String schemaNamespace;
-            if (useScheamNameSpace) {
-                schemaNamespace = this.schemaTargetNameSpace;
-            } else {
-                schemaNamespace = Java2WSDLUtils.schemaNamespaceFromPackageName(type.getContainingPackage().
-                        getQualifiedName()).toString();
-            }
+            schemaNamespace = resolveSchemaNamespace(type.getContainingPackage().
+                                                         getQualifiedName()).toString();
             addImport(getXmlSchema(schemaNamespace), schemaTypeName);
 
         } else {
@@ -484,5 +492,54 @@
     public void setExtraClasses(ArrayList extraClasses) {
         this.extraClasses = extraClasses;
     }
+    
+    private String resolveSchemaNamespace(String packageName) {
+        //if all types must go into the wsdl types schema namespace
+        if ( useWSDLTypesNamespace ) {
+            //return schemaTargetNameSpace;
+            return (String)pkg2nsmap.get("all");
+        } else {
+            if ( pkg2nsmap != null && !pkg2nsmap.isEmpty() ) {
+                //if types should go into namespaces that are mapped against the package
name for the type
+                if ( pkg2nsmap.get(packageName) != null ) {
+                    //return that mapping
+                    return (String)pkg2nsmap.get(packageName);
+                } else {
+                    //return the wsdl types schema namespace as a default
+                    return nsGen.schemaNamespaceFromPackageName(packageName).toString();
+                }
+            } else {
+                return nsGen.schemaNamespaceFromPackageName(packageName).toString();
+            }
+        }
+    }
+
+    public boolean isUseWSDLTypesNamespace() {
+        return useWSDLTypesNamespace;
+    }
+
+    public void setUseWSDLTypesNamespace(boolean useWSDLTypesNamespace) {
+        this.useWSDLTypesNamespace = useWSDLTypesNamespace;
+    }
+
+    public String getNsGenClassName() {
+        return nsGenClassName;
+    }
+
+    public void setNsGenClassName(String nsGenClassName) throws Exception {
+        this.nsGenClassName = nsGenClassName;
+        if ( this.nsGenClassName != null ){
+            setNsGen((NamespaceGenerator)Class.forName(this.nsGenClassName).newInstance());
+        }
+    }
+
+    public Map getPkg2nsmap() {
+        return pkg2nsmap;
+    }
+
+    public void setPkg2nsmap(Map pkg2nsmap) {
+        this.pkg2nsmap = pkg2nsmap;
+    }
+    
 
 }

Modified: webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/utils/Java2WSDLOptionsValidator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/utils/Java2WSDLOptionsValidator.java?view=diff&rev=463395&r1=463394&r2=463395
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/utils/Java2WSDLOptionsValidator.java
(original)
+++ webservices/axis2/branches/java/1_1/modules/java2wsdl/src/org/apache/ws/java2wsdl/utils/Java2WSDLOptionsValidator.java
Thu Oct 12 12:49:54 2006
@@ -1,63 +1,67 @@
-package org.apache.ws.java2wsdl.utils;
-
-import org.apache.ws.java2wsdl.Java2WSDLConstants;
-/*
-* Copyright 2004,2005 The Apache Software Foundation.
-*
-* Licensed 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.
-*
-*/
-
-public class Java2WSDLOptionsValidator implements Java2WSDLConstants {
-    public boolean isInvalid(Java2WSDLCommandLineOption option) {
-        boolean invalid;
-        String optionType = option.getOptionType();
-
-        invalid = !((Java2WSDLConstants.CLASSNAME_OPTION).equalsIgnoreCase(optionType) ||
-                Java2WSDLConstants.OUTPUT_LOCATION_OPTION.equalsIgnoreCase(optionType) ||
-                Java2WSDLConstants.OUTPUT_FILENAME_OPTION.equalsIgnoreCase(optionType) ||
-                Java2WSDLConstants.CLASSPATH_OPTION.equalsIgnoreCase(optionType) ||
-                Java2WSDLConstants.TARGET_NAMESPACE_OPTION.equalsIgnoreCase(optionType) ||
-                Java2WSDLConstants.TARGET_NAMESPACE_PREFIX_OPTION.equalsIgnoreCase(optionType)
||
-                Java2WSDLConstants.SCHEMA_TARGET_NAMESPACE_OPTION.equalsIgnoreCase(optionType)
||
-                Java2WSDLConstants.SCHEMA_TARGET_NAMESPACE_PREFIX_OPTION.equalsIgnoreCase(optionType)
||
-                Java2WSDLConstants.SERVICE_NAME_OPTION.equalsIgnoreCase(optionType) ||
-                Java2WSDLConstants.STYLE_OPTION.equalsIgnoreCase(optionType) ||
-                Java2WSDLConstants.USE_OPTION.equalsIgnoreCase(optionType) ||
-                Java2WSDLConstants.LOCATION_OPTION.equalsIgnoreCase(optionType) ||
-                Java2WSDLConstants.ATTR_FORM_DEFAULT_OPTION.equalsIgnoreCase(optionType)
||
-                Java2WSDLConstants.ELEMENT_FORM_DEFAULT_OPTION.equalsIgnoreCase(optionType)
||
-                Java2WSDLConstants.ATTR_FORM_DEFAULT_OPTION_LONG.equalsIgnoreCase(optionType)
||
-                Java2WSDLConstants.ELEMENT_FORM_DEFAULT_OPTION_LONG.equalsIgnoreCase(optionType)
||
-                Java2WSDLConstants.ELEMENT_FORM_DEFAULT_OPTION.equalsIgnoreCase(optionType)
||
-                Java2WSDLConstants.EXTRA_CLASSES_DEFAULT_OPTION_LONG.equalsIgnoreCase(optionType)
||
-                Java2WSDLConstants.EXTRA_CLASSES_DEFAULT_OPTION.equalsIgnoreCase(optionType)
||
-
-                Java2WSDLConstants.CLASSNAME_OPTION_LONG.equalsIgnoreCase(optionType) ||
-                Java2WSDLConstants.OUTPUT_FILENAME_OPTION_LONG.equalsIgnoreCase(optionType)
||
-                Java2WSDLConstants.OUTPUT_LOCATION_OPTION_LONG.equalsIgnoreCase(optionType)
||
-                Java2WSDLConstants.CLASSNAME_OPTION_LONG.equalsIgnoreCase(optionType) ||
-                Java2WSDLConstants.CLASSPATH_OPTION_LONG.equalsIgnoreCase(optionType) ||
-                Java2WSDLConstants.TARGET_NAMESPACE_OPTION_LONG.equalsIgnoreCase(optionType)
||
-                Java2WSDLConstants.TARGET_NAMESPACE_PREFIX_OPTION_LONG.equalsIgnoreCase(optionType)
||
-                Java2WSDLConstants.SCHEMA_TARGET_NAMESPACE_OPTION_LONG.equalsIgnoreCase(optionType)
||
-                Java2WSDLConstants.SCHEMA_TARGET_NAMESPACE_PREFIX_OPTION_LONG.equalsIgnoreCase(optionType)
||
-                Java2WSDLConstants.SERVICE_NAME_OPTION_LONG.equalsIgnoreCase(optionType)||
-                Java2WSDLConstants.STYLE_OPTION_LONG.equalsIgnoreCase(optionType)||
-                Java2WSDLConstants.USE_OPTION_LONG.equalsIgnoreCase(optionType)||
-                Java2WSDLConstants.LOCATION_OPTION_LONG.equalsIgnoreCase(optionType));
-
-
-        return invalid;
-    }
-}
+package org.apache.ws.java2wsdl.utils;
+
+import org.apache.ws.java2wsdl.Java2WSDLConstants;
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.
+*
+*/
+
+public class Java2WSDLOptionsValidator implements Java2WSDLConstants {
+    public boolean isInvalid(Java2WSDLCommandLineOption option) {
+        boolean invalid;
+        String optionType = option.getOptionType();
+
+        invalid = !((Java2WSDLConstants.CLASSNAME_OPTION).equalsIgnoreCase(optionType) ||
+                Java2WSDLConstants.OUTPUT_LOCATION_OPTION.equalsIgnoreCase(optionType) ||
+                Java2WSDLConstants.OUTPUT_FILENAME_OPTION.equalsIgnoreCase(optionType) ||
+                Java2WSDLConstants.CLASSPATH_OPTION.equalsIgnoreCase(optionType) ||
+                Java2WSDLConstants.TARGET_NAMESPACE_OPTION.equalsIgnoreCase(optionType) ||
+                Java2WSDLConstants.TARGET_NAMESPACE_PREFIX_OPTION.equalsIgnoreCase(optionType)
||
+                Java2WSDLConstants.SCHEMA_TARGET_NAMESPACE_OPTION.equalsIgnoreCase(optionType)
||
+                Java2WSDLConstants.SCHEMA_TARGET_NAMESPACE_PREFIX_OPTION.equalsIgnoreCase(optionType)
||
+                Java2WSDLConstants.SERVICE_NAME_OPTION.equalsIgnoreCase(optionType) ||
+                Java2WSDLConstants.STYLE_OPTION.equalsIgnoreCase(optionType) ||
+                Java2WSDLConstants.USE_OPTION.equalsIgnoreCase(optionType) ||
+                Java2WSDLConstants.LOCATION_OPTION.equalsIgnoreCase(optionType) ||
+                Java2WSDLConstants.ATTR_FORM_DEFAULT_OPTION.equalsIgnoreCase(optionType)
||
+                Java2WSDLConstants.ELEMENT_FORM_DEFAULT_OPTION.equalsIgnoreCase(optionType)
||
+                Java2WSDLConstants.ATTR_FORM_DEFAULT_OPTION_LONG.equalsIgnoreCase(optionType)
||
+                Java2WSDLConstants.ELEMENT_FORM_DEFAULT_OPTION_LONG.equalsIgnoreCase(optionType)
||
+                Java2WSDLConstants.ELEMENT_FORM_DEFAULT_OPTION.equalsIgnoreCase(optionType)
||
+                Java2WSDLConstants.EXTRA_CLASSES_DEFAULT_OPTION_LONG.equalsIgnoreCase(optionType)
||
+                Java2WSDLConstants.EXTRA_CLASSES_DEFAULT_OPTION.equalsIgnoreCase(optionType)
||
+                Java2WSDLConstants.NAMESPACE_GENERATOR_OPTION.equalsIgnoreCase(optionType)
||
+                Java2WSDLConstants.NAMESPACE_GENERATOR_OPTION_LONG.equalsIgnoreCase(optionType)
||
+                Java2WSDLConstants.JAVA_PKG_2_NSMAP_OPTION.equalsIgnoreCase(optionType) ||
+                Java2WSDLConstants.JAVA_PKG_2_NSMAP_OPTION_LONG.equalsIgnoreCase(optionType)
||
+
+                Java2WSDLConstants.CLASSNAME_OPTION_LONG.equalsIgnoreCase(optionType) ||
+                Java2WSDLConstants.OUTPUT_FILENAME_OPTION_LONG.equalsIgnoreCase(optionType)
||
+                Java2WSDLConstants.OUTPUT_LOCATION_OPTION_LONG.equalsIgnoreCase(optionType)
||
+                Java2WSDLConstants.CLASSNAME_OPTION_LONG.equalsIgnoreCase(optionType) ||
+                Java2WSDLConstants.CLASSPATH_OPTION_LONG.equalsIgnoreCase(optionType) ||
+                Java2WSDLConstants.TARGET_NAMESPACE_OPTION_LONG.equalsIgnoreCase(optionType)
||
+                Java2WSDLConstants.TARGET_NAMESPACE_PREFIX_OPTION_LONG.equalsIgnoreCase(optionType)
||
+                Java2WSDLConstants.SCHEMA_TARGET_NAMESPACE_OPTION_LONG.equalsIgnoreCase(optionType)
||
+                Java2WSDLConstants.SCHEMA_TARGET_NAMESPACE_PREFIX_OPTION_LONG.equalsIgnoreCase(optionType)
||
+                Java2WSDLConstants.SERVICE_NAME_OPTION_LONG.equalsIgnoreCase(optionType)||
+                Java2WSDLConstants.STYLE_OPTION_LONG.equalsIgnoreCase(optionType)||
+                Java2WSDLConstants.USE_OPTION_LONG.equalsIgnoreCase(optionType)||
+                Java2WSDLConstants.LOCATION_OPTION_LONG.equalsIgnoreCase(optionType));
+
+
+        return invalid;
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org


Mime
View raw message