1 package org.objectweb.celtix.tools.generators.wsdl2; 2 3 import java.util.Iterator ; 4 import java.util.Map ; 5 6 import org.objectweb.celtix.tools.common.ProcessorEnvironment; 7 import org.objectweb.celtix.tools.common.ToolConstants; 8 import org.objectweb.celtix.tools.common.ToolException; 9 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 + "/client.vm"; 18 19 public ClientGenerator(JavaModel jmodel, ProcessorEnvironment env) { 20 super(jmodel, env); 21 this.name = ToolConstants.CLT_GENERATOR; 22 } 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.getInterfaces(); 39 JavaServiceClass js = null; 40 JavaPort jp = null; 41 42 for (Iterator iter = interfaces.keySet().iterator(); iter.hasNext();) { 43 String interfaceName = (String )iter.next(); 44 JavaInterface intf = interfaces.get(interfaceName); 45 46 Iterator it = javaModel.getServiceClasses().values().iterator(); 47 while (it.hasNext()) { 48 String serviceName = ""; 49 js = (JavaServiceClass)it.next(); 50 Iterator i = js.getPorts().iterator(); 51 while (i.hasNext()) { 52 jp = (JavaPort)i.next(); 53 if (jp.getPortType() == interfaceName) { 54 serviceName = js.getName(); 55 break; 56 } 57 } 58 if (!"".equals(serviceName)) { 59 break; 60 } 61 } 62 63 64 String clientClassName = interfaceName + "Client"; 65 while (isCollision(intf.getPackageName(), clientClassName)) { 66 clientClassName = clientClassName + "_Client"; 67 } 68 69 clearAttributes(); 70 setAttributes("clientClassName", clientClassName); 71 setAttributes("intf", intf); 72 setAttributes("service", js); 73 setAttributes("port", jp); 74 setCommonAttributes(); 75 76 doWrite(CLT_TEMPLATE, parseOutputName(intf.getPackageName(), 77 clientClassName)); 78 } 79 } 80 } 81 | Popular Tags |