1 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 45 public class J2EERenameRefactoringPlugin implements RefactoringPlugin { 46 47 48 private static ThreadLocal semafor = new ThreadLocal (); 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"); 64 65 public J2EERenameRefactoringPlugin(AbstractRefactoring refactoring) { 66 this.renameRefactoring = (RenameRefactoring) refactoring; 67 } 68 69 72 public Problem preCheck() { 73 Problem problem = null; 74 if (semafor.get() == null) { 75 semafor.set(new Object ()); 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")); 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 ()); 102 103 RefObject refO = (RefObject) renameRefactoring.getRefactoredObject(); 104 err.log("refO: " + refO); 105 106 String 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 125 public Problem checkParameters() { 126 Problem problem = null; 127 if (semafor.get() == null) { 128 semafor.set(new Object ()); 129 130 RefObject refO = (RefObject) renameRefactoring.getRefactoredObject(); 131 err.log("refO: " + refO); 132 133 String 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 155 public Problem prepare(RefactoringElementsBag refactoringElements) { 156 Problem problem = null; 157 158 if (semafor.get() == null) { 159 semafor.set(new Object ()); 160 161 RefObject refO = (RefObject) renameRefactoring.getRefactoredObject(); 162 err.log("refO: " + refO); 163 164 String 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 |