~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to j2ee/refactoring/src/org/netbeans/modules/j2ee/refactoring/rename/WebservicesXmlRenameRefactoring.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
6
 * The contents of this file are subject to the terms of either the GNU
 
7
 * General Public License Version 2 only ("GPL") or the Common
 
8
 * Development and Distribution License("CDDL") (collectively, the
 
9
 * "License"). You may not use this file except in compliance with the
 
10
 * License. You can obtain a copy of the License at
 
11
 * http://www.netbeans.org/cddl-gplv2.html
 
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
 
13
 * specific language governing permissions and limitations under the
 
14
 * License.  When distributing the software, include this License Header
 
15
 * Notice in each file and include the License file at
 
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
 
17
 * particular file as subject to the "Classpath" exception as provided
 
18
 * by Sun in the GPL Version 2 section of the License file that
 
19
 * accompanied this code. If applicable, add the following below the
 
20
 * License Header, with the fields enclosed by brackets [] replaced by
 
21
 * your own identifying information:
 
22
 * "Portions Copyrighted [year] [name of copyright owner]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * The Original Software is NetBeans. The Initial Developer of the Original
 
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
 
28
 * Microsystems, Inc. All Rights Reserved.
 
29
 *
 
30
 * If you wish your version of this file to be governed by only the CDDL
 
31
 * or only the GPL Version 2, indicate your decision by adding
 
32
 * "[Contributor] elects to include this software in this distribution
 
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
 
34
 * single choice of license, a recipient has the option to distribute
 
35
 * your version of this file under either the CDDL, the GPL Version 2 or
 
36
 * to extend the choice of license to its licensees as provided above.
 
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
 
38
 * Version 2 license, then the option applies only if the new code is
 
39
 * made subject to such option by the copyright holder.
 
40
 */
 
41
 
 
42
package org.netbeans.modules.j2ee.refactoring.rename;
 
43
 
 
44
import java.io.File;
 
45
import java.io.IOException;
 
46
import java.text.MessageFormat;
 
47
import java.util.ArrayList;
 
48
import java.util.Collection;
 
49
import java.util.Iterator;
 
50
import java.util.Map;
 
51
import javax.jmi.reflect.RefObject;
 
52
import org.netbeans.api.project.FileOwnerQuery;
 
53
import org.netbeans.api.project.Project;
 
54
import org.netbeans.api.project.ProjectUtils;
 
55
import org.netbeans.jmi.javamodel.ClassDefinition;
 
56
import org.netbeans.jmi.javamodel.Method;
 
57
import org.netbeans.jmi.javamodel.UnresolvedClass;
 
58
import org.netbeans.modules.j2ee.dd.api.web.Filter;
 
59
import org.netbeans.modules.j2ee.dd.api.web.Listener;
 
60
import org.netbeans.modules.j2ee.dd.api.web.Servlet;
 
61
import org.netbeans.modules.j2ee.dd.api.web.WebApp;
 
62
import org.netbeans.jmi.javamodel.JavaClass;
 
63
import org.netbeans.jmi.javamodel.Resource;
 
64
import org.netbeans.modules.j2ee.dd.api.webservices.PortComponent;
 
65
import org.netbeans.modules.j2ee.dd.api.webservices.PortComponentHandler;
 
66
import org.netbeans.modules.j2ee.dd.api.webservices.WebserviceDescription;
 
67
import org.netbeans.modules.j2ee.dd.api.webservices.Webservices;
 
68
import org.netbeans.modules.j2ee.refactoring.Utility;
 
69
import org.netbeans.modules.javacore.api.JavaModel;
 
70
import org.netbeans.modules.javacore.internalapi.ExternalChange;
 
71
import org.netbeans.modules.javacore.internalapi.JavaMetamodel;
 
72
import org.netbeans.modules.refactoring.api.AbstractRefactoring;
 
73
import org.netbeans.modules.refactoring.api.Problem;
 
74
import org.netbeans.modules.refactoring.api.RefactoringSession;
 
75
import org.netbeans.modules.refactoring.api.RenameRefactoring;
 
76
import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
 
77
import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation;
 
78
import org.netbeans.modules.schema2beans.QName;
 
79
import org.netbeans.modules.web.api.webmodule.WebModule;
 
80
import org.netbeans.modules.websvc.api.webservices.WebServicesSupport;
 
81
import org.netbeans.modules.websvc.spi.webservices.WebServicesConstants;
 
