1 19 20 package org.netbeans.modules.j2ee.refactoring; 21 22 import java.io.IOException ; 23 import java.util.*; 24 import javax.jmi.reflect.RefObject; 25 26 import org.netbeans.api.java.classpath.GlobalPathRegistry; 27 import org.netbeans.api.project.FileOwnerQuery; 28 import org.netbeans.api.project.Project; 29 import org.netbeans.api.project.ui.OpenProjects; 30 import org.netbeans.jmi.javamodel.*; 31 import org.netbeans.jmi.javamodel.Method; 32 import org.netbeans.modules.j2ee.dd.api.ejb.*; 33 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeAppProvider; 34 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; 35 import org.netbeans.modules.javacore.api.JavaModel; 36 import org.netbeans.modules.refactoring.api.Problem; 37 import org.netbeans.modules.web.api.webmodule.WebModule; 38 import org.netbeans.modules.web.spi.webmodule.WebModuleImplementation; 39 import org.netbeans.modules.websvc.api.webservices.WebServicesSupport; 40 import org.netbeans.spi.project.SubprojectProvider; 41 import org.openide.ErrorManager; 42 import org.openide.filesystems.FileObject; 43 44 48 public class Utility { 49 50 private static final ErrorManager err = 51 ErrorManager.getDefault().getInstance("org.netbeans.modules.j2ee.refactoring"); 53 public static final String ENTERPRISE_BEAN = "javax.ejb.EnterpriseBean"; public static final String SESSION_BEAN = "javax.ejb.SessionBean"; public static final String ENTITY_BEAN = "javax.ejb.EntityBean"; public static final String MESSAGE_DRIVEN_BEAN = "javax.ejb.MessageDrivenBean"; public static final String EJB_LOCAL_HOME = "javax.ejb.EJBLocalHome"; public static final String EJB_HOME = "javax.ejb.EJBHome"; public static final String EJB_LOCAL_OBJECT = "javax.ejb.EJBLocalObject"; public static final String EJB_OBJECT = "javax.ejb.EJBObject"; 62 public static final String MESSAGE_LISTENER = "javax.jms.MessageListener"; 64 public static final String EJB_CREATE = "ejbCreate"; public static final String EJB_ACTIVATE = "ejbActivate"; public static final String EJB_PASSIVATE = "ejbPassivate"; public static final String EJB_REMOVE = "ejbRemove"; public static final String EJB_LOAD = "ejbLoad"; public static final String EJB_STORE = "ejbStore"; public static final String SET_SESSION_CONTEXT = "setSessionContext"; public static final String SET_ENTITY_CONTEXT = "setEntityContext"; public static final String SET_MSG_CONTEXT = "setMessageDrivenContext"; public static final String UNSET_ENTITY_CONTEXT = "unsetEntityContext"; public static final String ON_MESSAGE = "onMessage"; 76 public static final String [] NO_PARAMS = new String [] {}; 77 public static final String [] SET_SESSION_CONTEXT_PARAMTYPENAMES = new String [] {"javax.ejb.SessionContext"}; 78 public static final String [] SET_ENTITY_CONTEXT_PARAMTYPENAMES = new String [] {"javax.ejb.EntityContext"}; 79 public static final String [] SET_MSG_CONTEXT_PARAMTYPENAMES = new String [] {"javax.ejb.MessageDrivenContext"}; 80 public static final String [] ON_MESSAGE_PARAMTYPENAMES = new String [] {"javax.jms.Message"}; 81 public static final String PREFIX_SET = "set"; public static final String PREFIX_GET = "get"; public static final String PREFIX_FIND = "find"; public static final String PREFIX_EJBSELECT = "ejbSelect"; public static final String PREFIX_EJBPOSTCREATE = "ejbPostCreate"; public static final String PREFIX_EJBCREATE = "ejbCreate"; public static final String PREFIX_CREATE = "create"; public static final String PREFIX_EJBHOME = "ejbHome"; public static final String PREFIX_EJBFIND = "ejbFind"; private static final String PREFIX_POSTCREATE = "postCreate"; 91 92 93 public Utility() { 94 } 95 96 public static List getTypedParams(List params) { 97 if (params != null) { 98 List typedParams = new ArrayList(params.size()); 99 for (int i=0; i < params.size(); i++) { 100 Element param = (Element) params.get(i); 101 Type type = param instanceof Parameter ? ((Parameter) param).getType() : (Type) param; 102 typedParams.add(type); 103 } 104 return typedParams; 105 } 106 return Collections.EMPTY_LIST; 107 } 108 109 public static EnterpriseBeans getEnterpriseBeansFromDD(FileObject fo) { 110 err.log(">Utility.getEnterpriseBeansFromDD (" + fo + ")" ); 111 org.netbeans.modules.j2ee.api.ejbjar.EjbJar emod = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(fo); 112 if (emod != null) { 113 FileObject ejbJarFO = emod.getDeploymentDescriptor(); 114 EjbJar ejbJarDD = null; 115 try { 116 ejbJarDD = org.netbeans.modules.j2ee.dd.api.ejb.DDProvider.getDefault().getMergedDDRoot(emod.getMetadataUnit()); 117 } catch (IOException ioe) { 118 } 120 if ((ejbJarDD != null) && (ejbJarDD.getStatus()!=EjbJar.STATE_INVALID_UNPARSABLE)) { 121 return ejbJarDD.getEnterpriseBeans(); 122 } 123 } 124 return null; 125 } 126 127 public static JavaClass getImplClassForHome(EnterpriseBeans eBeans, Class beanType, String homeClassName, 128 boolean local) { 129 if (eBeans != null) { 130 Ejb[] ejbs = eBeans.getEjbs(); 131 if (ejbs != null) { 132 for (int i = 0; i < ejbs.length; i++) { 133 Ejb ejb = ejbs[i]; 134 if (ejb != null && beanType.isAssignableFrom(ejb.getClass())) { 135 EntityAndSession bean = (EntityAndSession) ejb; 136 if (homeClassName.equals(getHomeInterface(bean, local))) { 137 JavaClass javaClass = resolveRealClass(bean.getEjbClass()); 138 if (javaClass != null) { 139 return javaClass; 140 } 141 } 142 } 143 } 144 } 145 } 146 return null; 147 } 148 149 public static Method getMethodInImplClassForHome(FileObject fo, Class beanType, String className, 150 String methodName, List parameters, boolean local) { 151 if (methodName == null || methodName.length() == 0) { 152 return null; 153 } 154 JavaClass ejbImplClass = getImplClassForHome(getEnterpriseBeansFromDD(fo), beanType, className, local); 155 if (ejbImplClass != null) { 156 return ejbImplClass.getMethod(methodName, getTypedParams(parameters), false); 157 } else { 158 return null; 159 } 160 } 161 162 private static JavaClass getOtherHomeClassForHome(EnterpriseBeans eBeans, Class beanType, String homeClassName, 163 boolean local) { 164 if (eBeans != null) { 165 Ejb[] ejbs = eBeans.getEjbs(); 166 if (ejbs != null) { 167 for (int i = 0; i < ejbs.length; i++) { 168 Ejb ejb = ejbs[i]; 169 if (ejb != null && beanType.isAssignableFrom(ejb.getClass())) { 170 EntityAndSession bean = (EntityAndSession) ejbs[i]; 171 if (homeClassName.equals(getHomeInterface(bean, !local))) { 172 JavaClass javaClass = resolveRealClass(getHomeInterface(bean, local)); 173 if (isSubTypeOf(javaClass, local ? EJB_LOCAL_HOME : EJB_HOME)) { 174 return javaClass; 175 } 176 } 177 } 178 } 179 } 180 } 181 return null; 182 } 183 184 public static Method getMethodInOtherHomeClassForHome(FileObject fo, Class beanType, String className, 185 String methodName, List parameters, boolean local) { 186 JavaClass ejbHomeClass = getOtherHomeClassForHome(getEnterpriseBeansFromDD(fo), beanType, className, local); 187 if (ejbHomeClass != null) { 188 return ejbHomeClass.getMethod(methodName, getTypedParams(parameters), false); 189 } 190 return null; 191 } 192 193 private static JavaClass getHomeClassForImpl(EnterpriseBeans eBeans, Class beanType, String implClassName, 194 boolean local) { 195 Ejb bean = EjbInterfaceType.BEAN_IMPL.getBean(eBeans, beanType, implClassName); 196 if (bean != null) { 197 EjbInterfaceType ejbInterfaceType = local ? EjbInterfaceType.LOCAL : EjbInterfaceType.LOCAL_HOME; 198 return ejbInterfaceType.resolveClass(bean); 199 } else { 200 return null; 201 } 202 } 203 204 public static Method getMethodInHomeClassForImpl(FileObject fo, Class beanType, String className, 205 String methodName, List parameters, boolean local) { 206 if (methodName == null || methodName.length() == 0) { 207 return null; 208 } 209 JavaClass ejbHomeClass = getHomeClassForImpl(getEnterpriseBeansFromDD(fo), beanType, className, local); 210 if (ejbHomeClass != null) { 211 return ejbHomeClass.getMethod(methodName, getTypedParams(parameters), false); 212 } 213 return null; 214 } 215 216 private static String getHomeInterface(EntityAndSession bean, boolean local) { 217 return local ? bean.getLocalHome() : bean.getHome(); 218 } 219 220 public static String addPrefix(String methodName, String prefix) { 221 return prefix + methodName.substring(0,1).toUpperCase() + methodName.substring(1); 222 } 223 224 public static String stripNonEmptyPrefix(String methodName, String prefix) { 225 methodName = stripPrefix(methodName, prefix); 226 if (methodName != null && methodName.length() > 1 && isFirstUpperCase(methodName)) { 227 return methodName.substring(0, 1).toLowerCase() + methodName.substring(1); 228 } 229 return null; 230 } 231 232 233 public static String stripPrefix(String methodName, String prefix) { 234 if (methodName.startsWith(prefix)) { 235 return methodName.substring(prefix.length()); 236 } 237 return null; 238 } 239 240 public static String replacePrefix(String methodName, String oldPrefix, String newPrefix) { 241 if (newPrefix == null) { 242 return stripNonEmptyPrefix(methodName, oldPrefix); 243 } else if (methodName.startsWith(oldPrefix) && methodName.length() > oldPrefix.length()) { 244 return newPrefix + methodName.substring(oldPrefix.length()); 245 } else { 246 return null; 247 } 248 } 249 250 251 public static Method getImplFinderMethodForHomeFinderMethod(Method method, FileObject fo, String className, boolean local) { 252 err.log(">Utility.getImplFinderMethodForHomeFinderMethod (" + method + ", " + fo + ", " + className + ", " + local + ")" ); 253 return getMethodInImplClassForHome(fo, EntityAndSession.class, className, local, method, PREFIX_FIND, PREFIX_EJBFIND); 254 } 255 256 257 public static Method getImplCreateMethodForHomeCreateMethod(Method method, FileObject fo, String className, boolean local) { 258 err.log(">Utility.getImplCreateMethodForHomeCreateMethod (" + method + ", " + fo + ", " + className + ", " + local + ")"); 259 String oldPrefix = PREFIX_CREATE; 260 String newPrefix = PREFIX_EJBCREATE; 261 Class beanType = EntityAndSession.class; 262 return getMethodInImplClassForHome(fo, beanType, className, local, method, oldPrefix, newPrefix); 263 264 } 265 266 267 public static Method getImplPostCreateMethodForHomeCreateMethod(Method method, FileObject fo, String className, boolean local) { 268 err.log(">Utility.getImplPostCreateMethodForHomeCreateMethod (" + method + ", " + fo + ", " + className + ", " + local + ")"); 269 return getMethodInImplClassForHome(fo, EntityAndSession.class, className, local, method, PREFIX_EJBPOSTCREATE, PREFIX_CREATE); 270 } 271 272 public static Method getMethod(Method origMethod, String origPrefix, String prefix) { 273 ClassDefinition jc = origMethod.getDeclaringClass(); err.log("classdefinition classDefinition: " + jc); 275 if ((jc instanceof JavaClass)) { 276 String methodName = replacePrefix(origMethod.getName(), origPrefix, prefix); 277 if (methodName == null || methodName.length() == 0) { 278 return null; 279 } 280 return jc.getMethod(methodName, getTypedParams(origMethod.getParameters()), false); 281 } else { 282 return null; 283 } 284 } 285 286 public static Method getMethodInHomeClassForImpl(FileObject fo, Class beanType, String className, boolean local, 287 Method origMethod, String origPrefix, String prefix) { 288 String methodName = replacePrefix(origMethod.getName(), origPrefix, prefix); 289 return getMethodInHomeClassForImpl(fo, beanType, className, methodName, origMethod.getParameters(), 290 local); 291 } 292 293 public static Method getMethodInImplClassForHome(FileObject fo, Class beanType, String className, boolean local, 294 Method origMethod, String origPrefix, String prefix) { 295 String methodName = replacePrefix(origMethod.getName(), origPrefix, prefix); 296 return getMethodInImplClassForHome(fo, beanType, className, methodName, 297 origMethod.getParameters(), local); 298 } 299 300 301 public static Method getImplHomeMethodForHomeHomeMethod(Method method, FileObject fo, String className, boolean local) { 302 err.log(">Utility.getImplHomeMethodForHomeHomeMethod (" + method + ", " + fo + ", " + className + ", " + local + ")"); 303 String implMethodName = addPrefix(method.getName(), PREFIX_EJBHOME); 304 return getMethodInImplClassForHome(fo, EntityAndSession.class, className, implMethodName, 305 method.getParameters(), local); 306 } 307 308 309 public static Method getHomeHomeMethodForHomeHomeMethod(Method method, FileObject fo, String className, boolean local) { 310 err.log(">Utility.getHomeHomeMethodForHomeHomeMethod (" + method + ", " + fo + ", " + className + ", " + local + ")"); 311 String methodName = method.getName(); 312 return getMethodInOtherHomeClassForHome(fo, EntityAndSession.class, className, methodName, 313 method.getParameters(), local); 314 } 315 316 317 public static Method getHomeFinderMethodForHomeFinderMethod(Method method, FileObject fo, String className, boolean local) { 318 err.log(">Utility.getHomeFinderMethodForHomeFinderMethod (" + method + ", " + fo + ", " + className + ", " + local + ")"); 319 String methodName = method.getName(); 320 if (!methodName.startsWith(PREFIX_FIND)) { 321 return null; 322 } 323 return getMethodInOtherHomeClassForHome(fo, EntityAndSession.class, className, methodName, 324 method.getParameters(), local); 325 } 326 327 328 public static Method getHomeCreateMethodForHomeCreateMethod(Method method, FileObject fo, String className, boolean local) { 329 err.log(">Utility.getHomeCreateMethodForHomeCreateMethod (" + method + ", " + fo + ", " + className + ", " + local + ")"); 330 String methodName = method.getName(); 331 if (!methodName.startsWith(PREFIX_CREATE)) { 332 return null; 333 } 334 return getMethodInOtherHomeClassForHome(fo, EntityAndSession.class, className, methodName, 335 method.getParameters(), local); 336 } 337 338 339 public static Method getHomeFinderMethodForImplFinderMethod(Method method, FileObject fo, String className, boolean local) { 340 err.log(">Utility.getHomeFinderMethodForImplFinderMethod (" + method + ", " + fo + ", " + className + ", " + local + ")"); 341 return getMethodInHomeClassForImpl(fo, Entity.class, className, local, method, PREFIX_FIND, PREFIX_EJBFIND); 342 } 343 344 345 public static Method getHomeHomeMethodForEntityImplHomeMethod(Method method, FileObject fo, String className, boolean local) { 346 err.log(">Utility.getHomeHomeMethodForEntityImplHomeMethod (" + method + ", " + fo + ", " + className + ", " + local + ")"); 347 String methodName = stripNonEmptyPrefix(method.getName(), PREFIX_EJBHOME); 348 return getMethodInHomeClassForImpl(fo, Entity.class, className, methodName, method.getParameters(), local); 349 } 350 351 352 public static Method getHomeHomeMethodForSessionImplHomeMethod(Method method, FileObject fo, String className, boolean local) { 353 err.log(">Utility.getHomeHomeMethodForSessionImplHomeMethod (" + method + ", " + fo + ", " + className + ", " + local + ")"); 354 String methodName = stripNonEmptyPrefix(method.getName(), PREFIX_EJBHOME); 355 return getMethodInHomeClassForImpl(fo, Session.class, className, methodName, method.getParameters(), local); 356 } 357 358 359 public static Method getHomeCreateMethodForSessionImplCreateMethod(Method method, FileObject fo, String className, boolean local) { 360 err.log(">Utility.getHomeCreateMethodForSessionImplCreateMethod (" + method + ", " + fo + ", " + className + ", " + local + ")"); 361 return getMethodInHomeClassForImpl(fo, Session.class, className, local, method, PREFIX_EJBCREATE, PREFIX_CREATE); 362 } 363 364 367 public static Method getHomeCreateMethodForEntityImplCreateMethod(Method method, FileObject fo, String className, 368 boolean local) { 369 err.log(">Utility.getHomeCreateMethodForEntityImplCreateMethod (" + method + ", " + fo + ", " + className + 370 ", " + local + ")"); 371 String oldPrefix = PREFIX_EJBCREATE; 372 String newPrefix = PREFIX_CREATE; 373 Class beanType = Entity.class; 374 return getMethodInHomeClassForImpl(fo, beanType, className, local, method, oldPrefix, newPrefix); 375 } 376 377 378 public static Method getHomeCreateMethodForEntityImplPostCreateMethod(Method method, FileObject fo, String className, boolean local) { 379 err.log(">Utility.getHomeCreateMethodForEntityImplPostCreateMethod (" + method + ", " + fo + ", " + className + ", " + local + ")"); 380 return getMethodInHomeClassForImpl(fo, Entity.class, className, local, method, PREFIX_EJBPOSTCREATE, PREFIX_CREATE); 381 } 382 383 384 public static Method getHomePostCreateMethodForEntityImplCreateMethod(Method method, FileObject fo, String className, boolean local) { 385 err.log(">Utility.getHomePostCreateMethodForEntityImplCreateMethod (" + method + ", " + fo + ", " + className + ", " + local + ")"); 386 return getMethodInHomeClassForImpl(fo, Entity.class, className, local, method, PREFIX_EJBCREATE, PREFIX_POSTCREATE); 387 } 388 389 390 public static Method getImplPostCreateMethodForEntityImplCreateMethod(Method method) { 391 return getMethod(method, PREFIX_EJBCREATE, PREFIX_EJBPOSTCREATE); 392 } 393 394 395 public static Method getImplCreateMethodForEntityImplPostCreateMethod(Method method) { 396 String oldPrefix = PREFIX_EJBPOSTCREATE; 397 String newPrefix = PREFIX_EJBCREATE; 398 return getMethod(method, oldPrefix, newPrefix); 399 } 400 401 402 public static boolean isSignatureFromSessionBeanInterface(Method method) { 403 return (equalMethods(method, EJB_PASSIVATE, NO_PARAMS)) || 404 (equalMethods(method, EJB_ACTIVATE, NO_PARAMS)) || 405 (equalMethods(method, EJB_REMOVE, NO_PARAMS)) || 406 (equalMethods(method, SET_SESSION_CONTEXT, SET_SESSION_CONTEXT_PARAMTYPENAMES)); 407 } 408 409 410 public static boolean isSignatureFromEntityBeanInterface(Method method) { 411 return (equalMethods(method, EJB_PASSIVATE, NO_PARAMS)) || 412 (equalMethods(method, EJB_ACTIVATE, NO_PARAMS)) || 413 (equalMethods(method, EJB_REMOVE, NO_PARAMS)) || 414 (equalMethods(method, EJB_LOAD, NO_PARAMS)) || 415 (equalMethods(method, EJB_STORE, NO_PARAMS)) || 416 (equalMethods(method, UNSET_ENTITY_CONTEXT, NO_PARAMS)) || 417 (equalMethods(method, SET_ENTITY_CONTEXT, SET_ENTITY_CONTEXT_PARAMTYPENAMES)); 418 } 419 420 421 public static boolean isSignatureFromMessageDrivenBeanInterface(Method method) { 422 return (equalMethods(method, EJB_CREATE, NO_PARAMS)) || 423 (equalMethods(method, EJB_REMOVE, NO_PARAMS)) || 424 (equalMethods(method, SET_MSG_CONTEXT, SET_MSG_CONTEXT_PARAMTYPENAMES)); 425 } 426 427 428 public static boolean isSignatureFromMessageListenerInterface(Method method) { 429 return equalMethods(method, Utility.ON_MESSAGE, Utility.ON_MESSAGE_PARAMTYPENAMES); 430 } 431 432 433 public static EjbJar getEjbJar(org.netbeans.modules.j2ee.api.ejbjar.EjbJar emodule) { 434 if (emodule != null) { 435 FileObject ejbJarFO = emodule.getDeploymentDescriptor(); 436 try { 437 return org.netbeans.modules.j2ee.dd.api.ejb.DDProvider.getDefault().getMergedDDRoot(emodule.getMetadataUnit()); 438 } catch (IOException ioe) { 439 } 441 } 442 return null; 443 } 444 445 446 public static Entity[] getEntityBeans(org.netbeans.modules.j2ee.api.ejbjar.EjbJar emodule) { 447 EjbJar ejbJarDD = getEjbJar(emodule); 448 if (ejbJarDD != null) { 449 EnterpriseBeans eBeans = ejbJarDD.getEnterpriseBeans(); 450 if (eBeans != null) { 451 return eBeans.getEntity(); 452 } 453 } 454 return null; 455 } 456 457 458 public static EjbRelation[] getRelationships(org.netbeans.modules.j2ee.api.ejbjar.EjbJar emodule) { 459 EjbJar ejbJarDD = getEjbJar(emodule); 460 if (ejbJarDD != null) { 461 Relationships rels = ejbJarDD.getSingleRelationships(); 462 if (rels != null) { 463 return rels.getEjbRelation(); 464 } 465 } 466 return null; 467 } 468 469 470 public static AssemblyDescriptor getAssemblyDescriptor(org.netbeans.modules.j2ee.api.ejbjar.EjbJar emodule) { 471 EjbJar ejbJarDD = getEjbJar(emodule); 472 if (ejbJarDD != null) { 473 return ejbJarDD.getSingleAssemblyDescriptor(); 474 } 475 return null; 476 } 477 478 public static String getEjbNameForClass(org.netbeans.modules.j2ee.dd.api.ejb.EjbJar ejbJarDD, ClassDefinition jc) { 479 EnterpriseBeans eBeans = ejbJarDD.getEnterpriseBeans(); 480 if ((eBeans != null)) { 481 Ejb[] ejbs = eBeans.getEjbs(); 482 for (int e=0; e<ejbs.length; e++) { 483 Ejb ejb = ejbs[e]; 484 String ejbClass = ejb.getEjbClass(); 485 err.log("ejbclass: " + ejbClass); 486 if (ejbClass.equals(jc.getName())) { 487 return ejb.getEjbName(); 488 } 489 } 490 } 491 return null; 492 } 493 494 495 public static Session[] getSessionBeans(org.netbeans.modules.j2ee.api.ejbjar.EjbJar emodule) { 496 EjbJar ejbJarDD = getEjbJar(emodule); 497 if (ejbJarDD != null) { 498 EnterpriseBeans eBeans = ejbJarDD.getEnterpriseBeans(); 499 if (eBeans != null) { 500 return eBeans.getSession(); 501 } 502 } 503 return null; 504 } 505 506 507 public static boolean equalMethods(Method method, String name, String [] paramNames) { 508 if (!name.equals(method.getName())) { 509 return false; 510 } 511 if (method.getParameters().size() != paramNames.length) { 512 return false; 513 } 514 Iterator it = method.getParameters().iterator(); 515 for (int i=0; i < paramNames.length; i++) { 516 Parameter param = (Parameter)it.next(); 517 if (!param.getType().getName().equals(paramNames[i])) { 518 return false; 519 } 520 } 521 return true; 522 } 523 524 public static boolean equalMethods(Method method1, Method method2) { 525 if (method1 == null || method2 == null) { 526 return method1 == method2; 527 } 528 if (!method1.getName().equals(method2.getName())) { 529 return false; 530 } 531 List parameters1 = method1.getParameters(); 532 List parameters2 = method2.getParameters(); 533 int n = parameters1.size(); 534 if (n != parameters2.size()) { 535 return false; 536 } 537 for (int i = 0; i < n; i++) { 538 Parameter param1 = (Parameter) parameters1.get(i); 539 Parameter param2 = (Parameter) parameters2.get(i); 540 if (!param1.getType().getName().equals(param2.getType().getName())) { 541 return false; 542 } 543 } 544 return true; 545 } 546 547 public static void addProblemsToEnd(Problem[] where, Problem what) { 548 where[0] = addProblemsToEnd(where[0], what); 549 } 550 551 public static Problem addProblemsToEnd(Problem where, Problem what) { 552 if (where == null) { 553 return what; 554 } else{ 555 if(what != null) { 556 Problem tail = where; 557 while (tail.getNext() != null) { 558 tail = tail.getNext(); 559 } 560 tail.setNext(what); 561 } 562 return where; 563 } 564 } 565 566 567 public static Collection getRelevantEjbModules(Element element) { 568 FileObject fo = JavaModel.getFileObject(element.getResource()); 569 return Utility.getRelevantEjbModules(fo); 570 } 571 572 public static Collection getRelevantEjbModules(RefObject refObject) { 573 if (refObject instanceof Element){ 574 return getRelevantEjbModules((Element)refObject); 575 } 576 return Collections.emptyList(); 577 } 578 579 580 public static Collection getRelevantEjbModules(FileObject fo) { 581 582 Project affectedProject = FileOwnerQuery.getOwner(fo); 583 Collection ejbmodules = new ArrayList(); 584 Collection projects = new ArrayList(); 585 586 if (affectedProject != null) { 587 org.netbeans.modules.j2ee.api.ejbjar.EjbJar emod = 589 org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(affectedProject.getProjectDirectory()); 590 if (emod != null) { 591 projects.add(affectedProject); 592 } else { 593 return Collections.EMPTY_SET; 594 } 595 for (Project project : OpenProjects.getDefault().getOpenProjects()){ 596 Object isJ2eeApp = project.getLookup().lookup(J2eeAppProvider.class); 597 if (isJ2eeApp != null) { 598 J2eeAppProvider j2eeApp = (J2eeAppProvider) isJ2eeApp; 599 J2eeModuleProvider[] j2eeModules = j2eeApp.getChildModuleProviders(); 600 601 if (j2eeModules != null) { 602 J2eeModuleProvider affectedPrjProvider = 603 (J2eeModuleProvider) affectedProject.getLookup().lookup(J2eeModuleProvider.class); 604 605 if (affectedPrjProvider != null) { 606 if (Arrays.asList(j2eeModules).contains(affectedPrjProvider)) { 607 for (int k = 0; k < j2eeModules.length; k++) { 608 FileObject[] sourceRoots = j2eeModules[k].getSourceRoots(); 609 if (sourceRoots != null && sourceRoots.length > 0){ 610 FileObject srcRoot = sourceRoots[0]; 611 Project p = FileOwnerQuery.getOwner(srcRoot); 612 if ((p != null) && (!projects.contains(p))) { 613 projects.add(p); 614 } 615 } 616 } 617 } 618 } 619 } 620 } 621 Object obj = project.getLookup().lookup(SubprojectProvider.class); 622 if ((obj != null) && (obj instanceof SubprojectProvider)) { 623 Set subprojects = ((SubprojectProvider) obj).getSubprojects(); 624 if (subprojects.contains(affectedProject)) { 625 org.netbeans.modules.j2ee.api.ejbjar.EjbJar em = org.netbeans.modules.j2ee.api.ejbjar.EjbJar 626 .getEjbJar(project.getProjectDirectory()); 627 if (em != null) { 628 if (!projects.contains(project)) { projects.add(project); 630 } 631 } 632 } 633 } 634 } 635 } 636 637 for (int j=0; j < projects.size(); j++) { 638 Project prj = (Project)((ArrayList)projects).get(j); 639 org.netbeans.modules.j2ee.api.ejbjar.EjbJar ejb = 640 org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(prj.getProjectDirectory()); 641 if (ejb != null) { 642 ejbmodules.add(ejb); 643 } 644 } 645 646 err.log("Affected ejb modules: " + ejbmodules); 647 return ejbmodules; 648 } 649 650 651 public static Collection getRelevantWSModules(FileObject fo) { 652 653 Project affectedProject = FileOwnerQuery.getOwner(fo); 654 Collection wsmodules = new ArrayList(); 655 Collection projects = new ArrayList(); 656 657 if (affectedProject != null) { 658 WebServicesSupport wsmod = WebServicesSupport.getWebServicesSupport(affectedProject.getProjectDirectory()); 660 if (wsmod != null) { 661 projects.add(affectedProject); 662 } else { 663 return Collections.EMPTY_SET; 664 } 665 666 for (Project project : OpenProjects.getDefault().getOpenProjects()){ 667 668 Object isJ2eeApp = project.getLookup().lookup(J2eeAppProvider.class); 669 if (isJ2eeApp != null) { 670 J2eeAppProvider j2eeApp = (J2eeAppProvider)isJ2eeApp; 671 J2eeModuleProvider[] j2eeModules = j2eeApp.getChildModuleProviders(); 672 673 if (j2eeModules != null) { 674 J2eeModuleProvider affectedPrjProvider = 675 (J2eeModuleProvider)affectedProject.getLookup().lookup(J2eeModuleProvider.class); 676 if (affectedPrjProvider != null) { 677 if (Arrays.asList(j2eeModules).contains(affectedPrjProvider)) { 678 for (int i=0; i<j2eeModules.length; i++) { 679 FileObject[] sourceRoots = j2eeModules[i].getSourceRoots(); 680 if (sourceRoots != null && sourceRoots.length > 0){ 681 FileObject srcRoot = sourceRoots[0]; 682 Project p = FileOwnerQuery.getOwner(srcRoot); 683 if ((p != null) && (!projects.contains(p))) { 684 projects.add(p); 685 } 686 } 687 } 688 } 689 } 690 } 691 Object obj = project.getLookup().lookup(SubprojectProvider.class); 692 if ((obj != null) && (obj instanceof SubprojectProvider)) { 693 Set subprojects = ((SubprojectProvider)obj).getSubprojects(); 694 if (subprojects.contains(affectedProject)) { 695 WebServicesSupport ws = 696 WebServicesSupport.getWebServicesSupport(project.getProjectDirectory()); 697 if (ws != null) { 698 if (!projects.contains(project)) { projects.add(project); 700 } 701 } 702 } 703 } 704 } 705 } 706 } 707 708 for (int j=0; j < projects.size(); j++) { 709 Project prj = (Project)((ArrayList)projects).get(j); 710 WebServicesSupport websvc = WebServicesSupport.getWebServicesSupport(prj.getProjectDirectory()); 711 wsmodules.add(websvc); 712 } 713 714 err.log("Affected ws modules: " + wsmodules); 715 return wsmodules; 716 } 717 718 719 public static Collection getRelevantWebModules(Element e) { 720 Resource r = e.getResource(); 721 if (r != null) { 722 FileObject f = JavaModel.getFileObject(r); 723 if (f != null) { 724 Collection c = getRelevantWebModules(f); 725 return c; 726 } 727 728 } 729 return Collections.EMPTY_LIST; 730 } 731 732 733 public static Collection getRelevantWebModules(FileObject fo) { 734 735 Collection webmodules = new ArrayList(); 736 Collection projects = new ArrayList(); 737 738 if ( fo == null ) { 739 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "Passed null to getRelevantWebModules()"); 740 return webmodules; 741 } 742 743 Project affectedProject = FileOwnerQuery.getOwner(fo); 744 if (affectedProject != null) { 745 WebModule wmod = WebModule.getWebModule(affectedProject.getProjectDirectory()); 747 if (wmod != null) { 748 projects.add(affectedProject); 749 } else { 750 return Collections.EMPTY_SET; 751 } 752 Set globalPath = GlobalPathRegistry.getDefault().getSourceRoots(); 753 Iterator iter = globalPath.iterator(); 754 while (iter.hasNext()) { 755 FileObject sourceRoot = (FileObject)iter.next(); 756 Project project = FileOwnerQuery.getOwner(sourceRoot); 757 if (project != null) { 758 err.log("found this project: " + project); 759 Object isJ2eeApp = project.getLookup().lookup(J2eeAppProvider.class); 760 if (isJ2eeApp != null) { 761 J2eeAppProvider j2eeApp = (J2eeAppProvider)isJ2eeApp; 762 err.log("j2eeapp: " + j2eeApp); 763 J2eeModuleProvider[] j2eeModules = j2eeApp.getChildModuleProviders(); 764 err.log("j2ee modules: " + j2eeModules); 765 if (j2eeModules != null) { 766 J2eeModuleProvider affectedPrjProvider = 767 (J2eeModuleProvider)affectedProject.getLookup().lookup(J2eeModuleProvider.class); 768 if (affectedPrjProvider != null) { 769 if (Arrays.asList(j2eeModules).contains(affectedPrjProvider)) { 770 for (int i=0; i<j2eeModules.length; i++) { 771 if (j2eeModules[i] instanceof WebModuleImplementation) { 772 FileObject docBase = 773 ((WebModuleImplementation)j2eeModules[i]).getDocumentBase(); 774 Project p = FileOwnerQuery.getOwner(docBase); 775 if ((p != null) && (!projects.contains(p))) { 776 projects.add(p); 777 } 778 } 779 } 780 } 781 } 782 } 783 } 784 Object obj = project.getLookup().lookup(SubprojectProvider.class); 785 if ((obj != null) && (obj instanceof SubprojectProvider)) { 786 Set subprojects = ((SubprojectProvider)obj).getSubprojects(); 787 if (subprojects.contains(affectedProject)) { 788 WebModule wm = WebModule.getWebModule(project.getProjectDirectory()); 789 if (wm != null) { 790 if (!projects.contains(project)) { projects.add(project); 792 } 793 } 794 } 795 } 796 } 797 } 798 } 799 800 for (int j=0; j < projects.size(); j++) { 801 Project prj = (Project)((ArrayList)projects).get(j); 802 WebModule web = WebModule.getWebModule(prj.getProjectDirectory()); 803 webmodules.add(web); 804 } 805 806 return webmodules; 808 } 809 810 public static boolean isCmpField(JavaClass jc, String fieldName) { 811 if ((jc != null) && (fieldName != null)) { 812 Collection emodules = getRelevantEjbModules(jc); 813 Iterator e = emodules.iterator(); 814 while (e.hasNext()) { 815 org.netbeans.modules.j2ee.api.ejbjar.EjbJar ejbJar = 816 (org.netbeans.modules.j2ee.api.ejbjar.EjbJar)e.next(); 817 Entity[] eBeans = getEntityBeans(ejbJar); 818 if (eBeans != null) { 819 for (int i=0; i < eBeans.length; i++) { 820 Entity ent = eBeans[i]; 821 String ejbClass = ent.getEjbClass(); 822 if (jc.getName().equals(ejbClass)) { 823 CmpField[] cmpFields = ent.getCmpField(); 824 if (cmpFields != null) { 825 for (int c=0; c<cmpFields.length; c++) { 826 CmpField cmpField = cmpFields[c]; 827 if (fieldName.equalsIgnoreCase(cmpField.getFieldName())) { 830 return true; 831 } 832 } 833 } 834 return false; 835 } 836 } 837 } 838 } 839 } 840 return false; 841 } 842 843 public static boolean isCmrField(JavaClass jc, String fieldName) { 844 if ((jc != null) && (fieldName != null)) { 845 Collection emodules = Utility.getRelevantEjbModules(jc); 846 Iterator e = emodules.iterator(); 847 while (e.hasNext()) { 848 org.netbeans.modules.j2ee.api.ejbjar.EjbJar ejbJar = 849 (org.netbeans.modules.j2ee.api.ejbjar.EjbJar)e.next(); 850 EjbRelation[] ejbRelations = getRelationships(ejbJar); 851 if (ejbRelations != null) { 852 String ejbName = getEntityEjbNameForClass(jc); 853 for (int i=0; i < ejbRelations.length; i++) { 854 EjbRelation relation = ejbRelations[i]; 855 if (relation != null) { 856 EjbRelationshipRole role = relation.getEjbRelationshipRole(); 857 if (role != null) { 858 RelationshipRoleSource relSource = role.getRelationshipRoleSource(); 859 String roleEjbName = relSource.getEjbName(); 860 if (roleEjbName.equals(ejbName)) { 861 CmrField cmrField = role.getCmrField(); 862 if (cmrField != null) { 863 String cmrFieldName = cmrField.getCmrFieldName(); 864 if (cmrFieldName.equalsIgnoreCase(fieldName)) { 867 return true; 868 } 869 } 870 } 871 } 872 EjbRelationshipRole role2 = relation.getEjbRelationshipRole2(); 873 if (role2 != null) { 874 RelationshipRoleSource relSource = role2.getRelationshipRoleSource(); 875 String roleEjbName = relSource.getEjbName(); 876 if (roleEjbName.equals(ejbName)) { 877 CmrField cmrField = role2.getCmrField(); 878 if (cmrField != null) { 879 String cmrFieldName = cmrField.getCmrFieldName(); 880 if (cmrFieldName.equalsIgnoreCase(fieldName)) { 883 return true; 884 } 885 } 886 } 887 } 888 } 889 } 890 } 891 } 892 } 893 return false; 894 } 895 896 897 public static String getEntityEjbNameForClass(JavaClass jc) { 898 if (jc == null) { 899 return null; 900 } 901 Resource res = jc.getResource(); 902 if (res != null) { 903 FileObject fo = JavaModel.getFileObject(res); 904 if (fo != null) { 905 Project prj = FileOwnerQuery.getOwner(fo); 906 if (prj != null) { 907 org.netbeans.modules.j2ee.api.ejbjar.EjbJar emod = 908 org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(prj.getProjectDirectory()); 909 Entity[] entityBeans = getEntityBeans(emod); 910 if (entityBeans != null) { 911 for (int e=0; e<entityBeans.length; e++) { 912 Entity entity = entityBeans[e]; 913 String ejbClass = entity.getEjbClass(); 914 err.log("ejbclass: " + ejbClass); 915 if (ejbClass.equals(jc.getName())) { 916 return entity.getEjbName(); 917 } 918 } 919 } 920 } 921 } 922 } 923 924 return null; 925 } 926 927 933 public static String getClassName(String pkg, final String simpleName) { 934 return (pkg == null || pkg.length() == 0 ? "" : pkg + ".") + simpleName; 935 } 936 937 public static Ejb getEjb(EjbJar ejbJar, ClassDefinition classDefinition) { 938 if (classDefinition == null) { 939 return null; 940 } 941 EnterpriseBeans enterpriseBeans = ejbJar.getEnterpriseBeans(); 942 if (enterpriseBeans == null) { 943 return null; 944 } 945 String className = classDefinition.getName(); 946 Ejb[] ejbs = enterpriseBeans.getEjbs(); 947 for (int i = 0; i < ejbs.length; i++) { 948 Ejb ejb = ejbs[i]; 949 if (className.equals(ejb.getEjbClass())) { 950 return ejb; 951 } 952 if (ejb instanceof EntityAndSession) { 953 EntityAndSession entityAndSession = ((EntityAndSession) ejb); 954 if (isSubTypeOf(entityAndSession.getLocal(), classDefinition) || 955 isSubTypeOf(entityAndSession.getLocalHome(), classDefinition) || 956 isSubTypeOf(entityAndSession.getRemote(), classDefinition) || 957 isSubTypeOf(entityAndSession.getHome(), classDefinition)) { 958 return ejb; 959 } 960 } 961 } 962 return null; 963 } 964 965 private static boolean isSubTypeOf(String thisClassName, ClassDefinition classDefinition) { 966 return thisClassName != null && resolveClass(thisClassName).isSubTypeOf(classDefinition); 967 } 968 969 public static String getFieldName(Method method) { 970 final String methodName = method.getName(); 971 if (methodName.length() > 3 && (methodName.startsWith(PREFIX_SET) || methodName.startsWith(PREFIX_GET))) { 972 final char c = methodName.charAt(3); 973 if (Character.isUpperCase(c)) { 974 return Character.toLowerCase(c) + methodName.substring(4); 975 } 976 } 977 return null; 978 } 979 980 private static String getGetterName(String fieldName) { 981 return PREFIX_GET + firstToUpperCase(fieldName); 982 } 983 984 985 private static String getSetterName(String fieldName) { 986 return PREFIX_SET + firstToUpperCase(fieldName); 987 } 988 989 public static Method getGetterMethod(JavaClass javaClass, String fieldName) { 990 if (javaClass == null) { 991 return null; 992 } 993 return javaClass.getMethod(getGetterName(fieldName), Collections.EMPTY_LIST, true); 994 } 995 996 private static Method getSetterMethod(JavaClass javaClass, String fieldName, Type type) { 997 if (javaClass == null) { 998 return null; 999 } 1000 return javaClass.getMethod(getSetterName(fieldName), Arrays.asList(new Type[]{type}), true); 1001 } 1002 1003 public static Collection getAccessMethods(Entity entity, String fieldName) { 1004 Collection accessMethods = new LinkedList(); 1005 JavaClass javaClass = resolveClass(entity.getEjbClass()); 1006 Method method = getGetterMethod(javaClass, fieldName); 1007 if (method != null) { 1008 accessMethods.add(method); 1009 Type type = method.getType(); 1010 addToCollection(accessMethods, getSetterMethod(javaClass, fieldName, type)); 1011 1012 addAccessMethods(accessMethods, resolveClass(entity.getLocal()), fieldName, type); 1013 addAccessMethods(accessMethods, resolveClass(entity.getRemote()), fieldName, type); 1014 } 1015 return accessMethods; 1016 } 1017 1018 private static void addAccessMethods(Collection accessMethods, JavaClass javaClass, String fieldName, Type type) { 1019 if (javaClass != null) { 1020 addToCollection(accessMethods, getGetterMethod(javaClass, fieldName)); 1021 addToCollection(accessMethods, getSetterMethod(javaClass, fieldName, type)); 1022 } 1023 } 1024 1025 public static JavaClass resolveClass(String className) { 1026 return (JavaClass) resolveType(className); 1027 } 1028 1029 private static Type resolveType(String typeName) { 1030 Type type = JavaModel.getDefaultExtent().getType().resolve(typeName); 1031 if (type instanceof UnresolvedClass) { 1032 Type basicType = JavaModel.getDefaultExtent().getType().resolve("java.lang." + typeName); if (!(basicType instanceof UnresolvedClass)) { 1034 return basicType; 1035 } 1036 } 1037 return type; 1038 } 1039 1040 1041 1042 public static void addToCollection(Collection collection, Object object) { 1043 if (object != null) { 1044 collection.add(object); 1045 } 1046 } 1047 1048 public static org.netbeans.modules.j2ee.api.ejbjar.EjbJar getApiEjbJar(Element element) { 1049 FileObject fileObject = JavaModel.getFileObject(element.getResource()); 1050 if (fileObject != null) { 1051 return org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(fileObject); 1052 } 1053 return null; 1054 } 1055 1056 public static FileObject getEjbJarFileObject(Element element) { 1057 FileObject fileObject = JavaModel.getFileObject(element.getResource()); 1058 if (fileObject != null) { 1059 Project project = FileOwnerQuery.getOwner(fileObject); 1060 if (project != null) { 1061 final org.netbeans.modules.j2ee.api.ejbjar.EjbJar ejbJar = 1062 org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(project.getProjectDirectory()); 1063 if (ejbJar != null) { 1064 return ejbJar.getDeploymentDescriptor(); 1065 } 1066 } 1067 } 1068 return null; 1069 } 1070 1071 public static EjbJar getEjbJar(FileObject fo) { 1072 if (fo != null) { 1073 try { 1074 return DDProvider.getDefault().getMergedDDRoot(org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(fo).getMetadataUnit()); 1075 } catch (IOException ioe) { 1076 } 1078 } 1079 return null; 1080 } 1081 1082 public static Method findMethod(ClassDefinition classDefinition, Method method, 1083 boolean includeSuperTypes) { 1084 return getMethod(classDefinition, method.getName(), method.getParameters(), includeSuperTypes); 1085 } 1086 1087 public static Method getMethod(ClassDefinition classDefinition, String methodName, List parameters, 1088 boolean includeSuperTypes) { 1089 if (classDefinition == null || methodName == null) { 1090 return null; 1091 } 1092 return classDefinition.getMethod(methodName, getTypedParams(parameters), includeSuperTypes); 1093 } 1094 1095 private static List getQueryMethodParams(Query query) { 1096 String [] methodParam = query.getQueryMethod().getMethodParams().getMethodParam(); 1097 List params = new LinkedList(); 1098 for (int i = 0; i < methodParam.length; i++) { 1099 params.add(resolveType(methodParam[i])); 1100 } 1101 return params; 1102 } 1103 1104 private static void addMethodToCollection(String className, Collection queryMethods, String methodName, 1105 List params) { 1106 JavaClass javaClass = resolveClass(className); 1107 addToCollection(queryMethods, getMethod(javaClass, methodName, params, false)); 1108 } 1109 1110 public static Collection getQueryMethods(Entity entity, Query query) { 1111 Collection queryMethods = new LinkedList(); 1112 final List params = getQueryMethodParams(query); 1113 final String methodName = query.getQueryMethod().getMethodName(); 1114 if (methodName.startsWith(PREFIX_EJBSELECT)) { 1115 addMethodToCollection(entity.getEjbClass(), queryMethods, methodName, params); 1116 } else if (methodName.startsWith(PREFIX_FIND)) { 1117 addMethodToCollection(entity.getLocalHome(), queryMethods, methodName, params); 1118 addMethodToCollection(entity.getHome(), queryMethods, methodName, params); 1119 } 1120 return queryMethods; 1121 } 1122 1123 public static JavaClass resolveRealClass(String className) { 1124 JavaClass javaClass = resolveClass(className); 1125 return javaClass instanceof UnresolvedClass ? null : javaClass; 1126 } 1127 1128 public static boolean isSubTypeOf(ClassDefinition classDefinition, String className) { 1129 if (classDefinition == null) { 1130 return false; 1131 } 1132 JavaClass javaClass = resolveClass(className); 1133 if (javaClass instanceof UnresolvedClass) { 1134 for (Iterator it = classDefinition.getInterfaces().iterator(); it.hasNext();) { 1135 if (className.equals(((JavaClass) it.next()).getName())) { 1136 return true; 1137 } 1138 } 1139 return false; 1140 } else { 1141 return classDefinition.isSubTypeOf(javaClass); 1142 } 1143 } 1144 1145 public static boolean isFirstUpperCase(String s) { 1146 return s.length() != 0 && Character.isUpperCase(s.charAt(0)); 1147 } 1148 1149 public static boolean isFirstLowerCase(String s) { 1150 return s.length() != 0 && Character.isLowerCase(s.charAt(0)); 1151 } 1152 1153 public static String firstToUpperCase(String s) { 1154 return s.length() == 0 ? s : Character.toUpperCase(s.charAt(0)) + s.substring(1); 1155 } 1156 1157 public static String firstToLowerCase(String s) { 1158 return s.length() == 0 ? s : Character.toLowerCase(s.charAt(0)) + s.substring(1); 1159 } 1160 1161 1167 public static String renameClass(String originalFullyQualifiedName, String newName){ 1168 if (isEmpty(originalFullyQualifiedName) || isEmpty(newName)){ 1169 throw new IllegalArgumentException ("Old and new name of the class must be given."); 1170 } 1171 int lastDot = originalFullyQualifiedName.lastIndexOf('.'); 1172 return (lastDot <= 0) ? newName : originalFullyQualifiedName.substring(0, lastDot + 1) + newName; 1173 } 1174 1175 1179 public static String unqualify(String qualifiedName){ 1180 int lastDot = qualifiedName.lastIndexOf("."); 1181 return (lastDot < 0 ) ? qualifiedName : qualifiedName.substring(lastDot + 1); 1182 1183 } 1184 1185 1188 public static boolean isEmpty(String str){ 1189 return str == null || "".equals(str.trim()); 1190 } 1191 1192 1198 public static String getPropertyName(String getter){ 1199 if (!getter.startsWith("get")){ 1200 return getter; 1201 } 1202 String sub = getter.substring(3); 1203 char c = sub.charAt(0); 1204 if (!Character.isUpperCase(c)){ 1205 return getter; 1206 } 1207 return Character.toLowerCase(c) + sub.substring(1); 1208 } 1209 1210 1214 public static boolean isEjb30(Project project){ 1215 if (project == null){ 1216 return false; 1217 } 1218 try { 1219 org.netbeans.modules.j2ee.api.ejbjar.EjbJar[] modules = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJars(project); 1220 if (modules != null && modules.length > 0){ 1221 return org.netbeans.modules.j2ee.dd.api.ejb.EjbJar.VERSION_3_0.equals(DDProvider.getDefault().getMergedDDRoot(modules[0].getMetadataUnit()).getVersion().toString()); 1222 } 1223 } catch (IOException e) { 1224 ErrorManager.getDefault().notify(e); 1225 } 1226 return false; 1227 } 1228 1229 1233 public static boolean isEjb30(RefObject refObject){ 1234 if (!(refObject instanceof Element)){ 1235 return false; 1236 } 1237 Element element = (Element) refObject; 1238 FileObject fo = JavaModel.getFileObject(element.getResource()); 1239 return isEjb30(FileOwnerQuery.getOwner(fo)); 1240 } 1241 1242 1246 public static boolean hasEjbJar(Collection ejbModules){ 1247 for (Object elem : ejbModules) { 1248 org.netbeans.modules.j2ee.api.ejbjar.EjbJar em = (org.netbeans.modules.j2ee.api.ejbjar.EjbJar)elem; 1249 FileObject ejbJarFO = em.getDeploymentDescriptor(); 1250 if (ejbJarFO != null){ 1251 return true; 1252 } 1253 } 1254 return false; 1255 } 1256 1257 1262 public static boolean hasEjbJar(RefObject refObject){ 1263 return hasEjbJar(getRelevantEjbModules(refObject)); 1264 } 1265} 1266 | Popular Tags |