1 19 20 package org.netbeans.modules.xml.wsdl.ui.actions; 21 22 import java.io.IOException ; 23 import java.util.Collection ; 24 import java.util.Iterator ; 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 48 protected int mode() { 49 return MODE_ALL; 50 } 51 52 @Override 53 protected Class [] cookieClasses() { 54 return new Class [] {CreateBindingFromOperationCookie.class}; 55 } 56 57 @Override 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 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 faults = operation.getFaults(); 90 if (faults != null && faults.size() > 0) { 91 Iterator 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 109 public String getName() { 110 return NbBundle.getMessage(CreateBindingFromOperationAction.class, "CreateBindingFromOperation_DISPLAY_NAME"); 111 } 112 113 @Override 114 public HelpCtx getHelpCtx() { 115 return HelpCtx.DEFAULT_HELP; 116 } 117 118 } 119 | Popular Tags |