Index: Wsdl2javaAntTask.java
===================================================================
RCS file: /home/cvspublic/xml-axis/java/test/wsdl/Wsdl2javaAntTask.java,v
retrieving revision 1.24
diff -u -r1.24 Wsdl2javaAntTask.java
--- Wsdl2javaAntTask.java	27 Mar 2002 22:58:17 -0000	1.24
+++ Wsdl2javaAntTask.java	13 Apr 2002 23:11:50 -0000
@@ -1,7 +1,7 @@
 /*
  * The Apache Software License, Version 1.1
  *
- * Copyright (c) 2001 The Apache Software Foundation.  All rights
+ * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -70,7 +70,8 @@
 
 /**
  * Simple Ant task for running Wsdl2java utility. 
- *
+ * @ant.task category="xml"
+ * @author steve loughran
  * @author Davanum Srinivas (dims@yahoo.com)
  */
 public class Wsdl2javaAntTask extends Task
@@ -90,26 +91,66 @@
     private String tm = "1.2";
     private long timeout = 45000;
 
-    // The method executing the task
-    public void execute() throws BuildException {
+    /**
+     * do we print a stack trace when someting goes wrong
+     */
+    private boolean printStackTraceOnFailure=false;
+    /**
+     * what action to take when there was a failure and the source was some
+     * URL
+     */
+    private boolean failOnNetworkErrors=false;
+    
+    /**
+     * validation code
+     * @throws  BuildException  if validation failed
+     */ 
+    protected void validate() 
+            throws BuildException {
+        if(url==null || url.length()==0) {
+            throw new BuildException("No url specified");
+        }
+        if(timeout<0) {
+            throw new BuildException("negative timeout supplied");
+        }
+        if (!"application".equalsIgnoreCase(deployScope) 
+            && !"request".equalsIgnoreCase(deployScope)
+            && !"session".equalsIgnoreCase(deployScope)
+            && !"none".equalsIgnoreCase(deployScope)) {
+                throw new BuildException("Unrecognized scope:  " + deployScope);
+            }
+    }
+    
+    /**
+     * trace out parameters
+     * @param level to log at
+     * @see org.apache.tools.ant.Project#log
+     */
+    public void traceParams(int logLevel) {
+        log("Running Wsdl2javaAntTask with parameters:", logLevel);
+        log("  verbose:" + verbose, logLevel);
+        log("  server-side:" + server, logLevel);
+        log("  skeletonDeploy:" + skeletonDeploy, logLevel);
+        log("  testCase:" + testCase, logLevel);
+        log("  noImports:" + noImports, logLevel);
+        log("  NStoPkg:" + namespaceMap, logLevel);
+        log("  output:" + output, logLevel);
+        log("  deployScope:" + deployScope, logLevel);
+        log("  URL:" + url, logLevel);
+        log("  all:" + all, logLevel);
+        log("  typeMappingVersion:" + tm, logLevel);
+        log("  timeout:" + timeout, logLevel);
+    }
+    
+    /**
+     * The method executing the task
+     * @throws  BuildException  if validation or execution failed
+     */ 
+     public void execute() throws BuildException {
+        traceParams(Project.MSG_DEBUG);
+        validate();
         try {
-            log("Running Wsdl2javaAntTask with parameters:", Project.MSG_VERBOSE);
-            log("\tverbose:" + verbose, Project.MSG_VERBOSE);
-            log("\tserver-side:" + server, Project.MSG_VERBOSE);
-            log("\tskeletonDeploy:" + skeletonDeploy, Project.MSG_VERBOSE);
-            log("\thelperGen:" + helperGen, Project.MSG_VERBOSE);
-            log("\tfactory:" + factory, Project.MSG_VERBOSE);
-            log("\ttestCase:" + testCase, Project.MSG_VERBOSE);
-            log("\tnoImports:" + noImports, Project.MSG_VERBOSE);
-            log("\tNStoPkg:" + namespaceMap, Project.MSG_VERBOSE);
-            log("\toutput:" + output, Project.MSG_VERBOSE);
-            log("\tdeployScope:" + deployScope, Project.MSG_VERBOSE);
-            log("\tURL:" + url, Project.MSG_VERBOSE);
-            log("\tall:" + all, Project.MSG_VERBOSE);
-            log("\ttypeMappingVersion:" + tm, Project.MSG_VERBOSE);
-            log("\ttimeout:" + timeout, Project.MSG_VERBOSE);
-
-            // Instantiate the emitter
+             // Instantiate the emitter
             WSDL2Java emitter = new WSDL2Java();
 
             if ("application".equalsIgnoreCase(deployScope)) {
@@ -152,15 +193,25 @@
                 if (url.startsWith("http://")) {
                     // What we have is either a network error or invalid XML -
                     // the latter most likely an HTML error page.  This makes
-                    // it impossible to continue with the test, so issue
-                    // a warning, and return without reporting a fatal error.
-                    log(e.toString(), Project.MSG_WARN);
-                    return;
+                    // it impossible to continue with the test, so 
+                    if(!failOnNetworkErrors) {
+                        // test mode, issue a warning, and return without
+                        //reporting a fatal error.
+                        log(e.toString(), Project.MSG_WARN);
+                        return;
+                    } else {
+                        //in 'consumer' mode, bail out with the URL
+                        throw new BuildException("when fetching "+url,e);
+                    }
+                } else {
+                    throw e;
                 }
-                throw e;
             }
         } catch (Throwable t) {
-            t.printStackTrace();
+            if(printStackTraceOnFailure) {
+                traceParams(Project.MSG_INFO);
+                t.printStackTrace();
+            }
             throw new BuildException("Error while running " + getClass().getName(), t); 
         }
     }
@@ -171,37 +222,37 @@
     }
 
     // The setter for the "server-side" attribute
