KickJava   Java API By Example, From Geeks To Geeks.

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


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.ArrayList JavaDoc;
24 import java.util.Collection JavaDoc;
25 import java.util.List JavaDoc;
26
27 import org.netbeans.modules.xml.wsdl.model.BindingFault;
28 import org.netbeans.modules.xml.wsdl.model.BindingOperation;
29 import org.netbeans.modules.xml.wsdl.model.Fault;
30 import org.netbeans.modules.xml.wsdl.model.Operation;
31 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
32 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
33 import org.netbeans.modules.xml.wsdl.ui.actions.ActionHelper;
34 import org.openide.util.NbBundle;
35 import org.openide.util.datatransfer.NewType;
36
37 public class BindingOperationFaultNewType extends NewType {
38     private BindingOperation mBindingOperation = null;
39     
40     public BindingOperationFaultNewType(WSDLComponent message) {
41         mBindingOperation = (BindingOperation) message;
42     }
43     
44
45     @Override JavaDoc
46     public String JavaDoc getName() {
47         return NbBundle.getMessage(BindingOperationFaultNewType.class, "LBL_NewType_BindingOperationFault");
48     }
49
50
51     @Override JavaDoc
52     public void create() throws IOException JavaDoc {
53         BindingOperation bo = mBindingOperation;
54         WSDLModel model = mBindingOperation.getModel();
55         List JavaDoc<Fault> faultsNameSet = new ArrayList JavaDoc<Fault>();
56         if (bo.getOperation() != null) {
57             Operation operation = bo.getOperation().get();
58             if (operation != null) {
59                 Collection JavaDoc<Fault> faults = operation.getFaults();
60                 for (Fault fault : faults) {
61                     faultsNameSet.add(fault);
62                 }
63             }
64             Collection JavaDoc<BindingFault> bindingFaults = mBindingOperation.getBindingFaults();
65             if (bindingFaults != null && !bindingFaults.isEmpty()) {
66                 for (BindingFault bFault : bindingFaults) {
67                     if (bFault.getFault() != null) {
68                         Fault fault = bFault.getFault().get();
69                         if (!faultsNameSet.remove(fault)) {
70                             break;
71                         }
72                     }
73                 }
74             }
75             
76             if (!faultsNameSet.isEmpty()) {
77                 model.startTransaction();
78                 Fault fault = faultsNameSet.get(0);
79                 BindingFault bindingOperationFault = model.getFactory().createBindingFault();
80                 bindingOperationFault.setName(fault.getName());
81                 bo.addBindingFault(bindingOperationFault);
82                 model.endTransaction();
83                 ActionHelper.selectNode(bindingOperationFault);
84             }
85         }
86     }
87
88 }
89
Popular Tags