| 1 22 package org.jboss.verifier.strategy; 23 24 26 import org.jboss.logging.Logger; 27 import org.jboss.metadata.BeanMetaData; 28 import org.jboss.metadata.EntityMetaData; 29 import org.jboss.metadata.MessageDrivenMetaData; 30 import org.jboss.metadata.SessionMetaData; 31 import org.jboss.verifier.Section; 32 33 import java.lang.reflect.Method ; 34 import java.util.Arrays ; 35 import java.util.Iterator ; 36 37 48 public class EJBVerifier20 extends AbstractEJB2xVerifier 49 { 50 private static Logger log = Logger.getLogger(EJBVerifier20.class); 51 52 55 public EJBVerifier20(VerificationContext context) 56 { 57 super(context); 58 } 59 60 public String getMessageBundle() 61 { 62 return "EJB20Messages.properties"; 63 } 64 65 70 public void checkSession(SessionMetaData session) 71 { 72 boolean localOrRemoteExists = false; 73 boolean verified = false; 74 75 if (!verifyBean(session)) 76 return; 77 78 verified = verifySessionBean(session); 79 80 if (hasRemoteInterfaces(session)) 81 { 82 localOrRemoteExists = true; 84 verified = verified && verifySessionRemote(session); 85 verified = verified && verifySessionHome(session); 86 } 87 88 if (hasLocalInterfaces(session)) 89 { 90 localOrRemoteExists = true; 92 verified = verified && verifySessionLocal(session); 93 verified = verified && verifySessionLocalHome(session); 94 } 95 96 if (!localOrRemoteExists) 103 { 104 fireSpecViolationEvent(session, new Section("7.10.1")); 105 verified = false; 106 } 107 108 if (verified) 109 { 110 fireBeanVerifiedEvent(session); 112 } 113 } 114 115 public void checkEntity(EntityMetaData entity) 116 { 117 if (entity.isCMP1x()) 118 { 119 cmp1XVerifier.checkEntity(entity); 120 } 121 else 122 { 123 checkBmpOrCmp2Entity(entity); 124 } 125 } 126 127 public void checkMessageBean(MessageDrivenMetaData mdb) 128 { 129 boolean beanVerified = false; 130 131 if (!verifyBean(mdb)) 132 return; 133 134 beanVerified = verifyMessageDrivenBean(mdb); 135 136 if (beanVerified) 137 { 138 fireBeanVerifiedEvent(mdb); 140 } 141 } 142 143 private void checkBmpOrCmp2Entity(EntityMetaData entity) 144 { 145 boolean localOrRemoteExists = false; 146 boolean verified = false; 147 148 if (!verifyBean(entity)) 149 return; 150 151 if (entity.isCMP()) 152 { 153 verified = verifyCMPEntityBean(entity); 154 } 155 else if (entity.isBMP()) 156 { 157 verified = verifyBMPEntityBean(entity); 158 } 159 160 if (hasRemoteInterfaces(entity)) 161 { 162 localOrRemoteExists = true; 164 verified = verified && verifyEntityRemote(entity); 165 verified = verified && verifyEntityHome(entity); 166 } 167 168 if (hasLocalInterfaces(entity)) 169 { 170 localOrRemoteExists = true; 172 verified = verified && verifyEntityLocal(entity); 173 verified = verified && verifyEntityLocalHome(entity); 174 } 175 176 verified = verified && verifyPrimaryKey(entity); 177 178 if (!localOrRemoteExists) 179 { 180 if (entity.isCMP()) 187 { 188 fireSpecViolationEvent(entity, new Section("10.6.1")); 189 verified = false; 190 } 191 else 192 { 193 fireSpecViolationEvent(entity, new Section("12.2.1")); 194 verified = false; 195 } 196 } 197 198 if (verified) 199 { 200 fireBeanVerifiedEvent(entity); 201 } 202 } 203 204 210 protected boolean verifyBean(BeanMetaData theBean) 211 { 212 String beanName = theBean.getEjbClass(); 213 214 if (beanName == null) 215 return false; 216 217 try 218 { 219 bean = classloader.loadClass(beanName); 220 return true; 221 } 222 catch (ClassNotFoundException cnfe) 223 { 224 fireSpecViolationEvent(theBean, new Section("22.2.b", 225 "Class not found on '" + beanName + "': " + cnfe.getMessage())); 226 return false; 227 } 228 } 229 230 236 protected boolean hasRemoteInterfaces(BeanMetaData bean) 237 { 238 boolean status = true; 239 String homeName = bean.getHome(); 240 String remoteName = bean.getRemote(); 241 242 if (homeName == null || remoteName == null) 243 return false; 244 245 try 247 { 248 home = classloader.loadClass(homeName); 249 } 250 catch (ClassNotFoundException cnfe) 251 { 252 fireSpecViolationEvent(bean, new Section("22.2.c", 253 "Class not found on '" + homeName + "': " + cnfe.getMessage())); 254 status = false; 255 } 256 257 try 259 { 260 remote = classloader.loadClass(remoteName); 261 } 262 catch (ClassNotFoundException cnfe) 263 { 264 fireSpecViolationEvent(bean, new Section("22.2.d", 265 "Class not found on '" + remoteName + "': " + cnfe.getMessage())); 266 status = false; 267 } 268 269 return status; 270 } 271 272 278 protected boolean hasLocalInterfaces(BeanMetaData bean) 279 { 280 boolean status = true; 281 String localHomeName = bean.getLocalHome(); 282 String localName = bean.getLocal(); 283 284 if (localHomeName == null || localName == null) 285 return false; 286 287 try 289 { 290 localHome = classloader.loadClass(localHomeName); 291 } 292 catch (ClassNotFoundException cnfe) 293 { 294 fireSpecViolationEvent(bean, new Section("22.2.e", 295 "Class not found on '" + localHomeName + "': " + 296 cnfe.getMessage())); 297 status = false; 298 } 299 300 try 301 { 302 local = classloader.loadClass(localName); 303 } 304 catch (ClassNotFoundException cnfe) 305 { 306 fireSpecViolationEvent(bean, new Section("22.2.f", 307 "Class not found on '" + localName + "': " + cnfe.getMessage())); 308 status = false; 309 } 310 311 return status; 312 } 313 314 320 protected boolean verifySessionHome(SessionMetaData session) 321 { 322 boolean status = true; 323 324 if (session.isStateless()) 335 { 336 if (!hasDefaultCreateMethod(home)) 337 { 338 fireSpecViolationEvent(session, new Section("7.10.6.d2")); 339 status = false; 340 } 341 else 342 { 343 Method create = getDefaultCreateMethod(home); 344 345 if (hasMoreThanOneCreateMethods(home)) 346 { 347 fireSpecViolationEvent(session, new Section("7.10.6.d2")); 348 status = false; 349 } 350 } 351 } 352 353 if (!hasEJBHomeInterface(home)) 359 { 360 fireSpecViolationEvent(session, new Section("7.10.6.a")); 361 status = false; 362 } 363 364 Iterator it = Arrays.asList(home.getMethods()).iterator(); 376 while (it.hasNext()) 377 { 378 Method method = (Method )it.next(); 379 380 if (!hasLegalRMIIIOPArguments(method)) 381 { 382 fireSpecViolationEvent(session, method, new Section("7.10.6.b1")); 383 status = false; 384 } 385 386 if (!hasLegalRMIIIOPReturnType(method)) 387 { 388 fireSpecViolationEvent(session, method, new Section("7.10.6.b2")); 389 status = false; 390 } 391 392 if (!throwsRemoteException(method)) 393 { 394 fireSpecViolationEvent(session, method, new Section("7.10.6.b3")); 395 status = false; 396 } 397 } 398 399 if (!hasCreateMethod(home)) 405 { 406 fireSpecViolationEvent(session, new Section("7.10.6.d1")); 407 status = false; 408 } 409 410 Iterator createMethods = getCreateMethods(home); 431 while (createMethods.hasNext()) 432 { 433 Method create = (Method )createMethods.next(); 434 435 if (!hasMatchingEJBCreate(bean, create)) 436 { 437 fireSpecViolationEvent(session, create, new Section("7.10.6.e")); 438 status = false; 439 } 440 441 if (!hasRemoteReturnType(session, create)) 442 { 443 fireSpecViolationEvent(session, create, new Section("7.10.6.f")); 444 status = false; 445 } 446 447 if (hasMatchingEJBCreate(bean, create)) 448 { 449 Method ejbCreate = getMatchingEJBCreate(bean, create); 450 if (!hasMatchingExceptions(ejbCreate, create)) 451 { 452 fireSpecViolationEvent(session, create, 453 new Section("7.10.6.g")); 454 status = false; 455 } 456 } 457 458 if (!throwsCreateException(create)) 459 { 460 fireSpecViolationEvent(session, create, new Section("7.10.6.h")); 461 status = false; 462 } 463 } 464 465 return status; 466 } 467 468 474 protected boolean verifySessionLocalHome(SessionMetaData session) 475 { 476 boolean status = true; 477 478 if (session.isStateless()) 486 { 487 if (!hasDefaultCreateMethod(localHome)) 488 { 489 fireSpecViolationEvent(session, new Section("7.10.8.d2")); 490 status = false; 491 } 492 else 493 { 494 Method create = getDefaultCreateMethod(localHome); 495 496 if (hasMoreThanOneCreateMethods(localHome)) 497 { 498 fireSpecViolationEvent(session, new Section("7.10.8.d2")); 499 status = false; 500 } 501 } 502 } 503 504 if (!hasEJBLocalHomeInterface(localHome)) 510 { 511 fireSpecViolationEvent(session, new Section("7.10.8.a")); 512 status = false; 513 } 514 515 Iterator it = Arrays.asList(localHome.getMethods()).iterator(); 521 while (it.hasNext()) 522 { 523 Method method = (Method )it.next(); 524 525 if (throwsRemoteException(method)) 526 { 527 fireSpecViolationEvent(session, method, new Section("7.10.8.b")); 528 status = false; 529 } 530 } 531 532 if (!hasCreateMethod(localHome)) 538 { 539 fireSpecViolationEvent(session, new Section("7.10.8.d1")); 540 status = false; 541 } 542 543 Iterator createMethods = getCreateMethods(localHome); 564 while (createMethods.hasNext()) 565 { 566 Method create = (Method )createMethods.next(); 567 568 if (!hasMatchingEJBCreate(bean, create)) 569 { 570 fireSpecViolationEvent(session, create, 571 new Section("7.10.8.e")); 572 status = false; 573 } 574 575 if (!hasLocalReturnType(session, create)) 576 { 577 fireSpecViolationEvent(session, create, 578 new Section("7.10.8.f")); 579 status = false; 580 } 581 582 if (hasMatchingEJBCreate(bean, create)) 583 { 584 Method ejbCreate = getMatchingEJBCreate(bean, create); 585 if (!hasMatchingExceptions(ejbCreate, create)) 586 { 587 fireSpecViolationEvent(session, create, 588 new Section("7.10.8.g")); 589 } 590 } 591 592 if (!throwsCreateException(create)) 593 { 594 fireSpecViolationEvent(session, create, 595 new Section("7.10.8.h")); 596 status = false; 597 } 598 } 599 600 return status; 601 } 602 603 606 protected boolean verifySessionRemote(SessionMetaData session) 607 { 608 boolean status = true; 609 610 if (!hasEJBObjectInterface(remote)) 616 { 617 fireSpecViolationEvent(session, new Section("7.10.5.a")); 618 status = false; 619 } 620 621 Iterator it = Arrays.asList(remote.getMethods()).iterator(); 633 while (it.hasNext()) 634 { 635 Method method = (Method )it.next(); 636 637 if (!hasLegalRMIIIOPArguments(method)) 638 { 639 fireSpecViolationEvent(session, method, new Section("7.10.5.b1")); 640 status = false; 641 } 642 643 if (!hasLegalRMIIIOPReturnType(method)) 644 { 645 fireSpecViolationEvent(session, method, new Section("7.10.5.b2")); 646 status = false; 647 } 648 649 if (!throwsRemoteException(method)) 650 { 651 fireSpecViolationEvent(session, method, new Section("7.10.5.b3")); 652 status = false; 653 } 654 } 655 656 it = Arrays.asList(remote.getDeclaredMethods()).iterator(); 670 while (it.hasNext()) 671 { 672 Method remoteMethod = (Method )it.next(); 673 674 if (!hasMatchingMethod(bean, remoteMethod)) 675 { 676 fireSpecViolationEvent(session, remoteMethod, 677 new Section("7.10.5.d1")); 678 679 status = false; 680 } 681 682 if (hasMatchingMethod(bean, remoteMethod)) 683 { 684 try 685 { 686 Method beanMethod = bean.getMethod(remoteMethod.getName(), 687 remoteMethod.getParameterTypes()); 688 689 if (!hasMatchingReturnType(remoteMethod, beanMethod)) 690 { 691 fireSpecViolationEvent(session, remoteMethod, 692 new Section("7.10.5.d2")); 693 status = false; 694 } 695 696 if (!hasMatchingExceptions(beanMethod, remoteMethod)) 697 { 698 fireSpecViolationEvent(session, remoteMethod, 699 new Section("7.10.5.d3")); 700 status = false; 701 } 702 } 703 catch (NoSuchMethodException ignored) 704 { 705 } 706 } 707 } 708 709 return status; 710 } 711 712 715 protected boolean verifySessionLocal(SessionMetaData session) 716 { 717 boolean status = true; 718 719 if (!hasEJBLocalObjectInterface(local)) 725 { 726 fireSpecViolationEvent(session, new Section("7.10.7.a")); 727 status = false; 728 } 729 730 Iterator it = Arrays.asList(local.getMethods()).iterator(); 736 while (it.hasNext()) 737 { 738 Method method = (Method )it.next(); 739 if (throwsRemoteException(method)) 740 { 741 fireSpecViolationEvent(session, method, new Section("7.10.7.b")); 742 status = false; 743 } 744 } 745 746 it = Arrays.asList(local.getDeclaredMethods()).iterator(); 760 while (it.hasNext()) 761 { 762 Method localMethod = (Method )it.next(); 763 764 if (!hasMatchingMethod(bean, localMethod)) 765 { 766 fireSpecViolationEvent(session, localMethod, 767 new Section("7.10.7.d1")); 768 status = false; 769 } 770 771 if (hasMatchingMethod(bean, localMethod)) 772 { 773 try 774 { 775 Method beanMethod = bean.getMethod(localMethod.getName(), 776 localMethod.getParameterTypes()); 777 778 if (!hasMatchingReturnType(localMethod, beanMethod)) 779 { 780 fireSpecViolationEvent(session, localMethod, 781 new Section("7.10.7.d2")); 782 status = false; 783 } 784 785 if (!hasMatchingExceptions(beanMethod, localMethod)) 786 { 787 fireSpecViolationEvent(session, localMethod, 788 new Section("7.10.7.d3")); 789 status = false; 790 } 791 } 792 catch (NoSuchMethodException ignored) 793 { 794 } 795 } 796 } 797 798 return status; 799 } 800 801 804 protected boolean verifySessionBean(SessionMetaData session) 805 { 806 boolean status = true; 807 808 if (!hasSessionBeanInterface(bean)) 814 { 815 fireSpecViolationEvent(session, new Section("7.10.2.a")); 816 status = false; 817 } 818 819 if (hasSessionSynchronizationInterface(bean)) 829 { 830 if (session.isStateless()) 831 { 832 fireSpecViolationEvent(session, new Section("7.5.3.a")); 833 status = false; 834 } 835 836 if (session.isBeanManagedTx()) 837 { 838 fireSpecViolationEvent(session, new Section("7.5.3.b")); 839 status = false; 840 } 841 } 842 843 if (!hasEJBCreateMethod(bean, true)) 849 { 850 fireSpecViolationEvent(session, new Section("7.10.3")); 851 status = false; 852 } 853 854 if (hasSessionSynchronizationInterface(bean) 860 && session.isBeanManagedTx()) 861 { 862 fireSpecViolationEvent(session, new Section("7.6.1")); 863 status = false; 864 } 865 866 if (!isPublic(bean)) 871 { 872 fireSpecViolationEvent(session, new Section("7.10.2.b1")); 873 status = false; 874 } 875 876 if (isFinal(bean)) 881 { 882 fireSpecViolationEvent(session, new Section("7.10.2.b2")); 883 status = false; 884 } 885 886 if (isAbstract(bean)) 891 { 892 fireSpecViolationEvent(session, new Section("7.10.2.b3")); 893 status = false; 894 } 895 896 if (!hasDefaultConstructor(bean)) 902 { 903 fireSpecViolationEvent(session, new Section("7.10.2.c")); 904 status = false; 905 } 906 907 if (hasFinalizer(bean)) 912 { 913 fireSpecViolationEvent(session, new Section("7.10.2.d")); 914 status = false; 915 } 916 917 if (hasEJBCreateMethod(bean, true)) 930 { 931 Iterator it = getEJBCreateMethods(bean); 932 while (it.hasNext()) 933 { 934 Method ejbCreate = (Method )it.next(); 935 936 if (!isPublic(ejbCreate)) 937 { 938 fireSpecViolationEvent(session, ejbCreate, 939 new Section("7.10.3.b")); 940 status = false; 941 } 942 943 if ((isFinal(ejbCreate)) || (isStatic(ejbCreate))) 944 { 945 fireSpecViolationEvent(session, ejbCreate, 946 new Section("7.10.3.c")); 947 status = false; 948 } 949 950 if (!hasVoidReturnType(ejbCreate)) 951 { 952 fireSpecViolationEvent(session, ejbCreate, 953 new Section("7.10.3.d")); 954 status = false; 955 } 956 957 if (!hasLegalRMIIIOPArguments(ejbCreate)) 958 { 959 &nbs
|