KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Collection JavaDoc;
23 import javax.jmi.reflect.RefObject;
24 import org.netbeans.jmi.javamodel.Method;
25 import org.netbeans.modules.j2ee.refactoring.whereused.EjbJarWhereUsedRefactoring;
26 import org.netbeans.modules.j2ee.refactoring.whereused.EntityWhereUsedRefactoring;
27 import org.netbeans.modules.j2ee.refactoring.whereused.JaxWsXmlWhereUsedRefactoring;
28 import org.netbeans.modules.j2ee.refactoring.whereused.PersistenceXmlWhereUsedRefactoring;
29 import org.netbeans.modules.j2ee.refactoring.whereused.SunJaxWsXmlWhereUsedRefactoring;
30 import org.netbeans.modules.j2ee.refactoring.whereused.TldWhereUsedRefactoring;
31 import org.netbeans.modules.j2ee.refactoring.whereused.WebXmlWhereUsedRefactoring;
32 import org.netbeans.modules.j2ee.refactoring.whereused.WebservicesXmlWhereUsedRefactoring;
33 import org.netbeans.modules.refactoring.api.AbstractRefactoring;
34 import org.netbeans.modules.refactoring.api.Problem;
35 import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
36 import org.netbeans.modules.refactoring.api.WhereUsedQuery;
37 import org.netbeans.modules.refactoring.spi.RefactoringPlugin;
38 import org.openide.ErrorManager;
39 import org.openide.util.NbBundle;
40
41
42 /**
43  *
44  * @author Martin Grebac
45  */

