axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nadira...@apache.org
Subject svn commit: r690427 - in /webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws: CLArgParser.java WSDL2Ws.java info/WSDLInfo.java
Date Fri, 29 Aug 2008 23:40:21 GMT
Author: nadiramra
Date: Fri Aug 29 16:40:21 2008
New Revision: 690427

URL: http://svn.apache.org/viewvc?rev=690427&view=rev
Log:
Refactor to put code in proper classes.

Modified:
    webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/CLArgParser.java
    webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/WSDL2Ws.java
    webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/info/WSDLInfo.java

Modified: webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/CLArgParser.java
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/CLArgParser.java?rev=690427&r1=690426&r2=690427&view=diff
==============================================================================
--- webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/CLArgParser.java (original)
+++ webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/CLArgParser.java Fri Aug
29 16:40:21 2008
@@ -22,14 +22,21 @@
 
 package org.apache.axis.wsdl.wsdl2ws;
 
+import java.io.File;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Hashtable;
 
+/**
+ * Parsers user-specified options on the command.
+ * 
+ */
 public class CLArgParser 
 {
     private boolean optionsAreValid = true;
-    public Hashtable bag;
-    public ArrayList args;
+    
+    public Hashtable bag  = new Hashtable();
+    public ArrayList args = new ArrayList();
 
     /**
      * Not very good argument parser, could be improved.  For example, there can be no spaces
between
@@ -37,10 +44,7 @@
      * In addition, only single character options are allowed.
      */
     public CLArgParser(String[] args) 
-    {
-        this.bag = new Hashtable();
-        this.args = new ArrayList();
-        
+    {        
         for (int i = 0; i < args.length; i++) 
         {
             if (!args[i].startsWith("-"))
@@ -79,28 +83,116 @@
             }
         }
     }
+    
+    /**
+     * Return output directory.
+     * 
+     * @return
+     * @throws IOException
+     */
+    public String getOutputDirectory() throws IOException
+    {
+        String targetoutputLocation = getOptionBykey("o");
+        if (targetoutputLocation == null)
+            targetoutputLocation = "." + File.separator;
+        return (new File(targetoutputLocation)).getCanonicalPath();
+    }
+    
+    /**
+     * Return whether to generate wrapper-style
+     * 
+     * @return
+     */
+    public boolean isWrapperStyle()
+    {
+        String wsdlWrapStyle = getOptionBykey("w");
+        if (wsdlWrapStyle == null || wsdlWrapStyle.equalsIgnoreCase("wrapped"))
+            return true;
+        
+        return false;
+    }
+    
+    /**
+     * Return binding name.
+     * 
+     * @return
+     */
+    public String getBinding()
+    {
+        return getOptionBykey("b");
+    }
+    
+    /**
+     * Return target language.
+     * @return
+     */
+    public String getTargetLanguage()
+    {
+        String language = getOptionBykey("l");
+        if (language == null)
+            language = "c++";
+        return language;
+    }
 
     /**
-     * This method checks that we do not have extraneous inputs to the tool that we do not
support
-     * @return true if the args are all supported false otherwise.
+     * Return verbose information
+     * 
+     * @return
      */
-    public boolean areOptionsValid()
+    public boolean beVerbose()
     {
-        return optionsAreValid;
-    }    
+        return isSet("v");
+    }
     
     /**
-     * These are direct arguments not - type options
-     * @param i
+     * Return timeout value
+     * 
+     * @return
+     */
+    public long getTimeout()
+    {
+        String t = getOptionBykey("t");
+        if (t == null)
+            t = "0";
+        return Long.parseLong(t);
+    }
+    
+    /**
+     * Return target engine.
+     * 
+     * @return
+     */
+    public String getTargetEngine()
+    {
+        String targetEngine = getOptionBykey("s");
+        if (targetEngine == null)
+            targetEngine = "server";
+        
+        return targetEngine;
+    }
+    
+    /**
+     * Return URI to WSDL
+     * 
+     * @return
      */
-    public String getArgument(int i) 
+    public String getURIToWSDL()
     {
-        Object obj = args.get(i);
-        if(obj == null) 
-            return null;
-        else 
-            return (String)obj;
+        if (args.size() > 0)
+            return (String)args.get(0);
+        
+        return null;
     }
