You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by na...@apache.org on 2006/07/25 03:58:24 UTC

svn commit: r425253 - in /webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws: WSDL2Ws.java c/literal/ClientStubHeaderWriter.java info/Type.java

Author: nadiramra
Date: Mon Jul 24 18:58:23 2006
New Revision: 425253

URL: http://svn.apache.org/viewvc?rev=425253&view=rev
Log:
AXISCPP-864 and AXISCPP-862 - nested anonymous types not exposed, causing problems described
in the jira's.

Modified:
    webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/WSDL2Ws.java
    webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/c/literal/ClientStubHeaderWriter.java
    webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/info/Type.java

Modified: webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/WSDL2Ws.java
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/WSDL2Ws.java?rev=425253&r1=425252&r2=425253&view=diff
==============================================================================
--- webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/WSDL2Ws.java (original)
+++ webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/WSDL2Ws.java Mon Jul 24 18:58:23 2006
@@ -23,6 +23,8 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Vector;
+import java.util.Enumeration;
+import java.util.Hashtable;
 
 import javax.wsdl.Binding;
 import javax.wsdl.Fault;
@@ -788,16 +790,11 @@
             }            
             
             typedata = new Type(newqn, newqn.getLocalPart(), true, targetLanguage);
- 
-            if (WSDL2Ws.verbose)
-                System.out.println("Created new array type from array ref: " + newqn);
             
             if (type.getRefType().getRefType() != null)
                 typedata.setElementType(type.getRefType().getRefType().getQName().getLocalPart());
             else
                 typedata.setElementType(type.getRefType().getQName().getLocalPart());     
-
-            typeMap.addType(newqn, typedata);
         }
         else
         {
@@ -811,17 +808,16 @@
                 return typedata;
             }
             
-            typedata = new Type(type.getQName(),
-                                type.getQName().getLocalPart(),
-                                true,
-                                targetLanguage);
-
-            if (WSDL2Ws.verbose)
-                System.out.println("Created new type: " + type.getQName());
-            
-            typeMap.addType(type.getQName(), typedata);
+            typedata = 
+                new Type(type.getQName(), type.getQName().getLocalPart(), true, targetLanguage);
         }
         
+        // Add type to type map
+        if (WSDL2Ws.verbose)
+            System.out.println("Created new type: " + typedata.getName());
+        
+        typeMap.addType(typedata.getName(), typedata);
+        
         // work out whether this type will be generated or not 
         typedata.externalize(isTypeGenerated(type, typedata));
 
@@ -837,6 +833,7 @@
                 String localpart = type.getQName().getLocalPart() + "_value";
                 QName typeName =  new QName(type.getQName().getNamespaceURI(), localpart);
                 newSecondaryType = createTypeInfo(base.getQName(), targetLanguage);
+                typedata.addRelatedType(newSecondaryType);
                 ElementInfo eleinfo = new ElementInfo(typeName, newSecondaryType);
                 typedata.setExtensionBaseType(eleinfo);
                 if (WSDL2Ws.verbose)
@@ -860,6 +857,7 @@
                 for (int j = 0; j < attributes.size(); j += 2)
                 {
                     newSecondaryType = createTypeInfo(((TypeEntry) attributes.get(j)).getQName(), targetLanguage);
+                    typedata.addRelatedType(newSecondaryType);
                     typedata.setTypeForAttributeName(
                         ((QName) attributes.get(j + 1)).getLocalPart(), newSecondaryType);
                 }
@@ -867,6 +865,7 @@
         else if (type instanceof CollectionType)
         {
             newSecondaryType = createTypeInfo(type.getRefType().getQName(),targetLanguage);
+            typedata.addRelatedType(newSecondaryType);
             typedata.setTypeNameForElementName(new ElementInfo(type.getQName(),newSecondaryType));
             typedata.setArray(true);
         }
@@ -877,12 +876,14 @@
             if (arrayType != null)
             {
                 newSecondaryType = createTypeInfo(arrayType, targetLanguage);
+                typedata.addRelatedType(newSecondaryType);
                 typedata.setTypeNameForElementName(new ElementInfo(new QName("item"), newSecondaryType));
                 typedata.setArray(true);
             }
             else if ((arrayType = CSchemaUtils.getCollectionComponentQName(node)) != null)
             {
                 newSecondaryType = createTypeInfo(arrayType, targetLanguage);
+                typedata.addRelatedType(newSecondaryType);
                 typedata.setTypeNameForElementName(new ElementInfo(new QName("item"), newSecondaryType));
                 typedata.setArray(true);
             }
