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 ClientGenerator extends AbstractGenerator {
16:
17: private static final String CLT_TEMPLATE = TEMPLATE_BASE
18: + "/client.vm";
19:
20: public ClientGenerator(JavaModel jmodel, ProcessorEnvironment env) {
21: super (jmodel, env);
22: this .name = ToolConstants.CLT_GENERATOR;
23: }
24:
25: public boolean passthrough() {
26: if (env.optionSet(ToolConstants.CFG_CLIENT)
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: JavaServiceClass js = null;
41: JavaPort jp = null;
42:
43: for (Iterator iter = interfaces.keySet().iterator(); iter
44: .hasNext();) {
45: String interfaceName = (String) iter.next();
46: JavaInterface intf = interfaces.get(interfaceName);
47:
48: Iterator it = javaModel.getServiceClasses().values()
49: .iterator();
50: while (it.hasNext()) {
51: String serviceName = "";
52: js = (JavaServiceClass) it.next();
53: Iterator i = js.getPorts().iterator();
54: while (i.hasNext()) {
55: jp = (JavaPort) i.next();
56: if (jp.getPortType() == interfaceName) {
57: serviceName = js.getName();
58: break;
59: }
60: }
61: if (!"".equals(serviceName)) {
62: break;
63: }
64: }
65:
66: String clientClassName = interfaceName + "Client";
67: while (isCollision(intf.getPackageName(), clientClassName)) {
68: clientClassName = clientClassName + "_Client";
69: }
70:
71: clearAttributes();
72: setAttributes("clientClassName", clientClassName);
73: setAttributes("intf", intf);
74: setAttributes("service", js);
75: setAttributes("port", jp);
76: setCommonAttributes();
77:
78: doWrite(CLT_TEMPLATE, parseOutputName(
79: intf.getPackageName(), clientClassName));
80: }
81: }
82: }
|