View Javadoc

    1   package org.codehaus.xfire.xmlbeans.generator;
    2
    3   import java.io.File;
    4   import java.io.FileWriter;
    5   import java.io.InputStreamReader;
    6
    7   import org.apache.velocity.VelocityContext;
    8   import org.codehaus.xfire.xmlbeans.generator.WSDLInspector.Service;
    9
    10  /***
    11   * Generic strategy for creating a client stub.
    12   *
    13   * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
    14   * @since Nov 2, 2004
    15   */
    16  public class ClientGenerationStrategy
    17      extends VelocityGenerationStrategy
    18      implements GenerationStrategy
    19  {
    20      public void write( Service service, File outputDir, GeneratorTask task )
    21          throws Exception
    22      {
    23          File dir = new File(outputDir, task.getPackage().replace('.',File.separatorChar));
    24
    25          if ( !dir.exists() )
    26              dir.mkdirs();
    27
    28          String type = "Soap";
    29          if ( service.isRest() )
    30              type = "Rest";
    31          String name = service.getName();
    32          if ( task.getName() != null && task.getName().length() != 0 )
    33              name = task.getName();
    34
    35          File stub = new File(dir, name + type + "Client.java" );
    36
    37          if ( !stub.exists() || task.isOverwrite() )
    38          {
    39              FileWriter writer = new FileWriter(stub);
    40
    41              VelocityContext context = new VelocityContext();
    42              context.put("package", task.getPackage());
    43              context.put("name", task.getName());
    44              context.put("service", service);
    45
    46              generateStub(context, writer, new InputStreamReader(getClass().getResourceAsStream("ClientStub.vm")));
    47              writer.close();
    48          }
    49      }
    50
    51  }