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 ServerGenerationStrategy
    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 + File.separator + task.getPackage().replace('.','/'));
    24
    25          if ( !dir.exists() )
    26              dir.mkdirs();
    27
    28          File stub = new File(dir, service.getName() + ".java" );
    29
    30          if ( !stub.exists() || task.isOverwrite() )
    31          {
    32              FileWriter writer = new FileWriter(stub);
    33
    34              VelocityContext context = new VelocityContext();
    35              context.put("package", task.getPackage());
    36              context.put("service", service);
    37
    38              generateStub(context, writer, new InputStreamReader(getClass().getResourceAsStream("ServerIntfStub.vm")));
    39              writer.close();
    40          }
    41      }
    42
    43  }