1 19 20 package org.netbeans.modules.j2ee.refactoring.whereused; 21 22 import java.io.IOException ; 23 import java.text.MessageFormat ; 24 import java.util.Collection ; 25 import java.util.Iterator ; 26 import javax.jmi.reflect.RefObject; 27 import org.netbeans.api.project.FileOwnerQuery; 28 import org.netbeans.api.project.Project; 29 import org.netbeans.modules.j2ee.dd.api.ejb.AssemblyDescriptor; 30 import org.netbeans.modules.j2ee.dd.api.ejb.ContainerTransaction; 31 import org.netbeans.modules.j2ee.dd.api.ejb.ExcludeList; 32 import org.netbeans.modules.j2ee.dd.api.ejb.MethodPermission; 33 import org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException; 34 import org.netbeans.modules.j2ee.dd.api.common.EjbRef; 35 import org.netbeans.modules.j2ee.dd.api.common.EjbLocalRef; 36 import org.netbeans.jmi.javamodel.ClassDefinition; 37 import org.netbeans.jmi.javamodel.JavaClass; 38 import org.netbeans.jmi.javamodel.Method; 39 import org.netbeans.jmi.javamodel.UnresolvedClass; 40 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; 41 import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans; 42 import org.netbeans.modules.j2ee.dd.api.ejb.Entity; 43 import org.netbeans.modules.j2ee.dd.api.ejb.MessageDriven; 44 import org.netbeans.modules.j2ee.dd.api.ejb.Query; 45 import org.netbeans.modules.j2ee.dd.api.ejb.QueryMethod; 46 import org.netbeans.modules.j2ee.dd.api.ejb.Session; 47 import org.netbeans.modules.j2ee.refactoring.Utility; 48 import org.netbeans.modules.javacore.api.JavaModel; 49 import org.netbeans.modules.refactoring.api.AbstractRefactoring; 50 import org.netbeans.modules.refactoring.api.Problem; 51 import org.netbeans.modules.refactoring.api.RefactoringSession; 52 import org.netbeans.modules.refactoring.spi.RefactoringElementsBag; 53 import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation; 54 import org.netbeans.modules.refactoring.api.WhereUsedQuery; 55 import org.openide.ErrorManager; 56 import org.openide.filesystems.FileObject; 57 import org.openide.util.NbBundle; 58 59 63 public final class EjbJarWhereUsedRefactoring { 64 65 private static final ErrorManager err = ErrorManager.getDefault().getInstance("org.netbeans.modules.j2ee.refactoring.whereused"); 67 public EjbJarWhereUsedRefactoring() { } 68 69 public Problem prepare(AbstractRefactoring refactoring, RefObject refObject, RefactoringElementsBag refactoringElements) { 70 RefactoringSession session = refactoringElements.getSession(); 71 Problem problem = null; 72 if (refObject instanceof JavaClass) { 73 74 JavaClass jClass = (JavaClass)refObject; 75 err.log("jClass: " + jClass); 76 77 String name = jClass.getName(); 78 err.log("name: " + name); 79 Collection emodules = Utility.getRelevantEjbModules(jClass); 80 Iterator emIter = null; 81 82 if (emodules != null) { 83 emIter = emodules.iterator(); 84 } 85 if (emIter != null) { 86 while (emIter.hasNext()) { 87 org.netbeans.modules.j2ee.api.ejbjar.EjbJar em = (org.netbeans.modules.j2ee.api.ejbjar.EjbJar)emIter.next(); 88 if (em != null) { FileObject ejbJarFO = em.getDeploymentDescriptor(); 90 EjbJar ejbJarDD = null; 91 try { 92 ejbJarDD = org.netbeans.modules.j2ee.dd.api.ejb.DDProvider.getDefault().getMergedDDRoot(em.getMetadataUnit()); 93 } catch (IOException ioe) { 94 } 96 if ((ejbJarDD != null) && (ejbJarDD.getStatus()!=EjbJar.STATE_INVALID_UNPARSABLE) && ejbJarFO != null) { 97 EnterpriseBeans eBeans = ejbJarDD.getEnterpriseBeans(); 98 99 100 Session [] sessionBeans = eBeans.getSession(); 101 err.log("Session Beans: " + sessionBeans); 102 if ((sessionBeans != null) && (sessionBeans.length > 0)) { 103 for (int b=0; b < sessionBeans.length; b++) { 104 Session sBean = sessionBeans[b]; 105 err.log("Session Bean: " + sBean); 106 String ejbClass = sBean.getEjbClass(); 107 err.log("EJB Class: " + ejbClass); 108 if ((ejbClass != null) && (ejbClass.equals(name))) { 109 RefactoringElementImplementation elem = new EjbJarBeanClassWhereUsedRefactoringElement(ejbJarDD, name, ejbJarFO); 110 refactoringElements.add(refactoring, elem); 111 } 112 String ejbLocal = sBean.getLocal(); 113 err.log("EJB Local: " + ejbLocal); 114 if ((ejbLocal != null) && (ejbLocal.equals(name))) { 115 RefactoringElementImplementation elem = new EjbJarLocalWhereUsedRefactoringElement(ejbJarDD, name, ejbJarFO); 116 refactoringElements.add(refactoring, elem); 117 } 118 String ejbLocalHome = sBean.getLocalHome(); 119 err.log("EJB LocalHome: " + ejbLocalHome); 120 if ((ejbLocalHome != null) && (ejbLocalHome.equals(name))) { 121 RefactoringElementImplementation elem = new EjbJarLocalHomeWhereUsedRefactoringElement(ejbJarDD, name, ejbJarFO); 122 refactoringElements.add(refactoring, elem); 123 } 124 String ejbHome = sBean.getHome(); 125 err.log("EJB Home: " + ejbHome); 126 if ((ejbHome != null) && (ejbHome.equals(name))) { 127 RefactoringElementImplementation elem = new EjbJarHomeWhereUsedRefactoringElement(ejbJarDD, name, ejbJarFO); 128 refactoringElements.add(refactoring, elem); 129 } 130 String ejbRemote = sBean.getRemote(); 131 err.log("EJB Remote: " + ejbRemote); 132 if ((ejbRemote != null) && (ejbRemote.equals(name))) { 133 RefactoringElementImplementation elem = new EjbJarRemoteWhereUsedRefactoringElement(ejbJarDD, name, ejbJarFO); 134 refactoringElements.add(refactoring, elem); 135 } 136 137 String serviceEndpoint; 139 try { 140 serviceEndpoint = sBean.getServiceEndpoint(); 141 err.log("EJB Service Endpoint: " + serviceEndpoint); 142 if ((serviceEndpoint != null) && (serviceEndpoint.equals(name))) { 143 RefactoringElementImplementation elem = new EjbJarServiceEndpointWhereUsedRefactoringElement(ejbJarDD, name, ejbJarFO); 144 refactoringElements.add(refactoring, elem); 145 } 146 } catch (VersionNotSupportedException versionex) { 147 err.log("Service endpoint not supported in this version of dd."); 149 } 150 EjbRef[] refs = sBean.getEjbRef(); 152 if ((refs != null) && (refs.length > 0)) { 153 for (int l=0; l < refs.length; l++) { 154 EjbRef ref = refs[l]; 155 err.log("EJB ref: " + ref); 156 String refHome = ref.getHome(); 157 if ((refHome != null) && (refHome.equals(name))) { 158 RefactoringElementImplementation elem = new EjbJarRefHomeWhereUsedRefactoringElement(ejbJarDD, name, ejbJarFO); 159 refactoringElements.add(refactoring, elem); 160 } 161 String refRemote = ref.getRemote(); 162 if ((refRemote != null) && (refRemote.equals(name))) { 163 RefactoringElementImplementation elem = new EjbJarRefRemoteWhereUsedRefactoringElement(ejbJarDD, name, ejbJarFO); 164 refactoringElements.add(refactoring, elem); 165 } 166 } 167 } 168 EjbLocalRef[] localRefs = sBean.getEjbLocalRef(); 170 if ((localRefs != null) && (localRefs.length > 0)) { 171 for (int l=0; l < localRefs.length; l++) { 172 EjbLocalRef localRef = localRefs[l]; 173 err.log("EJB local ref: " + localRef); 174 String refLocal = localRef.getLocal(); 175 if ((refLocal != null) && (refLocal.equals(name))) { 176 RefactoringElementImplementation elem = new EjbJarRefLocalWhereUsedRefactoringElement(ejbJarDD, name, ejbJarFO); 177 refactoringElements.add(refactoring, elem); 178 } 179 String refLocalHome = localRef.getLocalHome(); 180 if ((refLocalHome != null) && (refLocalHome.equals(name))) { 181 RefactoringElementImplementation elem = new EjbJarRefLocalHomeWhereUsedRefactoringElement(ejbJarDD, name, ejbJarFO); 182 refactoringElements.add(refactoring, elem); 183 } 184 } 185 } 186 } 187 } 188 189 190 Entity [] entityBeans = eBeans.getEntity(); 191 err.log("Entity Beans: " + entityBeans); 192 if ((entityBeans != null) && (entityBeans.length > 0)) { 193 for (int b=0; b < entityBeans.length; b++) { 194 Entity entBean = entityBeans[b]; 195 err.log("Entity Bean: " + entBean); 196 String ejbClass = entBean.getEjbClass(); 197 err.log("EJB Class: " + ejbClass); 198 if ((ejbClass != null) && (ejbClass.equals(name))) { 199 RefactoringElementImplementation elem = new EjbJarBeanClassWhereUsedRefactoringElement(ejbJarDD, name, ejbJarFO); 200 refactoringElements.add(refactoring, elem); 201 } 202 String ejbLocal = entBean.getLocal(); 203 err.log("EJB Local: " + ejbLocal); 204 if ((ejbLocal != null) && (ejbLocal.equals(name))) { 205 RefactoringElementImplementation elem = new EjbJarLocalWhereUsedRefactoringElement(ejbJarDD, name, ejbJarFO); 206 refactoringElements.add(refactoring, elem); 207 } 208 String ejbLocalHome = entBean.getLocalHome(); 209 err.log("EJB LocalHome: " + ejbLocalHome); 210 if ((ejbLocalHome != null) && (ejbLocalHome.equals(name))) { 211 RefactoringElementImplementation elem = new EjbJarLocalHomeWhereUsedRefactoringElement(ejbJarDD, name, ejbJarFO); 212 refactoringElements.add(refactoring, elem); 213 } 214 String ejbHome = entBean.getHome(); 215 err.log("EJB Home: " + ejbHome); 216 if ((ejbHome != null) && (ejbHome.equals(name))) { 217 RefactoringElementImplementation elem = new EjbJarHomeWhereUsedRefactoringElement(ejbJarDD, name, ejbJarFO); 218 refactoringElements.add(refactoring, elem); 219 } 220 String ejbRemote = entBean.getRemote(); 221 err.log("EJB Remote: " + ejbRemote); 222 if ((ejbRemote != null) && (ejbRemote.equals(name))) { 223 RefactoringElementImplementation elem = new EjbJarRemoteWhereUsedRefactoringElement(ejbJarDD, name, ejbJarFO); 224 refactoringElements.add(refactoring, elem); 225 } 226 227 EjbRef[] refs = entBean.getEjbRef(); 229 if ((refs != null) && (refs.length > 0)) { 230 for (int l=0; l < refs.length; l++) { 231 EjbRef ref = refs[l]; 232 err.log("EJB ref: " + ref); 233 String refHome = ref.getHome(); 234 if ((refHome != null) && (refHome.equals(name))) { 235 RefactoringElementImplementation elem = new EjbJarRefHomeWhereUsedRefactoringElement(ejbJarDD, name, ejbJarFO); 236 refactoringElements.add(refactoring, elem); 237 } 238 String refRemote = ref.getRemote(); 239 if ((refRemote != null) && (refRemote.equals(name))) { 240 RefactoringElementImplementation elem = new EjbJarRefRemoteWhereUsedRefactoringElement(ejbJarDD, name, ejbJarFO); 241 refactoringElements.add(refactoring, elem); 242 } 243 } 244 } 245 246 EjbLocalRef[] localRefs = entBean.getEjbLocalRef(); 248 if ((localRefs != null) && (localRefs.length > 0)) { 249 for (int l=0; l < localRefs.length; l++) { 250 EjbLocalRef localRef = localRefs[l]; 251 err.log("EJB local ref: " + localRef); 252 String refLocal = localRef.getLocal(); 253 if ((refLocal != null) && (refLocal.equals(name))) { 254 RefactoringElementImplementation elem = new EjbJarRefLocalWhereUsedRefactoringElement(ejbJarDD, name, ejbJarFO); 255 refactoringElements.add(refactoring, elem); 256 } 257 String refLocalHome = localRef.getLocalHome(); 258 if ((refLocalHome != null) && (refLocalHome.equals(name))) { 259 RefactoringElementImplementation elem = new EjbJarRefLocalHomeWhereUsedRefactoringElement(ejbJarDD, name, ejbJarFO); 260 refactoringElements.add(refactoring, elem); 261 } 262 } 263 } 264 } 265 } 266 267 268 MessageDriven [] messageBeans = eBeans.getMessageDriven(); 269 err.log("MessageDriven Beans: " + messageBeans); 270 if ((messageBeans != null) && (messageBeans.length > 0)) { 271 for (int b=0; b < messageBeans.length; b++) { 272 MessageDriven msgBean = messageBeans[b]; 273 err.log("MessageDriven Bean: " + msgBean); 274 String ejbClass = msgBean.getEjbClass(); 275 err.log("EJB Class: " + ejbClass); 276 if ((ejbClass != null) && (ejbClass.equals(name))) { 277 RefactoringElementImplementation elem = new EjbJarBeanClassWhereUsedRefactoringElement(ejbJarDD, name, ejbJarFO); 278 refactoringElements.add(refactoring, elem); 279 } 280 281 EjbRef[] refs = msgBean.getEjbRef(); 283 if ((refs != null) && (refs.length > 0)) { 284 for (int l=0; l < refs.length; l++) { 285 EjbRef ref = refs[l]; 286 err.log("EJB ref: " + ref); 287 String refHome = ref.getHome(); 288 if ((refHome != null) && (refHome.equals(name))) { 289 RefactoringElementImplementation elem = new EjbJarRefHomeWhereUsedRefactoringElement(ejbJarDD, name, ejbJarFO); 290 refactoringElements.add(refactoring, elem); 291 } 292 String refRemote = ref.getRemote(); 293 if ((refRemote != null) && (refRemote.equals(name))) { 294 RefactoringElementImplementation elem = new EjbJarRefRemoteWhereUsedRefactoringElement(ejbJarDD, name, ejbJarFO); 295 refactoringElements.add(refactoring, elem); 296 } 297 } 298 } 299 300 EjbLocalRef[] localRefs = msgBean.getEjbLocalRef(); 302 if ((localRefs != null) && (localRefs.length > 0)) { 303 for (int l=0; l < localRefs.length; l++) { 304 EjbLocalRef localRef = localRefs[l]; 305 err.log("EJB local ref: " + localRef); 306 String refLocal = localRef.getLocal(); 307 if ((refLocal != null) && (refLocal.equals(name))) { 308 RefactoringElementImplementation elem = new EjbJarRefLocalWhereUsedRefactoringElement(ejbJarDD, name, ejbJarFO); 309 refactoringElements.add(refactoring, elem); 310 } 311 String refLocalHome = localRef.getLocalHome(); 312 if ((refLocalHome != null) && (refLocalHome.equals(name))) { 313 RefactoringElementImplementation elem = new EjbJarRefLocalHomeWhereUsedRefactoringElement(ejbJarDD, name, ejbJarFO); 314 refactoringElements.add(refactoring, elem); 315 } 316 } 317 } 318 } 319 } 320 321 } else { 322 Problem newProblem = new Problem(false, NbBundle.getMessage(EjbJarWhereUsedRefactoring.class, "TXT_EjbJarWhereUsedInvalidProblem")); 323 problem = Utility.addProblemsToEnd(problem, newProblem); 324 } 325 } } 327 } 328 } 330 if (refObject instanceof Method) { 331 Method method = (Method)refObject; 332 FileObject fo = JavaModel.getFileObject(method.getResource()); 333 Collection emodules = Utility.getRelevantEjbModules(method); 334 if ((emodules != null) && (emodules.size() > 0)) { ClassDefinition jc = method.getDeclaringClass(); 336 err.log("classdefinition classDefinition: " + jc); 337 if (jc instanceof JavaClass) { 338 339 Iterator emIter = emodules.iterator(); 341 while (emIter.hasNext()) { 342 org.netbeans.modules.j2ee.api.ejbjar.EjbJar em = (org.netbeans.modules.j2ee.api.ejbjar.EjbJar)emIter.next(); 343 if (em != null) { FileObject ejbJarFO = em.getDeploymentDescriptor(); 345 EjbJar ejbJarDD = null; 346 try { 347 ejbJarDD = org.netbeans.modules.j2ee.dd.api.ejb.DDProvider.getDefault().getMergedDDRoot(em.getMetadataUnit()); 348 } catch (IOException ioe) { 349 } 351 if ((ejbJarDD != null) && (ejbJarDD.getStatus()!=EjbJar.STATE_INVALID_UNPARSABLE) && ejbJarFO != null) { 352 AssemblyDescriptor asmDesc = ejbJarDD.getSingleAssemblyDescriptor(); 353 err.log("asm desc: " + asmDesc); 354 355 if (asmDesc != null) { 356 ContainerTransaction[] contTx = asmDesc.getContainerTransaction(); 358 if ((contTx != null) && (contTx.length > 0)) { 359 for (int c=0; c<contTx.length; c++) { 360 ContainerTransaction cTx = contTx[c]; 361 err.log("ctx: " + cTx); 362 if (cTx != null) { 363 org.netbeans.modules.j2ee.dd.api.ejb.Method[] mtds = cTx.getMethod(); 364 if ((mtds != null) && (mtds.length > 0)) { 365 for (int m=0; m < mtds.length; m++) { 366 org.netbeans.modules.j2ee.dd.api.ejb.Method mtd = mtds[m]; 367 err.log("mtd: " + mtd); 368 String mtdName = mtd.getMethodName(); 369 err.log("mtdName: " + mtdName); 370 if (mtdName.equals(method.getName())) { 371 String invokedEjbName = mtd.getEjbName(); 372 err.log("invokedejb: " + invokedEjbName); 373 String ejbName = Utility.getEjbNameForClass(ejbJarDD, jc); 374 err.log("ejbname: " + ejbName); 375 if (invokedEjbName.equals(ejbName)) { 376 RefactoringElementImplementation elem = new EjbJarContainerTxWhereUsedRefactoringElement(ejbJarDD, mtdName, ejbName, ejbJarFO); 377 refactoringElements.add(refactoring, elem); 378 } 379 } 380 381 } 382 } 383 } 384 } 385 } 386 387 MethodPermission[] mtdPerms = asmDesc.getMethodPermission(); 389 if ((mtdPerms != null) && (mtdPerms.length > 0)) { 390 for (int c=0; c<mtdPerms.length; c++) { 391 MethodPermission mtdPerm = mtdPerms[c]; 392 err.log("mtdPerm: " + mtdPerm); 393 if (mtdPerm != null) { 394 org.netbeans.modules.j2ee.dd.api.ejb.Method[] mtds = mtdPerm.getMethod(); 395 if ((mtds != null) && (mtds.length > 0)) { 396 for (int m=0; m < mtds.length; m++) { 397 org.netbeans.modules.j2ee.dd.api.ejb.Method mtd = mtds[m]; 398 err.log("mtd: " + mtd); 399 String mtdName = mtd.getMethodName(); 400 err.log("mtdName: " + mtdName); 401 if (mtdName.equals(method.getName())) { 402 String invokedEjbName = mtd.getEjbName(); 403 err.log("invokedejb: " + invokedEjbName); 404 String ejbName = Utility.getEjbNameForClass(ejbJarDD, jc); 405 err.log("ejbname: " + ejbName); 406 if (invokedEjbName.equals(ejbName)) { 407 RefactoringElementImplementation elem = new EjbJarMethodPermissionWhereUsedRefactoringElement(ejbJarDD, mtdName, ejbName, ejbJarFO); 408 refactoringElements.add(refactoring, elem); 409 } 410 } 411 412 } 413 } 414 } 415 } 416 } 417 418 ExcludeList excList = asmDesc.getExcludeList(); 420 err.log("excList: " + excList); 421 if (excList != null) { 422 org.netbeans.modules.j2ee.dd.api.ejb.Method[] mtds = excList.getMethod(); 423 if ((mtds != null) && (mtds.length > 0)) { 424 for (int m=0; m < mtds.length; m++) { 425 org.netbeans.modules.j2ee.dd.api.ejb.Method mtd = mtds[m]; 426 err.log("mtd: " + mtd); 427 String mtdName = mtd.getMethodName(); 428 err.log("mtdName: " + mtdName); 429 if (mtdName.equals(method.getName())) { 430 String invokedEjbName = mtd.getEjbName(); 431 err.log("invokedejb: " + invokedEjbName); 432 String ejbName = Utility.getEjbNameForClass(ejbJarDD, jc); 433 err.log("ejbname: " + ejbName); 434 if (invokedEjbName.equals(ejbName)) { 435 RefactoringElementImplementation elem = new EjbJarExcludeListWhereUsedRefactoringElement(ejbJarDD, mtdName, ejbName, ejbJarFO); 436 refactoringElements.add(refactoring, elem); 437 } 438 } 439 440 } 441 } 442 } 443 } 444 445 } else { 446 Problem newProblem = new Problem(false, NbBundle.getMessage(EjbJarWhereUsedRefactoring.class, "TXT_EjbJarWhereUsedInvalidProblem")); 447 problem = Utility.addProblemsToEnd(problem, newProblem); 448 } 449 } 450 451 } 452 453 JavaClass javaClass = (JavaClass)JavaModel.getDefaultExtent().getType().resolve(Utility.SESSION_BEAN); 455 err.log("javaclass: " + javaClass); 456 if (!(javaClass instanceof UnresolvedClass)) { 457 if (jc.isSubTypeOf(javaClass)) { 458 Method homeInHome = Utility.getHomeHomeMethodForSessionImplHomeMethod(method, fo, jc.getName(), false ); 459 Method homeInLocalHome = Utility.getHomeHomeMethodForSessionImplHomeMethod(method, fo, jc.getName(), true ); 460 if (homeInHome != null) { 461 WhereUsedQuery whereHomeInHome = new WhereUsedQuery(homeInHome); 462 Problem p = whereHomeInHome.prepare(session); 463 problem = Utility.addProblemsToEnd(problem, p); 464 } 465 if (homeInLocalHome != null) { 466 WhereUsedQuery whereHomeInLocalHome = new WhereUsedQuery(homeInLocalHome); 467 Problem p = whereHomeInLocalHome.prepare(session); 468 problem = Utility.addProblemsToEnd(problem, p); 469 } 470 471 return problem; 472 } 473 } 474 475 javaClass = (JavaClass)JavaModel.getDefaultExtent().getType().resolve(Utility.ENTITY_BEAN); 477 err.log("javaclass: " + javaClass); 478 if (!(javaClass instanceof UnresolvedClass)) { 479 if (jc.isSubTypeOf(javaClass)) { 481 482 Method finderInHome = Utility.getHomeFinderMethodForImplFinderMethod(method, fo, jc.getName(), false ); 484 Method finderInLocalHome = Utility.getHomeFinderMethodForImplFinderMethod(method, fo, jc.getName(), true ); 485 if (finderInHome != null) { 486 WhereUsedQuery whereFinderInHome = new WhereUsedQuery(finderInHome); 487 Problem p = whereFinderInHome.prepare(session); 488 problem = Utility.addProblemsToEnd(problem, p); 489 } 490 if (finderInLocalHome != null) { 491 WhereUsedQuery whereFinderInLocalHome = new WhereUsedQuery(finderInLocalHome); 492 Problem p = whereFinderInLocalHome.prepare(session); 493 problem = Utility.addProblemsToEnd(problem, p); 494 } 495 496 Method homeInHome = Utility.getHomeHomeMethodForSessionImplHomeMethod(method, fo, jc.getName(), false ); 497 Method homeInLocalHome = Utility.getHomeHomeMethodForSessionImplHomeMethod(method, fo, jc.getName(), true ); 498 if (homeInHome != null) { 499 WhereUsedQuery whereHomeInHome = new WhereUsedQuery(homeInHome); 500 Problem p = whereHomeInHome.prepare(session); 501 problem = Utility.addProblemsToEnd(problem, p); 502 } 503 if (homeInLocalHome != null) { 504 WhereUsedQuery whereHomeInLocalHome = new WhereUsedQuery(homeInLocalHome); 505 Problem p = whereHomeInLocalHome.prepare(session); 506 problem = Utility.addProblemsToEnd(problem, p); 507 } 508 509 if (method.getName().startsWith("ejbSelect")) { Project prj = FileOwnerQuery.getOwner(fo); 511 if (prj != null) { 512 org.netbeans.modules.j2ee.api.ejbjar.EjbJar emod = 513 org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(prj.getProjectDirectory()); 514 Entity[] eBeans = Utility.getEntityBeans(emod); 515 EjbJar ejbJarDD = Utility.getEjbJar(emod); 516 if ((eBeans != null) && (ejbJarDD != null)) { 517 for (int e = 0; e < eBeans.length; e++) { 518 Entity entity = eBeans[e]; 519 String ejbClass = entity.getEjbClass(); 520 if (jc.getName().equals(ejbClass)) { 521 Query[] queries = entity.getQuery(); 522 for (int q = 0; q < queries.length; q++) { 523 Query query = queries[q]; 524 QueryMethod qm = query.getQueryMethod(); 525 err.log("query method: " + qm); 526 if (method.getName().equals(qm.getMethodName())) { 527 RefactoringElementImplementation elem = 528 new EjbJarSelectMethodWhereUsedRefactoringElement( 529 ejbJarDD, method.getName(), 530 emod.getDeploymentDescriptor()); 531 refactoringElements.add(refactoring, elem); 532 } 533 } 534 } 535 } 536 } 537 } 538 } 539 540 return problem; 541 } 542 } 543 544 javaClass = (JavaClass)JavaModel.getDefaultExtent().getType().resolve(Utility.EJB_HOME); 546 err.log("javaclass: " + javaClass); 547 if (!(javaClass instanceof UnresolvedClass)) { 548 if (jc.isSubTypeOf(javaClass)) { 549 550 Method finderInImpl = Utility.getImplFinderMethodForHomeFinderMethod(method, fo, jc.getName(), false ); 552 Method finderInLocalHome = Utility.getHomeFinderMethodForHomeFinderMethod(method, fo, jc.getName(), true ); 553 if (finderInImpl != null) { 554 WhereUsedQuery renameFinderInImpl = new WhereUsedQuery(finderInImpl); 555 Problem p = renameFinderInImpl.prepare(session); 556 problem = Utility.addProblemsToEnd(problem, p); 557 } 558 if (finderInLocalHome != null) { 559 WhereUsedQuery renameFinderInLocalHome = new WhereUsedQuery(finderInLocalHome); 560 Problem p = renameFinderInLocalHome.prepare(session); 561 problem = Utility.addProblemsToEnd(problem, p); 562 } 563 Project prj = FileOwnerQuery.getOwner(fo); 564 if (prj != null) { 565 org.netbeans.modules.j2ee.api.ejbjar.EjbJar emod = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(prj.getProjectDirectory()); 566 Entity[] eBeans = Utility.getEntityBeans(emod); 567 EjbJar ejbJarDD = Utility.getEjbJar(emod); 568 if ((eBeans != null) && (ejbJarDD != null)) { 569 for (int e=0; e < eBeans.length; e++) { 570 Entity entity = eBeans[e]; 571 String ejbClass = entity.getHome(); 572 if (jc.getName().equals(ejbClass)) { 573 Query[] queries = entity.getQuery(); 574 for (int q=0; q<queries.length; q++) { 575 Query query = queries[q]; 576 QueryMethod qm = query.getQueryMethod(); 577 err.log("query method: " + qm); 578 if (method.getName().equals(qm.getMethodName())) { 579 RefactoringElementImplementation elem = 580 new EjbJarFinderMethodWhereUsedRefactoringElement(ejbJarDD, method.getName(), emod.getDeploymentDescriptor()); 581 refactoringElements.add(refactoring, elem); 582 } 583 } 584 } 585 } 586 } 587 } 588 589 Method homeInImpl = Utility.getImplHomeMethodForHomeHomeMethod(method, fo, jc.getName(), false ); 591 Method homeInLocalHome = Utility.getHomeHomeMethodForHomeHomeMethod(method, fo, jc.getName(), true ); 592 if (homeInImpl != null) { 593 WhereUsedQuery renameHomeInImpl = new WhereUsedQuery(homeInImpl); 594 Problem p = renameHomeInImpl.prepare(session); 595 problem = Utility.addProblemsToEnd(problem, p); 596 } 597 if (homeInLocalHome != null) { 598 WhereUsedQuery renameHomeInLocalHome = new WhereUsedQuery(homeInLocalHome); 599 Problem p = renameHomeInLocalHome.prepare(session); 600 problem = Utility.addProblemsToEnd(problem, p); 601 } 602 return problem; 603 } 604 } 605 606 javaClass = (JavaClass)JavaModel.getDefaultExtent().getType().resolve(Utility.EJB_LOCAL_HOME); 608 err.log("javaclass: " + javaClass); 609 if (!(javaClass instanceof UnresolvedClass)) { 610 if (jc.isSubTypeOf(javaClass)) { 611 612 Method finderInImpl = Utility.getImplFinderMethodForHomeFinderMethod(method, fo, jc.getName(), true ); 613 Method finderInHome = Utility.getHomeFinderMethodForHomeFinderMethod(method, fo, jc.getName(), false ); 614 if (finderInImpl != null) { 615 WhereUsedQuery renameFinderInImpl = new WhereUsedQuery(finderInImpl); 616 Problem p = renameFinderInImpl.prepare(session); 617 problem = Utility.addProblemsToEnd(problem, p); 618 } 619 if (finderInHome != null) { 620 WhereUsedQuery renameFinderInHome = new WhereUsedQuery(finderInHome); 621 Problem p = renameFinderInHome.prepare(session); 622 problem = Utility.addProblemsToEnd(problem, p); 623 } 624 625 Project prj = FileOwnerQuery.getOwner(fo); 626 if (prj != null) { 627 org.netbeans.modules.j2ee.api.ejbjar.EjbJar emod = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(prj.getProjectDirectory()); 628 Entity[] eBeans = Utility.getEntityBeans(emod); 629 EjbJar ejbJarDD = Utility.getEjbJar(emod); 630 if ((eBeans != null) && (ejbJarDD != null)) { 631 for (int e=0; e < eBeans.length; e++) { 632 Entity entity = eBeans[e]; 633 String ejbClass = entity.getLocalHome(); 634 if (jc.getName().equals(ejbClass)) { 635 Query[] queries = entity.getQuery(); 636 for (int q=0; q<queries.length; q++) { 637 Query query = queries[q]; 638 QueryMethod qm = query.getQueryMethod(); 639 err.log("query method: " + qm); 640 if (method.getName().equals(qm.getMethodName())) { 641 RefactoringElementImplementation elem = 642 new EjbJarFinderMethodWhereUsedRefactoringElement(ejbJarDD, method.getName(), emod.getDeploymentDescriptor()); 643 refactoringElements.add(refactoring, elem); 644 } 645 } 646 } 647 } 648 } 649 } 650 651 Method homeInImpl = Utility.getImplHomeMethodForHomeHomeMethod(method, fo, jc.getName(), true ); 653 Method homeInHome = Utility.getHomeHomeMethodForHomeHomeMethod(method, fo, jc.getName(), false ); 654 if (homeInImpl != null) { 655 WhereUsedQuery renameHomeInImpl = new WhereUsedQuery(homeInImpl); 656 Problem p = renameHomeInImpl.prepare(session); 657 problem = Utility.addProblemsToEnd(problem, p); 658 } 659 if (homeInHome != null) { 660 WhereUsedQuery renameHomeInHome = new WhereUsedQuery(homeInHome); 661 Problem p = renameHomeInHome.prepare(session); 662 problem = Utility.addProblemsToEnd(problem, p); 663 } 664 return problem; 665 } 666 } 667 } 668 } 669 670 } 672 return problem; 673 } 674 675 public final class EjbJarBeanClassWhereUsedRefactoringElement extends AbstractWhereUsedRefactoringElement { 676 677 protected EjbJar ejbJarDD; 678 679 680 public EjbJarBeanClassWhereUsedRefactoringElement(EjbJar ejbJarDD, String name, FileObject parentFile) { 681 this.ejbJarDD = ejbJarDD; 682 this.name = name; 683 this.parentFile = parentFile; 684 } 685 686 689 public String getDisplayText() { 690 Object [] args = new Object [] {name}; 691 return MessageFormat.format(NbBundle.getMessage(EjbJarWhereUsedRefactoring.class, "TXT_EjbJarBeanClassWhereUsed"), args); 692 } 693 } 694 695 public final class EjbJarLocalWhereUsedRefactoringElement extends AbstractWhereUsedRefactoringElement { 696 697 protected EjbJar ejbJarDD; 698 699 700 public EjbJarLocalWhereUsedRefactoringElement(EjbJar ejbJarDD, String name, FileObject parentFile) { 701 this.ejbJarDD = ejbJarDD; 702 this.name = name; 703 this.parentFile = parentFile; 704 } 705 706 709 public String getDisplayText() { 710 Object [] args = new Object [] {name}; 711 return MessageFormat.format(NbBundle.getMessage(EjbJarWhereUsedRefactoring.class, "TXT_EjbJarLocalWhereUsed"), args); 712 } 713 } 714 715 public final class EjbJarLocalHomeWhereUsedRefactoringElement extends AbstractWhereUsedRefactoringElement { 716 717 protected EjbJar ejbJarDD; 718 719 720 public EjbJarLocalHomeWhereUsedRefactoringElement(EjbJar ejbJarDD, String name, FileObject parentFile) { 721 this.ejbJarDD = ejbJarDD; 722 this.name = name; 723 this.parentFile = parentFile; 724 } 725 726 729 public String getDisplayText() { 730 Object [] args = new Object [] {name}; 731 return MessageFormat.format(NbBundle.getMessage(EjbJarWhereUsedRefactoring.class, "TXT_EjbJarLocalHomeWhereUsed"), args); 732 } 733 } 734 735 public final class EjbJarHomeWhereUsedRefactoringElement extends AbstractWhereUsedRefactoringElement { 736 737 protected EjbJar ejbJarDD; 738 739 740 public EjbJarHomeWhereUsedRefactoringElement(EjbJar ejbJarDD, String name, FileObject parentFile) { 741 this.ejbJarDD = ejbJarDD; 742 this.name = name; 743 this.parentFile = parentFile; 744 } 745 746 749 public String getDisplayText() { 750 Object [] args = new Object [] {name}; 751 return MessageFormat.format(NbBundle.getMessage(EjbJarWhereUsedRefactoring.class, "TXT_EjbJarHomeWhereUsed"), args); 752 } 753 } 754 755 public final class EjbJarRemoteWhereUsedRefactoringElement extends AbstractWhereUsedRefactoringElement { 756 757 protected EjbJar ejbJarDD; 758 759 760 public EjbJarRemoteWhereUsedRefactoringElement(EjbJar ejbJarDD, String name, FileObject parentFile) { 761 this.ejbJarDD = ejbJarDD; 762 this.name = name; 763 this.parentFile = parentFile; 764 } 765 766 769 public String getDisplayText() { 770 Object [] args = new Object [] {name}; 771 return MessageFormat.format(NbBundle.getMessage(EjbJarWhereUsedRefactoring.class, "TXT_EjbJarRemoteWhereUsed"), args); 772 } 773 } 774 775 public final class EjbJarServiceEndpointWhereUsedRefactoringElement extends AbstractWhereUsedRefactoringElement { 776 777 protected EjbJar ejbJarDD; 778 779 780 public EjbJarServiceEndpointWhereUsedRefactoringElement(EjbJar ejbJarDD, String name, FileObject parentFile) { 781 this.ejbJarDD = ejbJarDD; 782 this.name = name; 783 this.parentFile = parentFile; 784 } 785 786 789 public String getDisplayText() { 790 Object [] args = new Object [] {name}; 791 return MessageFormat.format(NbBundle.getMessage(EjbJarWhereUsedRefactoring.class, "TXT_EjbJarServiceEndpointWhereUsed"), args); 792 } 793 } 794 795 public final class EjbJarRefLocalWhereUsedRefactoringElement extends AbstractWhereUsedRefactoringElement { 796 797 protected EjbJar ejbJarDD; 798 799 800 public EjbJarRefLocalWhereUsedRefactoringElement(EjbJar ejbJarDD, String name, FileObject parentFile) { 801 this.ejbJarDD = ejbJarDD; 802 this.name = name; 803 this.parentFile = parentFile; 804 } 805 806 809 public String getDisplayText() { 810 Object [] args = new Object [] {name}; 811 return MessageFormat.format(NbBundle.getMessage(EjbJarWhereUsedRefactoring.class, "TXT_EjbJarRefLocalWhereUsed"), args); 812 } 813 } 814 815 public final class EjbJarRefLocalHomeWhereUsedRefactoringElement extends AbstractWhereUsedRefactoringElement { 816 817 protected EjbJar ejbJarDD; 818 819 820 public EjbJarRefLocalHomeWhereUsedRefactoringElement(EjbJar ejbJarDD, String name, FileObject parentFile) { 821 this.ejbJarDD = ejbJarDD; 822 this.name = name; 823 this.parentFile = parentFile; 824 } 825 826 829 public String getDisplayText() { 830 Object [] args = new Object [] {name}; 831 return MessageFormat.format(NbBundle.getMessage(EjbJarWhereUsedRefactoring.class, "TXT_EjbJarRefLocalHomeWhereUsed"), args); 832 } 833 } 834 835 public final class EjbJarRefHomeWhereUsedRefactoringElement extends AbstractWhereUsedRefactoringElement { 836 837 protected EjbJar ejbJarDD; 838 839 840 public EjbJarRefHomeWhereUsedRefactoringElement(EjbJar ejbJarDD, String name, FileObject parentFile) { 841 this.ejbJarDD = ejbJarDD; 842 this.name = name; 843 this.parentFile = parentFile; 844 } 845 846 849 public String getDisplayText() { 850 Object [] args = new Object [] {name}; 851 return MessageFormat.format(NbBundle.getMessage(EjbJarWhereUsedRefactoring.class, "TXT_EjbJarRefHomeWhereUsed"), args); 852 } 853 } 854 855 public final class EjbJarRefRemoteWhereUsedRefactoringElement extends AbstractWhereUsedRefactoringElement { 856 857 protected EjbJar ejbJarDD; 858 859 860 public EjbJarRefRemoteWhereUsedRefactoringElement(EjbJar ejbJarDD, String name, FileObject parentFile) { 861 this.ejbJarDD = ejbJarDD; 862 this.name = name; 863 this.parentFile = parentFile; 864 } 865 866 869 public String getDisplayText() { 870 Object [] args = new Object [] {name}; 871 return MessageFormat.format(NbBundle.getMessage(EjbJarWhereUsedRefactoring.class, "TXT_EjbJarRefRemoteWhereUsed"), args); 872 } 873 } 874 875 public final class EjbJarFinderMethodWhereUsedRefactoringElement extends AbstractWhereUsedRefactoringElement { 876 877 protected EjbJar ejbJarDD; 878 879 880 public EjbJarFinderMethodWhereUsedRefactoringElement(EjbJar ejbJarDD, String name, FileObject parentFile) { 881 this.ejbJarDD = ejbJarDD; 882 this.name = name; 883 this.parentFile = parentFile; 884 } 885 886 889 public String getDisplayText() { 890 Object [] args = new Object [] {name}; 891 return MessageFormat.format(NbBundle.getMessage(EjbJarWhereUsedRefactoring.class, "TXT_EjbJarFinderMethodWhereUsed"), args); 892 } 893 } 894 895 public final class EjbJarSelectMethodWhereUsedRefactoringElement extends AbstractWhereUsedRefactoringElement { 896 897 protected EjbJar ejbJarDD; 898 899 900 public EjbJarSelectMethodWhereUsedRefactoringElement(EjbJar ejbJarDD, String name, FileObject parentFile) { 901 this.ejbJarDD = ejbJarDD; 902 this.name = name; 903 this.parentFile = parentFile; 904 } 905 906 909 public String getDisplayText() { 910 Object [] args = new Object [] {name}; 911 return MessageFormat.format(NbBundle.getMessage(EjbJarWhereUsedRefactoring.class, "TXT_EjbJarSelectMethodWhereUsed"), args); 912 } 913 } 914 915 public final class EjbJarContainerTxWhereUsedRefactoringElement extends AbstractWhereUsedRefactoringElement { 916 917 protected EjbJar ejbJarDD; 918 protected String ejbName; 919 920 921 public EjbJarContainerTxWhereUsedRefactoringElement(EjbJar ejbJarDD, String mtdName, String ejbName, FileObject parentFile) { 922 this.ejbJarDD = ejbJarDD; 923 this.name = mtdName; 924 this.ejbName = ejbName; 925 this.parentFile = parentFile; 926 } 927 928 931 public String getDisplayText() { 932 Object [] args = new Object [] {name, ejbName}; 933 return MessageFormat.format(NbBundle.getMessage(EjbJarWhereUsedRefactoring.class, "TXT_EjbJarContainerTxMethodWhereUsed"), args); 934 } 935 } 936 937 public final class EjbJarExcludeListWhereUsedRefactoringElement extends AbstractWhereUsedRefactoringElement { 938 939 protected EjbJar ejbJarDD; 940 protected String ejbName; 941 942 943 public EjbJarExcludeListWhereUsedRefactoringElement(EjbJar ejbJarDD, String mtdName, String ejbName, FileObject parentFile) { 944 this.ejbJarDD = ejbJarDD; 945 this.name = mtdName; 946 this.ejbName = ejbName; 947 this.parentFile = parentFile; 948 } 949 950 953 public String getDisplayText() { 954 Object [] args = new Object [] {name, ejbName}; 955 return MessageFormat.format(NbBundle.getMessage(EjbJarWhereUsedRefactoring.class, "TXT_EjbJarExcludeListMethodWhereUsed"), args); 956 } 957 } 958 959 public final class EjbJarMethodPermissionWhereUsedRefactoringElement extends AbstractWhereUsedRefactoringElement { 960 961 protected EjbJar ejbJarDD; 962 protected String ejbName; 963 964 965 public EjbJarMethodPermissionWhereUsedRefactoringElement(EjbJar ejbJarDD, String mtdName, String ejbName, FileObject parentFile) { 966 this.ejbJarDD = ejbJarDD; 967 this.name = mtdName; 968 this.ejbName = ejbName; 969 this.parentFile = parentFile; 970 } 971 972 975 public String getDisplayText() { 976 Object [] args = new Object [] {name, ejbName}; 977 return MessageFormat.format(NbBundle.getMessage(EjbJarWhereUsedRefactoring.class, "TXT_EjbJarMethodPermissionMethodWhereUsed"), args); 978 } 979 } 980 981 } 982 | Popular Tags |