@@ -930,6 +931,7 @@
                         {
                             newSecondaryType = createTypeInfo(((TypeEntry) attributes.get(j)).getQName(),
                                                               targetLanguage);
+                            typedata.addRelatedType(newSecondaryType);
                             typedata.setTypeForAttributeName(((QName) attributes.get(j + 1)).getLocalPart(), 
                                                              newSecondaryType);
                         }
@@ -974,6 +976,7 @@
                                     newSecondaryType = createTypeInfo(typeName, targetLanguage);
                             }
                             
+                            typedata.addRelatedType(newSecondaryType);
                             eleinfo = new ElementInfo(elem.getName(), newSecondaryType);
                             
                             eleinfo.setMinOccurs(elem.getMinOccurs());
@@ -1102,13 +1105,11 @@
                             {
                                 if(WSDL2Ws.verbose)
                                     System.out.println( "EXPOSE1: Exposing ref-type "+referencedType.getQName());
-                                
+
                                 Type innerClassType = wsContext.getTypemap().getType(referencedType.getQName());
-                                innerClassType.setLanguageSpecificName(new QName(defType.getQName().getLocalPart()).toString());
                                 
-                                // also have to set the QName becuase this is used in generating the header info.
-                                innerClassType.setName(new QName(innerClassType.getName().getNamespaceURI(), innerClassType.getLanguageSpecificName()));
-                                innerClassType.externalize(true);
+                                String newLocalPart =  new QName(defType.getQName().getLocalPart()).toString();
+                                innerClassType.externalize(new QName(innerClassType.getName().getNamespaceURI(), newLocalPart));
                             }
                         }
                     }
@@ -1121,9 +1122,6 @@
     /**
      * This method attempts to find anonymous types in the parameter list of 
      * web-service methods to determine if the type should be exposed.
-     * TODO: Current problem that needs to be fixed is when an anonymous type is 
-     *       encountered, we do not check for nested types within the anonymous type
-     *       in order to expose those types.
      * @param wsContext
      */
     private void exposeMessagePartsThatAreAnonymousTypes(WebServiceContext wsContext)
@@ -1166,15 +1164,10 @@
                                   Type innerClassType =  wsContext.getTypemap().getType(oldName);
                                   if (innerClassType != null && !innerClassType.isExternalized())
                                   {
-                                      String newLocalPart = parameterType.getLanguageSpecificName();
-                                      QName newTypeName   =  new QName(parameterType.getName().getNamespaceURI(), newLocalPart);
-                                      
-                                      // First thing to do is to expose the type so it gets created.
-                                      innerClassType.setLanguageSpecificName(newLocalPart);
-                                      
-                                      // also have to set the QName since it used in generating the header info.
-                                      innerClassType.setName(newTypeName);
-                                      innerClassType.externalize(true);
+                                      QName newTypeName   =  new QName(parameterType.getName().getNamespaceURI(), 
+                                                                       parameterType.getLanguageSpecificName());
+
+                                      innerClassType.externalize(newTypeName);
                                       
                                       // Update the typemap with new info
                                       wsContext.getTypemap().removeType(oldName);
@@ -1199,16 +1192,11 @@
                                   Type innerClassType =  wsContext.getTypemap().getType(oldName);
                                   if (innerClassType != null && !innerClassType.isExternalized())
                                   {
-                                      String newLocalPart =  parameterType.getLanguageSpecificName();
-                                      QName newTypeName   =  new QName(parameterType.getName().getNamespaceURI(), newLocalPart);
-                                      
-                                      // First thing to do is to expose the type so it gets created.
-                                      innerClassType.setLanguageSpecificName(newLocalPart);
-                                      
-                                      // also have to set the QName since it used in generating the header info.
-                                      innerClassType.setName(newTypeName);
-                                      innerClassType.externalize(true);
-                                      
+                                      QName newTypeName   =  new QName(parameterType.getName().getNamespaceURI(), 
+                                                                       parameterType.getLanguageSpecificName());
+
+                                      innerClassType.externalize(newTypeName);
+
                                       // Update the typemap with new info
                                       wsContext.getTypemap().removeType(oldName);
                                       wsContext.getTypemap().addType(newTypeName, innerClassType);
@@ -1220,71 +1208,90 @@
             }
         }
     }
