You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by di...@apache.org on 2005/06/12 16:54:44 UTC

cvs commit: ws-axis/java/src/org/apache/axis/wsdl/fromJava Types.java

dims        2005/06/12 07:54:44

  Modified:    java/src/org/apache/axis/wsdl/toJava JavaDeployWriter.java
               java/src/org/apache/axis/wsdl/symbolTable SymbolTable.java
               java/src/org/apache/axis/wsdl/fromJava Types.java
  Log:
  Fix for AXIS-1366 - Service re-creates incorrect WSDL
  
  http://issues.apache.org/jira/browse/AXIS-1366
  
  Revision  Changes    Path
  1.98      +33 -3     ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaDeployWriter.java
  
  Index: JavaDeployWriter.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaDeployWriter.java,v
  retrieving revision 1.97
  retrieving revision 1.98
  diff -u -r1.97 -r1.98
  --- JavaDeployWriter.java	24 May 2005 15:51:36 -0000	1.97
  +++ JavaDeployWriter.java	12 Jun 2005 14:54:44 -0000	1.98
  @@ -406,14 +406,44 @@
                   + service.getQName().getNamespaceURI() + "\"/>");
           pw.println("      <parameter name=\"wsdlServiceElement\" value=\""
                   + service.getQName().getLocalPart() + "\"/>");
  -        pw.println("      <parameter name=\"wsdlServicePort\" value=\""
  -                + serviceName + "\"/>");
  -
           // MIME attachments don't work with multiref, so turn it off.
           if (hasMIME) {
               pw.println(
                       "      <parameter name=\"sendMultiRefs\" value=\"false\"/>");
           }
  +        ArrayList qualified = new ArrayList();
  +        ArrayList unqualified = new ArrayList();
  +        Map elementFormDefaults = symbolTable.getElementFormDefaults();
  +        for(Iterator it = elementFormDefaults.entrySet().iterator();it.hasNext();){
  +            Map.Entry entry =  (Map.Entry) it.next();
  +            if(entry.getValue().equals("qualified")){
  +                qualified.add(entry.getKey());
  +            } else {
  +                unqualified.add(entry.getKey());
  +            }
  +        }
  +        if(qualified.size()>0){
  +            pw.print("      <parameter name=\"schemaQualified\" value=\"");
  +            for(int i=0;i<qualified.size();i++){
  +                pw.print(qualified.get(i));
  +                if(i != qualified.size()-1){
  +                    pw.print(',');
  +                }
  +            }
  +            pw.println("\"/>");
  +        }
  +        if(unqualified.size()>0){
  +            pw.print("      <parameter name=\"schemaUnqualified\" value=\"");
  +            for(int i=0;i<unqualified.size();i++){
  +                pw.print(unqualified.get(i));
  +                if(i != unqualified.size()-1){
  +                    pw.print(',');
  +                }
  +            }
  +            pw.println("\"/>");
  +        }
  +        pw.println("      <parameter name=\"wsdlServicePort\" value=\""
  +                + serviceName + "\"/>");
   
           writeDeployBinding(pw, bEntry);
           writeDeployTypes(pw, bEntry.getBinding(), hasLiteral, hasMIME, use);
  
  
  
  1.121     +16 -1     ws-axis/java/src/org/apache/axis/wsdl/symbolTable/SymbolTable.java
  
  Index: SymbolTable.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/symbolTable/SymbolTable.java,v
  retrieving revision 1.120
  retrieving revision 1.121
  diff -u -r1.120 -r1.121
  --- SymbolTable.java	3 Jun 2005 22:23:50 -0000	1.120
  +++ SymbolTable.java	12 Jun 2005 14:54:44 -0000	1.121
  @@ -175,6 +175,8 @@
   
       Set arrayTypeQNames = new HashSet();
   
  +    /** Field elementFormDefaults */
  +    private final Map elementFormDefaults = new HashMap();
       /**
        * Construct a symbol table with the given Namespaces.
        * 
  @@ -1096,6 +1098,15 @@
               if ((localPart != null)
                   && localPart.equals("schema")) {
                   level = SCHEMA_LEVEL;
  +                String targetNamespace = ((org.w3c.dom.Element) node).getAttribute("targetNamespace");
  +                String elementFormDefault = ((org.w3c.dom.Element) node).getAttribute("elementFormDefault");
  +                if (targetNamespace != null && targetNamespace.length() > 0) {
  +                    elementFormDefault = (elementFormDefault == null || elementFormDefault.length() == 0) ?
  +                            "unqualified" : elementFormDefault;
  +                    if(elementFormDefaults.get(targetNamespace)==null) {
  +                        elementFormDefaults.put(targetNamespace, elementFormDefault);
  +                    }
  +                }
               }
           } else {
               ++level;
  @@ -3786,4 +3797,8 @@
       public void setWrapArrays(boolean wrapArrays) {
           this.wrapArrays = wrapArrays;
       }
  -}    // class SymbolTable
  +
  +    public Map getElementFormDefaults() {
  +        return elementFormDefaults;
  +    }
  +}
  
  
  
  1.114     +64 -37    ws-axis/java/src/org/apache/axis/wsdl/fromJava/Types.java
  
  Index: Types.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/fromJava/Types.java,v
  retrieving revision 1.113
  retrieving revision 1.114
  diff -u -r1.113 -r1.114
  --- Types.java	12 Apr 2005 22:18:16 -0000	1.113
  +++ Types.java	12 Jun 2005 14:54:44 -0000	1.114
  @@ -20,6 +20,7 @@
   import org.apache.axis.Constants;
   import org.apache.axis.InternalException;
   import org.apache.axis.MessageContext;
  +import org.apache.axis.handlers.soap.SOAPService;
   import org.apache.axis.components.logger.LogFactory;
   import org.apache.axis.constants.Style;
   import org.apache.axis.description.ServiceDesc;
  @@ -33,6 +34,7 @@
   import org.apache.axis.utils.JavaUtils;
   import org.apache.axis.utils.Messages;
   import org.apache.axis.utils.XMLUtils;
  +import org.apache.axis.utils.StringUtils;
   import org.apache.axis.wsdl.symbolTable.BaseTypeMapping;
   import org.apache.axis.wsdl.symbolTable.SymbolTable;
   import org.apache.axis.wsdl.symbolTable.TypeEntry;
  @@ -116,10 +118,10 @@
   
       /** Keep track of the element QNames we've written to avoid dups */
       private Set writtenElementQNames = new HashSet();
  -    
  +
       /** Which types have we already written? */
       Class [] mappedTypes = null;
  -    
  +
       /** The java to wsdl emitter */
       Emitter emitter = null;
   
  @@ -169,7 +171,7 @@
           this.defaultTM = defaultTM;
   
           mappedTypes = tm.getAllClasses();
  -        
  +
           this.namespaces = namespaces;
           this.targetNamespace = targetNamespace;
           this.stopClasses = stopClasses;
  @@ -190,10 +192,10 @@
        * @param stopClasses
        * @param serviceDesc
        * @param emitter         Java2Wsdl emitter
  -     */    
  +     */
       public Types(Definition def, TypeMapping tm, TypeMapping defaultTM,
  -            Namespaces namespaces, String targetNamespace,
  -            List stopClasses, ServiceDesc serviceDesc, Emitter emitter) {
  +                 Namespaces namespaces, String targetNamespace,
  +                 List stopClasses, ServiceDesc serviceDesc, Emitter emitter) {
           this(def, tm, defaultTM, namespaces, targetNamespace, stopClasses, serviceDesc);
           this.emitter = emitter;
       }
  @@ -393,14 +395,14 @@
           // replicable test data to the Axis team via bugzilla
   
           /*
  -         * if( type==null ) {
  -         *   return null;
  -         * }
  -         */
  +        * if( type==null ) {
  +        *   return null;
  +        * }
  +        */
           if (type.getName().equals("void")) {
               return null;
           }
  -        
  +
           if (Holder.class.isAssignableFrom(type)) {
               type = JavaUtils.getHolderValueType(type);
           }
  @@ -422,7 +424,7 @@
   
           return qname;
       }
  -    
  +
       /**
        * Write out a type (and its subtypes) referenced by a part type attribute.
        *
  @@ -435,39 +437,39 @@
        */
       public QName writeTypeAndSubTypeForPart(Class type, QName qname)
               throws AxisFault {
  -        
  +
           // Write out type in parameter
           QName qNameRet = writeTypeForPart(type, qname);
  -        
  +
           // If mappedTypesexists 
           // Will write subTypes of the type in parameters
           if (mappedTypes != null) {
               for (int i = 0; i < mappedTypes.length; i++) {
                   Class tempMappedType = mappedTypes[i];
                   QName name;
  -                
  +
                   // If tempMappedType is subtype of the "type" parameter
                   // and type is not Object (Object superclass of all Java class...)  
                   // write the subtype
                   if (tempMappedType != null &&
  -                        type != Object.class && 
  +                        type != Object.class &&
                           tempMappedType != type &&
                           type.isAssignableFrom(tempMappedType)) {
                       name = tm.getTypeQName(tempMappedType);
                       if (!isAnonymousType(name)) {
                           writeTypeForPart(tempMappedType, name);
                       }
  -                    
  +
                       // Only do each one once.  This is OK to do because each
                       // Types instance is for generating a single WSDL.
                       mappedTypes[i] = null;
                   }
               }
           } //if (mappedTyped != null) {
  -        
  -        return qNameRet;    
  +
  +        return qNameRet;
       }
  -    
  +
       /**
        * Write out an element referenced by a part element attribute.
        *
  @@ -484,10 +486,10 @@
           // replicable test data to the Axis team via bugzilla
   
           /*
  -         * if( type==null ) {
  -         *   return null;
  -         * }
  -         */
  +        * if( type==null ) {
  +        *   return null;
  +        * }
  +        */
           if (type.getName().equals("void")) {
               return null;
           }
  @@ -733,7 +735,7 @@
           // If the javaType is an array and the qName is
           // SOAP_ARRAY, construct the QName using the
           // QName of the component type
  -        if (isArray(javaType) && 
  +        if (isArray(javaType) &&
                   Constants.equals(Constants.SOAP_ARRAY, qName)) {
               Class componentType = getComponentType(javaType);
   
  @@ -746,7 +748,7 @@
               if (isWSICompliant) {
                   arrayTypePrefix = "MyArrayOf";
               }
  -            
  +
               // If component namespace uri == targetNamespace
               // Construct ArrayOf<componentLocalPart>
               // Else
  @@ -944,7 +946,15 @@
                           Constants.URI_DEFAULT_SOAP_ENC);
               }
   
  -            if ((serviceDesc.getStyle() == Style.DOCUMENT)
  +            SOAPService service = null;
  +            if(MessageContext.getCurrentContext() != null) {
  +                service = MessageContext.getCurrentContext().getService();
  +            }
  +            if(service != null && isPresent((String) service.getOption("schemaQualified"), namespaceURI)){
  +                schemaElem.setAttribute("elementFormDefault", "qualified");
  +            } else if(service != null && isPresent((String) service.getOption("schemaUnqualified"), namespaceURI)){
  +                // DO nothing..default is unqualified.
  +            } else if ((serviceDesc.getStyle() == Style.DOCUMENT)
                       || (serviceDesc.getStyle() == Style.WRAPPED)) {
                   schemaElem.setAttribute("elementFormDefault", "qualified");
               }
  @@ -956,6 +966,23 @@
       }
   
       /**
  +     * check if the namespace is present in the list.
  +     * @param list
  +     * @param namespace
  +     * @return
  +     */
  +    private boolean isPresent(String list, String namespace) {
  +        if(list == null || list.length()==0)
  +                return false;
  +        String[] array = StringUtils.split(list,',');
  +        for(int i=0;i<array.length;i++){
  +            if(array[i].equals(namespace))
  +                return true;
  +        }
  +        return false;
  +    }
  +
  +    /**
        * Get the Types element for the WSDL document. If not present, create one
        */
       private void writeWsdlTypesElement() {
  @@ -1022,7 +1049,7 @@
           SOAPConstants constants;
           MessageContext mc = MessageContext.getCurrentContext();
           if(mc==null||mc.getSOAPConstants()==null){
  -            constants = SOAPConstants.SOAP11_CONSTANTS;    
  +            constants = SOAPConstants.SOAP11_CONSTANTS;
           } else {
               constants = mc.getSOAPConstants();
           }
  @@ -1042,7 +1069,7 @@
           Element attribute = docHolder.createElement("attribute");
   
           restriction.appendChild(attribute);
  -        
  +
           attribute.setAttribute("ref",
                   prefix + ":arrayType");
   
  @@ -1556,7 +1583,7 @@
   
           updateNamespaces();
   
  -        if (wsdlTypesElem == null) 
  +        if (wsdlTypesElem == null)
               return;
   
           // Make sure that definitions from each embedded schema are allowed
  @@ -1597,7 +1624,7 @@
               }
               schemaElem = null;
               tns = null;
  -        }  
  +        }
   
           // Import the wsdlTypesElement into the doc.
           org.w3c.dom.Node node = doc.importNode(wsdlTypesElem, true);
  @@ -1605,7 +1632,7 @@
           doc.getDocumentElement().
                   insertBefore(node,
                           doc.getDocumentElement().getFirstChild());
  -    }  
  +    }
   
       /**
        * Return the list of classes that we should not emit WSDL for.
  @@ -1784,7 +1811,7 @@
           // because we've already written it), just add the type="" attribute
           // (if appropriate) and return.
           if (!addToTypesList(qName) && !anonymous) {
  -        	if (containingElement != null) {
  +            if (containingElement != null) {
                   containingElement.setAttribute("type", getQNameString(qName));
               }
   
  @@ -1829,11 +1856,11 @@
           // containingElement to the right QName, and make sure the type is
           // correctly written into the appropriate <schema> element.
           if (anonymous) {
  -        	if (typeEl == null) {
  +            if (typeEl == null) {
                   containingElement.setAttribute("type", getQNameString(getTypeQName(type)));
  -        	} else {
  +            } else {
                   containingElement.appendChild(typeEl);
  -        	}
  +            }
           } else {
               if (typeEl != null) {
                   typeEl.setAttribute("name", qName.getLocalPart());
  @@ -1858,7 +1885,7 @@
       /**
        * return the service description
        * @return
  -     */ 
  +     */
       public ServiceDesc getServiceDesc() {
           return serviceDesc;
       }