KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > refactoring > rename > WebservicesXmlRenameRefactoring


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.j2ee.refactoring.rename;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.text.MessageFormat JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.Collection JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.Map JavaDoc;
29 import javax.jmi.reflect.RefObject;
30 import org.netbeans.api.project.FileOwnerQuery;
31 import org.netbeans.api.project.Project;
32 import org.netbeans.api.project.ProjectUtils;
33 import org.netbeans.jmi.javamodel.ClassDefinition;
34 import org.netbeans.jmi.javamodel.Method;
35 import org.netbeans.jmi.javamodel.UnresolvedClass;
36 import org.netbeans.modules.j2ee.dd.api.web.Filter;
37 import org.netbeans.modules.j2ee.dd.api.web.Listener;
38 import org.netbeans.modules.j2ee.dd.api.web.Servlet;
39 import org.netbeans.modules.j2ee.dd.api.web.WebApp;
40 import org.netbeans.jmi.javamodel.JavaClass;
41 import org.netbeans.jmi.javamodel.Resource;
42 import org.netbeans.modules.j2ee.dd.api.webservices.PortComponent;
43 import org.netbeans.modules.j2ee.dd.api.webservices.PortComponentHandler;
44 import org.netbeans.modules.j2ee.dd.api.webservices.WebserviceDescription;
45 import org.netbeans.modules.j2ee.dd.api.webservices.Webservices;
46 import org.netbeans.modules.j2ee.refactoring.Utility;
47 import org.netbeans.modules.javacore.api.JavaModel;
48 import org.netbeans.modules.javacore.internalapi.ExternalChange;
49 import org.netbeans.modules.javacore.internalapi.JavaMetamodel;
50 import org.netbeans.modules.refactoring.api.AbstractRefactoring;
51 import org.netbeans.modules.refactoring.api.Problem;
52 import org.netbeans.modules.refactoring.api.RefactoringSession;
53 import org.netbeans.modules.refactoring.api.RenameRefactoring;
54 import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
55 import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation;
56 import org.netbeans.modules.schema2beans.QName;
57 import org.netbeans.modules.web.api.webmodule.WebModule;
58 import org.netbeans.modules.websvc.api.webservices.WebServicesSupport;
59 import org.netbeans.modules.websvc.spi.webservices.WebServicesConstants;
60 import org.netbeans.modules.websvc.wsdl.config.api.Configuration;
61 import org.netbeans.spi.project.support.ant.AntProjectHelper;
62 import org.netbeans.spi.project.support.ant.EditableProperties;
63 import org.openide.ErrorManager;
64 import org.openide.filesystems.FileObject;
65 import org.openide.filesystems.FileUtil;
66 import org.openide.util.NbBundle;
67
68 /**
69  *
70  * @author Martin Grebac
71  */

