1 19 20 28 29 package org.netbeans.modules.xml.wsdl.ui.wizard; 30 31 import java.util.Collection ; 32 import java.util.Iterator ; 33 import java.util.Map ; 34 35 import org.netbeans.modules.xml.wsdl.model.Binding; 36 import org.netbeans.modules.xml.wsdl.model.BindingFault; 37 import org.netbeans.modules.xml.wsdl.model.BindingInput; 38 import org.netbeans.modules.xml.wsdl.model.BindingOperation; 39 import org.netbeans.modules.xml.wsdl.model.BindingOutput; 40 import org.netbeans.modules.xml.wsdl.model.Fault; 41 import org.netbeans.modules.xml.wsdl.model.Input; 42 import org.netbeans.modules.xml.wsdl.model.NotificationOperation; 43 import org.netbeans.modules.xml.wsdl.model.OneWayOperation; 44 import org.netbeans.modules.xml.wsdl.model.Operation; 45 import org.netbeans.modules.xml.wsdl.model.Output; 46 import org.netbeans.modules.xml.wsdl.model.Port; 47 import org.netbeans.modules.xml.wsdl.model.PortType; 48 import org.netbeans.modules.xml.wsdl.model.RequestResponseOperation; 49 import org.netbeans.modules.xml.wsdl.model.Service; 50 import org.netbeans.modules.xml.wsdl.model.SolicitResponseOperation; 51 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 52 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElements; 53 import org.netbeans.modules.xml.wsdl.ui.view.wizard.localized.LocalizedTemplate; 54 import org.netbeans.modules.xml.xam.dom.NamedComponentReference; 55 56 60 public class BindingGenerator implements Command { 61 62 private WSDLModel mModel; 63 64 private PortType mPortType; 65 66 67 private Map mConfigurationMap; 68 69 private WsdlGenerationUtil mUtil; 70 71 private Binding mBinding; 72 73 private Service mService; 74 75 private Port mPort; 76 77 78 public BindingGenerator(WSDLModel model, PortType pt, Map configurationMap) { 79 this.mModel = model; 80 this.mPortType = pt; 81 this.mConfigurationMap = configurationMap; 82 this.mUtil = new WsdlGenerationUtil(this.mModel); 83 } 84 85 public Binding getBinding() { 86 return this.mBinding; 87 } 88 89 public Service getService() { 90 return this.mService; 91 } 92 93 public Port getPort() { 94 return this.mPort; 95 } 96 97 public void execute() { 98 String bindingName = (String ) this.mConfigurationMap.get(WizardBindingConfigurationStep.BINDING_NAME); 100 if (bindingName == null) return; 101 Binding b = mModel.getFactory().createBinding(); 102 this.mBinding = b; 103 b.setName(bindingName); 104 NamedComponentReference<PortType> ptRef = b.createReferenceTo(this.mPortType, PortType.class); 105 b.setType(ptRef); 106 mModel.getDefinitions().addBinding(b); 107 108 LocalizedTemplate bindingSubType = (LocalizedTemplate) this.mConfigurationMap.get(WizardBindingConfigurationStep.BINDING_SUBTYPE); 111 if(bindingSubType != null) { 112 createAndAddBindingProtocol(b, bindingSubType); 114 115 Collection <Operation> operations = mPortType.getOperations(); 116 for (Operation operation : operations) { 117 BindingOperation bo = this.mModel.getFactory().createBindingOperation(); 119 NamedComponentReference<Operation> opRef = bo.createReferenceTo(operation, Operation.class); 120 bo.setOperation(opRef); 121 b.addBindingOperation(bo); 122 123 createAndAddBindingOperationProtocolElements(bo, bindingSubType, operation); 125 } 126 127 } else { 128 130 } 131 132 String serviceName = (String ) this.mConfigurationMap.get(WizardBindingConfigurationStep.SERVICE_NAME); 134 String servicePortName = (String ) this.mConfigurationMap.get(WizardBindingConfigurationStep.SERVICEPORT_NAME); 135 136 Collection <Service> services = mModel.getDefinitions().getServices(); 137 Service service = null; 138 for (Service svc : services) { 139 if (svc.getName().equals(serviceName)) { 140 service = svc; 141 break; 142 } 143 } 144 145 if (service == null) { 146 service = mModel.getFactory().createService(); 147 this.mService = service; 148 service.setName(serviceName); 149 mModel.getDefinitions().addService(service); 150 } 151 152 155 163 Collection <Port> ports = service.getPorts(); 164 Port port = null; 165 for (Port p : ports) { 166 if (p.getName().equals(servicePortName)) { 167 port = p; 168 break; 169 } 170 } 171 172 if (port == null) { 173 port = mModel.getFactory().createPort(); 174 this.mPort = port; 175 port.setName(servicePortName); 176 service.addPort(port); 177 } 178 NamedComponentReference<Binding> bindingRef = port.createReferenceTo(b, Binding.class); 179 port.setBinding(bindingRef); 180 createAndAddServicePortProtocolElements(port, bindingSubType); 181 182 } 183 184 private void createAndAddBindingProtocol(Binding b, LocalizedTemplate bindingSubType) { 185 this.mUtil.createAndAddExtensionElementAndAttribute(WSDLExtensibilityElements.ELEMENT_BINDING, bindingSubType, b); 186 } 187 188 189 private void createAndAddBindingOperationProtocolElements(BindingOperation bOperation, 190 LocalizedTemplate bindingSubType, 191 Operation portTypeOperation) { 192 193 194 this.mUtil.createAndAddExtensionElementAndAttribute(WSDLExtensibilityElements.ELEMENT_BINDING_OPERATION, bindingSubType, bOperation); 195 196 if(portTypeOperation instanceof RequestResponseOperation) { 197 Input input = portTypeOperation.getInput(); 198 Output output = portTypeOperation.getOutput(); 199 Collection <Fault> faults = portTypeOperation.getFaults(); 200 201 if(input != null) { 202 BindingInput bIn = createAndAddBindingOperationInput(bOperation, bindingSubType); 203 bIn.setName(input.getName()); 204 } 205 206 if(output != null) { 207 BindingOutput bOut = createAndAddBindingOperationOutput(bOperation, bindingSubType); 208 bOut.setName(output.getName()); 209 } 210 211 if(faults != null) { 212 Iterator <Fault> it = faults.iterator(); 213 while(it.hasNext()) { 214 Fault fault = it.next(); 215 BindingFault bFault = createAndAddBindingOperationFault(bOperation, bindingSubType); 216 bFault.setName(fault.getName()); 217 } 218 } 219 220 } else if(portTypeOperation instanceof OneWayOperation) { 221 Input input = portTypeOperation.getInput(); 222 223 if(input != null) { 224 BindingInput bIn = createAndAddBindingOperationInput(bOperation, bindingSubType); 225 bIn.setName(input.getName()); 226 } 227 228 } else if(portTypeOperation instanceof SolicitResponseOperation) { 229 Input input = portTypeOperation.getInput(); 230 Output output = portTypeOperation.getOutput(); 231 Collection <Fault> faults = portTypeOperation.getFaults(); 232 233 if(input != null) { 234 BindingInput bIn = createAndAddBindingOperationInput(bOperation, bindingSubType); 235 bIn.setName(input.getName()); 236 } 237 238 if(output != null) { 239 BindingOutput bOut = createAndAddBindingOperationOutput(bOperation, bindingSubType); 240 bOut.setName(output.getName()); 241 } 242 243 if(faults != null) { 244 Iterator <Fault> it = faults.iterator(); 245 while(it.hasNext()) { 246 Fault fault = it.next(); 247 BindingFault bFault = createAndAddBindingOperationFault(bOperation, bindingSubType); 248 bFault.setName(fault.getName()); 249 } 250 } 251 } else if(portTypeOperation instanceof NotificationOperation) { 252 Output output = portTypeOperation.getOutput(); 253 if(output != null) { 254 BindingOutput bOut = createAndAddBindingOperationOutput(bOperation, bindingSubType); 255 bOut.setName(output.getName()); 256 } 257 } 258 } 259 260 private BindingInput createAndAddBindingOperationInput(BindingOperation bOperation, LocalizedTemplate bindingSubType) { 261 BindingInput bIn = this.mModel.getFactory().createBindingInput(); 262 bOperation.setBindingInput(bIn); 263 this.mUtil.createAndAddExtensionElementAndAttribute(WSDLExtensibilityElements.ELEMENT_BINDING_OPERATION_INPUT, 264 bindingSubType, 265 bIn); 266 267 return bIn; 268 } 269 270 271 private BindingOutput createAndAddBindingOperationOutput(BindingOperation bOperation, LocalizedTemplate bindingSubType) { 272 BindingOutput bOut = this.mModel.getFactory().createBindingOutput(); 273 bOperation.setBindingOutput(bOut); 274 this.mUtil.createAndAddExtensionElementAndAttribute(WSDLExtensibilityElements.ELEMENT_BINDING_OPERATION_OUTPUT, 275 bindingSubType, 276 bOut); 277 278 return bOut; 279 } 280 281 private BindingFault createAndAddBindingOperationFault(BindingOperation bOperation, LocalizedTemplate bindingSubType) { 282 BindingFault bFault = this.mModel.getFactory().createBindingFault(); 283 bOperation.addBindingFault(bFault); 284 this.mUtil.createAndAddExtensionElementAndAttribute(WSDLExtensibilityElements.ELEMENT_BINDING_OPERATION_FAULT, 285 bindingSubType, 286 bFault); 287 288 return bFault; 289 } 290 291 private void createAndAddServicePortProtocolElements(Port port, LocalizedTemplate bindingSubType) { 292 this.mUtil.createAndAddExtensionElementAndAttribute(WSDLExtensibilityElements.ELEMENT_SERVICE_PORT, 293 bindingSubType, 294 port); 295 296 } 297 } 298 | Popular Tags |