KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > wsitconf > refactoring > WSITXmlRenameRefactoring


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
20 package org.netbeans.modules.websvc.wsitconf.refactoring;
21
22 import java.io.IOException JavaDoc;
23 import java.text.MessageFormat JavaDoc;
24 import java.util.Collection JavaDoc;
25 //import javax.jmi.reflect.RefObject;
26
import javax.xml.namespace.QName JavaDoc;
27 //import org.netbeans.jmi.javamodel.Annotation;
28
//import org.netbeans.jmi.javamodel.AttributeValue;
29
//import org.netbeans.jmi.javamodel.JavaClass;
30
//import org.netbeans.jmi.javamodel.Method;
31
//import org.netbeans.jmi.javamodel.Resource;
32
//import org.netbeans.modules.javacore.api.JavaModel;
33
//import org.netbeans.modules.javacore.internalapi.JavaMetamodel;
34
//import org.netbeans.modules.refactoring.api.AbstractRefactoring;
35
//import org.netbeans.modules.refactoring.api.Problem;
36
//import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
37
//import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation;
38
import org.netbeans.modules.websvc.jaxws.api.JAXWSSupport;
39 //import org.netbeans.modules.websvc.wsitconf.util.JMIUtils;
40
import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.WSITModelSupport;
41 import static org.netbeans.modules.websvc.wsitconf.wsdlmodelext.WSITModelSupport.CONFIG_WSDL_EXTENSION;
42 import static org.netbeans.modules.websvc.wsitconf.wsdlmodelext.WSITModelSupport.CONFIG_WSDL_SERVICE_PREFIX;
43 import org.netbeans.modules.xml.wsdl.model.Binding;
44 import org.netbeans.modules.xml.wsdl.model.BindingOperation;
45 import org.netbeans.modules.xml.wsdl.model.Definitions;
46 import org.netbeans.modules.xml.wsdl.model.Input;
47 import org.netbeans.modules.xml.wsdl.model.Message;
48 import org.netbeans.modules.xml.wsdl.model.Operation;
49 import org.netbeans.modules.xml.wsdl.model.Output;
50 import org.netbeans.modules.xml.wsdl.model.PortType;
51 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
52 import org.openide.ErrorManager;
53 import org.openide.filesystems.FileLock;
54 import org.openide.filesystems.FileObject;
55 import org.openide.util.NbBundle;
56
57 /**
58  *
59  * @author Martin Grebac
60  */

