KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > view > treeeditor > newtype > BindingOperationNewType


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.view.treeeditor.newtype;
21
22 import java.io.IOException JavaDoc;
23 import java.util.Collection JavaDoc;
24
25 import org.netbeans.modules.xml.wsdl.model.Binding;
26 import org.netbeans.modules.xml.wsdl.model.BindingFault;
27 import org.netbeans.modules.xml.wsdl.model.BindingInput;
28 import org.netbeans.modules.xml.wsdl.model.BindingOperation;
29 import org.netbeans.modules.xml.wsdl.model.BindingOutput;
30 import org.netbeans.modules.xml.wsdl.model.Fault;
31 import org.netbeans.modules.xml.wsdl.model.Input;
32 import org.netbeans.modules.xml.wsdl.model.Operation;
33 import org.netbeans.modules.xml.wsdl.model.Output;
34 import org.netbeans.modules.xml.wsdl.model.PortType;
35 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
36 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
37 import org.netbeans.modules.xml.wsdl.ui.netbeans.module.Utility;
38 import org.netbeans.modules.xml.wsdl.ui.view.BindingOperationView;
39 import org.openide.DialogDescriptor;
40 import org.openide.DialogDisplayer;
41 import org.openide.ErrorManager;
42 import org.openide.NotifyDescriptor;
43 import org.openide.util.NbBundle;
44 import org.openide.util.datatransfer.NewType;
45
46 public class BindingOperationNewType extends NewType {
47     private WSDLComponent mDef = null;
48     
49     public BindingOperationNewType(WSDLComponent def) {
50         mDef = def;
51     }
52     
53     
54     @Override JavaDoc
55     public String JavaDoc getName() {
56         return NbBundle.getMessage(BindingOperationNewType.class, "LBL_NewType_BindingOperation");
57     }
58     
59     
60     @Override JavaDoc
61     public void create() throws IOException JavaDoc {
62         Binding binding = (Binding) mDef;
63         if(!isValidBinding(binding)) {
64             return;
65         }
66         
67         PortType portType = binding.getType().get();
68         Operation[] selectedOperations = null;
69         //If there is only one implementable operation then add it, without showing dialog
70
Collection JavaDoc<Operation> operations = Utility.getImplementableOperations(portType, binding);
71         if (operations != null && operations.size() == 1) {
72             selectedOperations = new Operation[]{operations.iterator().next()};
73         } else {
74             BindingOperationView operationView = new BindingOperationView(operations);
75             
76             DialogDescriptor dd =
77                 new DialogDescriptor(operationView,
78                         NbBundle.getMessage(BindingOperationNewType.class, "AddBindingOperationView_SELECT_OPERATION") ,
79                         true,
80                         DialogDescriptor.OK_CANCEL_OPTION,
81                         DialogDescriptor.CANCEL_OPTION,
82                         null);
83             
84             if(DialogDisplayer.getDefault().notify(dd) == DialogDescriptor.OK_OPTION) {
85                 selectedOperations = operationView.getSelectedOperations();
86             }
87         }
88         if (selectedOperations != null && selectedOperations.length > 0) {
89             WSDLModel document = binding.getModel();
90             document.startTransaction();
91             for (Operation operation : selectedOperations) {
92                 BindingOperation bindingOperation = document.getFactory().createBindingOperation();
93                 if(operation != null) {
94                     bindingOperation.setName(operation.getName());
95                     Input input = operation.getInput();
96                     Output output = operation.getOutput();
97                     Collection JavaDoc<Fault> faults = operation.getFaults();
98                     if(input != null) {
99                         BindingInput bIn = document.getFactory().createBindingInput();
100                         if(input.getName() != null) {
101                             bIn.setName(input.getName());
102                         }
103                         bindingOperation.setBindingInput(bIn);
104                     }
105                     
106                     if(output != null) {
107                         BindingOutput bOut = document.getFactory().createBindingOutput();
108                         if(output.getName() != null) {
109                             bOut.setName(output.getName());
110                         }
111                         bindingOperation.setBindingOutput(bOut);
112                     }
113                     
114                     if(faults != null) {
115                         for (Fault fault : faults) {
116                             BindingFault bFault = document.getFactory().createBindingFault();
117                             if(fault.getName() != null) {
118                                 bFault.setName(fault.getName());
119                             }
120                             bindingOperation.addBindingFault(bFault);
121                         }
122                         
123                     }
124                 }
125                 binding.addBindingOperation(bindingOperation);
126             }
127                 document.endTransaction();
128         }
129     }
130     
131     
132     private boolean isValidBinding(Binding binding) {
133         boolean valid = false;
134         String JavaDoc message = null;
135         if(binding != null && binding.getType() != null) {
136             PortType portType = binding.getType().get();
137             if(portType != null && portType.getOperations() != null && portType.getOperations().size() > 0) {
138                 
139                 valid = true;
140             } else {
141                 valid = false;
142                 message = NbBundle.getMessage(BindingOperationNewType.class, "AddBindingOperationView_LONG_DESCRIPTION_MISSING_OPERATION_IN_BINDING_PORTTYPE");
143             }
144         } else {
145             valid = false;
146             message = NbBundle.getMessage(BindingOperationNewType.class, "AddBindingOperationView_LONG_DESCRIPTION1_MISSING_PORTTYPE_IN_BINDING");
147         }
148         
149         if(!valid) {
150             
151             NotifyDescriptor nd = new NotifyDescriptor.Message(message, NotifyDescriptor.INFORMATION_MESSAGE);
152             DialogDisplayer.getDefault().notify(nd);
153         }
154         
155         return valid;
156     }
157 }
158
Popular Tags