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 am...@apache.org on 2007/03/13 05:12:27 UTC

svn commit: r517518 - in /webservices/axis2/trunk/java/modules: codegen/src/org/apache/axis2/wsdl/codegen/ codegen/src/org/apache/axis2/wsdl/codegen/emitter/ codegen/src/org/apache/axis2/wsdl/codegen/writer/ kernel/src/org/apache/axis2/deployment/repos...

Author: amilas
Date: Mon Mar 12 21:12:26 2007
New Revision: 517518

URL: http://svn.apache.org/viewvc?view=rev&rev=517518
Log:
change the wsdl11writer to change the original wsdl file as it is.
to do this we keep an orginal wsdl definition object in the configuration.

Modified:
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenConfiguration.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenerationEngine.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/AxisServiceBasedMultiLanguageEmitter.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/WSDL11Writer.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/CommandLineOption.java

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenConfiguration.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenConfiguration.java?view=diff&rev=517518&r1=517517&r2=517518
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenConfiguration.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenConfiguration.java Mon Mar 12 21:12:26 2007
@@ -22,6 +22,7 @@
 import org.apache.axis2.wsdl.databinding.TypeMapper;
 import org.apache.axis2.wsdl.util.ConfigPropertyFileLoader;
 
+import javax.wsdl.Definition;
 import java.io.File;
 import java.util.*;
 
@@ -527,5 +528,18 @@
             schemas.addAll(axisService.getSchema());
         }
         return schemas;
+    }
+
+    /**
+     * keep this wsdl definition to write the wsdl file later
+     */
+    private Definition wsdlDefinition;
+
+    public Definition getWsdlDefinition() {
+        return wsdlDefinition;
+    }
+
+    public void setWsdlDefinition(Definition wsdlDefinition) {
+        this.wsdlDefinition = wsdlDefinition;
     }
 }

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenerationEngine.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenerationEngine.java?view=diff&rev=517518&r1=517517&r2=517518
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenerationEngine.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/CodeGenerationEngine.java Mon Mar 12 21:12:26 2007
@@ -100,11 +100,20 @@
             }else{
                 //It'll be WSDL 1.1
                 Definition wsdl4jDef = readInTheWSDLFile(wsdlUri);
+
+                // we save the original wsdl definition to write it to the resource folder later
+                // this is required only if it has imports
+                Map imports = wsdl4jDef.getImports();
+                if ((imports != null) && (imports.size() > 0)){
+                    configuration.setWsdlDefinition(readInTheWSDLFile(wsdlUri));
+                } else {
+                    configuration.setWsdlDefinition(wsdl4jDef);
+                }
+
                 // we generate the code for one service and one port if the
                 // user has specified them.
                 // otherwise generate the code for every service.
                 // TODO: find out a permanant solution for this.
-
                 QName serviceQname = null;
 
                 if (configuration.getServiceName() != null) {

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/AxisServiceBasedMultiLanguageEmitter.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/AxisServiceBasedMultiLanguageEmitter.java?view=diff&rev=517518&r1=517517&r2=517518
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/AxisServiceBasedMultiLanguageEmitter.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/AxisServiceBasedMultiLanguageEmitter.java Mon Mar 12 21:12:26 2007
@@ -1180,6 +1180,8 @@
                                 codeGenConfiguration.getResourceLocation()));
 
 
+        // first write all the schmas.
+        // then use the changedMap got above to adjust the names.
         Map schemaMappings = axisService.getSchemaMappingTable();
         Iterator keys = schemaMappings.keySet().iterator();
         while (keys.hasNext()) {
@@ -1190,37 +1192,27 @@
             );
         }
 
