KickJava   Java API By Example, From Geeks To Geeks.

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


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.modules.refactoring.api.AbstractRefactoring;
25 import org.netbeans.modules.refactoring.api.ChangeParametersRefactoring.ParameterInfo;
26 import org.netbeans.modules.refactoring.api.Problem;
27 import org.netbeans.modules.refactoring.api.ChangeParametersRefactoring;
28 import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
29 import org.netbeans.modules.refactoring.spi.RefactoringPlugin;
30 import org.openide.ErrorManager;
31
32 import org.netbeans.modules.j2ee.refactoring.changeparam.*;
33 import org.openide.util.NbBundle;
34
35 /**
36  *
37  * @author Martin Grebac
38  */

39 public class J2EEChangeParamRefactoringPlugin implements RefactoringPlugin {
40     
41     /** This one is important creature - makes sure that cycles between plugins won't appear */
42     private static ThreadLocal JavaDoc semafor = new ThreadLocal JavaDoc();
43     
44     private EjbJarChangeParamRefactoring ejbJarChangeParamRefactor;
45 // private WebXmlChangeParamRefactoring webXmlChangeParamRefactor;
46
// private TldChangeParamRefactoring tldChangeParamRefactor;
47
private WebservicesXmlChangeParamRefactoring webservicesXmlChangeParamRefactor;
48     
49     private AbstractRefactoring refactoring;
50     
51     private static ErrorManager err = ErrorManager.getDefault().getInstance("org.netbeans.modules.j2ee.refactoring.changeparam"); // NOI18N
52

53     /** Creates a new instance of J2EEChangeParamRefactoringPlugin */
54     public J2EEChangeParamRefactoringPlugin(AbstractRefactoring refactoring) {
55         this.refactoring = refactoring;
56     }
57     
58     /** Checks pre-conditions of the refactoring and returns problems.
59      * @return Problems found or null (if no problems were identified)
60      */

61     public Problem preCheck() {
62         Problem problem = null;
63         if (semafor.get() == null) {
64             semafor.set(new Object JavaDoc());
65             ChangeParametersRefactoring changeParamRefactor = ((ChangeParametersRefactoring)refactoring);
66             
67             RefObject refO = (RefObject) changeParamRefactor.getRefactoredObject();
68             err.log("refO: " + refO);
69             if (!Utility.isEjb30(refO)){
70                 Problem ejbJarProblem = getEjbJarChangeParamRefactor().preCheck(refO);
71                 problem = Utility.addProblemsToEnd(problem, ejbJarProblem);
72             } else if (Utility.hasEjbJar(refO)){
73                 Problem ejbJarProblem = new Problem(false, NbBundle.getMessage(J2EEChangeParamRefactoringPlugin.class, "TXT_EjbJarChangeParamsWarning")); //NOI18N
74
problem = Utility.addProblemsToEnd(problem, ejbJarProblem);
75             }
76             
77             Problem websvcProblem = getWebservicesXmlChangeParamRefactor().preCheck(refO);
78             problem = Utility.addProblemsToEnd(problem, websvcProblem);
79             
80             semafor.set(null);
81         }
82         
83         return problem;
84     }
85     
86     public Problem fastCheckParameters() {
87         Problem problem = null;
88         if (semafor.get() == null) {
89             semafor.set(new Object JavaDoc());
90             ChangeParametersRefactoring changeParamRefactor = ((ChangeParametersRefactoring)refactoring);
91             
92             RefObject refO = (RefObject) changeParamRefactor.getRefactoredObject();
93             err.log("refO: " + refO);
94             
95             if (!Utility.isEjb30(refO)){
96                 Problem ejbJarProblem = getEjbJarChangeParamRefactor().fastCheckParameters(refO);
97                 problem = Utility.addProblemsToEnd(problem, ejbJarProblem);
98             }
99             
100             Problem websvcProblem = getWebservicesXmlChangeParamRefactor().fastCheckParameters(refO);
101             problem = Utility.addProblemsToEnd(problem, websvcProblem);
102             
103             semafor.set(null);
104         }
105         return problem;
106     }
107     
108     /** Checks parameters of the refactoring.
109      * @return Problems found or null (if no problems were identified)
110      */

111     public Problem checkParameters() {
112         return fastCheckParameters();
113     }
114     
115     /** Collects refactoring elements for a given refactoring.
116      * @param refactoringElements Collection of refactoring elements - the implementation of this method
117      * should add refactoring elements to this collections. It should make no assumptions about the collection
118      * content.
119      * @return Problems found or null (if no problems were identified)
120      */

121     public Problem prepare(RefactoringElementsBag refactoringElements) {
122         Problem problem = null;
123         if (semafor.get() == null) {
124             semafor.set(new Object JavaDoc());
125             ChangeParametersRefactoring changeParamRefactor = ((ChangeParametersRefactoring)refactoring);
126             
127             RefObject refO = (RefObject) changeParamRefactor.getRefactoredObject();
128             ParameterInfo[] paramInfo = changeParamRefactor.getParameterInfo();
129             int modifiers = changeParamRefactor.getModifiers();
130             
131             err.log("refO: " + refO);
132             
133             // Problem webXmlProblem = getWebXmlChangeParamRefactor().prepare(refO, newName, refactoringElements);
134
// problem = Utility.addProblemsToEnd(problem, webXmlProblem);
135
//
136
// Problem tldProblem = getTldChangeParamRefactor().prepare(refO, newName, refactoringElements);
137
// problem = Utility.addProblemsToEnd(problem, tldProblem);
138

139             if (!Utility.isEjb30(refO)){
140                 Problem ejbJarProblem = getEjbJarChangeParamRefactor().prepare(refactoring, refO, paramInfo, modifiers, refactoringElements);
141                 problem = Utility.addProblemsToEnd(problem, ejbJarProblem);
142             }
143             
144             Problem webservicesProblem = getWebservicesXmlChangeParamRefactor().prepare(refactoring, refO, paramInfo, modifiers, refactoringElements);
145             problem = Utility.addProblemsToEnd(problem, webservicesProblem);
146             
147             semafor.set(null);
148         }
149         err.log("Gonna return problem: " + problem);
150         return problem;
151     }
152     
153     public void cancelRequest() { }
154     
155     private EjbJarChangeParamRefactoring getEjbJarChangeParamRefactor() {
156         if (ejbJarChangeParamRefactor == null) {
157             ejbJarChangeParamRefactor = new EjbJarChangeParamRefactoring();
158         }
159         return ejbJarChangeParamRefactor;
160     }
161     
162 // private WebXmlChangeParamRefactoring getWebXmlChangeParamRefactor() {
163
// if (webXmlChangeParamRefactor == null) {
164
// webXmlChangeParamRefactor = new WebXmlChangeParamRefactoring();
165
// }
166
// return webXmlChangeParamRefactor;
167
// }
168
//
169
// private TldChangeParamRefactoring getTldChangeParamRefactor() {
170
// if (tldChangeParamRefactor == null) {
171
// tldChangeParamRefactor = new TldChangeParamRefactoring();
172
// }
173
// return tldChangeParamRefactor;
174
// }
175
//
176
private WebservicesXmlChangeParamRefactoring getWebservicesXmlChangeParamRefactor() {
177         if (webservicesXmlChangeParamRefactor == null) {
178             webservicesXmlChangeParamRefactor = new WebservicesXmlChangeParamRefactoring();
179         }
180         return webservicesXmlChangeParamRefactor;
181     }
182     
183 }
184
Popular Tags