+    
+    /**
+     * This method checks that we do not have extraneous inputs to the tool that we do not
support
+     * 
+     * @return true if the args are all supported false otherwise.
+     */
+    public boolean areOptionsValid()
+    {
+        return optionsAreValid;
+    }    
 
     /**
      * These are direct arguments not - type options
@@ -110,11 +202,23 @@
         return this.args.size();
     }
 
+    /**
+     * Return the value specified for an option.
+     * 
+     * @param key
+     * @return
+     */
     public String getOptionBykey(String key) 
     {
         return (String) bag.get(key);
     }
 
+    /**
+     * Determines whether an option is set.
+     * 
+     * @param key
+     * @return
+     */
     public boolean isSet(String key) 
     {
         return bag.containsKey(key);

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=690427&r1=690426&r2=690427&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 Fri Aug 29
16:40:21 2008
@@ -17,7 +17,6 @@
 
 package org.apache.axis.wsdl.wsdl2ws;
 
-import java.io.File;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
@@ -64,12 +63,9 @@
 {
     public static boolean c_verbose = false;
 
-    private String  c_language;
-    private boolean c_wsdlWrappingStyle;
-    private boolean c_userRequestedWSDLWrappingStyle = false;
-    private String  c_targetoutputLocation = null;
-    private String  c_targetEngine = null;
-        
+    // Command line arguments
+    private CLArgParser c_cmdLineArgs = null;
+            
     // WSDL parser symbol table
     private SymbolTable c_symbolTable;
     
@@ -101,22 +97,11 @@
      */
     public static void main(String[] args) throws Exception
     {
-        // Get parameters and validate
-        CLArgParser data = new CLArgParser(args);
-        
-        if (!data.areOptionsValid() || data.isSet("h") || data.getArgumentCount() != 1)
-        {
-            usage();
-            return;
-        }
-
         // Kick off code generation
         try
         {
-            WSDL2Ws gen = new WSDL2Ws(data);
+            WSDL2Ws gen = new WSDL2Ws(args);
             gen.generateWrappers();
-
-            System.out.println("\nCode generation completed. Generated files in directory
'" + gen.getTargetOutputLocation() + "'.");
         }
         catch (Exception e)
         {
@@ -128,58 +113,40 @@
     /**
      * Gathers the parameters passed in and parses the WSDL file, generating the symbol table.

      * 
-     * @param cmdLineArgs
+     * @param args
      * @throws WrapperFault
      */
-    public WSDL2Ws(CLArgParser cmdLineArgs) throws WrapperFault
+    public WSDL2Ws(String[] args) throws WrapperFault
     {
         try
         {
             // ==================================================
             // Process the parameters
             // ==================================================            
+
+            // Get parameters and validate
+            c_cmdLineArgs = new CLArgParser(args);
+            if (!c_cmdLineArgs.areOptionsValid() 
+                    || c_cmdLineArgs.isSet("h") || c_cmdLineArgs.getArgumentCount() != 1)
+            {
+                usage();
+                return;
+            }
             
             // Verbose mode?
-            if (cmdLineArgs.isSet("v"))
-                c_verbose = true;
-            
-            // Target location - we resolve to canonical path and use path in completion
message later on.
-            c_targetoutputLocation = cmdLineArgs.getOptionBykey("o");
-            if (c_targetoutputLocation == null)
-                c_targetoutputLocation = "." + File.separator;
-            c_targetoutputLocation = (new File(c_targetoutputLocation)).getCanonicalPath();
+            c_verbose = c_cmdLineArgs.beVerbose();
             
             // language c or c++ - CUtils.setLanguage MUST be invoked at the very beginning!
-            c_language = cmdLineArgs.getOptionBykey("l");
-            if (c_language == null)
-                c_language = "c++";
-            CUtils.setLanguage(c_language);
-            
-            // generate artifacts for server, client or both?
-            c_targetEngine = cmdLineArgs.getOptionBykey("s");
-            if (c_targetEngine == null)
-                c_targetEngine = "server";
-            
-            // Wrapped or unwrapped? The default will be wrapped. 
-            String wsdlWrapStyle = cmdLineArgs.getOptionBykey("w");
-            if (wsdlWrapStyle == null)
-                c_wsdlWrappingStyle = true;
-            else if (wsdlWrapStyle.equalsIgnoreCase("wrapped"))
-            {
-                c_wsdlWrappingStyle = true;
-                c_userRequestedWSDLWrappingStyle = true;
-            }
-            else
-                c_wsdlWrappingStyle = false;            
+            CUtils.setLanguage(c_cmdLineArgs.getTargetLanguage());
             
             // ==================================================
             // Parse the WSDL file
             // ==================================================
             
-            c_wsdlInfo = new WSDLInfo(cmdLineArgs.getArgument(0));
+            c_wsdlInfo = new WSDLInfo(c_cmdLineArgs.getURIToWSDL());
             c_wsdlInfo.setVerbose(c_verbose);
-            c_wsdlInfo.setTimeout(cmdLineArgs.getOptionBykey("t")); 
-            c_wsdlInfo.setNoWrapperStyle(c_wsdlWrappingStyle == false);
+            c_wsdlInfo.setTimeout(c_cmdLineArgs.getTimeout()); 
+            c_wsdlInfo.setNoWrapperStyle(c_cmdLineArgs.isWrapperStyle() == false);
 
             c_symbolTable = c_wsdlInfo.parse();
             
@@ -245,12 +212,17 @@
         // Wrapper info
         WrapperInfo wrapperInfo = 
             new WrapperInfo(bindingEntry.getBindingStyle().getName(), 
-                            c_language, c_targetoutputLocation, c_targetEngine,
+                            CUtils.getLanguage(), 
+                            c_cmdLineArgs.getOutputDirectory(), 
+                            c_cmdLineArgs.getTargetEngine(),
                             c_wsdlInfo.getTargetNameSpaceOfWSDL());
         
         // Service info
+        boolean userRequestedWSDLWrappingStyle = c_cmdLineArgs.isSet("w") && c_cmdLineArgs.isWrapperStyle();
         String serviceName       = WSDLInfo.getServiceName(bindingEntry);
-        ArrayList serviceMethods = c_wsdlInfo.processServiceMethods(bindingEntry, c_wsdlWrappingStyle,
c_userRequestedWSDLWrappingStyle);
+        ArrayList serviceMethods = c_wsdlInfo.processServiceMethods(bindingEntry, 
+                                                                    c_cmdLineArgs.isWrapperStyle(),

+                                                                    userRequestedWSDLWrappingStyle);
         ServiceInfo serviceInfo  = new ServiceInfo(serviceName, serviceMethods, WSDLInfo.getTargetEndPointURI(port));
         
         // Context
@@ -277,19 +249,13 @@
         // Generate the artifacts
         // ================================================== 
         
+        // Generate code
         wsg.generate();
+        
+        // Indicate code generation complete and show where stored.
+        System.out.println("\nCode generation completed. Generated files in directory '"
+ c_cmdLineArgs.getOutputDirectory() + "'.");
     }    
     
-    /**
-     * Returns absolute path to where the generated code will be located. 
-     * 
-     * @return the absolute path to the target location
-     */
-    public String getTargetOutputLocation()
-    {
-        return c_targetoutputLocation;
-    }
-    
     // The following 3 exposeXXX methods attempts to expose anonymous types so that 
     // the types are externalized to the user.  
     

Modified: webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/info/WSDLInfo.java
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/info/WSDLInfo.java?rev=690427&r1=690426&r2=690427&view=diff
==============================================================================
--- webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/info/WSDLInfo.java (original)
+++ webservices/axis/trunk/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/info/WSDLInfo.java Fri
Aug 29 16:40:21 2008
@@ -210,12 +210,9 @@
      * 
      * @param t  timeout value in seconds. Null implies 0 timeout (no timeout).
      */
-    public void setTimeout(String t)
+    public void setTimeout(long t)
     {
-        if (t == null)
-            t = "0"; 
-        
-        c_timeout = Long.parseLong(t);
+        c_timeout = t;
     }
     
     /**



Mime
View raw message