KickJava   Java API By Example, From Geeks To Geeks.

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


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.IOException JavaDoc;
23 import java.text.MessageFormat JavaDoc;
24 import javax.jmi.reflect.RefObject;
25 import org.netbeans.api.project.FileOwnerQuery;
26 import org.netbeans.api.project.Project;
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.Resource;
31 import org.netbeans.modules.j2ee.refactoring.jaxwssupport.JaxWsXmlRefactoringElementSupport;
32 import org.netbeans.modules.j2ee.refactoring.Utility;
33 import org.netbeans.modules.j2ee.refactoring.jaxwssupport.JaxWsXmlRefactoringSupport;
34 import org.netbeans.modules.javacore.api.JavaModel;
35 import org.netbeans.modules.javacore.internalapi.ExternalChange;
36 import org.netbeans.modules.javacore.internalapi.JavaMetamodel;
37 import org.netbeans.modules.refactoring.api.AbstractRefactoring;
38 import org.netbeans.modules.refactoring.api.Problem;
39 import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation;
40 import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
41 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel;
42 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModelProvider;
43 import org.netbeans.modules.websvc.api.jaxws.project.config.Service;
44 import org.openide.ErrorManager;
45 import org.openide.filesystems.FileObject;
46 import org.openide.util.NbBundle;
47
48 /**
49  * This class handles renaming of a webservice imlementation class
50  * in jax-ws.xml (handles only webservices from WSDL file, other types
51  * of webservices are supported through other means).
52  *
53  * @author Erno Mononen
54  */

55 public class JaxWsXmlRenameRefactoring extends JaxWsXmlRefactoringSupport {
56     
57     /**
58      * Creates a new instance of JaxWsXmlRenameRefactoring
59      */

60     public JaxWsXmlRenameRefactoring() {
61     }
62     
63     /**
64      * Find usages in jax-ws.xml.
65      */

66     public Problem prepare(AbstractRefactoring refactor, RefObject refObject,
67             String JavaDoc newName, RefactoringElementsBag refactoringElements) {
68         
69         if (!(refObject instanceof JavaClass) || !isWebSvcFromWsdl((JavaClass) refObject)){
70             return null;
71         }
72         
73         JavaClass javaClass = (JavaClass) refObject;
74         
75         JaxWsModel model = getModel(javaClass);
76         if (model == null){
77             return null;
78         }
79         newName = Utility.renameClass(javaClass.getName(), newName);
80         
81         Service service = model.findServiceByImplementationClass(javaClass.getName());
82         if (service != null){
83             RefactoringElementImplementation refactoringElem =
84                     new JaxWsXmlRenameRefactoringElement(javaClass.getName(), newName, model, service, model.getJaxWsFile());
85             
86             refactoringElements.add(refactor, refactoringElem);
87         }
88         
89         return null;
90     }
91     
92     /**
93      * Rename refactoring element for jax-ws.xml
94      */

95     private static class JaxWsXmlRenameRefactoringElement extends JaxWsXmlRefactoringElementSupport {
96         
97         /**
98          * Creates a new instance of JaxWsXmlRenameRefactoringElement
99          * @param oldName the fully qualified old name of the implementation class
100          * @param newName the fully qualified new name of the implementation class
101          * @service the service whose implementation class is to be renamed
102          * @parentFile the file object representing jax-ws.xml
103          */

104         public JaxWsXmlRenameRefactoringElement(String JavaDoc oldName, String JavaDoc newName,
105                 JaxWsModel model, Service service, FileObject parentFile) {
106             super(oldName, newName, model, service, parentFile);
107         }
108         
109         /**
110          * Returns text describing the refactoring formatted for display (using HTML tags).
111          * @return Formatted text.
112          */

113         public String JavaDoc getDisplayText() {
114             Object JavaDoc[] args = new Object JavaDoc [] {parentFile.getNameExt(), oldName, newName};
115             return MessageFormat.format(NbBundle.getMessage(JaxWsXmlRenameRefactoring.class, "TXT_JaxWsXmlRename"), args);
116         }
117     }
118     
119 }
120
Popular Tags