KickJava   Java API By Example, From Geeks To Geeks.

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


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.text.MessageFormat JavaDoc;
23 import javax.jmi.reflect.RefObject;
24 import org.netbeans.jmi.javamodel.JavaClass;
25 import org.netbeans.modules.j2ee.refactoring.Utility;
26 import org.netbeans.modules.j2ee.refactoring.jaxwssupport.JaxWsXmlRefactoringSupport;
27 import org.netbeans.modules.j2ee.refactoring.jaxwssupport.SunJaxWsXmlElementSupport;
28 import org.netbeans.modules.refactoring.api.AbstractRefactoring;
29 import org.netbeans.modules.refactoring.api.Problem;
30 import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation;
31 import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
32 import org.netbeans.modules.websvc.api.jaxws.project.config.Endpoint;
33 import org.netbeans.modules.websvc.api.jaxws.project.config.Endpoints;
34 import org.openide.filesystems.FileObject;
35 import org.openide.util.NbBundle;
36
37 /**
38  * This class handles renaming of a webservice endpoint imlementation class
39  * in sun-jaxws.xml (handles only webservices from WSDL file, other types
40  * of web services are supported through other means).
41  *
42  * @author Erno Mononen
43  */

44 public class SunJaxWsXmlRenameRefactoring extends JaxWsXmlRefactoringSupport {
45     
46     /**
47      * Creates a new instance of SunJaxWsXmlRenameRefactoring
48      */

49     public SunJaxWsXmlRenameRefactoring() {
50     }
51     
52     /**
53      * Find usages in jax-ws.xml.
54      */

55     public Problem prepare(AbstractRefactoring refactor, RefObject refObject,
56             String JavaDoc newName, RefactoringElementsBag refactoringElements) {
57         
58         if (!(refObject instanceof JavaClass) || !isWebSvcFromWsdl((JavaClass) refObject)){
59             return null;
60         }
61         
62         JavaClass javaClass = (JavaClass) refObject;
63         Endpoints model = getEndpointsModel(javaClass);
64         if (model == null){
65             return null;
66         }
67         
68         FileObject sunjaxwsfile = getSunJaxWsXmlFile(javaClass);
69         for (Endpoint each : getEndpoints(javaClass)) {
70             RefactoringElementImplementation refactoringElem =
71                     new SunJaxWsXmlRenameRefactoringElement(javaClass.getName(), Utility.renameClass(javaClass.getName(), newName), model, each, sunjaxwsfile);
72             refactoringElements.add(refactor, refactoringElem);
73             
74         }
75         
76         return null;
77     }
78     
79     /**
80      * Rename refactoring element for jax-ws.xml
81      */

82     private static class SunJaxWsXmlRenameRefactoringElement extends SunJaxWsXmlElementSupport {
83         
84         public SunJaxWsXmlRenameRefactoringElement(String JavaDoc oldName, String JavaDoc newName,
85                 Endpoints model, Endpoint endpoint, FileObject parentFile) {
86             super(oldName, newName, model, endpoint, parentFile);
87         }
88         
89         public String JavaDoc getDisplayText() {
90             Object JavaDoc[] args = new Object JavaDoc [] {parentFile.getNameExt(), oldName, newName};
91             return MessageFormat.format(NbBundle.getMessage(SunJaxWsXmlRenameRefactoring.class, "TXT_SunJaxWsXmlRename"), args);
92         }
93
94     }
95     
96 }
97
Popular Tags