KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > actions > CreateBindingFromOperationAction


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 package org.netbeans.modules.xml.wsdl.ui.actions;
21
22 import java.io.IOException JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.Iterator JavaDoc;
25
26 import org.netbeans.modules.xml.wsdl.model.Binding;
27 import org.netbeans.modules.xml.wsdl.model.BindingFault;
28 import org.netbeans.modules.xml.wsdl.model.BindingInput;
29 import org.netbeans.modules.xml.wsdl.model.BindingOperation;
30 import org.netbeans.modules.xml.wsdl.model.BindingOutput;
31 import org.netbeans.modules.xml.wsdl.model.Fault;
32 import org.netbeans.modules.xml.wsdl.model.Input;
33 import org.netbeans.modules.xml.wsdl.model.Operation;
34 import org.netbeans.modules.xml.wsdl.model.Output;
35 import org.netbeans.modules.xml.wsdl.model.PortType;
36 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
37 import org.netbeans.modules.xml.wsdl.ui.cookies.CreateBindingFromOperationCookie;
38 import org.openide.ErrorManager;
39 import org.openide.nodes.Node;
40 import org.openide.util.HelpCtx;
41 import org.openide.util.NbBundle;
42
43 public class CreateBindingFromOperationAction extends CommonNodeAction {
44
45     private static final long serialVersionUID = 8950680955260279104L;
46
47     @Override JavaDoc
48     protected int mode() {
49         return MODE_ALL;
50     }
51
52     @Override JavaDoc
53     protected Class JavaDoc[] cookieClasses() {
54         return new Class JavaDoc[] {CreateBindingFromOperationCookie.class};
55     }
56
57     @Override JavaDoc
58     protected void performAction(Node[] activatedNodes) {
59         if (activatedNodes != null) {
60             for (int i = 0; i < activatedNodes.length; i++) {
61                 Node node = activatedNodes[i];
62                 CreateBindingFromOperationCookie cookie = (CreateBindingFromOperationCookie) node.getCookie(CreateBindingFromOperationCookie.class);
63                 if (cookie != null) {
64                     Operation operation = cookie.getOperation();
65                     WSDLModel model = operation.getModel();
66                     
67                     model.startTransaction();
68                     PortType portType = (PortType)operation.getParent();
69                     Binding binding = model.getFactory().createBinding();
70                     String JavaDoc bindingName = NameGenerator.getInstance().generateUniqueBindingName(model, portType.getName());
71                     binding.setName(bindingName);
72                     binding.setType(binding.createReferenceTo(portType, PortType.class));
73                     BindingOperation bo = model.getFactory().createBindingOperation();
74                     bo.setName(operation.getName());
75                     bo.setOperation(bo.createReferenceTo(operation, Operation.class));
76                     binding.addBindingOperation(bo);
77                     Input input = operation.getInput();
78                     if (input != null) {
79                         BindingInput ip = model.getFactory().createBindingInput();
80                         ip.setName(input.getName());
81                         bo.setBindingInput(ip);
82                     }
83                     Output output = operation.getOutput();
84                     if (output != null) {
85                         BindingOutput op = model.getFactory().createBindingOutput();
86                         op.setName(output.getName());
87                         bo.setBindingOutput(op);
88                     }
89                     Collection JavaDoc faults = operation.getFaults();
90                     if (faults != null && faults.size() > 0) {
91                         Iterator JavaDoc faultIter = faults.iterator();
92                         while (faultIter.hasNext()) {
93                             Fault fault = (Fault) faultIter.next();
94                             BindingFault bf = model.getFactory().createBindingFault();
95                             bf.setName(fault.getName());
96                             bo.addBindingFault(bf);
97                         }
98                     }
99                     model.getDefinitions().addBinding(binding);
100                     model.endTransaction();
101                 }
102                 
103             }
104         }
105
106     }
107
108     @Override JavaDoc
109     public String JavaDoc getName() {
110         return NbBundle.getMessage(CreateBindingFromOperationAction.class, "CreateBindingFromOperation_DISPLAY_NAME");
111     }
112
113     @Override JavaDoc
114     public HelpCtx getHelpCtx() {
115         return HelpCtx.DEFAULT_HELP;
116     }
117
118 }
119
Popular Tags