1 package org.controlhaus.xfire.client;
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.GenerationStrategy;
9 import org.codehaus.xfire.xmlbeans.generator.GeneratorTask;
10 import org.codehaus.xfire.xmlbeans.generator.VelocityGenerationStrategy;
11 import org.codehaus.xfire.xmlbeans.generator.WSDLInspector.Service;
12
13 /***
14 * A strategy which generates XMLBeans client controls for a given WSDL.
15 *
16 * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
17 * @since Nov 2, 2004
18 */
19 public class BeehiveClientStrategy
20 extends VelocityGenerationStrategy
21 implements GenerationStrategy
22 {
23
24
25
26
27 public void write(Service service, File outputDir, GeneratorTask task)
28 throws Exception
29 {
30 File dir = new File(outputDir + File.separator + task.getPackage().replace('.','/'));
31
32 if ( !dir.exists() )
33 dir.mkdirs();
34
35 String type = "";
36 if ( service.isRest() )
37 type = "Rest";
38
39 String name = service.getName();
40 if ( task.getName() != null )
41 name = task.getName();
42
43 String intfName = name + type + "ClientControl";
44 File intfFile = new File(dir, intfName + ".java" );
45
46 if ( !intfFile.exists() || task.isOverwrite() )
47 {
48 FileWriter writer = new FileWriter(intfFile);
49
50 VelocityContext context = new VelocityContext();
51 context.put("package", task.getPackage());
52 context.put("service", service);
53 context.put("interfaceType", intfName);
54
55 generateStub(context,
56 writer,
57 new InputStreamReader(getClass().getResourceAsStream("ControlInterface.vm")));
58
59 writer.close();
60 }
61 }
62
63 }