72 public final class WebservicesXmlRenameRefactoring {
73     
74     private static final ErrorManager err = ErrorManager.getDefault().getInstance("org.netbeans.modules.j2ee.refactoring.rename"); // NOI18N
75

76     /* stores collection of interface refactorings to be invoked */
77     ArrayList JavaDoc otherRefactors = new ArrayList JavaDoc();
78     
79     public WebservicesXmlRenameRefactoring() { }
80     
81     public Problem preCheck(RefObject refObject) {
82         
83         Problem problem = null;
84         if (refObject instanceof Method) {
85             
86             Method method = (Method)refObject;
87             Resource res = method.getResource();
88             FileObject fo = JavaModel.getFileObject(res);
89             Collection JavaDoc wsmodules = Utility.getRelevantWSModules(fo);
90             Iterator JavaDoc wsIter = wsmodules.iterator();
91             String JavaDoc methodName = method.getName();
92             ClassDefinition classDef = method.getDeclaringClass(); // get affected class
93

94             if ((wsmodules != null) && (wsmodules.size() > 0)) { // there are web/ejb modules that can be affected by the change
95
while (wsIter.hasNext()) {
96                     WebServicesSupport ws = (WebServicesSupport)wsIter.next();
97                     if (ws != null) {
98                         FileObject webservicesXmlFO = ws.getWebservicesDD();
99                         Webservices webservicesXmlDD = null;
100                         try {
101                             webservicesXmlDD = org.netbeans.modules.j2ee.dd.api.webservices.DDProvider.getDefault().getDDRoot(webservicesXmlFO);
102                         } catch (IOException JavaDoc ioe) {
103                             //ignore
104
}
105                         
106                         if ((webservicesXmlDD != null) && (webservicesXmlDD.getStatus()!=Webservices.STATE_INVALID_UNPARSABLE)) {
107                             WebserviceDescription[] wservices = webservicesXmlDD.getWebserviceDescription();
108                             err.log("Web Services: " + wservices); //NOI18N
109
if ((wservices != null) && (wservices.length > 0)) {
110                                 for (int w=0; w < wservices.length; w++) {
111                                     WebserviceDescription webService = (WebserviceDescription)wservices[w];
112                                     err.log("Web Service: " + webService); //NOI18N
113

114                                     PortComponent[] ports = webService.getPortComponent();
115                                     err.log("Ports: " + ports);
116                                     if ((ports != null) && (ports.length > 0)) {
117                                         for (int p=0; p < ports.length; p++) {
118                                             
119                                             /* First check for presence in webservices.xml port */
120                                             PortComponent portComponent = (PortComponent)ports[p];
121                                             err.log("Port Component: " + portComponent); //NOI18N
122

123                                             /* try to locate the local wscompile config file:
124                                              * get project for webservices.xml, get name of the webservice and try to find properties of the type
125                                              * $propertyname-config.name - if found, get the property valu and the path and locate the descriptor,
126                                              * then get the dd api descriptor object
127                                              */

128                                             
129                                             String JavaDoc portName = portComponent.getPortComponentName();
130                                             Project project = FileOwnerQuery.getOwner(webservicesXmlFO);
131                                             Map JavaDoc properties = ws.getAntProjectHelper().getStandardPropertyEvaluator().getProperties();
132                                             String JavaDoc propertyName = portName + WebServicesConstants.CONFIG_PROP_SUFFIX;
133                                             String JavaDoc propertyValue = (String JavaDoc)properties.get(propertyName);
134                                             
135                                             if (propertyValue != null) { // there's such property in the project
136
FileObject wsConfigXmlFO = null;
137                                                 
138                                                 File JavaDoc f = new File JavaDoc(propertyValue);
139                                                 if (f.isAbsolute()) {
140                                                     wsConfigXmlFO = FileUtil.toFileObject(f);
141                                                 } else {
142                                                     wsConfigXmlFO = project.getProjectDirectory().getFileObject(propertyValue);
143                                                 }
144                                                 if (wsConfigXmlFO != null) {
145                                                     Configuration wsConfigXmlDD = null;
146                                                     try {
147                                                         if (wsConfigXmlFO != null) {
148                                                             wsConfigXmlDD = org.netbeans.modules.websvc.wsdl.config.api.DDProvider.getDefault().getDDRoot(wsConfigXmlFO);
149                                                         }
150                                                     } catch (IOException JavaDoc ioe) {
151                                                         //ignore
152
}
153                                                     if (wsConfigXmlDD != null) {
154                                                         org.netbeans.modules.websvc.wsdl.config.api.Service service = wsConfigXmlDD.getService();
155                                                         if (service != null) {
156                                                             org.netbeans.modules.websvc.wsdl.config.api.Interface[] interfaces = service.getInterface();
157                                                             if ((interfaces != null) && (interfaces.length > 0)) {
158                                                                 for (int ii=0; ii < interfaces.length; ii++) {
159                                                                     org.netbeans.modules.websvc.wsdl.config.api.Interface iface = interfaces[ii];
160                                                                     String JavaDoc servant = iface.getServantName();
161                                                                     String JavaDoc iname = iface.getName();
162                                                                     
163                                                                     if (classDef.getName().equals(iname)) {
164                                                                         
165                                                                         JavaClass jcl = (JavaClass)JavaModel.getDefaultExtent().getType().resolve(servant);
166                                                                         Method beanMethod = null;
167                                                                         if (!(jcl instanceof UnresolvedClass)) {
168                                                                             beanMethod = jcl.getMethod(methodName, Utility.getTypedParams(method.getParameters()), false); //NOI18N
169
err.log("beanmethod: " + beanMethod); //NOI18N
170
}
171                                                                         
172                                                                         RenameRefactoring renameBeanMethod = new RenameRefactoring(beanMethod);
173                                                                         Problem prob = renameBeanMethod.preCheck();
174                                                                         problem = Utility.addProblemsToEnd(problem, prob);
175                                                                         otherRefactors.add(renameBeanMethod);
176                                                                         
177                                                                     } else if (classDef.getName().equals(servant)) {
178                                                                         
179                                                                         JavaClass jcl = (JavaClass)JavaModel.getDefaultExtent().getType().resolve(iname);
180                                                                         Method iMethod = null;
181                                                                         if (!(jcl instanceof UnresolvedClass)) {
182                                                                             iMethod = jcl.getMethod(methodName, Utility.getTypedParams(method.getParameters()), false); //NOI18N
183
err.log("ifacemethod: " + iMethod); //NOI18N
184
}
185                                                                         
186                                                                         RenameRefactoring renameIfaceMethod = new RenameRefactoring(iMethod);
187                                                                         Problem prob = renameIfaceMethod.preCheck();
188                                                                         problem = Utility.addProblemsToEnd(problem, prob);
189                                                                         otherRefactors.add(renameIfaceMethod);
190                                                                     }
191                                                                 }
192                                                             }
193                                                         }
194                                                     } else {
195                                                         Problem newProblem = new Problem(false, NbBundle.getMessage(WebservicesXmlRenameRefactoring.class, "TXT_WebservicesConfigXmlRenameInvalidProblem")); //NOI18N
196
problem = Utility.addProblemsToEnd(problem, newProblem);
197                                                     }
198                                                 }
199                                             }
200                                         }
201                                     }
202                                 }
203                             }
204                         }
205                     }
206                 } //while
207
}
208         } // method
209

210         err.log("other refactors: " + otherRefactors); //NOI18N
211
return problem;
212     }
213     
214     public Problem fastCheckParameters(RefObject refObject, String JavaDoc newName) {
215         Problem problem = null;
216         if (refObject instanceof Method) {
217             for (int i=0; i < otherRefactors.size(); i++) {
218                 RenameRefactoring rr = (RenameRefactoring)otherRefactors.get(i);
219                 rr.setNewName(newName);
220                 Problem p = rr.fastCheckParameters();
221                 problem = Utility.addProblemsToEnd(problem, p);
222             }
223         }
224         return problem;
225     }
226     
227     public Problem checkParameters(RefObject refObject, String JavaDoc newName) {
228         return fastCheckParameters(refObject, newName);
229     }
230     
231     /** Find usages in web deployment descriptor: web.xml
232      */

233     public Problem prepare(AbstractRefactoring refactor, RefObject refObject, String JavaDoc newName, RefactoringElementsBag refactoringElements) {
234         
235         RefactoringSession session = refactoringElements.getSession();
236         Problem problem = null;
237         if (refObject instanceof JavaClass) {
238             
239             JavaClass jClass = (JavaClass)refObject;
240             
241             String JavaDoc name = jClass.getName();
242             err.log("name: " + name); //NOI18N
243

244             String JavaDoc newSimpleName = newName;
245             err.log("newSimpleName: " + newSimpleName); //NOI18N
246

247             newName = name.substring(0, name.lastIndexOf('.') + 1) + newName;
248             err.log("newName: " + newName); //NOI18N
249

250             Resource res = jClass.getResource();
251             FileObject fo = JavaModel.getFileObject(res);
252             
253             WebServicesSupport wsm = WebServicesSupport.getWebServicesSupport(fo);
254             if (wsm != null) { // the class is in a module with web services support
255

256                 FileObject webservicesXmlFO = wsm.getWebservicesDD();
257                 Webservices webservicesXmlDD = null;
258                 try {
259                     webservicesXmlDD = org.netbeans.modules.j2ee.dd.api.webservices.DDProvider.getDefault().getDDRoot(webservicesXmlFO);
260                 } catch (IOException JavaDoc ioe) {
261                     //ignore
262
}
263                 
264                 if ((webservicesXmlDD != null) && (webservicesXmlDD.getStatus()!=Webservices.STATE_INVALID_UNPARSABLE)) {
265                     WebserviceDescription[] wservices = webservicesXmlDD.getWebserviceDescription();
266                     err.log("Web Services: " + wservices); //NOI18N
267
if ((wservices != null) && (wservices.length > 0)) {
268                         for (int w=0; w < wservices.length; w++) {
269                             WebserviceDescription webService = (WebserviceDescription)wservices[w];
270                             err.log("Web Service: " + webService); //NOI18N
271

272                             /* And update the actual web service reference direct in webservices.xml */
273                             PortComponent[] ports = webService.getPortComponent();
274                             err.log("Ports: " + ports);
275                             if ((ports != null) && (ports.length > 0)) {
276                                 for (int p=0; p < ports.length; p++) {
277                                     
278                                     /* First check for presence in webservices.xml port */
279                                     PortComponent portComponent = (PortComponent)ports[p];
280                                     err.log("Port Component: " + portComponent); //NOI18N
281

282                                     // check message handlers
283
PortComponentHandler[] handlers = portComponent.getHandler();
284                                     for (int k = 0; k < handlers.length; k++) {
285                                         if (name.equals(handlers[k].getHandlerClass())){
286                                             RefactoringElementImplementation elem = new WebservicesHandlerRenameRefactoringElement(webservicesXmlDD, name, newName, handlers[k], webservicesXmlFO);
287                                             refactoringElements.add(refactor, elem);
288                                         }
289                                     }
290                                     
291                                     // wsdl-port is generated from sei class name as well
292
QName wsdlPort = portComponent.getWsdlPort();
293                                     err.log("WSDL Port: " + wsdlPort); //NOI18N
294
if (wsdlPort != null) {
295                                         String JavaDoc localPart = wsdlPort.getLocalPart();
296                                         if (jClass.getSimpleName().concat("Port").equals(localPart)) { //NOI18N
297
String JavaDoc newLocalPart = newSimpleName.concat("Port"); //NOI18N
298
QName newPort = new QName(wsdlPort.getNamespaceURI(), newLocalPart, wsdlPort.getPrefix());
299                                             RefactoringElementImplementation elem =
300                                                     new WebservicesWsdlPortRenameRefactoringElement(
301                                                     webservicesXmlDD, wsdlPort, newPort, portComponent, webservicesXmlFO); //NOI18N
302
refactoringElements.add(refactor, elem);
303                                         }
304                                     }
305                                     
306                                     String JavaDoc serviceEndpointInterface = portComponent.getServiceEndpointInterface();
307                                     err.log("serviceEndpointInterface: " + serviceEndpointInterface); //NOI18N
308
if ((serviceEndpointInterface != null) && (serviceEndpointInterface.equals(name))) {
309                                         RefactoringElementImplementation elem = new WebservicesSEIRenameRefactoringElement(webservicesXmlDD, name, newName, portComponent, webservicesXmlFO);
310                                         refactoringElements.add(refactor, elem);
311                                     }
312                                     /* try to locate the local wscompile config file:
313                                      * get project for webservices.xml, get name of the webservice and try to find properties of the type
314                                      * $propertyname-config.name - if found, get the property valu and the path and locate the descriptor,
315                                      * then get the dd api descriptor object
316                                      */

317                                     String JavaDoc portName = portComponent.getPortComponentName();
318                                     Project project = FileOwnerQuery.getOwner(webservicesXmlFO);
319                                     Map JavaDoc properties = wsm.getAntProjectHelper().getStandardPropertyEvaluator().getProperties();
320                                     String JavaDoc propertyName = portName + WebServicesConstants.CONFIG_PROP_SUFFIX;
321                                     String JavaDoc propertyValue = (String JavaDoc)properties.get(propertyName);
322                                     if (propertyValue != null) { // there's such property in the project
323
FileObject wsConfigXmlFO = null;
324                                         
325                                         File JavaDoc f = new File JavaDoc(propertyValue);
326                                         if (f.isAbsolute()) {
327                                             wsConfigXmlFO = FileUtil.toFileObject(f);
328                                         } else {
329                                             wsConfigXmlFO = project.getProjectDirectory().getFileObject(propertyValue);
330                                         }
331                                         if (wsConfigXmlFO != null) {
332                                             Configuration wsConfigXmlDD = null;
333                                             try {
334                                                 wsConfigXmlDD = org.netbeans.modules.websvc.wsdl.config.api.DDProvider.getDefault().getDDRoot(wsConfigXmlFO);
335                                             } catch (IOException JavaDoc ioe) {
336                                                 //ignore
337
}
338                                             if (wsConfigXmlDD != null) {
339                                                 org.netbeans.modules.websvc.wsdl.config.api.Service service = wsConfigXmlDD.getService();
340                                                 if (service != null) {
341                                                     org.netbeans.modules.websvc.wsdl.config.api.Interface[] interfaces = service.getInterface();
342                                                     if ((interfaces != null) && (interfaces.length > 0)) {
343                                                         for (int ii=0; ii < interfaces.length; ii++) {
344                                                             org.netbeans.modules.websvc.wsdl.config.api.Interface iface = interfaces[ii];
345                                                             String JavaDoc servant = iface.getServantName();
346                                                             String JavaDoc iname = iface.getName();
347                                                             if ((servant != null) && (servant.equals(name))) {
348                                                                 RefactoringElementImplementation elem = new WebservicesConfigXmlServantRenameRefactoringElement(wsConfigXmlDD, name, newName, iface, wsConfigXmlFO);
349                                                                 refactoringElements.add(refactor, elem);
350                                                             }
351                                                             if ((iname != null) && (iname.equals(name))) {
352                                                                 RefactoringElementImplementation elem = new WebservicesConfigXmlInterfaceRenameRefactoringElement(wsConfigXmlDD, name, newName, iface, wsConfigXmlFO);
353                                                                 refactoringElements.add(refactor, elem);
354                                                             }
355                                                         }
356                                                     }
357                                                 }
358                                             } else {
359                                                 Problem newProblem = new Problem(false, NbBundle.getMessage(WebservicesXmlRenameRefactoring.class, "TXT_WebservicesConfigXmlRenameInvalidProblem")); //NOI18N
360
problem = Utility.addProblemsToEnd(problem, newProblem);
361                                             }
362                                         }
363                                     }
364                                 }
365                             }
366                         }
367                     }
368                 } else if (webservicesXmlDD != null) {
369                     Problem newProblem = new Problem(false, NbBundle.getMessage(WebservicesXmlRenameRefactoring.class, "TXT_WebservicesXmlRenameInvalidProblem")); //NOI18N
370
if (problem == null) {
371                         problem = newProblem;
372                     } else {
373                         if (newProblem != null) problem.setNext(newProblem);
374                     }
375                 }
376             } //refactor webservices.xml
377
} // javaclass
378

379         if (refObject instanceof Method) {
380             for (int i=0; i < otherRefactors.size(); i++) {
381                 RenameRefactoring rr = (RenameRefactoring)otherRefactors.get(i);
382                 Problem p = rr.prepare(session);
383                 problem = Utility.addProblemsToEnd(problem, p);
384             }
385             return problem;
386         }
387         
388         return problem;
389     }
390     
391     public final class WebservicesSEIRenameRefactoringElement extends AbstractRenameRefactoringElement implements ExternalChange {
392         
393         protected Webservices webservicesXmlDD;
394         private PortComponent portComponent;
395         
396         /** Creates a new instance of WebservicesSEIRenameRefactoringElement */
397         public WebservicesSEIRenameRefactoringElement(Webservices webservicesXmlDD, String JavaDoc oldName, String JavaDoc newName, PortComponent portComponent, FileObject parentFile) {
398             this.webservicesXmlDD = webservicesXmlDD;
399             this.oldName = oldName;
400             this.newName = newName;
401             this.portComponent = portComponent;
402             this.parentFile = parentFile;
403         }
404         
405         /** Returns text describing the refactoring formatted for display (using HTML tags).
406          * @return Formatted text.
407          */

408         public String JavaDoc getDisplayText() {
409             Object JavaDoc[] args = new Object JavaDoc [] {parentFile.getNameExt(), oldName, newName};
410             return MessageFormat.format(NbBundle.getMessage(WebservicesXmlRenameRefactoring.class, "TXT_WebservicesXmlSEIRename"), args); //NOI18N
411
}
412         
413         /** Performs the change represented by this refactoring element.
414          */

415         public void performChange() {
416             JavaMetamodel.getManager().registerExtChange(this);
417         }
418         
419         public void performExternalChange() {
420             portComponent.setServiceEndpointInterface(newName);
421             try {
422                 webservicesXmlDD.write(parentFile);
423             } catch (IOException JavaDoc ioe) {
424                 //TODO
425
}
426         }
427         
428         public void undoExternalChange() {
429             portComponent.setServiceEndpointInterface(oldName);
430             try {
431                 webservicesXmlDD.write(parentFile);
432             } catch (IOException JavaDoc ioe) {
433                 //TODO
434
}
435         }
436     }
437     
438     /**
439      * Rename refactoring element for message handlers.
440      */

441     public final class WebservicesHandlerRenameRefactoringElement extends AbstractRenameRefactoringElement implements ExternalChange {
442         
443         protected Webservices webservicesXmlDD;
444         private PortComponentHandler handler;
445         
446         public WebservicesHandlerRenameRefactoringElement(Webservices webservicesXmlDD, String JavaDoc oldName, String JavaDoc newName, PortComponentHandler handler, FileObject parentFile) {
447             this.webservicesXmlDD = webservicesXmlDD;
448             this.oldName = oldName;
449             this.newName = newName;
450             this.handler = handler;
451             this.parentFile = parentFile;
452         }
453         
454         /** Returns text describing the refactoring formatted for display (using HTML tags).
455          * @return Formatted text.
456          */

457         public String JavaDoc getDisplayText() {
458             Object JavaDoc[] args = new Object JavaDoc [] {parentFile.getNameExt(), oldName, newName};
459             return MessageFormat.format(NbBundle.getMessage(WebservicesXmlRenameRefactoring.class, "TXT_WebservicesXmlHandlerRename"), args); //NOI18N
460
}
461         
462         /** Performs the change represented by this refactoring element.
463          */

464         public void performChange() {
465             JavaMetamodel.getManager().registerExtChange(this);
466         }
467         
468         public void performExternalChange() {
469             handler.setHandlerClass(newName);
470             write();
471         }
472         
473         public void undoExternalChange() {
474             handler.setHandlerClass(oldName);
475             write();
476         }
477         
478         private void write(){
479             try {
480                 webservicesXmlDD.write(parentFile);
481             } catch (IOException JavaDoc ioe) {
482                 ErrorManager.getDefault().notify(ioe);
483             }
484         }
485     }
486     public final class WebservicesWsdlPortRenameRefactoringElement extends AbstractRenameRefactoringElement implements ExternalChange {
487         
488         protected Webservices webservicesXmlDD;
489         private PortComponent portComponent;
490         
491         private QName oldPort;
492         private QName newPort;
493         
494         /** Creates a new instance of WebservicesWsdlPortRenameRefactoringElement */
495         public WebservicesWsdlPortRenameRefactoringElement(Webservices webservicesXmlDD, QName oldPort, QName newPort, PortComponent portComponent, FileObject parentFile) {
496             this.webservicesXmlDD = webservicesXmlDD;
497             this.oldPort = oldPort;
498             this.newPort = newPort;
499             this.portComponent = portComponent;
500             this.parentFile = parentFile;
501         }
502         
503         /** Returns text describing the refactoring formatted for display (using HTML tags).
504          * @return Formatted text.
505          */

506         public String JavaDoc getDisplayText() {
507             String JavaDoc oldStr = oldPort.getPrefix() + ":" + oldPort.getLocalPart(); //NOI18N
508
String JavaDoc newStr = newPort.getPrefix() + ":" + newPort.getLocalPart(); //NOI18N
509

510             Object JavaDoc[] args = new Object JavaDoc [] {parentFile.getNameExt(), oldStr, newStr};
511             return MessageFormat.format(NbBundle.getMessage(WebservicesXmlRenameRefactoring.class, "TXT_WebservicesXmlWsdlPortRename"), args); //NOI18N
512
}
513         
514         /** Performs the change represented by this refactoring element.
515          */

516         public void performChange() {
517             JavaMetamodel.getManager().registerExtChange(this);
518         }
519         
520         public void performExternalChange() {
521             portComponent.setWsdlPort(newPort);
522             try {
523                 webservicesXmlDD.write(parentFile);
524             } catch (IOException JavaDoc ioe) {
525                 //TODO
526
}
527         }
528         
529         public void undoExternalChange() {
530             portComponent.setWsdlPort(oldPort);
531             try {
532                 webservicesXmlDD.write(parentFile);
533             } catch (IOException JavaDoc ioe) {
534                 //TODO
535
}
536         }
537     }
538     
539     public final class WebservicesConfigXmlServantRenameRefactoringElement extends AbstractRenameRefactoringElement implements ExternalChange {
540         
541         protected Configuration wsConfigXmlDD;
542         private org.netbeans.modules.websvc.wsdl.config.api.Interface iface;
543         
544         /** Creates a new instance of WebservicesConfigXmlServantRenameRefactoringElement */
545         public WebservicesConfigXmlServantRenameRefactoringElement(Configuration wsConfigXmlDD, String JavaDoc oldName, String JavaDoc newName, org.netbeans.modules.websvc.wsdl.config.api.Interface iface, FileObject parentFile) {
546             this.wsConfigXmlDD = wsConfigXmlDD;
547             this.oldName = oldName;
548             this.newName = newName;
549             this.iface = iface;
550             this.parentFile = parentFile;
551         }
552         
553         /** Returns text describing the refactoring formatted for display (using HTML tags).
554          * @return Formatted text.
555          */

556         public String JavaDoc getDisplayText() {
557             Object JavaDoc[] args = new Object JavaDoc [] {parentFile.getNameExt(), oldName, newName};
558             return MessageFormat.format(NbBundle.getMessage(WebservicesXmlRenameRefactoring.class, "TXT_WebservicesConfigXmlServantRename"), args); //NOI18N
559
}
560         
561         /** Performs the change represented by this refactoring element.
562          */

563         public void performChange() {
564             JavaMetamodel.getManager().registerExtChange(this);
565         }
566         
567         public void performExternalChange() {
568             iface.setServantName(newName);
569             try {
570                 wsConfigXmlDD.write(parentFile);
571             } catch (IOException JavaDoc ioe) {
572                 //TODO
573
}
574         }
575         
576         public void undoExternalChange() {
577             iface.setServantName(oldName);
578             try {
579                 wsConfigXmlDD.write(parentFile);
580             } catch (IOException JavaDoc ioe) {
581                 //TODO
582
}
583         }
584     }
585     
586     public final class WebservicesConfigXmlInterfaceRenameRefactoringElement extends AbstractRenameRefactoringElement implements ExternalChange {
587         
588         protected Configuration wsConfigXmlDD;
589         private org.netbeans.modules.websvc.wsdl.config.api.Interface iface;
590         
591         /** Creates a new instance of WebservicesConfigXmlInterfaceRenameRefactoringElement */
592         public WebservicesConfigXmlInterfaceRenameRefactoringElement(Configuration wsConfigXmlDD, String JavaDoc oldName, String JavaDoc newName, org.netbeans.modules.websvc.wsdl.config.api.Interface iface, FileObject parentFile) {
593             this.wsConfigXmlDD = wsConfigXmlDD;
594             this.oldName = oldName;
595             this.newName = newName;
596             this.iface = iface;
597             this.parentFile = parentFile;
598         }
599         
600         /** Returns text describing the refactoring formatted for display (using HTML tags).
601          * @return Formatted text.
602          */

603         public String JavaDoc getDisplayText() {
604             Object JavaDoc[] args = new Object JavaDoc [] {parentFile.getNameExt(), oldName, newName};
605             return MessageFormat.format(NbBundle.getMessage(WebservicesXmlRenameRefactoring.class, "TXT_WebservicesConfigXmlInterfaceRename"), args); //NOI18N
606
}
607         
608         /** Performs the change represented by this refactoring element.
609          */

610         public void performChange() {
611             JavaMetamodel.getManager().registerExtChange(this);
612         }
613         
614         public void performExternalChange() {
615             iface.setName(newName);
616             try {
617                 wsConfigXmlDD.write(parentFile);
618             } catch (IOException JavaDoc ioe) {
619                 //TODO
620
}
621         }
622         
623         public void undoExternalChange() {
624             iface.setName(oldName);
625             try {
626                 wsConfigXmlDD.write(parentFile);
627             } catch (IOException JavaDoc ioe) {
628                 //TODO
629
}
630         }
631     }
632     
633 }
634
Popular Tags