View Javadoc

    1   package org.codehaus.xfire.xmlbeans.generator;
    2
    3   import java.io.File;
    4   import java.net.MalformedURLException;
    5   import java.net.URL;
    6   import java.util.Iterator;
    7   import java.util.List;
    8
    9   import org.apache.tools.ant.BuildException;
    10  import org.apache.tools.ant.Task;
    11
    12  /***
    13   * An ant task which takes a WSDL and generates the SOAP
    14   * client stubs.
    15   *
    16   * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
    17   * @since Oct 25, 2004
    18   */
    19  public class GeneratorTask
    20      extends Task
    21  {
    22      private String wsdl;
    23      private boolean overwrite = false;
    24      private File outputDir;
    25      private String packageName = "";
    26      private String strategy = ClientGenerationStrategy.class.getName();
    27      private String name;
    28
    29      public GeneratorTask()
    30      {
    31      }
    32
    33      public void execute() throws BuildException
    34      {
    35          try
    36          {
    37              WSDLInspector insp = new WSDLInspector();
    38
    39              URL url;
    40              try
    41              {
    42                  url = new URL(wsdl);
    43              }
    44              catch (MalformedURLException e )
    45              {
    46                  url = new File(wsdl).toURL();
    47              }
    48
    49              List services = insp.generateServices( url );
    50
    51              GenerationStrategy strat = getStrategy();
    52
    53              for ( Iterator itr = services.iterator(); itr.hasNext(); )
    54              {
    55                  strat.write( (WSDLInspector.Service) itr.next(), outputDir, this );
    56              }
    57          }
    58          catch (Exception e)
    59          {
    60              e.printStackTrace();
    61              throw new BuildException(e);
    62          }
    63      }
    64
    65      public GenerationStrategy getStrategy()
    66          throws InstantiationException, IllegalAccessException, ClassNotFoundException
    67      {
    68          return (GenerationStrategy) getClass().getClassLoader().loadClass(strategy).newInstance();
    69      }
    70
    71      public String getWsdl()
    72      {
    73          return wsdl;
    74      }
    75
    76      public void setWsdl(String wsdl)
    77      {
    78          this.wsdl = wsdl;
    79      }
    80
    81      public File getOutputDir()
    82      {
    83          return outputDir;
    84      }
    85
    86      public void setOutputDir(File outputDir)
    87      {
    88          this.outputDir = outputDir;
    89      }
    90
    91      public boolean isOverwrite()
    92      {
    93          return overwrite;
    94      }
    95
    96      public void setOverwrite(boolean overwrite)
    97      {
    98          this.overwrite = overwrite;
    99      }
    100
    101     public String getPackage()
    102     {
    103         return packageName;
    104     }
    105
    106     public void setPackage(String packageName)
    107     {
    108         this.packageName = packageName;
    109     }
    110
    111     public void setStrategy(String strategy)
    112     {
    113         this.strategy = strategy;
    114     }
    115
    116     public String getName()
    117     {
    118         return name;
    119     }
    120
    121     public void setName(String name)
    122     {
    123         this.name = name;
    124     }
    125 }