| 1 22 package org.jboss.verifier.strategy; 23 24 26 import org.jboss.metadata.EntityMetaData; 27 import org.jboss.metadata.SessionMetaData; 28 import org.jboss.verifier.Section; 29 30 import java.lang.reflect.Field ; 31 import java.lang.reflect.Method ; 32 import java.util.Arrays ; 33 import java.util.Iterator ; 34 35 36 54 public class EJBVerifier11 extends AbstractVerifier 55 { 56 57 62 public EJBVerifier11(VerificationContext context) 63 { 64 super(context); 65 } 66 67 public String getMessageBundle() 68 { 69 return "EJB11Messages.properties"; 70 } 71 72 77 78 84 public void checkSession(SessionMetaData session) 85 { 86 boolean beanVerified = false; 87 boolean homeVerified = false; 88 boolean remoteVerified = false; 89 90 beanVerified = verifySessionBean(session); 91 homeVerified = verifySessionHome(session); 92 remoteVerified = verifySessionRemote(session); 93 94 if (beanVerified && homeVerified && remoteVerified) 95 { 96 100 fireBeanVerifiedEvent(session); 101 } 102 } 103 104 110 public void checkEntity(EntityMetaData entity) 111 { 112 boolean pkVerified = false; 113 boolean beanVerified = false; 114 boolean homeVerified = false; 115 boolean remoteVerified = false; 116 117 beanVerified = verifyEntityBean(entity); 118 homeVerified = verifyEntityHome(entity); 119 remoteVerified = verifyEntityRemote(entity); 120 pkVerified = verifyPrimaryKey(entity); 121 122 if (beanVerified && homeVerified && remoteVerified && pkVerified) 123 { 124 128 fireBeanVerifiedEvent(entity); 129 } 130 } 131 132 public boolean isCreateMethod(Method m) 133 { 134 return m.getName().equals(CREATE_METHOD); 135 } 136 137 public boolean isEjbCreateMethod(Method m) 138 { 139 return m.getName().equals(EJB_CREATE_METHOD); 140 } 141 142 143 150 151 157 private boolean verifySessionHome(SessionMetaData session) 158 { 159 163 boolean status = true; 164 165 String name = session.getHome(); 166 if (name == null) 167 return false; 168 169 try 170 { 171 Class home = classloader.loadClass(name); 172 173 184 if (session.isStateless()) 185 { 186 if (!hasDefaultCreateMethod(home)) 187 { 188 fireSpecViolationEvent(session, new Section("6.8.a")); 189 status = false; 190 } 191 else 192 { 193 Method create = getDefaultCreateMethod(home); 194 195 if (!hasRemoteReturnType(session, create)) 196 { 197 fireSpecViolationEvent(session, create, new Section("6.8.b")); 198 ; 199 status = false; 200 } 201 202 if (hasMoreThanOneCreateMethods(home)) 203 { 204 fireSpecViolationEvent(session, new Section("6.8.c")); 205 status = false; 206 } 207 } 208 } 209 210 216 if (!hasEJBHomeInterface(home)) 217 { 218 fireSpecViolationEvent(session, new Section("6.10.6.a")); 219 status = false; 220 } 221 222 234 Iterator it = Arrays.asList(home.getMethods()).iterator(); 235 while (it.hasNext()) 236 { 237 Method method = (Method )it.next(); 238 239 if (!hasLegalRMIIIOPArguments(method)) 240 { 241 fireSpecViolationEvent(session, method, new Section("6.10.6.b")); 242 status = false; 243 } 244 245 if (!hasLegalRMIIIOPReturnType(method)) 246 { 247 fireSpecViolationEvent(session, method, new Section("6.10.6.c")); 248 status = false; 249 } 250 251 if (!throwsRemoteException(method)) 252 { 253 fireSpecViolationEvent(session, method, new Section("6.10.6.d")); 254 status = false; 255 } 256 } 257 258 264 if (!hasCreateMethod(home)) 265 { 266 fireSpecViolationEvent(session, new Section("6.10.6.e")); 267 status = false; 268 } 269 270 290 Iterator createMethods = getCreateMethods(home); 291 try 292 { 293 String beanClass = session.getEjbClass(); 294 Class bean = classloader.loadClass(beanClass); 295 296 while (createMethods.hasNext()) 297 { 298 Method create = (Method )createMethods.next(); 299 300 if (!hasMatchingEJBCreate(bean, create)) 301 { 302 fireSpecViolationEvent(session, create, new Section("6.10.6.f")); 303 status = false; 304 } 305 306 if (!hasRemoteReturnType(session, create)) 307 { 308 fireSpecViolationEvent(session, create, new Section("6.10.6.g")); 309 status = false; 310 } 311 312 if (hasMatchingEJBCreate(bean, create)) 313 { 314 Method ejbCreate = getMatchingEJBCreate(bean, create); 315 316 if (!hasMatchingExceptions(ejbCreate, create)) 317 { 318 fireSpecViolationEvent(session, create, new Section("6.10.6.h")); 319 status = false; 320 } 321 } 322 323 if (!throwsCreateException(create)) 324 { 325 fireSpecViolationEvent(session, create, new Section("6.10.6.i")); 326 status = false; 327 } 328 } 329 } 330 catch (ClassNotFoundException ignored) 331 { 332 } 333 } 334 catch (ClassNotFoundException e) 335 { 336 342 fireSpecViolationEvent(session, new Section("16.2.c")); 343 status = false; 344 } 345 346 return status; 347 } 348 349 356 private boolean verifySessionRemote(SessionMetaData session) 357 { 358 362 boolean status = true; 363 364 String name = session.getRemote(); 365 if (name == null) 366 return false; 367 368 try 369 { 370 Class remote = classloader.loadClass(name); 371 372 378 if (!hasEJBObjectInterface(remote)) 379 { 380 fireSpecViolationEvent(session, new Section("6.10.5.a")); 381 status = false; 382 } 383 384 396 Iterator it = Arrays.asList(remote.getMethods()).iterator(); 397 while (it.hasNext()) 398 { 399 Method method = (Method )it.next(); 400 401 if (!hasLegalRMIIIOPArguments(method)) 402 { 403 fireSpecViolationEvent(session, method, new Section("6.10.5.b")); 404 status = false; 405 } 406 407 if (!hasLegalRMIIIOPReturnType(method)) 408 { 409 fireSpecViolationEvent(session, method, new Section("6.10.5.c")); 410 status = false; 411 } 412 413 if (!throwsRemoteException(method)) 414 { 415 fireSpecViolationEvent(session, method, new Section("6.10.5.d")); 416 status = false; 417 } 418 } 419 420 434 String beanName = session.getEjbClass(); 435 Class bean = classloader.loadClass(beanName); 436 437 Iterator iterator = Arrays.asList(remote.getDeclaredMethods()).iterator(); 438 while (iterator.hasNext()) 439 { 440 Method remoteMethod = (Method )iterator.next(); 441 442 if (!hasMatchingMethod(bean, remoteMethod)) 443 { 444 fireSpecViolationEvent(session, remoteMethod, new Section("6.10.5.e")); 445 status = false; 446 } 447 448 if (hasMatchingMethod(bean, remoteMethod)) 449 { 450 try 451 { 452 Method beanMethod = bean.getMethod(remoteMethod.getName(), remoteMethod.getParameterTypes()); 453 454 if (!hasMatchingReturnType(remoteMethod, beanMethod)) 455 { 456 fireSpecViolationEvent(session, remoteMethod, new Section("6.10.5.f")); 457 status = false; 458 } 459 460 if (!hasMatchingExceptions(beanMethod, remoteMethod)) 461 { 462 fireSpecViolationEvent(session, remoteMethod, new Section("6.10.5.g")); 463 status = false; 464 } 465 } 466 catch (NoSuchMethodException ignored) 467 { 468 } 469 } 470 } } 472 catch (ClassNotFoundException e) 473 { 474 480 fireSpecViolationEvent(session, new Section("16.2.d")); 481 status = false; 482 } 483 484 return status; 485 } 486 487 494 private boolean verifySessionBean(SessionMetaData session) 495 { 496 boolean status = true; 497 498 String name = session.getEjbClass(); 499 500 try 501 { 502 Class bean = classloader.loadClass(name); 503 504 511 if (!hasSessionBeanInterface(bean)) 512 { 513 fireSpecViolationEvent(session, new Section("6.5.1")); 514 status = false; 515 } 516 517 526 if (hasSessionSynchronizationInterface(bean)) 527 { 528 if (session.isStateless()) 529 { 530 fireSpecViolationEvent(session, new Section("6.5.3.a")); 531 status = false; 532 } 533 534 if (session.isBeanManagedTx()) 535 { 536 fireSpecViolationEvent(session, new Section("6.5.3.b")); 537 status = false; 538 } 539 } 540 541 546 if (!hasEJBCreateMethod(bean, true)) 547 { 548 fireSpecViolationEvent(session, new Section("6.5.5")); 549 status = false; 550 } 551 552 558 if (hasSessionSynchronizationInterface(bean) 559 && session.isBeanManagedTx()) 560 { 561 fireSpecViolationEvent(session, new Section("6.6.1")); 562 status = false; 563 } 564 565 570 if (!isPublic(bean)) 571 { 572 fireSpecViolationEvent(session, new Section("6.10.2.a")); 573 status = false; 574 } 575 576 581 if (isFinal(bean)) 582 { 583 fireSpecViolationEvent(session, new Section("6.10.2.b")); 584 status = false; 585 } 586 587 592 if (isAbstract(bean)) 593 { 594 fireSpecViolationEvent(session, new Section("6.10.2.c")); 595 status = false; 596 } 597 598 604 if (!hasDefaultConstructor(bean)) 605 { 606 fireSpecViolationEvent(session, new Section("6.10.2.d")); 607 status = false; 608 } 609 610 615 if (hasFinalizer(bean)) 616 { 617 fireSpecViolationEvent(session, new Section("6.10.2.e")); 618 status = false; 619 } 620 621 631 if (hasEJBCreateMethod(bean, true)) 632 { 633 Iterator it = getEJBCreateMethods(bean); 634 while (it.hasNext()) 635 { 636 Method ejbCreate = (Method )it.next(); 637 638 if (!isPublic(ejbCreate)) 639 { 640 fireSpecViolationEvent(session, ejbCreate, new Section("6.10.3.a")); 641 status = false; 642 } 643 644 if ((isFinal(ejbCreate)) || (isStatic(ejbCreate))) 645 { 646 fireSpecViolationEvent(session, ejbCreate, new Section("6.10.3.b")); 647 status = false; 648 } 649 650 if (!hasVoidReturnType(ejbCreate)) 651 { 652 fireSpecViolationEvent(session, ejbCreate, new Section("6.10.3.c")); 653 status = false; 654 } 655 656 if (!hasLegalRMIIIOPArguments(ejbCreate)) 657 { 658 fireSpecViolationEvent(session, ejbCreate, new Section("6.10.3.d")); 659 status = false; 660 } 661 } } 663 } 664 catch (ClassNotFoundException e) 665 { 666 673 fireSpecViolationEvent(session, new Section("16.2.b")); 674 status = false; 675 } 676 677 return status; 678 } 679 680 681 688 689 private boolean verifyEntityHome(EntityMetaData entity) 690 { 691 boolean status = true; 692 693 String name = entity.getHome(); 694 if (name == null) 695 return false; 696 697 try 698 { 699 Class home = classloader.loadClass(name); 700 701 707 if (!hasEJBHomeInterface(home)) 708 { 709 fireSpecViolationEvent(entity, new Section("9.2.8.a")); 710 status = false; 711 } 712 713 725 Iterator homeMethods = Arrays.asList(home.getMethods()).iterator(); 726 while (homeMethods.hasNext()) 727 { 728 Method method = (Method )homeMethods.next(); 729 730 if (!hasLegalRMIIIOPArguments(method)) 731 { 732 fireSpecViolationEvent(entity, method, new Section("9.2.8.b")); 733 734 status = false; 735 } 736 737 if (!hasLegalRMIIIOPReturnType(method)) 738 { 739 fireSpecViolationEvent(entity, method, new Section("9.2.8.c")); 740 status = false; 741 } 742 743 if (!throwsRemoteException(method)) 744 { 745 fireSpecViolationEvent(entity, method, new Section("9.2.8.d")); 746 status = false; 747 } 748 } 750 759 homeMethods = Arrays.asList(home.getMethods()).iterator(); 760 while (homeMethods.hasNext()) 761 { 762 Method method = (Method )homeMethods.next(); 763 764 if (method.getDeclaringClass().getName().equals(EJB_HOME_INTERFACE)) 766 continue; 767 768 if (!(isCreateMethod(method) || isFinderMethod(method))) 769 { 770 fireSpecViolationEvent(entity, method, new Section("9.2.8.e")); 771 status = false; 772 } 773 } 774 775 796 797 try 798 { 799 String beanClass = entity.getEjbClass(); 800 Class bean = classloader.loadClass(beanClass); 801 802 Iterator createMethods = getCreateMethods(home); 803 while (createMethods.hasNext()) 804 { 805 Method create = (Method )createMethods.next(); 806 807 if (!hasMatchingEJBCreate(bean, create)) 808 { 809 fireSpecViolationEvent(entity, create, new Section("9.2.8.f")); 810 status = false; 811 } 812 813 if (!hasRemoteReturnType(entity, create)) 814 { 815 fireSpecViolationEvent(entity, create, new Section("9.2.8.g")); 816 status = false; 817 } 818 819 if (hasMatchingEJBCreate(bean, create) 820 && hasMatchingEJBPostCreate(bean, create)) 821 { 822 Method ejbCreate = getMatchingEJBCreate(bean, create); 823 Method ejbPostCreate = getMatchingEJBPostCreate(bean, create); 824 825 if (!(hasMatchingExceptions(ejbCreate, create) 826 && hasMatchingExceptions(ejbPostCreate, create))) 827 { 828 fireSpecViolationEvent(entity, create, new Section("9.2.8.h")); 829 status = false; 830 } 831 } 832 833 if (!throwsCreateException(create)) 834 { 835 fireSpecViolationEvent(entity, create, new Section("9.2.8.i")); 836 status = false; 837 } 838 } 839 } 840 catch (ClassNotFoundException ignored) 841 { 842 } 843 844 864 try 865 { 866 String beanClass = entity.getEjbClass(); 867 Class bean = classloader.loadClass(beanClass); 868 869 Iterator finderMethods = getFinderMethods(home); 870 while (finderMethods.hasNext()) 871 { 872 Method finder = (Method )finderMethods.next(); 873 874 if ((entity.isBMP()) && (!hasMatchingEJBFind(bean, finder))) 875 { 876 fireSpecViolationEvent(entity, finder, new Section("9.2.8.j")); 877 status = false; 878 &nbs
|