KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > refactoring > J2EERenameRefactoringPlugin


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;
21
22 import javax.jmi.reflect.RefObject;
23 import org.netbeans.jmi.javamodel.Element;
24 import org.netbeans.modules.j2ee.refactoring.rename.EjbJarRenameRefactoring;
25 import org.netbeans.modules.j2ee.refactoring.rename.EntityRenameRefactoring;
26 import org.netbeans.modules.j2ee.refactoring.rename.JaxWsXmlRenameRefactoring;
27 import org.netbeans.modules.j2ee.refactoring.rename.PersistenceXmlRenameRefactoring;
28 import org.netbeans.modules.j2ee.refactoring.rename.SunJaxWsXmlRenameRefactoring;
29 import org.netbeans.modules.j2ee.refactoring.rename.TldRenameRefactoring;
30 import org.netbeans.modules.j2ee.refactoring.rename.WebXmlRenameRefactoring;
31 import org.netbeans.modules.j2ee.refactoring.rename.WebservicesXmlRenameRefactoring;
32 import org.netbeans.modules.refactoring.api.AbstractRefactoring;
33 import org.netbeans.modules.refactoring.api.Problem;
34 import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
35 import org.netbeans.modules.refactoring.api.RenameRefactoring;
36 import org.netbeans.modules.refactoring.spi.RefactoringPlugin;
37 import org.openide.ErrorManager;
38 import org.openide.util.NbBundle;
39
40
41 /**
42  *
43  * @author Martin Grebac
44  */