82
import org.netbeans.modules.websvc.wsdl.config.api.Configuration;
 
83
import org.netbeans.spi.project.support.ant.AntProjectHelper;
 
84
import org.netbeans.spi.project.support.ant.EditableProperties;
 
85
import org.openide.ErrorManager;
 
86
import org.openide.filesystems.FileObject;
 
87
import org.openide.filesystems.FileUtil;
 
88
import org.openide.util.NbBundle;
 
89
 
 
90
/**
 
91
 *
 
92
 * @author Martin Grebac
 
93
 */
 
94
public final class WebservicesXmlRenameRefactoring {
 
95
    
 
96
    private static final ErrorManager err = ErrorManager.getDefault().getInstance("org.netbeans.modules.j2ee.refactoring.rename");   // NOI18N
 
97
    
 
98
    /* stores collection of interface refactorings to be invoked */
 
99
    ArrayList otherRefactors = new ArrayList();
 
100
    
 
101
    public WebservicesXmlRenameRefactoring() { }
 
102
    
 
103
    public Problem preCheck(RefObject refObject) {
 
104
        
 
105
        Problem problem = null;
 
106
        if (refObject instanceof Method) {
 
107
            
 
108
            Method method = (Method)refObject;
 
109
            Resource res = method.getResource();
 
110
            FileObject fo = JavaModel.getFileObject(res);
 
111
            Collection wsmodules = Utility.getRelevantWSModules(fo);
 
112
            Iterator wsIter = wsmodules.iterator();
 
113
            String methodName = method.getName();
 
114
            ClassDefinition classDef = method.getDeclaringClass(); // get affected class
 
115
            
 
116
            if ((wsmodules != null) && (wsmodules.size() > 0)) { // there are web/ejb modules that can be affected by the change
 
117
                while (wsIter.hasNext()) {
 
118
                    WebServicesSupport ws = (WebServicesSupport)wsIter.next();
 
119
                    if (ws != null) {
 
120
                        FileObject webservicesXmlFO = ws.getWebservicesDD();
 
121
                        Webservices webservicesXmlDD = null;
 
122
                        try {
 
123
                            webservicesXmlDD = org.netbeans.modules.j2ee.dd.api.webservices.DDProvider.getDefault().getDDRoot(webservicesXmlFO);
 
124
                        } catch (IOException ioe) {
 
125
                            //ignore
 
126
                        }
 
127
                        
 
128
                        if ((webservicesXmlDD != null) && (webservicesXmlDD.getStatus()!=Webservices.STATE_INVALID_UNPARSABLE)) {
 
129
                            WebserviceDescription[] wservices = webservicesXmlDD.getWebserviceDescription();
 
130
                            err.log("Web Services: " + wservices); //NOI18N
 
131
                            if ((wservices != null) && (wservices.length > 0)) {
 
132
                                for (int w=0; w < wservices.length; w++) {
 
133
                                    WebserviceDescription webService = (WebserviceDescription)wservices[w];
 
134
                                    err.log("Web Service: " + webService); //NOI18N
 
135
                                    
 
136
                                    PortComponent[] ports = webService.getPortComponent();
 
137
                                    err.log("Ports: " + ports);
 
138
                                    if ((ports != null) && (ports.length > 0)) {
 
139
                                        for (int p=0; p < ports.length; p++) {
 
140
                                            
 
141
                                            /* First check for presence in webservices.xml port */
 
142
                                            PortComponent portComponent = (PortComponent)ports[p];
 
143
                                            err.log("Port Component: " + portComponent); //NOI18N
 
144
                                            
 
145
                                            /* try to locate the local wscompile config file:
 
146
                                             *   get project for webservices.xml, get name of the webservice and try to find properties of the type
 
147
                                             *   $propertyname-config.name - if found, get the property valu and the path and locate the descriptor,
 
148
                                             *   then get the dd api descriptor object
 
149
                                             */
 
150
                                            
 
151
                                            String portName = portComponent.getPortComponentName();
 
152
                                            Project project = FileOwnerQuery.getOwner(webservicesXmlFO);
 
153
                                            Map properties = ws.getAntProjectHelper().getStandardPropertyEvaluator().getProperties();
 
154
                                            String propertyName = portName + WebServicesConstants.CONFIG_PROP_SUFFIX;
 
155
                                            String propertyValue = (String)properties.get(propertyName);
 
156
                                            
 
157
                                            if (propertyValue != null) { // there's such property in the project
 
158
                                                FileObject wsConfigXmlFO = null;
 
159
                                                
 
160
                                                File f = new File(propertyValue);
 
161
                                                if (f.isAbsolute()) {
 
162
                                                    wsConfigXmlFO = FileUtil.toFileObject(f);
 
163
                                                } else {
 
164
                                                    wsConfigXmlFO = project.getProjectDirectory().getFileObject(propertyValue);
 
165
                                                }
 
166
                                                if (wsConfigXmlFO != null) {
 
167
                                                    Configuration wsConfigXmlDD = null;
 
168
                                                    try {
 
169
                                                        if (wsConfigXmlFO != null) {
 
170
                                                            wsConfigXmlDD = org.netbeans.modules.websvc.wsdl.config.api.DDProvider.getDefault().getDDRoot(wsConfigXmlFO);
 
171
                                                        }
 
172
                                                    } catch (IOException ioe) {
 
173
                                                        //ignore
 
174
                                                    }
 
175
                                                    if (wsConfigXmlDD != null) {
 
176
                                                        org.netbeans.modules.websvc.wsdl.config.api.Service service = wsConfigXmlDD.getService();
 
177
                                                        if (service != null) {
 
178
                                                            org.netbeans.modules.websvc.wsdl.config.api.Interface[] interfaces = service.getInterface();
 
179
                                                            if ((interfaces != null) && (interfaces.length > 0)) {
 
180
                                                                for (int ii=0; ii < interfaces.length; ii++) {
 
181
                                                                    org.netbeans.modules.websvc.wsdl.config.api.Interface iface = interfaces[ii];
 
182
                                                                    String servant = iface.getServantName();
 
183
                                                                    String iname = iface.getName();
 
184
                                                                    
 
185
                                                                    if (classDef.getName().equals(iname)) {
 
186
                                                                        
 
187
                                                                        JavaClass jcl = (JavaClass)JavaModel.getDefaultExtent().getType().resolve(servant);
 
188
                                                                        Method beanMethod = null;
 
189
                                                                        if (!(jcl instanceof UnresolvedClass)) {
 
190
                                                                            beanMethod = jcl.getMethod(methodName, Utility.getTypedParams(method.getParameters()), false); //NOI18N
 
191
                                                                            err.log("beanmethod: " + beanMethod); //NOI18N
 
192
                                                                        }
 
193
                                                                        
 
194
                                                                        RenameRefactoring renameBeanMethod = new RenameRefactoring(beanMethod);
 
195
                                                                        Problem prob = renameBeanMethod.preCheck();
 
196
                                                                        problem = Utility.addProblemsToEnd(problem, prob);
 
197
                                                                        otherRefactors.add(renameBeanMethod);
 
198
                                                                        
 
199
                                                                    } else if (classDef.getName().equals(servant)) {
 
200
                                                                        
 
201
                                                                        JavaClass jcl = (JavaClass)JavaModel.getDefaultExtent().getType().resolve(iname);
 
202
                                                                        Method iMethod = null;
 
203
                                                                        if (!(jcl instanceof UnresolvedClass)) {
 
204
                                                                            iMethod = jcl.getMethod(methodName, Utility.getTypedParams(method.getParameters()), false); //NOI18N
 
205
                                                                            err.log("ifacemethod: " + iMethod); //NOI18N
 
206
                                                                        }
 
207
                                                                        
 
208
                                                                        RenameRefactoring renameIfaceMethod = new RenameRefactoring(iMethod);
 
209
                                                                        Problem prob = renameIfaceMethod.preCheck();
 
210
                                                                        problem = Utility.addProblemsToEnd(problem, prob);
 
211
                                                                        otherRefactors.add(renameIfaceMethod);
 
212
                                                                    }
 
213
                                                                }
 
214
                                                            }
 
215
                                                        }
 
216
                                                    } else {
 
217
                                                        Problem newProblem = new Problem(false, NbBundle.getMessage(WebservicesXmlRenameRefactoring.class, "TXT_WebservicesConfigXmlRenameInvalidProblem")); //NOI18N
 
218
                                                        problem = Utility.addProblemsToEnd(problem, newProblem);
 
219
                                                    }
 
220
                                                }
 
221
                                            }
 
222
                                        }
 
223
                                    }
 
224
                                }
 
225
                            }
 
226
                        }
 
227
                    }
 
228
                } //while
 
229
            }
 
230
        } // method
 
231
        
 
232
        err.log("other refactors: " + otherRefactors);   //NOI18N
 
233
        return problem;
 
234
    }
 
235
    
 
236
    public Problem fastCheckParameters(RefObject refObject, String newName) {
 
237
        Problem problem = null;
 
238
        if (refObject instanceof Method) {
 
239
            for (int i=0; i < otherRefactors.size(); i++) {
 
240
                RenameRefactoring rr = (RenameRefactoring)otherRefactors.get(i);
 
241
                rr.setNewName(newName);
 
242
                Problem p = rr.fastCheckParameters();
 
243
                problem = Utility.addProblemsToEnd(problem, p);
 
244
            }
 
245
        }
 
246
        return problem;
 
247
    }
 
248
    
 
249
    public Problem checkParameters(RefObject refObject, String newName) {
 
250
        return fastCheckParameters(refObject, newName);
 
251
    }
 
252
    
 
253
    /** Find usages in web deployment descriptor: web.xml
 
254
     */
 
255
    public Problem prepare(AbstractRefactoring refactor, RefObject refObject, String newName, RefactoringElementsBag refactoringElements) {
 
256
        
 
257
        RefactoringSession session = refactoringElements.getSession();
 
258
        Problem problem = null;
 
259
        if (refObject instanceof JavaClass) {
 
260
            
 
261
            JavaClass jClass = (JavaClass)refObject;
 
262
            
 
263
            String name = jClass.getName();
 
264
            err.log("name: " + name); //NOI18N
 
265
            
 
266
            String newSimpleName = newName;
 
267
            err.log("newSimpleName: " + newSimpleName); //NOI18N
 
268
            
 
269
            newName = name.substring(0, name.lastIndexOf('.') + 1) + newName;
 
270
            err.log("newName: " + newName); //NOI18N
 
271
            
 
272
            Resource res = jClass.getResource();
 
273
            FileObject fo = JavaModel.getFileObject(res);
 
274
            
 
275
            WebServicesSupport wsm = WebServicesSupport.getWebServicesSupport(fo);
 
276
            if (wsm != null) {              // the class is in a module with web services support
 
277
                
 
278
                FileObject webservicesXmlFO = wsm.getWebservicesDD();
 
279
                Webservices webservicesXmlDD = null;
 
280
                try {
 
281
                    webservicesXmlDD = org.netbeans.modules.j2ee.dd.api.webservices.DDProvider.getDefault().getDDRoot(webservicesXmlFO);
 
282
                } catch (IOException ioe) {
 
283
                    //ignore
 
284
                }
 
285
                
 
286
                if ((webservicesXmlDD != null) && (webservicesXmlDD.getStatus()!=Webservices.STATE_INVALID_UNPARSABLE)) {
 
287
                    WebserviceDescription[] wservices = webservicesXmlDD.getWebserviceDescription();
 
288
                    err.log("Web Services: " + wservices); //NOI18N
 
289
                    if ((wservices != null) && (wservices.length > 0)) {
 
290
                        for (int w=0; w < wservices.length; w++) {
 
291
                            WebserviceDescription webService = (WebserviceDescription)wservices[w];
 
292
                            err.log("Web Service: " + webService); //NOI18N
 
293
                            
 
294
                            /* And update the actual web service reference direct in webservices.xml */
 
295
                            PortComponent[] ports = webService.getPortComponent();
 
296
                            err.log("Ports: " + ports);
 
297
                            if ((ports != null) && (ports.length > 0)) {
 
298
                                for (int p=0; p < ports.length; p++) {
 
299
                                    
 
300
                                    /* First check for presence in webservices.xml port */
 
301
                                    PortComponent portComponent = (PortComponent)ports[p];
 
302
                                    err.log("Port Component: " + portComponent); //NOI18N
 
303
                                    
 
304
                                    // check message handlers
 
305
                                    PortComponentHandler[] handlers = portComponent.getHandler();
 
306
                                    for (int k = 0; k < handlers.length; k++) {
 
307
                                        if (name.equals(handlers[k].getHandlerClass())){
 
308
                                            RefactoringElementImplementation elem = new WebservicesHandlerRenameRefactoringElement(webservicesXmlDD, name, newName, handlers[k], webservicesXmlFO);
 
309
                                            refactoringElements.add(refactor, elem);
 
310
                                        }
 
311
                                    }
 
312
                                    
 
313
                                    // wsdl-port is generated from sei class name as well
 
314
                                    QName wsdlPort = portComponent.getWsdlPort();
 
315
                                    err.log("WSDL Port: " + wsdlPort); //NOI18N
 
316
                                    if (wsdlPort != null) {
 
317
                                        String localPart = wsdlPort.getLocalPart();
 
318
                                        if (jClass.getSimpleName().concat("Port").equals(localPart)) { //NOI18N
 
319
                                            String newLocalPart = newSimpleName.concat("Port"); //NOI18N
 
320
                                            QName newPort = new QName(wsdlPort.getNamespaceURI(), newLocalPart, wsdlPort.getPrefix());
 
321
                                            RefactoringElementImplementation elem =
 
322
                                                    new WebservicesWsdlPortRenameRefactoringElement(
 
323
                                                    webservicesXmlDD, wsdlPort, newPort, portComponent, webservicesXmlFO); //NOI18N
 
324
                                            refactoringElements.add(refactor, elem);
 
325
                                        }
 
326
                                    }
 
327
                                    
 
328
                                    String serviceEndpointInterface = portComponent.getServiceEndpointInterface();
 
329
                                    err.log("serviceEndpointInterface: " + serviceEndpointInterface); //NOI18N
 
330
                                    if ((serviceEndpointInterface != null) && (serviceEndpointInterface.equals(name))) {
 
331
                                        RefactoringElementImplementation elem = new WebservicesSEIRenameRefactoringElement(webservicesXmlDD, name, newName, portComponent, webservicesXmlFO);
 
332
                                        refactoringElements.add(refactor, elem);
 
333
                                    }
 
334
                                    /* try to locate the local wscompile config file:
 
335
                                     *   get project for webservices.xml, get name of the webservice and try to find properties of the type
 
336
                                     *   $propertyname-config.name - if found, get the property valu and the path and locate the descriptor,
 
337
                                     *   then get the dd api descriptor object
 
338
                                     */
 
339
                                    String portName = portComponent.getPortComponentName();
 
340
                                    Project project = FileOwnerQuery.getOwner(webservicesXmlFO);
 
341
                                    Map properties = wsm.getAntProjectHelper().getStandardPropertyEvaluator().getProperties();
 
342
                                    String propertyName = portName + WebServicesConstants.CONFIG_PROP_SUFFIX;
 
343
                                    String propertyValue = (String)properties.get(propertyName);
 
344
                                    if (propertyValue != null) { // there's such property in the project
 
345
                                        FileObject wsConfigXmlFO = null;
 
346
                                        
 
347
                                        File f = new File(propertyValue);
 
348
                                        if (f.isAbsolute()) {
 
349
                                            wsConfigXmlFO = FileUtil.toFileObject(f);
 
350
                                        } else {
 
351
                                            wsConfigXmlFO = project.getProjectDirectory().getFileObject(propertyValue);
 
352
                                        }
 
353
                                        if (wsConfigXmlFO != null) {
 
354
                                            Configuration wsConfigXmlDD = null;
 
355
                                            try {
 
356
                                                wsConfigXmlDD = org.netbeans.modules.websvc.wsdl.config.api.DDProvider.getDefault().getDDRoot(wsConfigXmlFO);
 
357
                                            } catch (IOException ioe) {
 
358
                                                //ignore
 
359
                                            }
 
360
                                            if (wsConfigXmlDD != null) {
 
361
                                                org.netbeans.modules.websvc.wsdl.config.api.Service service = wsConfigXmlDD.getService();
 
362
                                                if (service != null) {
 
363
                                                    org.netbeans.modules.websvc.wsdl.config.api.Interface[] interfaces = service.getInterface();
 
364
                                                    if ((interfaces != null) && (interfaces.length > 0)) {
 
365
                                                        for (int ii=0; ii < interfaces.length; ii++) {
 
366
                                                            org.netbeans.modules.websvc.wsdl.config.api.Interface iface = interfaces[ii];
 
367
                                                            String servant = iface.getServantName();
 
368
                                                            String iname = iface.getName();
 
369
                                                            if ((servant != null) && (servant.equals(name))) {
 
370
                                                                RefactoringElementImplementation elem = new WebservicesConfigXmlServantRenameRefactoringElement(wsConfigXmlDD, name, newName, iface, wsConfigXmlFO);
 
371
                                                                refactoringElements.add(refactor, elem);
 
372
                                                            }
 
373
                                                            if ((iname != null) && (iname.equals(name))) {
 
374
                                                                RefactoringElementImplementation elem = new WebservicesConfigXmlInterfaceRenameRefactoringElement(wsConfigXmlDD, name, newName, iface, wsConfigXmlFO);
 
375
                                                                refactoringElements.add(refactor, elem);
 
376
                                                            }
 
377
                                                        }
 
378
                                                    }
 
379
                                                }
 
380
                                            } else {
 
381
                                                Problem newProblem = new Problem(false, NbBundle.getMessage(WebservicesXmlRenameRefactoring.class, "TXT_WebservicesConfigXmlRenameInvalidProblem")); //NOI18N
 
382
                                                problem = Utility.addProblemsToEnd(problem, newProblem);
 
383
                                            }
 
384
                                        }
 
385
                                    }
 
386
                                }
 
387
                            }
 
388
                        }
 
389
                    }
 
390
                } else if (webservicesXmlDD != null) {
 
391
                    Problem newProblem = new Problem(false, NbBundle.getMessage(WebservicesXmlRenameRefactoring.class, "TXT_WebservicesXmlRenameInvalidProblem")); //NOI18N
 
392
                    if (problem == null) {
 
393
                        problem = newProblem;
 
394
                    } else {
 
395
                        if (newProblem != null) problem.setNext(newProblem);
 
396
                    }
 
397
                }
 
398
            } //refactor webservices.xml
 
399
        } // javaclass
 
400
        
 
401
        if (refObject instanceof Method) {
 
402
            for (int i=0; i < otherRefactors.size(); i++) {
 
403
                RenameRefactoring rr = (RenameRefactoring)otherRefactors.get(i);
 
404
                Problem p = rr.prepare(session);
 
405
                problem = Utility.addProblemsToEnd(problem, p);
 
406
            }
 
407
            return problem;
 
408
        }
 
409
        
 
410
        return problem;
 
411
    }
 
412
    
 
413
    public final class WebservicesSEIRenameRefactoringElement extends AbstractRenameRefactoringElement implements ExternalChange {
 
414
        
 
415
        protected Webservices webservicesXmlDD;
 
416
        private PortComponent portComponent;
 
417
        
 
418
        /** Creates a new instance of WebservicesSEIRenameRefactoringElement */
 
419
        public WebservicesSEIRenameRefactoringElement(Webservices webservicesXmlDD, String oldName, String newName, PortComponent portComponent, FileObject parentFile) {
 
420
            this.webservicesXmlDD = webservicesXmlDD;
 
421
            this.oldName = oldName;
 
422
            this.newName = newName;
 
423
            this.portComponent = portComponent;
 
424
            this.parentFile = parentFile;
 
425
        }
 
426
        
 
427
        /** Returns text describing the refactoring formatted for display (using HTML tags).
 
428
         * @return Formatted text.
 
429
         */
 
430
        public String getDisplayText() {
 
431
            Object[] args = new Object [] {parentFile.getNameExt(), oldName, newName};
 
432
            return MessageFormat.format(NbBundle.getMessage(WebservicesXmlRenameRefactoring.class, "TXT_WebservicesXmlSEIRename"), args); //NOI18N
 
433
        }
 
434
        
 
435
        /** Performs the change represented by this refactoring element.
 
436
         */
 
437
        public void performChange() {
 
438
            JavaMetamodel.getManager().registerExtChange(this);
 
439
        }
 
440
        
 
441
        public void performExternalChange() {
 
442
            portComponent.setServiceEndpointInterface(newName);
 
443
            try {
 
444
                webservicesXmlDD.write(parentFile);
 
445
            } catch (IOException ioe) {
 
446
                //TODO
 
447
            }
 
448
        }
 
449
        
 
450
        public void undoExternalChange() {
 
451
            portComponent.setServiceEndpointInterface(oldName);
 
452
            try {
 
453
                webservicesXmlDD.write(parentFile);
 
454
            } catch (IOException ioe) {
 
455
                //TODO
 
456
            }
 
457
        }
 
458
    }
 
459
    
 
460
    /**
 
461
     * Rename refactoring element for message handlers.
 
462
     */
 
463
    public final class WebservicesHandlerRenameRefactoringElement extends AbstractRenameRefactoringElement implements ExternalChange {
 
464
        
 
465
        protected Webservices webservicesXmlDD;
 
466
        private PortComponentHandler handler;
 
467
        
 
468
        public WebservicesHandlerRenameRefactoringElement(Webservices webservicesXmlDD, String oldName, String newName, PortComponentHandler handler, FileObject parentFile) {
 
469
            this.webservicesXmlDD = webservicesXmlDD;
 
470
            this.oldName = oldName;
 
471
            this.newName = newName;
 
472
            this.handler = handler;
 
473
            this.parentFile = parentFile;
 
474
        }
 
475
        
 
476
        /** Returns text describing the refactoring formatted for display (using HTML tags).
 
477
         * @return Formatted text.
 
478
         */
 
479
        public String getDisplayText() {
 
480
            Object[] args = new Object [] {parentFile.getNameExt(), oldName, newName};
 
481
            return MessageFormat.format(NbBundle.getMessage(WebservicesXmlRenameRefactoring.class, "TXT_WebservicesXmlHandlerRename"), args); //NOI18N
 
482
        }
 
483
        
 
484
        /** Performs the change represented by this refactoring element.
 
485
         */
 
486
        public void performChange() {
 
487
            JavaMetamodel.getManager().registerExtChange(this);
 
488
        }
 
489
        
 
490
        public void performExternalChange() {
 
491
            handler.setHandlerClass(newName);
 
492
            write();
 
493
        }
 
494
        
 
495
        public void undoExternalChange() {
 
496
            handler.setHandlerClass(oldName);
 
497
            write();
 
498
        }
 
499
        
 
500
        private void write(){
 
501
            try {
 
502
                webservicesXmlDD.write(parentFile);
 
503
            } catch (IOException ioe) {
 
504
                ErrorManager.getDefault().notify(ioe);
 
505
            }
 
506
        }
 
507
    }
 
508
    public final class WebservicesWsdlPortRenameRefactoringElement extends AbstractRenameRefactoringElement implements ExternalChange {
 
509
        
 
510
        protected Webservices webservicesXmlDD;
 
511
        private PortComponent portComponent;
 
512
        
 
513
        private QName oldPort;
 
514
        private QName newPort;
 
515
        
 
516
        /** Creates a new instance of WebservicesWsdlPortRenameRefactoringElement */
 
517
        public WebservicesWsdlPortRenameRefactoringElement(Webservices webservicesXmlDD, QName oldPort, QName newPort, PortComponent portComponent, FileObject parentFile) {
 
518
            this.webservicesXmlDD = webservicesXmlDD;
 
519
            this.oldPort = oldPort;
 
520
            this.newPort = newPort;
 
521
            this.portComponent = portComponent;
 
522
            this.parentFile = parentFile;
 
523
        }
 
524
        
 
525
        /** Returns text describing the refactoring formatted for display (using HTML tags).
 
526
         * @return Formatted text.
 
527
         */
 
528
        public String getDisplayText() {
 
529
            String oldStr = oldPort.getPrefix() + ":" + oldPort.getLocalPart(); //NOI18N
 
530
            String newStr = newPort.getPrefix() + ":" + newPort.getLocalPart(); //NOI18N
 
531
            
 
532
            Object[] args = new Object [] {parentFile.getNameExt(), oldStr, newStr};
 
533
            return MessageFormat.format(NbBundle.getMessage(WebservicesXmlRenameRefactoring.class, "TXT_WebservicesXmlWsdlPortRename"), args); //NOI18N
 
534
        }
 
535
        
 
536
        /** Performs the change represented by this refactoring element.
 
537
         */
 
538
        public void performChange() {
 
539
            JavaMetamodel.getManager().registerExtChange(this);
 
540
        }
 
541
        
 
542
        public void performExternalChange() {
 
543
            portComponent.setWsdlPort(newPort);
 
544
            try {
 
545
                webservicesXmlDD.write(parentFile);
 
546
            } catch (IOException ioe) {
 
547
                //TODO
 
548
            }
 
549
        }
 
550
        
 
551
        public void undoExternalChange() {
 
552
            portComponent.setWsdlPort(oldPort);
 
553
            try {
 
554
                webservicesXmlDD.write(parentFile);
 
555
            } catch (IOException ioe) {
 
556
                //TODO
 
557
            }
 
558
        }
 
559
    }
 
560
    
 
561
    public final class WebservicesConfigXmlServantRenameRefactoringElement extends AbstractRenameRefactoringElement implements ExternalChange {
 
562
        
 
563
        protected Configuration wsConfigXmlDD;
 
564
        private org.netbeans.modules.websvc.wsdl.config.api.Interface iface;
 
565
        
 
566
        /** Creates a new instance of WebservicesConfigXmlServantRenameRefactoringElement */
 
567
        public WebservicesConfigXmlServantRenameRefactoringElement(Configuration wsConfigXmlDD, String oldName, String newName, org.netbeans.modules.websvc.wsdl.config.api.Interface iface, FileObject parentFile) {
 
568
            this.wsConfigXmlDD = wsConfigXmlDD;
 
569
            this.oldName = oldName;
 
570
            this.newName = newName;
 
571
            this.iface = iface;
 
572
            this.parentFile = parentFile;
 
573
        }
 
574
        
 
575
        /** Returns text describing the refactoring formatted for display (using HTML tags).
 
576
         * @return Formatted text.
 
577
         */
 
578
        public String getDisplayText() {
 
579
            Object[] args = new Object [] {parentFile.getNameExt(), oldName, newName};
 
580
            return MessageFormat.format(NbBundle.getMessage(WebservicesXmlRenameRefactoring.class, "TXT_WebservicesConfigXmlServantRename"), args); //NOI18N
 
581
        }
 
582
        
 
583
        /** Performs the change represented by this refactoring element.
 
584
         */
 
585
        public void performChange() {
 
586
            JavaMetamodel.getManager().registerExtChange(this);
 
587
        }
 
588
        
 
589
        public void performExternalChange() {
 
590
            iface.setServantName(newName);
 
591
            try {
 
592
                wsConfigXmlDD.write(parentFile);
 
593
            } catch (IOException ioe) {
 
594
                //TODO
 
595
            }
 
596
        }
 
597
        
 
598
        public void undoExternalChange() {
 
599
            iface.setServantName(oldName);
 
600
            try {
 
601
                wsConfigXmlDD.write(parentFile);
 
602
            } catch (IOException ioe) {
 
603
                //TODO
 
604
            }
 
605
        }
 
606
    }
 
607
    
 
608
    public final class WebservicesConfigXmlInterfaceRenameRefactoringElement extends AbstractRenameRefactoringElement implements ExternalChange {
 
609
        
 
610
        protected Configuration wsConfigXmlDD;
 
611
        private org.netbeans.modules.websvc.wsdl.config.api.Interface iface;
 
612
        
 
613
        /** Creates a new instance of WebservicesConfigXmlInterfaceRenameRefactoringElement */
 
614
        public WebservicesConfigXmlInterfaceRenameRefactoringElement(Configuration wsConfigXmlDD, String oldName, String newName, org.netbeans.modules.websvc.wsdl.config.api.Interface iface, FileObject parentFile) {
 
615
            this.wsConfigXmlDD = wsConfigXmlDD;
 
616
            this.oldName = oldName;
 
617
            this.newName = newName;
 
618
            this.iface = iface;
 
619
            this.parentFile = parentFile;
 
620
        }
 
621
        
 
622
        /** Returns text describing the refactoring formatted for display (using HTML tags).
 
623
         * @return Formatted text.
 
624
         */
 
625
        public String getDisplayText() {
 
626
            Object[] args = new Object [] {parentFile.getNameExt(), oldName, newName};
 
627
            return MessageFormat.format(NbBundle.getMessage(WebservicesXmlRenameRefactoring.class, "TXT_WebservicesConfigXmlInterfaceRename"), args); //NOI18N
 
628
        }
 
629
        
 
630
        /** Performs the change represented by this refactoring element.
 
631
         */
 
632
        public void performChange() {
 
633
            JavaMetamodel.getManager().registerExtChange(this);
 
634
        }
 
635
        
 
636
        public void performExternalChange() {
 
637
            iface.setName(newName);
 
638
            try {
 
639
                wsConfigXmlDD.write(parentFile);
 
640
            } catch (IOException ioe) {
 
641
                //TODO
 
642
            }
 
643
        }
 
644
        
 
645
        public void undoExternalChange() {
 
646
            iface.setName(oldName);
 
647
            try {
 
648
                wsConfigXmlDD.write(parentFile);
 
649
            } catch (IOException ioe) {
 
650
                //TODO
 
651
            }
 
652
        }
 
653
    }
 
654
    
 
655
}