+    
+    private void exposeRelatedTypes(TypeMap theOrigMap, Type theType, Hashtable nameMapper)
+    {
+        QName oldName = theType.getName();                              
+        Type classType =  theOrigMap.getType(oldName);
+        if (classType != null && !classType.isExternalized())
+        {
+            if(WSDL2Ws.verbose)
+                System.out.println("\nEXPOSE4: Externalizing type " + oldName);
+            
+            // Externalize the type - if anonymous we have to change to name
+            if (classType.isAnonymous())
+            {
+                QName newName   =  new QName(oldName.getNamespaceURI(), 
+                                             classType.getLanguageSpecificName());
+    
+                classType.externalize(newName);
+                
+                // add old name to new name mapping to name mapper hash table
+                nameMapper.put(oldName, newName);
+            }
+            else
+                classType.externalize(true);
 
+            // Now check to see related types of this type - recursively.
+            Iterator relatedTypesIt = theType.getRelatedTypes();
+            Type relatedType;
+            while (relatedTypesIt.hasNext())
+            {
+                relatedType = (Type) relatedTypesIt.next();
+                if (!relatedType.isExternalized())
+                    exposeRelatedTypes(theOrigMap, relatedType, nameMapper);
+            }            
+        }
+    }
+    
     /**
      * @param wsContext
      */
     private void exposeNestedTypesThatAreAnonymousTypes(WebServiceContext wsContext)
     {
-        // get the main types
-        Collection types = symbolTable.getTypeIndex().values();
-        Iterator typeIterator = types.iterator();   
-        while(typeIterator.hasNext())
+        // Go through the externalized types in the typemap and externalize the 
+        // related types used by each externalized type. In order to complete the externalization,
+        // we need to remove the entry from the typemap and replace it with a new name.  
+        // However, this will have to be done after we have iterated through the typemap since
+        // updating the typemap as we iterate through it will result in an exception.
+        // So we have a hash table to map old names to new names for those types that have been 
+        // externalized.
+        Hashtable nameMapper = new Hashtable();
+        Iterator typesIt = wsContext.getTypemap().getTypes().iterator();
+        Type type;
+        while (typesIt.hasNext())
         {
-            Object highLevelType = typeIterator.next();
-            if(!(highLevelType instanceof BaseType))
+            type = (Type) typesIt.next();
+            if (type.isExternalized())
             {
-                DefinedType type = (DefinedType)highLevelType;
-                if(!type.getQName().getLocalPart().toString().startsWith(">"))
+                if(WSDL2Ws.verbose)
+                    System.out.println("\nEXPOSE3: Checking related types for type " + type.getName());
+                
+                Iterator relatedTypesIt = type.getRelatedTypes();
+                Type relatedType;
+                while (relatedTypesIt.hasNext())
                 {
-                    if(WSDL2Ws.verbose)
-                        System.out.println( "EXPOSE3: Checking for nested anon types for "+type.getQName().getLocalPart());
-                        
-                    HashSet nestedTypes = type.getNestedTypes(symbolTable, true);
-                    Iterator iterator = nestedTypes.iterator();
-                    while(iterator.hasNext())
-                    {
-                        Object nestedObjectType = iterator.next();
-                        if(nestedObjectType instanceof DefinedType)
-                        {
-                            // If the nested parts are complex inner/anonymous types then they need to 
-                            // be exposed as seperate classes
-                            
-                            DefinedType nestedType =(DefinedType) nestedObjectType; 
-                            String name =nestedType.getQName().getLocalPart().toString(); 
-
-                            if(WSDL2Ws.verbose)
-                               System.out.println( "EXPOSE3: Checking whether to expose nested type "+ nestedType.getQName());
-                                
-                            if(name.startsWith(">") && name.lastIndexOf(">")>0)
-                            {     
-                              if(WSDL2Ws.verbose)
-                                  System.out.println( "EXPOSE3: Exposing nestedType "+nestedType.getQName());
- 
-                              QName oldName = nestedType.getQName();                              
-                              Type innerClassType =  wsContext.getTypemap().getType(oldName);
-                              if (innerClassType != null && !innerClassType.isExternalized())
-                              {
-                                  String newLocalPart =  innerClassType.getLanguageSpecificName();
-                                  QName newTypeName   =  new QName(oldName.getNamespaceURI(), newLocalPart);
-                                  
-                                  // First thing to do is to expose the type so it gets created.
-                                  innerClassType.setLanguageSpecificName(newLocalPart);
-                                  
-                                  // also have to set the QName since it used in generating the header info.
-                                  innerClassType.setName(newTypeName);
-                                  innerClassType.externalize(true);
-                                  
-                                  // Update the typemap with new info
-                                  wsContext.getTypemap().removeType(oldName);
-                                  wsContext.getTypemap().addType(newTypeName, innerClassType);
-                              }
-                            }
-                        }
-                    }
+                    relatedType = (Type) relatedTypesIt.next();
+                    if (!relatedType.isExternalized())
+                        exposeRelatedTypes(wsContext.getTypemap(), relatedType, nameMapper);
                 }
-                else if(WSDL2Ws.verbose)
-                    System.out.println( "EXPOSE3: Skipping nested types for anon type "+type.getQName().getLocalPart());
+            }              
+        }
+        
+        // Now update the typemap, replacing old names with new names, using the hash table that
+        // maps old names to new names.
+        QName oldName;
+        QName newName;
+        
+        for (Enumeration e = nameMapper.keys(); e.hasMoreElements() ;)
+        {
+            oldName = (QName) e.nextElement();
+            newName = (QName) nameMapper.get(oldName);
+            type    = wsContext.getTypemap().getType(oldName);
+            if (type != null)
+            {
+                wsContext.getTypemap().removeType(oldName);
+                wsContext.getTypemap().addType(newName, type);                
             }
         }
     }

