KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > jaxrpc > actions > AddOperationAction


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.websvc.jaxrpc.actions;
20
21 import java.beans.PropertyChangeEvent JavaDoc;
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.util.List JavaDoc;
24 // Retouche
25
//import javax.jmi.reflect.JmiException;
26
//import org.netbeans.jmi.javamodel.ClassMember;
27
//import org.netbeans.jmi.javamodel.JavaClass;
28
//import org.netbeans.jmi.javamodel.JavaModelPackage;
29
//import org.netbeans.jmi.javamodel.Method;
30
//import org.netbeans.jmi.javamodel.Resource;
31
//import org.netbeans.jmi.javamodel.Type;
32
//import org.netbeans.jmi.javamodel.TypeReference;
33
//import org.netbeans.modules.j2ee.common.JMIUtils;
34
//import org.netbeans.modules.j2ee.common.ui.nodes.MethodCollectorFactory;
35
//import org.netbeans.modules.j2ee.common.ui.nodes.MethodCustomizer;
36
//import org.netbeans.modules.javacore.api.JavaModel;
37
//import org.netbeans.modules.javacore.internalapi.JavaMetamodel;
38
//import org.netbeans.modules.websvc.core.jaxws.actions.JaxWsClassesCookie;
39
//import org.netbeans.modules.websvc.core.jaxws.actions.JaxWsCookieFactory;
40
//import org.netbeans.modules.websvc.jaxws.api.JAXWSSupport;
41
//import org.netbeans.modules.websvc.api.jaxws.project.config.Service;
42
//import org.openide.ErrorManager;
43
import org.openide.util.actions.CookieAction;
44 import org.openide.util.HelpCtx;
45 import org.openide.util.NbBundle;
46 import org.openide.nodes.Node;
47 import org.openide.DialogDisplayer;
48 import org.openide.NotifyDescriptor;
49 import java.lang.reflect.Modifier JavaDoc;
50 import org.netbeans.modules.j2ee.dd.api.webservices.WebserviceDescription;
51 import org.openide.filesystems.FileObject;
52 import org.netbeans.modules.websvc.api.webservices.WebServicesSupport;
53
54 public class AddOperationAction extends CookieAction {
55     //private Service service;
56
public String JavaDoc getName() {
57         return NbBundle.getMessage(AddOperationAction.class, "LBL_OperationAction");
58     }
59     
60     public HelpCtx getHelpCtx() {
61         return HelpCtx.DEFAULT_HELP;
62         // If you will provide context help then use:
63
// return new HelpCtx(AddOperationAction.class);
64
}
65     
66     protected int mode() {
67         return MODE_EXACTLY_ONE;
68     }
69     
70     protected Class JavaDoc[] cookieClasses() {
71         return new Class JavaDoc[] {WebServiceClassesCookie.class};
72     }
73     
74     protected boolean asynchronous() {
75         return false;
76     }
77     
78     protected boolean enable(Node[] activatedNodes) {
79         return activatedNodes.length == 1 &&
80 // Retouche
81
// ( activatedNodes[0].getLookup().lookup(ClassMember.class) != null || JMIUtils.getClassMemberFromNode(activatedNodes[0])!=null ) &&
82
// JMIUtils.getJavaClassFromNode(activatedNodes[0]) != null &&
83
(isJaxWsImplementationClass(activatedNodes[0]) ||
84                 (isWsImplBeanOrInterface(activatedNodes[0]) && !isFromWSDL(activatedNodes[0])));
85     }
86     
87     private boolean isWsImplBeanOrInterface(Node node) {
88 // Retouche
89
// JavaClass ce = JMIUtils.getJavaClassFromNode(node);
90
// Resource r = ce.getResource();
91
// FileObject f = JavaModel.getFileObject(r);
92
// if (f != null) {
93
//
94
// WebserviceDescription wsDesc = WebServiceCookieFactory.findWSDescriptionFromClass(ce, f);
95
// if (wsDesc != null) {
96
// return true;
97
// }
98
// }
99
return false;
100     }
101
102     private boolean isJaxWsImplementationClass(Node node) {
103 // Retouche
104
// JavaClass ce = JMIUtils.getJavaClassFromNode(node);
105
// Resource r = ce.getResource();
106
// FileObject fo = JavaModel.getFileObject(r);
107
// JAXWSSupport jaxWsSupport = JAXWSSupport.getJAXWSSupport(fo);
108
// if (jaxWsSupport!=null) {
109
// List services = jaxWsSupport.getServices();
110
// for (int i=0;i<services.size();i++) {
111
// Service serv = (Service)services.get(i);
112
// if (serv.getWsdlUrl()==null) {
113
// String implClass = serv.getImplementationClass();
114
// if (implClass.equals(ce.getName())) {
115
// service=serv;
116
// return true;
117
// }
118
// }
119
// }
120
// }
121
// service=null;
122
return false;
123     }
124     
125     private boolean isFromWSDL(Node node) {
126 // Retouche
127
// JavaClass ce = JMIUtils.getJavaClassFromNode(node);
128
// Resource r = ce.getResource();
129
// FileObject f = JavaModel.getFileObject(r);
130
// if (f != null) {
131
// WebserviceDescription wsDesc = WebServiceCookieFactory.findWSDescriptionFromClass(ce, f);
132
// if (wsDesc != null) {
133
// String wsName = wsDesc.getWebserviceDescriptionName();
134
// WebServicesSupport wsSupport = WebServicesSupport.getWebServicesSupport(f);
135
// assert wsSupport != null;
136
// return wsSupport.isFromWSDL(wsName);
137
// }
138
// }
139
return false;
140     }
141     
142     protected void performAction(Node[] activatedNodes) {
143 // Retouche
144
// JavaMetamodel.getManager().waitScanFinished();
145
//
146
// Node.Cookie cookie=null;
147
// if (service!=null) {
148
// cookie = JaxWsCookieFactory.getJaxWsClassesCookie(service,JMIUtils.getJavaClassFromNode(activatedNodes[0]));
149
// } else {
150
// cookie = WebServiceCookieFactory.getWebServiceClassesCookie(JMIUtils.getJavaClassFromNode(activatedNodes[0]));
151
// }
152
// if (cookie == null) return;
153
//
154
// Method m = null;
155
// JavaClass javaClass = JMIUtils.getJavaClassFromNode(activatedNodes[0]);
156
//
157
// if ((javaClass != null) && (javaClass.isValid())) {
158
// JMIUtils.beginJmiTransaction();
159
// try {
160
// m = JMIUtils.createMethod(javaClass);
161
// m.setModifiers(Modifier.PUBLIC);
162
// m.setName(NbBundle.getMessage(AddOperationAction.class, "TXT_DefaultOperationName")); //NOI18N
163
// // sets 'String' as a default return value for method.
164
// // method.setType(type) can't be used here since it would set
165
// // return value to 'java.lang.String' (#61178)
166
// TypeReference tr =
167
// ((JavaModelPackage)javaClass.refImmediatePackage()).getMultipartId().createMultipartId("String", null, null);
168
// m.setTypeName(tr);
169
//
170
// } catch (JmiException e) {
171
// ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, e.toString());
172
// ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, e.getElementInError().toString());
173
// ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, e.getObjectInError().toString());
174
// } finally {
175
// JMIUtils.endJmiTransaction();
176
// }
177
// if (m == null) {
178
// return;
179
// }
180
//
181
// MethodCustomizer mc = MethodCollectorFactory.operationCollector(m);
182
// final NotifyDescriptor nd = new NotifyDescriptor(mc, NbBundle.getMessage(AddOperationAction.class, "TTL_AddOperation"),
183
// NotifyDescriptor.OK_CANCEL_OPTION,
184
// NotifyDescriptor.PLAIN_MESSAGE,
185
// null, null
186
// );
187
// mc.addPropertyChangeListener(new PropertyChangeListener() {
188
// public void propertyChange(PropertyChangeEvent evt) {
189
// if (evt.getPropertyName().equals(MethodCustomizer.OK_ENABLED)) {
190
// Object newvalue = evt.getNewValue();
191
// if ((newvalue != null) && (newvalue instanceof Boolean)) {
192
// nd.setValid(((Boolean)newvalue).booleanValue());
193
// }
194
// }
195
// }
196
// });
197
// Object rv = DialogDisplayer.getDefault().notify(nd);
198
// mc.isOK(); // apply possible changes in dialog fields
199
// if (rv == NotifyDescriptor.OK_OPTION) {
200
// if (cookie instanceof JaxWsClassesCookie)
201
// ((JaxWsClassesCookie)cookie).addOperation(m);
202
// else
203
// ((WebServiceClassesCookie)cookie).addOperation(m);
204
// }
205
//
206
// }
207

208     }
209 }
210
Popular Tags