01: package org.objectweb.celtix.tools.generators.wsdl2;
02:
03: import java.util.Iterator;
04: import java.util.Map;
05:
06: import org.objectweb.celtix.tools.common.ProcessorEnvironment;
07: import org.objectweb.celtix.tools.common.ToolConstants;
08: import org.objectweb.celtix.tools.common.ToolException;
09: import org.objectweb.celtix.tools.common.model.JavaInterface;
10: import org.objectweb.celtix.tools.common.model.JavaModel;
11: import org.objectweb.celtix.tools.common.model.JavaPort;
12: import org.objectweb.celtix.tools.common.model.JavaServiceClass;
13: import org.objectweb.celtix.tools.generators.AbstractGenerator;
14:
15: public class ServerGenerator extends AbstractGenerator {
16:
17: private static final String SRV_TEMPLATE = TEMPLATE_BASE
18: + "/server.vm";
19:
20: public ServerGenerator(JavaModel jmodel, ProcessorEnvironment env) {
21: super (jmodel, env);
22: this .name = ToolConstants.SVR_GENERATOR;
23: }
24:
25: public boolean passthrough() {
26: if (env.optionSet(ToolConstants.CFG_SERVER)
27: || env.optionSet(ToolConstants.CFG_ALL)) {
28: return false;
29: }
30: return true;
31: }
32:
33: public void generate() throws ToolException {
34: if (passthrough()) {
35: return;
36: }
37:
38: Map<String, JavaInterface> interfaces = javaModel
39: .getInterfaces();
40: for (Iterator iter = interfaces.keySet().iterator(); iter
41: .hasNext();) {
42: String interfaceName = (String) iter.next();
43: JavaInterface intf = interfaces.get(interfaceName);
44: String address = "";
45:
46: Iterator it = javaModel.getServiceClasses().values()
47: .iterator();
48: while (it.hasNext()) {
49: JavaServiceClass js = (JavaServiceClass) it.next();
50: Iterator i = js.getPorts().iterator();
51: while (i.hasNext()) {
52: JavaPort jp = (JavaPort) i.next();
53: if (interfaceName.equals(jp.getPortType())) {
54: address = jp.getBindingAdress();
55: break;
56: }
57: }
58: if (!"".equals(address)) {
59: break;
60: }
61: }
62:
63: String serverClassName = interfaceName + "Server";
64:
65: while (isCollision(intf.getPackageName(), serverClassName)) {
66: serverClassName = serverClassName + "_Server";
67: }
68:
69: clearAttributes();
70: setAttributes("serverClassName", serverClassName);
71: setAttributes("intf", intf);
72: setAttributes("address", address);
73: setCommonAttributes();
74:
75: doWrite(SRV_TEMPLATE, parseOutputName(
76: intf.getPackageName(), serverClassName));
77: }
78: }
79:
80: }
|