1 package org.objectweb.celtix.tools.generators.java2; 2 3 import javax.wsdl.Binding; 4 import javax.wsdl.Definition; 5 import javax.wsdl.Port; 6 import javax.wsdl.Service; 7 import javax.wsdl.WSDLException; 8 import javax.wsdl.extensions.ExtensionRegistry; 9 import javax.wsdl.extensions.soap.SOAPAddress; 10 import javax.xml.namespace.QName ; 11 12 import org.objectweb.celtix.tools.common.ToolException; 13 import org.objectweb.celtix.tools.common.WSDLConstants; 14 import org.objectweb.celtix.tools.common.model.WSDLModel; 15 16 public class ServiceGenerator { 17 private static final String ADDRESS_URI = "http://localhost/changme"; 18 private WSDLModel wmodel; 19 private Definition definition; 20 private ExtensionRegistry extensionRegistry; 21 22 public ServiceGenerator(WSDLModel model) { 23 this.definition = model.getDefinition(); 24 this.wmodel = model; 25 extensionRegistry = definition.getExtensionRegistry(); 26 27 } 28 29 public void generate() { 30 Service service = definition.createService(); 31 service.setQName(new QName (WSDLConstants.WSDL_PREFIX, wmodel.getServiceName())); 32 Port port = definition.createPort(); 33 port.setName(wmodel.getPortName()); 34 Binding binding = definition.createBinding(); 35 String targetNameSpace = wmodel.getTargetNameSpace(); 36 binding.setQName(new QName (targetNameSpace, wmodel.getPortTypeName() + "Binding")); 37 port.setBinding(binding); 38 SOAPAddress soapAddress = null; 39 try { 40 soapAddress = (SOAPAddress)extensionRegistry 41 .createExtension(Port.class, new QName (WSDLConstants.SOAP11_NAMESPACE, "address")); 42 soapAddress.setLocationURI(ADDRESS_URI); 43 } catch (WSDLException e) { 44 throw new ToolException(e.getMessage(), e); 45 } 46 port.addExtensibilityElement(soapAddress); 47 service.addPort(port); 48 definition.addService(service); 49 } 50 } 51 | Popular Tags |