01: package org.objectweb.celtix.tools.generators.java2;
02:
03: import javax.wsdl.Binding;
04: import javax.wsdl.Definition;
05: import javax.wsdl.Port;
06: import javax.wsdl.Service;
07: import javax.wsdl.WSDLException;
08: import javax.wsdl.extensions.ExtensionRegistry;
09: 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
32: .getServiceName()));
33: Port port = definition.createPort();
34: port.setName(wmodel.getPortName());
35: Binding binding = definition.createBinding();
36: String targetNameSpace = wmodel.getTargetNameSpace();
37: binding.setQName(new QName(targetNameSpace, wmodel
38: .getPortTypeName()
39: + "Binding"));
40: port.setBinding(binding);
41: SOAPAddress soapAddress = null;
42: try {
43: soapAddress = (SOAPAddress) extensionRegistry
44: .createExtension(Port.class, new QName(
45: WSDLConstants.SOAP11_NAMESPACE, "address"));
46: soapAddress.setLocationURI(ADDRESS_URI);
47: } catch (WSDLException e) {
48: throw new ToolException(e.getMessage(), e);
49: }
50: port.addExtensibilityElement(soapAddress);
51: service.addPort(port);
52: definition.addService(service);
53: }
54: }
|