45 public class J2EERenameRefactoringPlugin implements RefactoringPlugin {
46     
47     /** This one is important creature - makes sure that cycles between plugins won't appear */
48     private static ThreadLocal JavaDoc semafor = new ThreadLocal JavaDoc();
49     
50     private EjbJarRenameRefactoring ejbJarRenameRefactor;
51     private WebXmlRenameRefactoring webXmlRenameRefactor;
52     private TldRenameRefactoring tldRenameRefactor;
53     private WebservicesXmlRenameRefactoring webservicesXmlRenameRefactor;
54     private PersistenceXmlRenameRefactoring persistenceXmlRenameRefactoring = new PersistenceXmlRenameRefactoring();
55     private EntityRenameRefactoring entityRenameRefactoring = new EntityRenameRefactoring();
56     private JaxWsXmlRenameRefactoring jaxWsXmlRenameRefactoring = new JaxWsXmlRenameRefactoring();
57     private SunJaxWsXmlRenameRefactoring sunJaxWsXmlRenameRefactoring = new SunJaxWsXmlRenameRefactoring();
58     
59     
60     private final RenameRefactoring renameRefactoring;
61     
62     private static ErrorManager err = ErrorManager.getDefault().getInstance("org.netbeans.modules.j2ee.renameRefactoring.rename"); // NOI18N
63

64     /** Creates a new instance of J2EERenameRefactoringPlugin */
65     public J2EERenameRefactoringPlugin(AbstractRefactoring refactoring) {
66         this.renameRefactoring = (RenameRefactoring) refactoring;
67     }
68     
69     /** Checks pre-conditions of the renameRefactoring and returns problems.
70      * @return Problems found or null (if no problems were identified)
71      */

72     public Problem preCheck() {
73         Problem problem = null;
74         if (semafor.get() == null) {
75             semafor.set(new Object JavaDoc());
76             
77             RefObject refO = (RefObject) renameRefactoring.getRefactoredObject();
78             err.log("refO: " + refO);
79             
80             
81             Problem webSvcProblem = getWebservicesXmlRenameRefactor().preCheck(refO);
82             problem = Utility.addProblemsToEnd(problem, webSvcProblem);
83
84             if (!Utility.isEjb30(refO)){
85                 Problem ejbJarProblem = getEjbJarRenameRefactor().preCheck(refO);
86                 problem = Utility.addProblemsToEnd(problem, ejbJarProblem);
87             } else if (Utility.hasEjbJar(Utility.getRelevantEjbModules(refO))){
88                 Problem ejbJarProblem = new Problem(false, NbBundle.getMessage(J2EERenameRefactoringPlugin.class, "TXT_EjbJarRenameWarning")); //NOI18N
89
problem = Utility.addProblemsToEnd(problem, ejbJarProblem);
90             }
91             
92             semafor.set(null);
93         }
94         return problem;
95     }
96     
97     
98     public Problem fastCheckParameters() {
99         Problem problem = null;
100         if (semafor.get() == null) {
101             semafor.set(new Object JavaDoc());
102             
103             RefObject refO = (RefObject) renameRefactoring.getRefactoredObject();
104             err.log("refO: " + refO);
105             
106             String JavaDoc newName = renameRefactoring.getNewName();
107             err.log("newname: " + newName);
108             
109             if (!Utility.isEjb30(refO)){
110                 Problem ejbJarProblem = getEjbJarRenameRefactor().fastCheckParameters(refO, newName);
111                 problem = Utility.addProblemsToEnd(problem, ejbJarProblem);
112             }
113             
114             Problem wsvcProblem = getWebservicesXmlRenameRefactor().fastCheckParameters(refO, newName);
115             problem = Utility.addProblemsToEnd(problem, wsvcProblem);
116             
117             semafor.set(null);
118         }
119         return problem;
120     }
121     
122     /** Checks parameters of the renameRefactoring.
123      * @return Problems found or null (if no problems were identified)
124      */

125     public Problem checkParameters() {
126         Problem problem = null;
127         if (semafor.get() == null) {
128             semafor.set(new Object JavaDoc());
129             
130             RefObject refO = (RefObject) renameRefactoring.getRefactoredObject();
131             err.log("refO: " + refO);
132             
133             String JavaDoc newName = renameRefactoring.getNewName();
134             err.log("newname: " + newName);
135             
136             if (!Utility.isEjb30(refO)){
137                 Problem ejbJarProblem = getEjbJarRenameRefactor().checkParameters(refO, newName);
138                 problem = Utility.addProblemsToEnd(problem, ejbJarProblem);
139             }
140             
141             Problem wsvcProblem = getWebservicesXmlRenameRefactor().checkParameters(refO, newName);
142             problem = Utility.addProblemsToEnd(problem, wsvcProblem);
143             
144             semafor.set(null);
145         }
146         return problem;
147     }
148     
149     /** Collects renameRefactoring elements for a given renameRefactoring.
150      * @param refactoringElements Collection of renameRefactoring elements - the implementation of this method
151      * should add renameRefactoring elements to this collections. It should make no assumptions about the collection
152      * content.
153      * @return Problems found or null (if no problems were identified)
154      */

155     public Problem prepare(RefactoringElementsBag refactoringElements) {
156         Problem problem = null;
157         
158         if (semafor.get() == null) {
159             semafor.set(new Object JavaDoc());
160             
161             RefObject refO = (RefObject) renameRefactoring.getRefactoredObject();
162             err.log("refO: " + refO);
163             
164             String JavaDoc newName = renameRefactoring.getNewName();
165             err.log("newname: " + newName);
166             
167             Problem webXmlProblem = getWebXmlRenameRefactor().prepare(renameRefactoring, refO, newName, refactoringElements);
168             problem = Utility.addProblemsToEnd(problem, webXmlProblem);
169             
170             Problem tldProblem = getTldRenameRefactor().prepare(renameRefactoring, refO, newName, refactoringElements);
171             problem = Utility.addProblemsToEnd(problem, tldProblem);
172             
173             if (!Utility.isEjb30(refO)){
174                 Problem ejbJarProblem = getEjbJarRenameRefactor().prepare(renameRefactoring, refO, newName, refactoringElements);
175                 problem = Utility.addProblemsToEnd(problem, ejbJarProblem);
176             }
177             
178             Problem webservicesProblem = getWebservicesXmlRenameRefactor().prepare(renameRefactoring, refO, newName, refactoringElements);
179             problem = Utility.addProblemsToEnd(problem, webservicesProblem);
180             
181             Problem persistenceXmlProblem = persistenceXmlRenameRefactoring.prepare(renameRefactoring, refO, newName, refactoringElements);
182             problem = Utility.addProblemsToEnd(problem, persistenceXmlProblem );
183             
184             Problem entityRenameProblem = entityRenameRefactoring.prepare(renameRefactoring, refO, newName, refactoringElements);
185             problem = Utility.addProblemsToEnd(problem, entityRenameProblem);
186             
187             Problem jaxXmlProblem = jaxWsXmlRenameRefactoring.prepare(renameRefactoring, refO, newName, refactoringElements);
188             problem = Utility.addProblemsToEnd(problem, jaxXmlProblem);
189             
190             Problem sunJaxXmlProblem = sunJaxWsXmlRenameRefactoring.prepare(renameRefactoring, refO, newName, refactoringElements);
191             problem = Utility.addProblemsToEnd(problem, sunJaxXmlProblem);
192             
193             semafor.set(null);
194         }
195         
196         err.log("Gonna return problem: " + problem);
197         return problem;
198     }
199     
200     public void cancelRequest() { }
201     
202     private EjbJarRenameRefactoring getEjbJarRenameRefactor() {
203         if (ejbJarRenameRefactor == null) {
204             ejbJarRenameRefactor = new EjbJarRenameRefactoring();
205         }
206         return ejbJarRenameRefactor;
207     }
208     
209     private WebXmlRenameRefactoring getWebXmlRenameRefactor() {
210         if (webXmlRenameRefactor == null) {
211             webXmlRenameRefactor = new WebXmlRenameRefactoring();
212         }
213         return webXmlRenameRefactor;
214     }
215     
216     private TldRenameRefactoring getTldRenameRefactor() {
217         if (tldRenameRefactor == null) {
218             tldRenameRefactor = new TldRenameRefactoring();
219         }
220         return tldRenameRefactor;
221     }
222     
223     private WebservicesXmlRenameRefactoring getWebservicesXmlRenameRefactor() {
224         if (webservicesXmlRenameRefactor == null) {
225             webservicesXmlRenameRefactor = new WebservicesXmlRenameRefactoring();
226         }
227         return webservicesXmlRenameRefactor;
228     }
229     
230 }
231
Popular Tags