-        //we should have a catch here
-        // we have to change the imports in the wsdl schemas
-        
-
         //switch between the correct writer
         if (CommandLineOptionConstants.WSDL2JavaConstants.WSDL_VERSION_2.
                 equals(codeGenConfiguration.getWSDLVersion())) {
 
-//            WSDL20Writer wsdl20Writer = new WSDL20Writer(
-//                    codeGenConfiguration.isFlattenFiles() ?
-//                            getOutputDirectory(codeGenConfiguration.getOutputLocation(), null) :
-//                            getOutputDirectory(codeGenConfiguration.getOutputLocation(),
-//                                    codeGenConfiguration.getResourceLocation())
-//            );
-//            wsdl20Writer.writeWSDL(axisService);
-
             // TODO : We can not write WSDL 2.0 documents. Even WSDL20Writer implementation is wrong.
             // wait till Woden implements it.
 
         } else {
-            axisService.adjustWSDLSchemaLocatins(changedMap);
+            // here we are going to write the wsdl and its imports
+            // with out using the axis service.
+
             WSDL11Writer wsdl11Writer = new WSDL11Writer(
                     codeGenConfiguration.isFlattenFiles() ?
                             getOutputDirectory(codeGenConfiguration.getOutputLocation(), null) :
                             getOutputDirectory(codeGenConfiguration.getOutputLocation(),
                                     codeGenConfiguration.getResourceLocation()));
-            wsdl11Writer.writeWSDL(axisService);
+            wsdl11Writer.writeWSDL(axisService,
+                    codeGenConfiguration.getWsdlDefinition(),
+                    changedMap);
 
         }
