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 ServerGenerator extends AbstractGenerator { 16 17 private static final String SRV_TEMPLATE = TEMPLATE_BASE + "/server.vm"; 18 19 public ServerGenerator(JavaModel jmodel, ProcessorEnvironment env) { 20 super(jmodel, env); 21 this.name = ToolConstants.SVR_GENERATOR; 22 } 23 24 public boolean passthrough() { 25 if (env.optionSet(ToolConstants.CFG_SERVER) 26 || env.optionSet(ToolConstants.CFG_ALL)) { 27 return false; 28 } 29 return true; 30 } 31 32 public void generate() throws ToolException { 33 if (passthrough()) { 34 return; 35 } 36 37 Map <String , JavaInterface> interfaces = javaModel.getInterfaces(); 38 for (Iterator iter = interfaces.keySet().iterator(); iter.hasNext();) { 39 String interfaceName = (String )iter.next(); 40 JavaInterface intf = interfaces.get(interfaceName); 41 String address = ""; 42 43 Iterator it = javaModel.getServiceClasses().values().iterator(); 44 while (it.hasNext()) { 45 JavaServiceClass js = (JavaServiceClass)it.next(); 46 Iterator i = js.getPorts().iterator(); 47 while (i.hasNext()) { 48 JavaPort jp = (JavaPort)i.next(); 49 if (interfaceName.equals(jp.getPortType())) { 50 address = jp.getBindingAdress(); 51 break; 52 } 53 } 54 if (!"".equals(address)) { 55 break; 56 } 57 } 58 59 60 String serverClassName = interfaceName + "Server"; 61 62 while (isCollision(intf.getPackageName(), serverClassName)) { 63 serverClassName = serverClassName + "_Server"; 64 } 65 66 clearAttributes(); 67 setAttributes("serverClassName", serverClassName); 68 setAttributes("intf", intf); 69 setAttributes("address", address); 70 setCommonAttributes(); 71 72 doWrite(SRV_TEMPLATE, parseOutputName(intf.getPackageName(), serverClassName)); 73 } 74 } 75 76 } 77 | Popular Tags |