61 public final class WSITXmlRenameRefactoring {
62     
63     /**
64      * Name of an annotation that represents web service.
65      */

66     protected static final String JavaDoc WS_ANNOTATION = "WebService";
67     /**
68      * Name of an annotation element that represents wsdl location.
69      */

70     protected static final String JavaDoc WSDL_LOCATION_ELEMENT = "wsdlLocation";
71
72     private static final ErrorManager err = ErrorManager.getDefault().getInstance("org.netbeans.modules.websvc.wsitconf.refactoring"); // NOI18N
73

74     public WSITXmlRenameRefactoring() { }
75     
76 // public Problem precheck() {
77
// return null;
78
// }
79
//
80
// /** Find usages in wsit deployment descriptors: wsit-*.xml
81
// */
82
// public Problem prepare(AbstractRefactoring refactoring, RefObject refObject, String newName, RefactoringElementsBag refactoringElements) {
83
//
84
// if (refObject instanceof JavaClass) {
85
// JavaClass javaClass = (JavaClass) refObject;
86
// if (isWebSvcFromWsdl(javaClass)) {
87
// return null;
88
// }
89
// Resource r = javaClass.getResource();
90
// FileObject fo = JavaModel.getFileObject(r);
91
// JAXWSSupport supp = JAXWSSupport.getJAXWSSupport(fo);
92
// WSDLModel model = null;
93
// try {
94
// model = WSITModelSupport.getModelForServiceFromJava(javaClass, supp, false, null);
95
// } catch (IOException ex) {
96
// ex.printStackTrace();
97
// } catch (Exception ex) {
98
// ex.printStackTrace();
99
// }
100
// if (model == null){
101
// return null;
102
// }
103
//
104
// RefactoringElementImplementation refactoringElem =
105
// new WSITXmlClassRenameRefactoringElement(javaClass.getName(), newName, model);
106
// refactoringElements.add(refactoring, refactoringElem);
107
//
108
// } else if (refObject instanceof Method) {
109
// Method mtd = (Method)refObject;
110
// JavaClass javaClass = JMIUtils.getDeclaringClass(mtd);
111
// if (isWebSvcFromWsdl(javaClass)) {
112
// return null;
113
// }
114
// Resource r = mtd.getResource();
115
// FileObject fo = JavaModel.getFileObject(r);
116
// JAXWSSupport supp = JAXWSSupport.getJAXWSSupport(fo);
117
// WSDLModel model = null;
118
// try {
119
// model = WSITModelSupport.getModelForServiceFromJava(javaClass, supp, false, null);
120
// } catch (IOException ex) {
121
// ex.printStackTrace();
122
// } catch (Exception ex) {
123
// ex.printStackTrace();
124
// }
125
// if (model == null){
126
// return null;
127
// }
128
//
129
// RefactoringElementImplementation refactoringElem =
130
// new WSITXmlMethodRenameRefactoringElement(mtd.getName(), newName, model);
131
// refactoringElements.add(refactoring, refactoringElem);
132
// }
133
//
134
// return null;
135
// }
136
//
137
// Problem preCheck(RefObject refO) {
138
// return null;
139
// }
140
//
141
// /**
142
// * Rename refactoring element for wsit-*.xml
143
// */
144
// private static class WSITXmlClassRenameRefactoringElement extends AbstractRenameRefactoringElement {
145
//
146
// private String oldConfigName, newConfigName;
147
//
148
// /**
149
// * Creates a new instance of WSITXmlClassRenameRefactoringElement
150
// *
151
// * @param oldName the fully qualified old name of the implementation class
152
// * @param newName the fully qualified new name of the implementation class
153
// */
154
// public WSITXmlClassRenameRefactoringElement(String oldName, String newName, WSDLModel model) {
155
// this.oldName = oldName;
156
// this.newName = newName;
157
// this.oldConfigName = CONFIG_WSDL_SERVICE_PREFIX + oldName;
158
// String pkg = oldName.substring(0, oldName.lastIndexOf('.')+1);
159
// this.newConfigName = CONFIG_WSDL_SERVICE_PREFIX + pkg + newName;
160
// this.model = model;
161
// this.parentFile = (FileObject) model.getModelSource().getLookup().lookup(FileObject.class);
162
// }
163
//
164
// public void performExternalChange() {
165
// FileLock lock;
166
// try {
167
// lock = parentFile.lock();
168
// parentFile.rename(lock, newConfigName, CONFIG_WSDL_EXTENSION);
169
// lock.releaseLock();
170
// } catch (IOException ex) {
171
// ex.printStackTrace();
172
// }
173
// }
174
//
175
// public void undoExternalChange() {
176
// FileLock lock;
177
// try {
178
// lock = parentFile.lock();
179
// parentFile.rename(lock, oldConfigName, CONFIG_WSDL_EXTENSION);
180
// lock.releaseLock();
181
// } catch (IOException ex) {
182
// ex.printStackTrace();
183
// }
184
// }
185
//
186
// public void performChange() {
187
// JavaMetamodel.getManager().registerExtChange(this);
188
// }
189
//
190
// /**
191
// * Returns text describing the refactoring formatted for display (using HTML tags).
192
// * @return Formatted text.
193
// */
194
// public String getDisplayText() {
195
// Object[] args = new Object [] {oldConfigName, newConfigName};
196
// return MessageFormat.format(NbBundle.getMessage(WSITXmlClassRenameRefactoringElement.class, "TXT_WsitXmlClassRename"), args);
197
// }
198
// }
199
//
200
// /**
201
// * Rename refactoring element for wsit-*.xml
202
// */
203
// private static class WSITXmlMethodRenameRefactoringElement extends AbstractRenameRefactoringElement {
204
//
205
// /**
206
// * Creates a new instance of WSITXmlMethodRenameRefactoringElement
207
// *
208
// * @param oldName old name of operation
209
// * @param newName new name of operation
210
// */
211
// public WSITXmlMethodRenameRefactoringElement(String oldName, String newName, WSDLModel model) {
212
// this.oldName = oldName;
213
// this.newName = newName;
214
// this.model = model;
215
// this.parentFile = (FileObject) model.getModelSource().getLookup().lookup(FileObject.class);
216
// }
217
//
218
// public void performExternalChange() {
219
// Definitions d = model.getDefinitions();
220
// Binding b = (Binding) d.getBindings().toArray()[0];
221
// Collection<BindingOperation> bOperations = b.getBindingOperations();
222
// PortType portType = (PortType) d.getPortTypes().toArray()[0];
223
// Collection<Operation> operations = portType.getOperations();
224
// model.startTransaction();
225
//
226
// for (BindingOperation bOperation : bOperations) {
227
// if (oldName.equals(bOperation.getName())) {
228
// bOperation.setName(newName);
229
// }
230
// }
231
//
232
// for (Operation o : operations) {
233
// if (oldName.equals(o.getName())) {
234
// o.setName(newName);
235
// Input i = o.getInput();
236
// if (i != null) {
237
// QName qname = i.getMessage().getQName();
238
// Message msg = model.findComponentByName(qname, Message.class);
239
// String oMsgName = msg.getName();
240
// if (oMsgName != null) {
241
// String nMsgName = oMsgName.replaceAll(oldName, newName);
242
// msg.setName(nMsgName);
243
// }
244
// i.setMessage(i.createReferenceTo(msg, Message.class));
245
// }
246
// Output out = o.getOutput();
247
// if (out != null) {
248
// QName qname = out.getMessage().getQName();
249
// Message msg = model.findComponentByName(qname, Message.class);
250
// String oMsgName = msg.getName();
251
// if (oMsgName != null) {
252
// String nMsgName = oMsgName.replaceAll(oldName, newName);
253
// msg.setName(nMsgName);
254
// }
255
// out.setMessage(out.createReferenceTo(msg, Message.class));
256
// }
257
// }
258
// }
259
// model.endTransaction();
260
// }
261
//
262
// public void undoExternalChange() {
263
// Definitions d = model.getDefinitions();
264
// Binding b = (Binding) d.getBindings().toArray()[0];
265
// Collection<BindingOperation> bOperations = b.getBindingOperations();
266
// PortType portType = (PortType) d.getPortTypes().toArray()[0];
267
// Collection<Operation> operations = portType.getOperations();
268
// model.startTransaction();
269
// for (BindingOperation bOperation : bOperations) {
270
// if (newName.equals(bOperation.getName())) {
271
// bOperation.setName(oldName);
272
// }
273
// }
274
// for (Operation o : operations) {
275
// if (newName.equals(o.getName())) {
276
// o.setName(oldName);
277
// Input i = o.getInput();
278
// if (i != null) {
279
// QName qname = i.getMessage().getQName();
280
// Message msg = model.findComponentByName(qname, Message.class);
281
// String oMsgName = msg.getName();
282
// if (oMsgName != null) {
283
// String nMsgName = oMsgName.replaceAll(newName, oldName);
284
// msg.setName(nMsgName);
285
// }
286
// i.setMessage(i.createReferenceTo(msg, Message.class));
287
// }
288
// Output out = o.getOutput();
289
// if (out != null) {
290
// QName qname = out.getMessage().getQName();
291
// Message msg = model.findComponentByName(qname, Message.class);
292
// String oMsgName = msg.getName();
293
// if (oMsgName != null) {
294
// String nMsgName = oMsgName.replaceAll(newName, oldName);
295
// msg.setName(nMsgName);
296
// }
297
// out.setMessage(out.createReferenceTo(msg, Message.class));
298
// }
299
// }
300
// }
301
// model.endTransaction();
302
// }
303
//
304
// public void performChange() {
305
// JavaMetamodel.getManager().registerExtChange(this);
306
// }
307
//
308
// /**
309
// * Returns text describing the refactoring formatted for display (using HTML tags).
310
// * @return Formatted text.
311
// */
312
// public String getDisplayText() {
313
// Object[] args = new Object [] {oldName, newName};
314
// return MessageFormat.format(NbBundle.getMessage(WSITXmlMethodRenameRefactoringElement.class, "TXT_WsitXmlMethodRename"), args);
315
// }
316
// }
317
//
318
// /**
319
// * @return true if the given javaClass represents a web service from wsdl.
320
// */
321
// protected boolean isWebSvcFromWsdl(JavaClass javaClass){
322
// for (Object elem : javaClass.getAnnotations()) {
323
// Annotation ann = (Annotation) elem;
324
// if (ann.getTypeName() == null){
325
// continue;
326
// }
327
// if (ann.getTypeName().getName().equals(WS_ANNOTATION)){
328
// for (Object elem2 : ann.getAttributeValues()) {
329
// AttributeValue value = (AttributeValue) elem2;
330
// if (value.getName().equals(WSDL_LOCATION_ELEMENT)){
331
// return true;
332
// }
333
// }
334
// }
335
// }
336
// return false;
337
// }
338
}
339
Popular Tags