-    public void setServerSide(String parameter) {
-        this.server = Project.toBoolean(parameter);
+    public void setServerSide(boolean parameter) {
+        this.server = parameter;
     }
 
     // The setter for the "skeletonDeploy" attribute
-    public void setSkeletonDeploy(String parameter) {
-        this.skeletonDeploy = Project.toBoolean(parameter);
+    public void setSkeletonDeploy(boolean parameter) {
+        this.skeletonDeploy = parameter;
     }
 
     // The setter for the "testcase" attribute
-    public void setTestCase(String parameter) {
-        this.testCase = Project.toBoolean(parameter);
+    public void setTestCase(boolean parameter) {
+        this.testCase = parameter;
     }
 
     // The setter for the "helperGen" attribute
-    public void setHelperGen(String parameter) {
-        this.helperGen = Project.toBoolean(parameter);
+    public void setHelperGen(boolean parameter) {
+        this.helperGen = parameter;
     }
 
     // The setter for the "factory" attribute
     public void setFactory(String parameter) {
         this.factory = parameter;
     }
-
+    
     // The setter for the "noimports" attribute
-    public void setNoImports(String parameter) {
-        this.noImports = Project.toBoolean(parameter);
+    public void setNoImports(boolean parameter) {
+        this.noImports = parameter;
     }
 
     // The setter for the "output" attribute
-    public void setOutput(File parameter) {
+    public void setOutput(File parameter) throws BuildException {
         try {
             this.output = parameter.getCanonicalPath();
         } catch (IOException ioe) {
@@ -220,8 +271,8 @@
     }
 
     // The setter for the "all" attribute
-    public void setAll(String parameter) {
-        this.all = Project.toBoolean(parameter);
+    public void setAll(boolean parameter) {
+        this.all = parameter;
     }
 
     // The setter for the "typeMappingVersion" attribute
@@ -230,12 +281,23 @@
     }
 
     // The setter for the "timeout" attribute
-    public void setTimeout(String parameter) {
-        try {
-            this.timeout = new Long(parameter).longValue();
-        } catch (NumberFormatException e) {
-            // Sorry, stick with default.
-        }
+    public void setTimeout(long parameter) {
+        this.timeout = parameter;
+    }
+
+    /**
+     * if we get an error and the url was remote, do we fail
+     */ 
+    public void setFailOnNetworkErrors(boolean failOnNetworkErrors) {
+        this.failOnNetworkErrors = failOnNetworkErrors;
+    }
+
+    /**
+     * do we want a stack trace when the build fails. useful for 
+     * debugging wsdl2java.
+     */ 
+    public void setPrintStackTraceOnFailure(boolean printStackTraceOnFailure) {
+        this.printStackTraceOnFailure = printStackTraceOnFailure;
     }
 
     /** the command arguments */
