Author: nadiramra
Date: Fri Jul  7 13:29:04 2006
New Revision: 419971

URL: http://svn.apache.org/viewvc?rev=419971&view=rev
Log:
Stage 1: Infrastructure to handle generation of unique names in order to better 
handle the
generation of anonymous type - i.e. the generation of names that do not include 
the parent. 
Basically instead of generation __Type1_Ident type, we would simply generate 
Ident type.
The code in this commit has a routine that ensures names are unique. 

Modified:
    webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/CUtils.java

Modified: 
webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/CUtils.java
URL: 
http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/CUtils.java?rev=419971&r1=419970&r2=419971&view=diff
==============================================================================
--- webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/CUtils.java 
(original)
+++ webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/CUtils.java 
Fri Jul  7 13:29:04 2006
@@ -78,6 +78,9 @@
     private static Hashtable isPointerBasedType = new Hashtable();
     private static boolean cpp = true;
     
+    private static Hashtable uniqueNameMapper = new Hashtable();
+    private static Vector uniqueNamesGenerated = new Vector();
+    
     static{        
         class2QNamemapCpp.put("xsd__duration",                new 
QName(WrapperConstants.SCHEMA_NAMESPACE, "duration"));
         class2QNamemapCpp.put("xsd__dateTime",                new 
QName(WrapperConstants.SCHEMA_NAMESPACE, "dateTime"));
@@ -1071,5 +1074,51 @@
         
         return sanitisedName;
     }
+
+    /**
+     * This routine is used to basically handle anonymous type naming.  
Anonymous types
+     * have names such as '>type' and '>>type>type2', the latter being a 
nested type. 
+     * When generating classes, we want to use the simplist name, which is the 
name after
+     * the last '>' character. This routine ensure the uniqueness of the name 
returned by
+     * keeping a hash table of mapped names and a vector of generated unique 
names.
+     */
+    public static String getUniqueName(String oldName)
+    {
+        // Should never happen, but just in case.
+        if (oldName == null)
+            return oldName;
+        
+        // If name already in hash table, return the corresponding name
+        String newName = (String)uniqueNameMapper.get(oldName);
+        
+        // If name was not in hash table, generate one, store in hash table.
+        if (newName == null)
+        {
+            newName = oldName;
+            
+            // get name after last '>'
+            int anonCharIndex = oldName.lastIndexOf(SymbolTable.ANON_TOKEN);
+            if (anonCharIndex != -1)
+                newName = oldName.substring(anonCharIndex+1);
+            
+            // Ensure invalid characters are replaced
+            for( int i=0; i < Array.getLength(invalidCChars); i++)
+                newName = newName.replace((char)invalidCChars[i], '_');        
     
+            
+            // Ensure name does not conflict with language constructs
+            newName = TypeMap.resolveWSDL2LanguageNameClashes(newName, 
WrapperConstants.LANGUAGE_CPP);
+            
+            // Ensure uniqueness
+            int suffix = 2;            
+            while (uniqueNamesGenerated.contains(newName))
+                newName = newName + Integer.toString(suffix++);
+            
+            // Put newname in hash tables
+            uniqueNameMapper.put(oldName, newName);
+            uniqueNamesGenerated.add(newName);
         }
+
+        return newName;
+    }
+}
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to