Modified: webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/c/literal/ClientStubHeaderWriter.java
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/c/literal/ClientStubHeaderWriter.java?rev=425253&r1=425252&r2=425253&view=diff
==============================================================================
--- webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/c/literal/ClientStubHeaderWriter.java (original)
+++ webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/c/literal/ClientStubHeaderWriter.java Mon Jul 24 18:58:23 2006
@@ -22,6 +22,7 @@
 package org.apache.axis.wsdl.wsdl2ws.c.literal;
 import java.io.IOException;
 import java.util.Iterator;
+import java.util.HashSet;
 import java.util.Vector;
 
 import org.apache.axis.wsdl.wsdl2ws.CUtils;
@@ -201,16 +202,30 @@
             Type atype;
             Iterator types = this.wscontext.getTypemap().getTypes().iterator();
             Vector typeSet = new Vector();
+            HashSet removeSet = new HashSet();
+
             while (types.hasNext())
             {
                 atype = (Type) types.next();
-                if (atype.isAnonymous() && !atype.isExternalized())
+                
+                if (!atype.isExternalized())
                     continue;
-                if (!atype.isArray())
-                    typeSet.insertElementAt(atype.getLanguageSpecificName(), 0);
-                else
-                    typeSet.add(atype.getLanguageSpecificName());
+
+                if (atype.isArray())
+                    if (atype.getElementType().equals("string"))
+                        removeSet.add(atype.getLanguageSpecificName());
+                
+                if (atype.getBaseType() != null)
+                    if (atype.getBaseType().getLocalPart().equals("string"))
+                        removeSet.add(atype.getLanguageSpecificName() + "_Array");
+
+                typeSet.add(atype.getLanguageSpecificName());
             }
+            
+            Iterator ritr = removeSet.iterator();
+            while (ritr.hasNext())
+                typeSet.remove(ritr.next());
+            
             Iterator itr = typeSet.iterator();
             while (itr.hasNext())
             {

Modified: webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/info/Type.java
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/info/Type.java?rev=425253&r1=425252&r2=425253&view=diff
==============================================================================
--- webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/info/Type.java (original)
+++ webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/info/Type.java Mon Jul 24 18:58:23 2006
@@ -109,6 +109,12 @@
     /* Is anonymous type? qname.localname is checked, and if starts with '>', then true */
     private boolean isAnonymous = false;
 
+    /* This vector was added in order to ensure that when a type is externalized, its 
+     * related types (types that are directly or indirectly referenced within this type) 
+     * are also externalized. 
+     */
+    private Vector vRelatedTypes = new Vector();
+    
     public Type(QName name, String languageSpecificName, boolean hasOrder, String language)
     {
         this.languageSpecificName = languageSpecificName;
@@ -492,5 +498,33 @@
     public void externalize(boolean flag)
     {           
         externalize = flag;
+    }  
+
+    /**
+     * Externalize type - changing qname and use localPart of qname as 
+     * platform specific language name.
+     */
+    public void externalize(QName newQName)
+    {           
+        externalize(true);
+        setName(newQName);
+        setLanguageSpecificName(newQName.getLocalPart());
+    }     
+    
+    /**
+     * Return iterator for vector of related non-simple types.
+     */
+    public Iterator getRelatedTypes()
+    {
+        return this.vRelatedTypes.iterator();
+    }  
+    
+    /*
+     * Add to vector a Type that is related that is non-simple.
+     */
+    public void addRelatedType(Type type)
+    {
+        if (type != null && !TypeMap.isSimpleType(type.getName()))
+            this.vRelatedTypes.add(type);
     }    
 }



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