KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > wizard > BindingGenerator


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * BindingGenerator.java
22  *
23  * Created on September 6, 2006, 4:36 PM
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

28
29 package org.netbeans.modules.xml.wsdl.ui.wizard;
30
31 import java.util.Collection JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import java.util.Map JavaDoc;
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 /**
57  *
58  * @author radval
59  */

60 public class BindingGenerator implements Command {
61     
62     private WSDLModel mModel;
63     
64     private PortType mPortType;
65     
66     
67     private Map JavaDoc mConfigurationMap;
68     
69     private WsdlGenerationUtil mUtil;
70     
71     private Binding mBinding;
72     
73     private Service mService;
74     
75     private Port mPort;
76     
77     /** Creates a new instance of BindingGenerator */
78     public BindingGenerator(WSDLModel model, PortType pt, Map JavaDoc 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         //binding
99
String JavaDoc bindingName = (String JavaDoc) 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             //Not used LocalizedTemplateGroup bindingType = (LocalizedTemplateGroup) this.mConfigurationMap.get(WizardBindingConfigurationStep.BINDING_TYPE);
109
//this could be null for a binding which does not have a sub type
110
LocalizedTemplate bindingSubType = (LocalizedTemplate) this.mConfigurationMap.get(WizardBindingConfigurationStep.BINDING_SUBTYPE);
111             if(bindingSubType != null) {
112                 //binding protocol
113
createAndAddBindingProtocol(b, bindingSubType);
114                 
115                 Collection JavaDoc<Operation> operations = mPortType.getOperations();
116                 for (Operation operation : operations) {
117                     //binding operation
118
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                     //binding operation protocol
124
createAndAddBindingOperationProtocolElements(bo, bindingSubType, operation);
125                 }
126                 
127             } else {
128                 //no binding subtype
129

130             }
131             
132             //service and port
133
String JavaDoc serviceName = (String JavaDoc) this.mConfigurationMap.get(WizardBindingConfigurationStep.SERVICE_NAME);
134             String JavaDoc servicePortName = (String JavaDoc) this.mConfigurationMap.get(WizardBindingConfigurationStep.SERVICEPORT_NAME);
135             
136             Collection JavaDoc<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         /*
153          01/02/07, following code replaced to allow the reuse of empty port element in CASA (T. Li)
154          */

155         // Port port = mModel.getFactory().createPort();
156
// this.mPort = port;
157
// port.setName(servicePortName);
158
// NamedComponentReference<Binding> bindingRef = port.createReferenceTo(b, Binding.class);
159
// port.setBinding(bindingRef);
160
// createAndAddServicePortProtocolElements(port, bindingSubType);
161
// service.addPort(port);
162

163             Collection JavaDoc<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 JavaDoc<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 JavaDoc<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 JavaDoc<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 JavaDoc<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