001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * BindingGenerator.java
044: *
045: * Created on September 6, 2006, 4:36 PM
046: *
047: * To change this template, choose Tools | Template Manager
048: * and open the template in the editor.
049: */
050:
051: package org.netbeans.modules.xml.wsdl.ui.wizard;
052:
053: import java.util.Collection;
054: import java.util.Iterator;
055:
056: import org.netbeans.modules.xml.wsdl.bindingsupport.spi.ExtensibilityElementTemplateProvider;
057: import org.netbeans.modules.xml.wsdl.bindingsupport.template.ExtensibilityElementTemplateFactory;
058: import org.netbeans.modules.xml.wsdl.bindingsupport.template.TemplateGroup;
059: import org.netbeans.modules.xml.wsdl.bindingsupport.template.TemplateType;
060: import org.netbeans.modules.xml.wsdl.bindingsupport.template.localized.LocalizedTemplate;
061: import org.netbeans.modules.xml.wsdl.bindingsupport.template.localized.LocalizedTemplateGroup;
062: import org.netbeans.modules.xml.wsdl.model.Binding;
063: import org.netbeans.modules.xml.wsdl.model.BindingFault;
064: import org.netbeans.modules.xml.wsdl.model.BindingInput;
065: import org.netbeans.modules.xml.wsdl.model.BindingOperation;
066: import org.netbeans.modules.xml.wsdl.model.BindingOutput;
067: import org.netbeans.modules.xml.wsdl.model.Fault;
068: import org.netbeans.modules.xml.wsdl.model.Input;
069: import org.netbeans.modules.xml.wsdl.model.NotificationOperation;
070: import org.netbeans.modules.xml.wsdl.model.OneWayOperation;
071: import org.netbeans.modules.xml.wsdl.model.Operation;
072: import org.netbeans.modules.xml.wsdl.model.Output;
073: import org.netbeans.modules.xml.wsdl.model.RequestResponseOperation;
074: import org.netbeans.modules.xml.wsdl.model.SolicitResponseOperation;
075: import org.netbeans.modules.xml.wsdl.model.WSDLModel;
076: import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElements;
077: import org.netbeans.modules.xml.wsdl.ui.model.StringAttribute;
078: import org.netbeans.modules.xml.xam.Named;
079: import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
080:
081: /**
082: *
083: * @author radval
084: */
085: public class BindingOperationGenerator implements Command {
086:
087: private WSDLModel mModel;
088:
089: private WsdlGenerationUtil mUtil;
090:
091: private Binding mBinding;
092:
093: private String namespace;
094:
095: private Operation[] mOperations;
096: private BindingOperation lastAddedBindingOperation;
097:
098: public BindingOperationGenerator(Binding binding, String namespace,
099: Operation[] operations) {
100: this .mModel = binding.getModel();
101: this .mUtil = new WsdlGenerationUtil(this .mModel);
102: this .namespace = namespace;
103: this .mOperations = operations;
104: mBinding = binding;
105: }
106:
107: public BindingOperation getBindingOperation() {
108: return lastAddedBindingOperation;
109: }
110:
111: public void execute() {
112: LocalizedTemplate bindingSubType = null;
113: /* if (namespace != null) {
114: ExtensibilityElementTemplateFactory factory = new ExtensibilityElementTemplateFactory();
115: ExtensibilityElementTemplateProvider provider = factory.getProvider(namespace);
116: String template = provider.getTemplateUsed(mBinding);
117: if (template != null) {
118: TemplateGroup group = factory.getExtensibilityElementTemplateGroup(namespace);
119: //get the proper LTG
120: LocalizedTemplateGroup lGroup = factory.getLocalizedTemplateGroup(group);
121: LocalizedTemplate[] lTemplates = lGroup.getTemplate();
122: for (LocalizedTemplate lTemplate : lTemplates) {
123: if (lTemplate.getDelegate().getName().equals(template)) {
124: bindingSubType = lTemplate;
125: break;
126: }
127: }
128:
129: }
130: }*/
131:
132: if (bindingSubType != null) {
133: for (Operation operation : mOperations) {
134: //binding operation
135: BindingOperation bo = this .mModel.getFactory()
136: .createBindingOperation();
137: mBinding.addBindingOperation(bo);
138: NamedComponentReference<Operation> opRef = bo
139: .createReferenceTo(operation, Operation.class);
140: bo.setOperation(opRef);
141:
142: //binding operation protocol
143: createAndAddBindingOperationProtocolElements(bo,
144: bindingSubType, operation);
145: lastAddedBindingOperation = bo;
146: }
147:
148: } else {
149: for (Operation operation : mOperations) {
150: BindingOperation bindingOperation = mModel.getFactory()
151: .createBindingOperation();
152: if (operation != null) {
153: bindingOperation.setName(operation.getName());
154: Input input = operation.getInput();
155: Output output = operation.getOutput();
156: Collection<Fault> faults = operation.getFaults();
157: if (input != null) {
158: BindingInput bIn = mModel.getFactory()
159: .createBindingInput();
160: if (input.getName() != null) {
161: bIn.setName(input.getName());
162: }
163: bindingOperation.setBindingInput(bIn);
164: }
165:
166: if (output != null) {
167: BindingOutput bOut = mModel.getFactory()
168: .createBindingOutput();
169: if (output.getName() != null) {
170: bOut.setName(output.getName());
171: }
172: bindingOperation.setBindingOutput(bOut);
173: }
174:
175: if (faults != null) {
176: for (Fault fault : faults) {
177: BindingFault bFault = mModel.getFactory()
178: .createBindingFault();
179: if (fault.getName() != null) {
180: bFault.setName(fault.getName());
181: }
182: bindingOperation.addBindingFault(bFault);
183: }
184:
185: }
186: }
187: mBinding.addBindingOperation(bindingOperation);
188: lastAddedBindingOperation = bindingOperation;
189: }
190:
191: }
192:
193: }
194:
195: private void createAndAddBindingOperationProtocolElements(
196: BindingOperation bOperation,
197: LocalizedTemplate bindingSubType,
198: Operation portTypeOperation) {
199:
200: this .mUtil.createAndAddExtensionElementAndAttribute(
201: WSDLExtensibilityElements.ELEMENT_BINDING_OPERATION,
202: bindingSubType, bOperation);
203:
204: if (portTypeOperation instanceof RequestResponseOperation) {
205: Input input = portTypeOperation.getInput();
206: Output output = portTypeOperation.getOutput();
207: Collection<Fault> faults = portTypeOperation.getFaults();
208:
209: if (input != null) {
210: BindingInput bIn = createAndAddBindingOperationInput(
211: bOperation, bindingSubType);
212: if (input.getAttribute(new StringAttribute(
213: Named.NAME_PROPERTY)) != null) {
214: bIn.setName(input.getName());
215: }
216: }
217:
218: if (output != null) {
219: BindingOutput bOut = createAndAddBindingOperationOutput(
220: bOperation, bindingSubType);
221: if (output.getAttribute(new StringAttribute(
222: Named.NAME_PROPERTY)) != null) {
223: bOut.setName(output.getName());
224: }
225: }
226:
227: if (faults != null) {
228: Iterator<Fault> it = faults.iterator();
229: while (it.hasNext()) {
230: Fault fault = it.next();
231: BindingFault bFault = createAndAddBindingOperationFault(
232: bOperation, bindingSubType);
233: bFault.setName(fault.getName());
234: }
235: }
236:
237: } else if (portTypeOperation instanceof OneWayOperation) {
238: Input input = portTypeOperation.getInput();
239:
240: if (input != null) {
241: BindingInput bIn = createAndAddBindingOperationInput(
242: bOperation, bindingSubType);
243: if (input.getAttribute(new StringAttribute(
244: Named.NAME_PROPERTY)) != null) {
245: bIn.setName(input.getName());
246: }
247: }
248:
249: } else if (portTypeOperation instanceof SolicitResponseOperation) {
250: Input input = portTypeOperation.getInput();
251: Output output = portTypeOperation.getOutput();
252: Collection<Fault> faults = portTypeOperation.getFaults();
253:
254: if (input != null) {
255: BindingInput bIn = createAndAddBindingOperationInput(
256: bOperation, bindingSubType);
257: if (input.getAttribute(new StringAttribute(
258: Named.NAME_PROPERTY)) != null) {
259: bIn.setName(input.getName());
260: }
261: }
262:
263: if (output != null) {
264: BindingOutput bOut = createAndAddBindingOperationOutput(
265: bOperation, bindingSubType);
266: if (output.getAttribute(new StringAttribute(
267: Named.NAME_PROPERTY)) != null) {
268: bOut.setName(output.getName());
269: }
270: }
271:
272: if (faults != null) {
273: Iterator<Fault> it = faults.iterator();
274: while (it.hasNext()) {
275: Fault fault = it.next();
276: BindingFault bFault = createAndAddBindingOperationFault(
277: bOperation, bindingSubType);
278: bFault.setName(fault.getName());
279: }
280: }
281: } else if (portTypeOperation instanceof NotificationOperation) {
282: Output output = portTypeOperation.getOutput();
283: if (output != null) {
284: BindingOutput bOut = createAndAddBindingOperationOutput(
285: bOperation, bindingSubType);
286: if (output.getAttribute(new StringAttribute(
287: Named.NAME_PROPERTY)) != null) {
288: bOut.setName(output.getName());
289: }
290: }
291: }
292: }
293:
294: private BindingInput createAndAddBindingOperationInput(
295: BindingOperation bOperation,
296: LocalizedTemplate bindingSubType) {
297: BindingInput bIn = this .mModel.getFactory()
298: .createBindingInput();
299: bOperation.setBindingInput(bIn);
300: this .mUtil
301: .createAndAddExtensionElementAndAttribute(
302: WSDLExtensibilityElements.ELEMENT_BINDING_OPERATION_INPUT,
303: bindingSubType, bIn);
304:
305: return bIn;
306: }
307:
308: private BindingOutput createAndAddBindingOperationOutput(
309: BindingOperation bOperation,
310: LocalizedTemplate bindingSubType) {
311: BindingOutput bOut = this .mModel.getFactory()
312: .createBindingOutput();
313: bOperation.setBindingOutput(bOut);
314: this .mUtil
315: .createAndAddExtensionElementAndAttribute(
316: WSDLExtensibilityElements.ELEMENT_BINDING_OPERATION_OUTPUT,
317: bindingSubType, bOut);
318:
319: return bOut;
320: }
321:
322: private BindingFault createAndAddBindingOperationFault(
323: BindingOperation bOperation,
324: LocalizedTemplate bindingSubType) {
325: BindingFault bFault = this.mModel.getFactory()
326: .createBindingFault();
327: bOperation.addBindingFault(bFault);
328: this.mUtil
329: .createAndAddExtensionElementAndAttribute(
330: WSDLExtensibilityElements.ELEMENT_BINDING_OPERATION_FAULT,
331: bindingSubType, bFault);
332:
333: return bFault;
334: }
335:
336: }
|