ws-axis-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r360507 - in /webservices/axis2/trunk/java/modules: codegen/src/org/apache/axis2/schema/writer/ codegen/src/org/apache/axis2/wsdl/codegen/emitter/ common/src/org/apache/axis2/util/
Date Sun, 01 Jan 2006 18:13:54 GMT
Author: dims
Date: Sun Jan  1 10:13:49 2006
New Revision: 360507

URL: http://svn.apache.org/viewcvs?rev=360507&view=rev
Log:
clean up class name generation


Modified:
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/MultiLanguageClientEmitter.java
    webservices/axis2/trunk/java/modules/common/src/org/apache/axis2/util/JavaUtils.java

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java?rev=360507&r1=360506&r2=360507&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java
(original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java
Sun Jan  1 10:13:49 2006
@@ -233,7 +233,7 @@
                 this.packageName + nameSpaceFromURL;
 
         String originalName = qName.getLocalPart();
-        String className = getNonConflictingName(this.namesList, originalName);
+        String className = makeUniqueJavaClassName(this.namesList, originalName);
 
         String packagePrefix = null;
 
@@ -344,14 +344,7 @@
             String xmlName = name.getLocalPart();
             XSLTUtils.addAttribute(model, "name", xmlName, property);
 
-            String javaName;
-            if (JavaUtils.isJavaKeyword(xmlName)) {
-                javaName = JavaUtils.makeNonJavaKeyword(xmlName);
-            } else {
-                javaName = JavaUtils.xmlNameToJava(xmlName, false);
-            }
-
-            javaName = getNonConflictingName(propertyNames, javaName);
+            String javaName = makeUniqueJavaClassName(propertyNames, xmlName);
             XSLTUtils.addAttribute(model, "name", xmlName, property);
             XSLTUtils.addAttribute(model, "javaname", javaName, property);
             String javaClassNameForElement = metainf.getClassNameForQName(name);
@@ -412,26 +405,27 @@
 
 
     /**
-     * gets a non conflicting java name
-     * the comparison with existing classnames need to be
-     * case insensitive, since certain file systems (specifaically
-     * the windows file system) has case insensitive file names)
+     * Given the xml name, make a unique class name taking into account that some
+     * file systems are case sensitive and some are not.
      *
      * @param listOfNames
-     * @param nameBase
+     * @param xmlName
      * @return
      */
-    private String getNonConflictingName(List listOfNames, String nameBase) {
-        String nameToReturn = nameBase;
-        if (JavaUtils.isJavaKeyword(nameToReturn)) {
-            nameToReturn = JavaUtils.makeNonJavaKeyword(nameToReturn);
+    private String makeUniqueJavaClassName(List listOfNames, String xmlName) {
+        String javaName;
+        if (JavaUtils.isJavaKeyword(xmlName)) {
+            javaName = JavaUtils.makeNonJavaKeyword(xmlName);
+        } else {
+            javaName = JavaUtils.capitalizeFirstChar(JavaUtils.xmlNameToJava(xmlName));
         }
-        while (listOfNames.contains(nameToReturn.toLowerCase())) {
-            nameToReturn = nameToReturn + count++;
+
+        while (listOfNames.contains(javaName.toLowerCase())) {
+            javaName = javaName + count++;
         }
 
-        listOfNames.add(nameToReturn.toLowerCase());
-        return nameToReturn;
+        listOfNames.add(javaName.toLowerCase());
+        return javaName;
     }
 
 

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/MultiLanguageClientEmitter.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/MultiLanguageClientEmitter.java?rev=360507&r1=360506&r2=360507&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/MultiLanguageClientEmitter.java
(original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/MultiLanguageClientEmitter.java
Sun Jan  1 10:13:49 2006
@@ -340,14 +340,14 @@
 
     private void updateMapperForStub(WSDLInterface boundInterface){
         String packageName = configuration.getPackageName();
-        String localPart = reformatName(boundInterface.getName().getLocalPart(), false);
+        String localPart = makeJavaClassName(boundInterface.getName().getLocalPart());
         String stubName = localPart + STUB_SUFFIX;
         updateMapperClassnames(boundInterface,packageName + "." + stubName + ".");
     }
 
     private void updateMapperForMessageReceiver(WSDLInterface boundInterface){
         String packageName = configuration.getPackageName();
-        String localPart = reformatName(boundInterface.getName().getLocalPart(), false);
+        String localPart = makeJavaClassName(boundInterface.getName().getLocalPart());
         String stubName = localPart + MESSAGE_RECEIVER_SUFFIX;
         updateMapperClassnames(boundInterface,packageName + "." + stubName + ".");
     }
@@ -576,7 +576,7 @@
                 rootElement);
         addAttribute(doc,
                 "name",
-                reformatName(boundInterface.getName().getLocalPart(), false) +
+                makeJavaClassName(boundInterface.getName().getLocalPart()) +
                         CALL_BACK_HANDLER_SUFFIX,
                 rootElement);
         addAttribute(doc,
@@ -737,7 +737,7 @@
 
         Document doc = getEmptyDocument();
         Element rootElement = doc.createElement("interface");
-        String localPart = reformatName(boundInterface.getName().getLocalPart(), false);
+        String localPart = makeJavaClassName(boundInterface.getName().getLocalPart());
         if (forTesting) {
             addAttribute(doc,
                     "package",
@@ -790,7 +790,7 @@
                 "package",
                 configuration.getPackageName(),
                 rootElement);
-        String localPart = reformatName(boundInterface.getName().getLocalPart(), false);
+        String localPart = makeJavaClassName(boundInterface.getName().getLocalPart());
         addAttribute(doc,
                 "name",
                 localPart + MESSAGE_RECEIVER_SUFFIX,
@@ -843,7 +843,7 @@
 
         Document doc = getEmptyDocument();
         Element rootElement = doc.createElement("ant");
-        String localPart = reformatName(wsdlInterface.getName().getLocalPart(), false);
+        String localPart = makeJavaClassName(wsdlInterface.getName().getLocalPart());
         String packageName = configuration.getPackageName();
         String[] dotSeparatedValues = packageName.split("\\.");
         addAttribute(doc,
@@ -870,7 +870,7 @@
 
         Document doc = getEmptyDocument();
         Element rootElement = doc.createElement("interface");
-        String localPart = reformatName(wsdlInterface.getName().getLocalPart(), false);
+        String localPart = makeJavaClassName(wsdlInterface.getName().getLocalPart());
         addAttribute(doc,
                 "package",
                 configuration.getPackageName(),
@@ -904,7 +904,7 @@
 
         Document doc = getEmptyDocument();
         Element rootElement = doc.createElement("interface");
-        String localpart = reformatName(boundInterface.getName().getLocalPart(), false);
+        String localpart = makeJavaClassName(boundInterface.getName().getLocalPart());
         addAttribute(doc,
                 "package",
                 configuration.getPackageName(),
@@ -963,7 +963,7 @@
                                 WSDLBinding binding) {
 
         Collection col = boundInterface.getOperations().values();
-        String portTypeName = reformatName(boundInterface.getName().getLocalPart(), false);
+        String portTypeName = makeJavaClassName(boundInterface.getName().getLocalPart());
 
         Element methodElement;
         WSDLOperation operation;
@@ -975,7 +975,7 @@
 
             operation = (WSDLOperation) iterator.next();
             methodElement = doc.createElement("method");
-            String localPart = reformatName(operation.getName().getLocalPart(), false);
+            String localPart = makeJavaClassName(operation.getName().getLocalPart());
             addAttribute(doc, "name", localPart, methodElement);
             addAttribute(doc,
                     "namespace",
@@ -1055,7 +1055,7 @@
 
     protected Document createDOMDocumentForTestCase(WSDLBinding binding) {
         WSDLInterface boundInterface = binding.getBoundInterface();
-        String localPart = reformatName(boundInterface.getName().getLocalPart(), false);
+        String localPart = makeJavaClassName(boundInterface.getName().getLocalPart());
         Document doc = getEmptyDocument();
         Element rootElement = doc.createElement("class");
         addAttribute(doc,
@@ -1194,7 +1194,7 @@
         WSDLInterface boundInterface = binding.getBoundInterface();
 
         String packageName = configuration.getPackageName();
-        String localPart = reformatName(boundInterface.getName().getLocalPart(), false);
+        String localPart = makeJavaClassName(boundInterface.getName().getLocalPart());
         String stubName = localPart + STUB_SUFFIX;
 
         HashMap endpoints = new HashMap(1);
@@ -1402,19 +1402,11 @@
      * @param word
      * @return character removed string
      */
-    protected String reformatName(String word) {
-        return reformatName(word, true);
-    }
-
-    /**
-     * @param word
-     * @return character removed string
-     */
-    protected String reformatName(String word, boolean decapitalizaFirst) {
+    protected String makeJavaClassName(String word) {
         if (JavaUtils.isJavaKeyword(word)) {
             return JavaUtils.makeNonJavaKeyword(word);
         } else {
-            return JavaUtils.xmlNameToJava(word, decapitalizaFirst);
+            return JavaUtils.capitalizeFirstChar(JavaUtils.xmlNameToJava(word));
         }
     }
 

Modified: webservices/axis2/trunk/java/modules/common/src/org/apache/axis2/util/JavaUtils.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/common/src/org/apache/axis2/util/JavaUtils.java?rev=360507&r1=360506&r2=360507&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/common/src/org/apache/axis2/util/JavaUtils.java (original)
+++ webservices/axis2/trunk/java/modules/common/src/org/apache/axis2/util/JavaUtils.java Sun
Jan  1 10:13:49 2006
@@ -83,10 +83,6 @@
     }
 
     public static String xmlNameToJava(String name) {
-        return xmlNameToJava(name,true);
-    }
-
-    public static String xmlNameToJava(String name,boolean decapitalizeFirst) {
         // protect ourselves from garbage
         if (name == null || name.equals(""))
             return name;
@@ -155,13 +151,6 @@
         // covert back to a String
         String newName = result.toString();
 
-        // Follow JavaBean rules, but we need to check if the first
-        // letter is uppercase first
-        // do the decapitalization only if requested
-        if (decapitalizeFirst){
-            if (Character.isUpperCase(newName.charAt(0)))
-                newName = Introspector.decapitalize(newName);
-        }
         // check for Java keywords
         if (isJavaKeyword(newName))
             newName = makeNonJavaKeyword(newName);
@@ -169,4 +158,26 @@
         return newName;
     } // xmlNameToJava
 
+    /**
+     * Capitalize the first character of the name.
+     *
+     * @param name
+     * @return
+     */
+    public static String capitalizeFirstChar(String name) {
+
+        if ((name == null) || name.equals("")) {
+            return name;
+        }
+
+        char start = name.charAt(0);
+
+        if (Character.isLowerCase(start)) {
+            start = Character.toUpperCase(start);
+
+            return start + name.substring(1);
+        }
+
+        return name;
+    }    // capitalizeFirstChar
 }



Mime
View raw message