01: package org.objectweb.celtix.tools.generators.java2;
02:
03: import javax.wsdl.Definition;
04: import javax.wsdl.factory.WSDLFactory;
05: import javax.wsdl.xml.WSDLWriter;
06:
07: import org.objectweb.celtix.tools.common.ProcessorEnvironment;
08: import org.objectweb.celtix.tools.common.ToolConstants;
09: import org.objectweb.celtix.tools.common.ToolException;
10: import org.objectweb.celtix.tools.common.model.WSDLModel;
11:
12: public class WSDLGenerator {
13: private final WSDLModel wmodel;
14:
15: private final ProcessorEnvironment env;
16:
17: private final Definition definition;
18:
19: private WSDLFactory wsdlFactory;
20:
21: private String wsdlFile;
22:
23: private String portTypeName;
24:
25: public WSDLGenerator(WSDLModel model, ProcessorEnvironment penv) {
26: wmodel = model;
27: env = penv;
28: definition = model.getDefinition();
29: try {
30: wsdlFactory = WSDLFactory.newInstance();
31: } catch (javax.wsdl.WSDLException e) {
32: throw new ToolException(e.getMessage(), e);
33: }
34: }
35:
36: public void generate() {
37: preGenerate();
38: TypesGenerator typeGen = new TypesGenerator(wmodel, env);
39: typeGen.generate();
40: MessagePortTypeGenerator messagePortTypeGen = new MessagePortTypeGenerator(
41: wmodel);
42: messagePortTypeGen.generate();
43: BindingGenerator bindingGen = new BindingGenerator(wmodel);
44: bindingGen.generate();
45: ServiceGenerator serviceGen = new ServiceGenerator(wmodel);
46: serviceGen.generate();
47: writeDefinition();
48:
49: }
50:
51: private void preGenerate() {
52: Object obj = env.get(ToolConstants.CFG_OUTPUTFILE);
53: wsdlFile = obj == null ? "./" + wmodel.getServiceName()
54: + ".wsdl" : (String) obj;
55: obj = env.get(ToolConstants.CFG_TNS);
56: String targetNameSpace;
57: targetNameSpace = obj == null ? wmodel.getTargetNameSpace()
58: : (String) obj;
59: wmodel.setTargetNameSpace(targetNameSpace);
60: obj = env.get(ToolConstants.CFG_PORTTYPE);
61: portTypeName = obj == null ? wmodel.getPortName()
62: : (String) obj;
63: wmodel.setPortName(portTypeName);
64:
65: }
66:
67: private boolean writeDefinition() {
68:
69: WSDLWriter writer = wsdlFactory.newWSDLWriter();
70:
71: java.io.File file = new java.io.File(wsdlFile);
72: java.io.OutputStream outstream = null;
73: try {
74: outstream = new java.io.FileOutputStream(file);
75: } catch (java.io.FileNotFoundException e) {
76: throw new ToolException(e.getMessage(), e);
77: }
78:
79: try {
80: writer.writeWSDL(this .definition, outstream);
81: } catch (javax.wsdl.WSDLException e) {
82: throw new ToolException(e.getMessage(), e);
83: }
84: return true;
85: }
86:
87: }
|