46 public class J2EEWhereUsedRefactoringPlugin implements RefactoringPlugin {
47     
48     /** This one is important creature - makes sure that cycles between plugins won't appear */
49     private static ThreadLocal JavaDoc semafor = new ThreadLocal JavaDoc();
50     
51     private EjbJarWhereUsedRefactoring ejbJarWhereUsedRefactor;
52     private WebXmlWhereUsedRefactoring webXmlWhereUsedRefactor;
53     private TldWhereUsedRefactoring tldWhereUsedRefactor;
54     private WebservicesXmlWhereUsedRefactoring webservicesXmlWhereUsedRefactor;
55     private JaxWsXmlWhereUsedRefactoring jaxWsXmlWhereUsedRefactor;
56     private PersistenceXmlWhereUsedRefactoring persistenceXmlWhereUsedRefactor;
57     private SunJaxWsXmlWhereUsedRefactoring sunJaxWsXmlWhereUsedRefactor;
58     private EntityWhereUsedRefactoring entityWhereUsedRefactor;
59     
60     public void cancelRequest() {
61         
62     }
63     
64     public Problem fastCheckParameters() {
65         return null;
66     }
67     
68     private AbstractRefactoring refactoring;
69     private static ErrorManager err = ErrorManager.getDefault().getInstance("org.netbeans.modules.j2ee.refactoring.whereused"); // NOI18N
70

71     /** Creates a new instance of J2EEWhereUsedRefactoringPlugin */
72     public J2EEWhereUsedRefactoringPlugin(AbstractRefactoring refactoring) {
73         this.refactoring = refactoring;
74     }
75     
76     /** Checks pre-conditions of the refactoring and returns problems.
77      * @return Problems found or null (if no problems were identified)
78      */

79     public Problem preCheck() {
80         return null;
81     }
82     
83     /** Checks parameters of the refactoring.
84      * @return Problems found or null (if no problems were identified)
85      */

86     public Problem checkParameters() {
87         Problem problem = null;
88         if (semafor.get() == null) {
89             semafor.set(new Object JavaDoc());
90             WhereUsedQuery whereUsedRefactor = ((WhereUsedQuery)refactoring);
91             RefObject refObject = (RefObject) whereUsedRefactor.getRefactoredObject();
92             try {
93                 if (Utility.isEjb30((refObject)) && Utility.hasEjbJar(refObject)){
94                     Problem ejbJarProblem = new Problem(false, NbBundle.getMessage(J2EEWhereUsedRefactoringPlugin.class, "TXT_EjbJarWhereUsedWarning")); //NOI18N
95
problem = Utility.addProblemsToEnd(problem, ejbJarProblem);
96                 }
97             }finally {
98                 semafor.set(null);
99             }
100         }
101         return problem;
102     }
103     
104     /** Collects refactoring elements for a given refactoring.
105      * @param refactoringElements Collection of refactoring elements - the implementation of this method
106      * should add refactoring elements to this collections. It should make no assumptions about the collection
107      * content.
108      * @return Problems found or null (if no problems were identified)
109      */

110     public Problem prepare(RefactoringElementsBag refactoringElements) {
111         if (semafor.get() != null) {
112             return null;
113         }
114         semafor.set(new Object JavaDoc());
115         try {
116             WhereUsedQuery whereUsedRefactor = ((WhereUsedQuery)refactoring);
117             
118             if (!whereUsedRefactor.isFindUsages()) { // there are no subtype definitions in server specific files, so we return something only when direct usages are to be found
119
return null;
120             }
121             
122             Problem problem = null;
123             
124             RefObject refO = (RefObject) whereUsedRefactor.getRefactoredObject();
125             err.log("refO: " + refO);
126             
127             Problem webXmlProblem = getWebXmlWhereUsedRefactor().prepare(whereUsedRefactor, refO, refactoringElements);
128             problem = Utility.addProblemsToEnd(problem, webXmlProblem);
129             
130             Problem tldProblem = getTldWhereUsedRefactor().prepare(whereUsedRefactor, refO, refactoringElements);
131             problem = Utility.addProblemsToEnd(problem, tldProblem);
132             
133             if (!Utility.isEjb30(refO)){
134                 Problem ejbJarProblem = getEjbJarWhereUsedRefactor().prepare(whereUsedRefactor, refO, refactoringElements);
135                 problem = Utility.addProblemsToEnd(problem, ejbJarProblem);
136             }
137             
138             Problem webservicesProblem = getWebservicesXmlWhereUsedRefactor().prepare(whereUsedRefactor, refO, refactoringElements);
139             problem = Utility.addProblemsToEnd(problem, webservicesProblem);
140             
141             Problem jaxWsXmlProblem = getJaxWsXmlWhereUsedRefactoring().prepare(whereUsedRefactor, refO, refactoringElements);
142             problem = Utility.addProblemsToEnd(problem, jaxWsXmlProblem);
143             
144             Problem persistenceXmlProblem = getPersistenceXmlWhereUsedRefactoring().prepare(whereUsedRefactor, refO, refactoringElements);
145             problem = Utility.addProblemsToEnd(problem, persistenceXmlProblem);
146             
147             Problem sunJaxWsXmlProblem = getSunJaxWsXmlWhereUsedRefactoring().prepare(whereUsedRefactor, refO, refactoringElements);
148             problem = Utility.addProblemsToEnd(problem, sunJaxWsXmlProblem);
149             
150             Problem entityProblem = getEntityWhereUsedRefactor().prepare(whereUsedRefactor, refO, refactoringElements);
151             problem = Utility.addProblemsToEnd(problem, entityProblem );
152             
153             
154             
155             // Method to be looked for
156
if (refO instanceof Method) {
157                 Method method = (Method)refO;
158                 method.getName();
159             }
160             
161             err.log("Gonna return problem: " + problem);
162             return problem;
163         } finally {
164             semafor.set(null);
165         }
166     }
167     
168     private EjbJarWhereUsedRefactoring getEjbJarWhereUsedRefactor() {
169         if (ejbJarWhereUsedRefactor == null) {
170             ejbJarWhereUsedRefactor = new EjbJarWhereUsedRefactoring();
171         }
172         return ejbJarWhereUsedRefactor;
173     }
174     
175     private WebXmlWhereUsedRefactoring getWebXmlWhereUsedRefactor() {
176         if (webXmlWhereUsedRefactor == null) {
177             webXmlWhereUsedRefactor = new WebXmlWhereUsedRefactoring();
178         }
179         return webXmlWhereUsedRefactor;
180     }
181     
182     private TldWhereUsedRefactoring getTldWhereUsedRefactor() {
183         if (tldWhereUsedRefactor == null) {
184             tldWhereUsedRefactor = new TldWhereUsedRefactoring();
185         }
186         return tldWhereUsedRefactor;
187     }
188     
189     private WebservicesXmlWhereUsedRefactoring getWebservicesXmlWhereUsedRefactor() {
190         if (webservicesXmlWhereUsedRefactor == null) {
191             webservicesXmlWhereUsedRefactor = new WebservicesXmlWhereUsedRefactoring();
192         }
193         return webservicesXmlWhereUsedRefactor;
194     }
195     
196     private JaxWsXmlWhereUsedRefactoring getJaxWsXmlWhereUsedRefactoring() {
197         if (jaxWsXmlWhereUsedRefactor == null) {
198             jaxWsXmlWhereUsedRefactor = new JaxWsXmlWhereUsedRefactoring();
199         }
200         return jaxWsXmlWhereUsedRefactor;
201     }
202     
203     private PersistenceXmlWhereUsedRefactoring getPersistenceXmlWhereUsedRefactoring(){
204         if (persistenceXmlWhereUsedRefactor == null){
205             persistenceXmlWhereUsedRefactor = new PersistenceXmlWhereUsedRefactoring();
206         }
207         return persistenceXmlWhereUsedRefactor;
208     }
209     
210     private SunJaxWsXmlWhereUsedRefactoring getSunJaxWsXmlWhereUsedRefactoring() {
211         if (sunJaxWsXmlWhereUsedRefactor == null) {
212             sunJaxWsXmlWhereUsedRefactor = new SunJaxWsXmlWhereUsedRefactoring();
213         }
214         return sunJaxWsXmlWhereUsedRefactor;
215     }
216     
217     private EntityWhereUsedRefactoring getEntityWhereUsedRefactor() {
218         if (entityWhereUsedRefactor == null){
219             entityWhereUsedRefactor = new EntityWhereUsedRefactoring();
220         }
221         return entityWhereUsedRefactor;
222     }
223     
224     
225     
226 }
227
Popular Tags