-
-
     }
 
     /**

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/WSDL11Writer.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/WSDL11Writer.java?view=diff&rev=517518&r1=517517&r2=517518
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/WSDL11Writer.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/WSDL11Writer.java Mon Mar 12 21:12:26 2007
@@ -1,10 +1,26 @@
 package org.apache.axis2.wsdl.codegen.writer;
 
 import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.Parameter;
 import org.apache.axis2.util.FileWriter;
+import org.apache.axis2.wsdl.WSDLConstants;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Node;
+import org.w3c.dom.NamedNodeMap;
 
+import javax.wsdl.Definition;
+import javax.wsdl.Import;
+import javax.wsdl.Types;
+import javax.wsdl.extensions.schema.Schema;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLWriter;
 import java.io.File;
 import java.io.FileOutputStream;
+import java.util.Map;
+import java.util.Vector;
+import java.util.Iterator;
+import java.util.List;
 /*
  * Copyright 2004,2005 The Apache Software Foundation.
  *
@@ -22,29 +38,126 @@
  */
 
 public class WSDL11Writer {
-      private File baseFolder = null;
 
+    public static final String IMPORT_TAG = "import";
+    public static final String INCLUDE_TAG = "include";
+    public static final String SCHEMA_LOCATION = "schemaLocation";
+
+    private File baseFolder = null;
+    private int count;
+
+
+    public WSDL11Writer(File baseFolder) {
+        this.baseFolder = baseFolder;
+        this.count = 0;
+    }
+
+    public void writeWSDL(AxisService axisService) {
+        try {
+            if (axisService != null) {
+                //create a output file
+                File outputFile = FileWriter.createClassFile(baseFolder,
+                        null,
+                        axisService.getName(),
+                        ".wsdl");
+                FileOutputStream fos = new FileOutputStream(outputFile);
+                axisService.printWSDL(fos);
+                fos.flush();
+                fos.close();
+            }
+        } catch (Exception e) {
+            throw new RuntimeException("WSDL writing failed!", e);
+        }
+    }
+
+    public void writeWSDL(AxisService axisService, Definition definition, Map changedMap) {
+        try {
+            if (axisService != null) {
+                writeWSDL(definition, axisService.getName(), changedMap);
+            }
+        } catch (Exception e) {
+            throw new RuntimeException("WSDL writing failed!", e);
+        }
+    }
+
+    private void writeWSDL(Definition definition,
+                           String fileName,
+                           Map changedMap) throws Exception {
+        // first process the imports and save them.
+        Map imports = definition.getImports();
+        if (imports != null && (imports.size() > 0)) {
+            Vector importsVector = null;
+            Import wsdlImport = null;
+            String wsdlName = null;
+            for (Iterator improtsVectorIter = imports.values().iterator(); improtsVectorIter.hasNext();) {
+                importsVector = (Vector) improtsVectorIter.next();
+                for (Iterator importsIter = importsVector.iterator(); importsIter.hasNext();) {
+                    wsdlImport = (Import) importsIter.next();
+                    wsdlName = "wsdl_" + count++ + ".wsdl";
+                    writeWSDL(wsdlImport.getDefinition(), wsdlName, changedMap);
+                    wsdlImport.setLocationURI(wsdlName);
+                }
+            }
+        }
+        // change the locations on the imported schemas
+        adjustWSDLSchemaLocatins(definition, changedMap);
+        // finally save the file
+        WSDLWriter wsdlWriter = WSDLFactory.newInstance().newWSDLWriter();
+        File outputFile = FileWriter.createClassFile(baseFolder,
+                null, fileName, ".wsdl");
+        FileOutputStream out = new FileOutputStream(outputFile);
+        wsdlWriter.writeWSDL(definition, out);
+        out.flush();
+        out.close();
+    }
+
+    /**
+     * adjust the schema locations in the original wsdl
+     *
+     * @param changedScheamLocations
+     */
+    public void adjustWSDLSchemaLocatins(Definition definition, Map changedScheamLocations) {
+        Types wsdlTypes = definition.getTypes();
+        if (wsdlTypes != null) {
+            List extensibilityElements = wsdlTypes.getExtensibilityElements();
+            Object currentObject;
+            Schema schema;
+            for (Iterator iter = extensibilityElements.iterator(); iter.hasNext();) {
+                currentObject = iter.next();
+                if (currentObject instanceof Schema) {
+                    schema = (Schema) currentObject;
+                    changeLocations(schema.getElement(), changedScheamLocations);
+                }
+            }
+        }
+    }
+
+    private void changeLocations(Element element, Map changedScheamLocations) {
+        NodeList nodeList = element.getChildNodes();
+        String tagName;
+        for (int i = 0; i < nodeList.getLength(); i++) {
+            tagName = nodeList.item(i).getLocalName();
+            if (IMPORT_TAG.equals(tagName) || INCLUDE_TAG.equals(tagName)) {
+                processImport(nodeList.item(i), changedScheamLocations);
+            }
+        }
+    }
+
+    private void processImport(Node importNode, Map changedScheamLocations) {
+        NamedNodeMap nodeMap = importNode.getAttributes();
+        Node attribute;
+        String attributeValue;
+        for (int i = 0; i < nodeMap.getLength(); i++) {
+            attribute = nodeMap.item(i);
+            if (attribute.getNodeName().equals("schemaLocation")) {
+                attributeValue = attribute.getNodeValue();
+                if (changedScheamLocations.get(attributeValue) != null) {
+                    attribute.setNodeValue(
+                            (String) changedScheamLocations.get(attributeValue));
+                }
+            }
+        }
+    }
 
-       public WSDL11Writer(File baseFolder) {
-           this.baseFolder = baseFolder;
-       }
-
-       public void writeWSDL(AxisService axisService){
-           try {
-               if (axisService!= null){
-                   //create a output file
-                   File outputFile = FileWriter.createClassFile(baseFolder,
-                           null,
-                           axisService.getName(),
-                           ".wsdl");
-                   FileOutputStream fos = new FileOutputStream(outputFile);
-                   axisService.printWSDL(fos);
-                   fos.flush();
-                   fos.close();
-               }
-           } catch (Exception e) {
-               throw new RuntimeException("WSDL writing failed!", e);
-           }
-       }
 
 }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java?view=diff&rev=517518&r1=517517&r2=517518
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java Mon Mar 12 21:12:26 2007
@@ -291,7 +291,10 @@
                             && entryName.endsWith(SUFFIX_WSDL)) {
                         out = new ByteArrayOutputStream();
 
-                        if (entryName.indexOf("/") != entryName.lastIndexOf("/")) {
+                        // we do not want to generate the services for the
+                        // imported wsdl of one file.
+                        if ((entryName.indexOf("/") != entryName.lastIndexOf("/"))
+                                || (entryName.indexOf("wsdl_") != -1)) {
                             //only care abt the toplevel wsdl
                             continue;
                         }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java?view=diff&rev=517518&r1=517517&r2=517518
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java Mon Mar 12 21:12:26 2007
@@ -1861,53 +1861,6 @@
         return changedScheamLocations;
     }
 
-    /**
-     * adjust the schema locations in the original wsdl 
-     * @param changedScheamLocations
-     */
-    public void adjustWSDLSchemaLocatins(Map changedScheamLocations) {
-        Parameter wsld4jdefinition = getParameter(WSDLConstants.WSDL_4_J_DEFINITION);
-        Definition definition = (Definition) wsld4jdefinition.getValue();
-        Types wsdlTypes = definition.getTypes();
-        List extensibilityElements = wsdlTypes.getExtensibilityElements();
-        Object currentObject;
-        Schema schema;
-        for (Iterator iter = extensibilityElements.iterator(); iter.hasNext();) {
-            currentObject = iter.next();
-            if (currentObject instanceof Schema) {
-                schema = (Schema) currentObject;
-                changeLocations(schema.getElement(), changedScheamLocations);
-            }
-        }
-
-    }
-
-    private void changeLocations(Element element, Map changedScheamLocations) {
-        NodeList nodeList = element.getChildNodes();
-        String tagName;
-        for (int i = 0; i < nodeList.getLength(); i++) {
-            tagName = nodeList.item(i).getNodeName();
-            if (tagName.equals("import") || tagName.equals("include")) {
-                processImport(nodeList.item(i), changedScheamLocations);
-            }
-        }
-    }
-
-    private void processImport(Node importNode, Map changedScheamLocations) {
-        NamedNodeMap nodeMap = importNode.getAttributes();
-        Node attribute;
-        String attributeValue;
-        for (int i = 0; i < nodeMap.getLength(); i++) {
-            attribute = nodeMap.item(i);
-            if (attribute.getNodeName().equals("schemaLocation")) {
-                attributeValue = attribute.getNodeValue();
-                if (changedScheamLocations.get(attributeValue) != null) {
-                    attribute.setNodeValue(
-                            (String) changedScheamLocations.get(attributeValue));
-                }
-            }
-        }
-    }
 
     /**
      * run 1 -calcualte unique names

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java?view=diff&rev=517518&r1=517517&r2=517518
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java Mon Mar 12 21:12:26 2007
@@ -292,7 +292,6 @@
             log.error(e);
             throw new AxisFault(e);
         } catch (Exception e) {
-            e.printStackTrace();
             log.error(e);
             throw new AxisFault(e);
         }
@@ -1392,7 +1391,7 @@
                         List parameterOrder = operation.getOperation().getParameterOrdering();
                         if (parameterOrder != null) {
                             parameterOrder = new ArrayList(parameterOrder);
-                            
+
                             parameterOrder.add("result");
                             partsIterator = message.getOrderedParts(parameterOrder).iterator();
                         } else {

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/CommandLineOption.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/CommandLineOption.java?view=diff&rev=517518&r1=517517&r2=517518
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/CommandLineOption.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/CommandLineOption.java Mon Mar 12 21:12:26 2007
@@ -71,7 +71,7 @@
      * @return Returns the optionValues.
      */
     public String getOptionValue() {
-        if (optionValues != null) {
+        if ((optionValues != null) && (optionValues.size() > 0)) {
             return (String) optionValues.get(0);
         } else {
             return null;



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