| 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 46 47 public class EJBVerifier21 extends AbstractEJB2xVerifier 48 { 49 private static Logger log = Logger.getLogger(EJBVerifier21.class); 51 52 55 public EJBVerifier21(VerificationContext context) 56 { 57 super(context); 58 } 59 60 public String getMessageBundle() 61 { 62 return "EJB21Messages.properties"; 63 } 64 65 70 public void checkSession(SessionMetaData session) 71 { 72 boolean localOrRemoteExists = false; 73 boolean serviceEndpointExists = false; 74 boolean verified = false; 75 76 if (!verifyBean(session)) 77 return; 78 79 verified = verifySessionBean(session); 80 81 if (hasRemoteInterfaces(session)) 82 { 83 localOrRemoteExists = true; 85 verified = verified && verifySessionRemote(session); 86 verified = verified && verifySessionHome(session); 87 } 88 89 if (hasLocalInterfaces(session)) 90 { 91 localOrRemoteExists = true; 93 verified = verified && verifySessionLocal(session); 94 verified = verified && verifySessionLocalHome(session); 95 } 96 97 if (hasServiceEndpointInterfaces(session)) 98 { 99 serviceEndpointExists = true; 101 verified = verified && verifyServiceEndpoint(session); 102 } 103 104 if (!localOrRemoteExists && !serviceEndpointExists) 113 { 114 fireSpecViolationEvent(session, new Section("7.11.1")); 115 verified = false; 116 } 117 118 if (verified) 119 { 120 fireBeanVerifiedEvent(session); 122 } 123 } 124 125 public void checkEntity(EntityMetaData entity) 126 { 127 if (entity.isCMP1x()) 128 { 129 cmp1XVerifier.checkEntity(entity); 130 } 131 else 132 { 133 checkBmpOrCmp2Entity(entity); 134 } 135 } 136 137 public void checkMessageBean(MessageDrivenMetaData mdb) 138 { 139 boolean beanVerified = false; 140 141 if (!verifyBean(mdb)) 142 return; 143 144 beanVerified = verifyMessageDrivenBean(mdb); 145 146 if (beanVerified) 147 { 148 fireBeanVerifiedEvent(mdb); 150 } 151 } 152 153 private void checkBmpOrCmp2Entity(EntityMetaData entity) 154 { 155 boolean localOrRemoteExists = false; 156 boolean verified = false; 157 158 if (!verifyBean(entity)) 159 return; 160 161 if (entity.isCMP()) 162 { 163 verified = verifyCMPEntityBean(entity); 164 } 165 else if (entity.isBMP()) 166 { 167 verified = verifyBMPEntityBean(entity); 168 } 169 170 if (hasRemoteInterfaces(entity)) 171 { 172 localOrRemoteExists = true; 174 verified = verified && verifyEntityRemote(entity); 175 verified = verified && verifyEntityHome(entity); 176 } 177 178 if (hasLocalInterfaces(entity)) 179 { 180 localOrRemoteExists = true; 182 verified = verified && verifyEntityLocal(entity); 183 verified = verified && verifyEntityLocalHome(entity); 184 } 185 186 verified = verified && verifyPrimaryKey(entity); 187 188 if (!localOrRemoteExists) 189 { 190 if (entity.isCMP()) 197 { 198 fireSpecViolationEvent(entity, new Section("10.6.1")); 199 verified = false; 200 } 201 else 202 { 203 fireSpecViolationEvent(entity, new Section("12.2.1")); 204 verified = false; 205 } 206 } 207 208 if (verified) 209 { 210 fireBeanVerifiedEvent(entity); 211 } 212 } 213 214 220 protected boolean verifyBean(BeanMetaData theBean) 221 { 222 String beanName = theBean.getEjbClass(); 223 224 if (beanName == null) 225 return false; 226 227 try 228 { 229 bean = classloader.loadClass(beanName); 230 return true; 231 } 232 catch (ClassNotFoundException cnfe) 233 { 234 fireSpecViolationEvent(theBean, new Section("22.2.b", 235 "Class not found on '" + beanName + "': " + cnfe.getMessage())); 236 return false; 237 } 238 } 239 240 246 protected boolean hasRemoteInterfaces(BeanMetaData bean) 247 { 248 boolean status = true; 249 String homeName = bean.getHome(); 250 String remoteName = bean.getRemote(); 251 252 if (homeName == null || remoteName == null) 253 return false; 254 255 try 257 { 258 home = classloader.loadClass(homeName); 259 } 260 catch (ClassNotFoundException cnfe) 261 { 262 fireSpecViolationEvent(bean, new Section("22.2.c", 263 "Class not found on '" + homeName + "': " + cnfe.getMessage())); 264 status = false; 265 } 266 267 try 269 { 270 remote = classloader.loadClass(remoteName); 271 } 272 catch (ClassNotFoundException cnfe) 273 { 274 fireSpecViolationEvent(bean, new Section("22.2.d", 275 "Class not found on '" + remoteName + "': " + cnfe.getMessage())); 276 status = false; 277 } 278 279 return status; 280 } 281 282 288 protected boolean hasLocalInterfaces(BeanMetaData bean) 289 { 290 boolean status = true; 291 String localHomeName = bean.getLocalHome(); 292 String localName = bean.getLocal(); 293 294 if (localHomeName == null || localName == null) 295 return false; 296 297 try 299 { 300 localHome = classloader.loadClass(localHomeName); 301 } 302 catch (ClassNotFoundException cnfe) 303 { 304 fireSpecViolationEvent(bean, new Section("22.2.e", 305 "Class not found on '" + localHomeName + "': " + 306 cnfe.getMessage())); 307 status = false; 308 } 309 310 try 311 { 312 local = classloader.loadClass(localName); 313 } 314 catch (ClassNotFoundException cnfe) 315 { 316 fireSpecViolationEvent(bean, new Section("22.2.f", 317 "Class not found on '" + localName + "': " + cnfe.getMessage())); 318 status = false; 319 } 320 321 return status; 322 } 323 324 330 protected boolean verifySessionHome(SessionMetaData session) 331 { 332 boolean status = true; 333 334 if (session.isStateless()) 345 { 346 if (!hasDefaultCreateMethod(home)) 347 { 348 fireSpecViolationEvent(session, new Section("7.11.6.d2")); 349 status = false; 350 } 351 else 352 { 353 Method create = getDefaultCreateMethod(home); 354 355 if (hasMoreThanOneCreateMethods(home)) 356 { 357 fireSpecViolationEvent(session, new Section("7.11.6.d2")); 358 status = false; 359 } 360 } 361 } 362 363 if (!hasEJBHomeInterface(home)) 369 { 370 fireSpecViolationEvent(session, new Section("7.11.6.a")); 371 status = false; 372 } 373 374 Iterator it = Arrays.asList(home.getMethods()).iterator(); 386 while (it.hasNext()) 387 { 388 Method method = (Method )it.next(); 389 390 if (!hasLegalRMIIIOPArguments(method)) 391 { 392 fireSpecViolationEvent(session, method, new Section("7.11.6.b1")); 393 status = false; 394 } 395 396 if (!hasLegalRMIIIOPReturnType(method)) 397 { 398 fireSpecViolationEvent(session, method, new Section("7.11.6.b2")); 399 status = false; 400 } 401 402 if (!throwsRemoteException(method)) 403 { 404 fireSpecViolationEvent(session, method, new Section("7.11.6.b3")); 405 status = false; 406 } 407 } 408 409 if (!hasCreateMethod(home)) 415 { 416 fireSpecViolationEvent(session, new Section("7.11.6.d1")); 417 status = false; 418 } 419 420 Iterator createMethods = getCreateMethods(home); 441 while (createMethods.hasNext()) 442 { 443 Method create = (Method )createMethods.next(); 444 445 if (!hasMatchingEJBCreate(bean, create)) 446 { 447 fireSpecViolationEvent(session, create, new Section("7.11.6.e")); 448 status = false; 449 } 450 451 if (!hasRemoteReturnType(session, create)) 452 { 453 fireSpecViolationEvent(session, create, new Section("7.11.6.f")); 454 status = false; 455 } 456 457 if (hasMatchingEJBCreate(bean, create)) 458 { 459 Method ejbCreate = getMatchingEJBCreate(bean, create); 460 if (!hasMatchingExceptions(ejbCreate, create)) 461 { 462 fireSpecViolationEvent(session, create, 463 new Section("7.11.6.g")); 464 status = false; 465 } 466 } 467 468 if (!throwsCreateException(create)) 469 { 470 fireSpecViolationEvent(session, create, new Section("7.11.6.h")); 471 status = false; 472 } 473 } 474 475 return status; 476 } 477 478 484 protected boolean verifySessionLocalHome(SessionMetaData session) 485 { 486 boolean status = true; 487 488 if (session.isStateless()) 496 { 497 if (!hasDefaultCreateMethod(localHome)) 498 { 499 fireSpecViolationEvent(session, new Section("7.11.8.d2")); 500 status = false; 501 } 502 else 503 { 504 Method create = getDefaultCreateMethod(localHome); 505 506 if (hasMoreThanOneCreateMethods(localHome)) 507 { 508 fireSpecViolationEvent(session, new Section("7.11.8.d2")); 509 status = false; 510 } 511 } 512 } 513 514 if (!hasEJBLocalHomeInterface(localHome)) 520 { 521 fireSpecViolationEvent(session, new Section("7.11.8.a")); 522 status = false; 523 } 524 525 Iterator it = Arrays.asList(localHome.getMethods()).iterator(); 531 while (it.hasNext()) 532 { 533 Method method = (Method )it.next(); 534 535 if (throwsRemoteException(method)) 536 { 537 fireSpecViolationEvent(session, method, new Section("7.11.8.b")); 538 status = false; 539 } 540 } 541 542 if (!hasCreateMethod(localHome)) 548 { 549 fireSpecViolationEvent(session, new Section("7.11.8.d1")); 550 status = false; 551 } 552 553 Iterator createMethods = getCreateMethods(localHome); 574 while (createMethods.hasNext()) 575 { 576 Method create = (Method )createMethods.next(); 577 578 if (!hasMatchingEJBCreate(bean, create)) 579 { 580 fireSpecViolationEvent(session, create, 581 new Section("7.11.8.e")); 582 status = false; 583 } 584 585 if (!hasLocalReturnType(session, create)) 586 { 587 fireSpecViolationEvent(session, create, 588 new Section("7.11.8.f")); 589 status = false; 590 } 591 592 if (hasMatchingEJBCreate(bean, create)) 593 { 594 Method ejbCreate = getMatchingEJBCreate(bean, create); 595 if (!hasMatchingExceptions(ejbCreate, create)) 596 { 597 fireSpecViolationEvent(session, create, 598 new Section("7.11.8.g")); 599 } 600 } 601 602 if (!throwsCreateException(create)) 603 { 604 fireSpecViolationEvent(session, create, 605 new Section("7.11.8.h")); 606 status = false; 607 } 608 } 609 610 return status; 611 } 612 613 616 protected boolean verifySessionRemote(SessionMetaData session) 617 { 618 boolean status = true; 619 620 if (!hasEJBObjectInterface(remote)) 626 { 627 fireSpecViolationEvent(session, new Section("7.11.5.a")); 628 status = false; 629 } 630 631 Iterator it = Arrays.asList(remote.getMethods()).iterator(); 643 while (it.hasNext()) 644 { 645 Method method = (Method )it.next(); 646 647 if (!hasLegalRMIIIOPArguments(method)) 648 { 649 fireSpecViolationEvent(session, method, new Section("7.11.5.b1")); 650 status = false; 651 } 652 653 if (!hasLegalRMIIIOPReturnType(method)) 654 { 655 fireSpecViolationEvent(session, method, new Section("7.11.5.b2")); 656 status = false; 657 } 658 659 if (!throwsRemoteException(method)) 660 { 661 fireSpecViolationEvent(session, method, new Section("7.11.5.b3")); 662 status = false; 663 } 664 } 665 666 it = Arrays.asList(remote.getDeclaredMethods()).iterator(); 680 while (it.hasNext()) 681 { 682 Method remoteMethod = (Method )it.next(); 683 684 if (!hasMatchingMethod(bean, remoteMethod)) 685 { 686 fireSpecViolationEvent(session, remoteMethod, 687 new Section("7.11.5.d1")); 688 689 status = false; 690 } 691 692 if (hasMatchingMethod(bean, remoteMethod)) 693 { 694 try 695 { 696 Method beanMethod = bean.getMethod(remoteMethod.getName(), 697 remoteMethod.getParameterTypes()); 698 699 if (!hasMatchingReturnType(remoteMethod, beanMethod)) 700 { 701 fireSpecViolationEvent(session, remoteMethod, 702 new Section("7.11.5.d2")); 703 status = false; 704 } 705 706 if (!hasMatchingExceptions(beanMethod, remoteMethod)) 707 { 708 fireSpecViolationEvent(session, remoteMethod, 709 new Section("7.11.5.d3")); 710 status = false; 711 } 712 } 713 catch (NoSuchMethodException ignored) 714 { 715 } 716 } 717 } 718 719 return status; 720 } 721 722 725 protected boolean verifySessionLocal(SessionMetaData session) 726 { 727 boolean status = true; 728 729 if (!hasEJBLocalObjectInterface(local)) 735 { 736 fireSpecViolationEvent(session, new Section("7.11.7.a")); 737 status = false; 738 } 739 740 Iterator it = Arrays.asList(local.getMethods()).iterator(); 746 while (it.hasNext()) 747 { 748 Method method = (Method )it.next(); 749 if (throwsRemoteException(method)) 750 { 751 fireSpecViolationEvent(session, method, new Section("7.11.7.b")); 752 status = false; 753 } 754 } 755 756 it = Arrays.asList(local.getDeclaredMethods()).iterator(); 770 while (it.hasNext()) 771 { 772 Method localMethod = (Method )it.next(); 773 774 if (!hasMatchingMethod(bean, localMethod)) 775 { 776 fireSpecViolationEvent(session, localMethod, 777 new Section("7.11.7.d1")); 778 status = false; 779 } 780 781 if (hasMatchingMethod(bean, localMethod)) 782 { 783 try 784 { 785 Method beanMethod = bean.getMethod(localMethod.getName(), 786 localMethod.getParameterTypes()); 787 788 if (!hasMatchingReturnType(localMethod, beanMethod)) 789 { 790 fireSpecViolationEvent(session, localMethod, 791 new Section("7.11.7.d2")); 792 status = false; 793 } 794 795 if (!hasMatchingExceptions(beanMethod, localMethod)) 796 { 797 fireSpecViolationEvent(session, localMethod, 798 new Section("7.11.7.d3")); 799 status = false; 800 } 801 } 802 catch (NoSuchMethodException ignored) 803 { 804 } 805 } 806 } 807 808 return status; 809 } 810 811 814 protected boolean verifySessionBean(SessionMetaData session) 815 { 816 boolean status = true; 817 818 if (!hasSessionBeanInterface(bean)) 824 { 825 fireSpecViolationEvent(session, new Section("7.11.2.a")); 826 status = false; 827 } 828 829 if (hasSessionSynchronizationInterface(bean)) 839 { 840 if (session.isStateless()) 841 { 842 fireSpecViolationEvent(session, new Section("7.5.3.a")); 843 status = false; 844 } 845 846 if (session.isBeanManagedTx()) 847 { 848 fireSpecViolationEvent(session, new Section("7.5.3.b")); 849 status = false; 850 } 851 } 852 853 if (!hasEJBCreateMethod(bean, true)) 859 { 860 fireSpecViolationEvent(session, new Section("7.11.3")); 861 status = false; 862 } 863 864 if (hasSessionSynchronizationInterface(bean) 870 && session.isBeanManagedTx()) 871 { 872 fireSpecViolationEvent(session, new Section("7.6.1")); 873 status = false; 874 } 875 876 if (!isPublic(bean)) 881 { 882 fireSpecViolationEvent(session, new Section("7.11.2.b1")); 883 status = false; 884 } 885 886 if (isFinal(bean)) 891 { 892 fireSpecViolationEvent(session, new Section("7.11.2.b2")); 893 status = false; 894 } 895 896 if (isAbstract(bean)) 901 { 902 fireSpecViolationEvent(session, new Section("7.11.2.b3")); 903 status = false; 904 } 905 906 if (!hasDefaultConstructor(bean)) 912 { 913 fireSpecViolationEvent(session, new Section("7.11.2.c")); 914 status = false; 915 } 916 917 if (hasFinalizer(bean)) 922 { 923 fireSpecViolationEvent(session, new Section("7.11.2.d")); 924 status = false; 925 } 926 927 if (hasEJBCreateMethod(bean, true)) 940 { 941 Iterator it = getEJBCreateMethods(bean); 942 while (it.hasNext()) 943 { 944 Method ejbCreate = (Method )it.next(); 945 946 if (!isPublic(ejbCreate)) 947 { 948 fireSpecViolationEvent(session, ejbCreate, 949 new Section("7.11.3.b")); 950 status = false; 951 } 952 953 if ((isFinal(ejbCreate)) || (isStatic(ejbCreate))) 954 { 955 fireSpecViolationEvent(session, ejbCreate, 956 new Section("7.11.3.c")); 957 status = false; 958 } 959 960 if (!hasVoidReturnType(ejbCreate)) 961 { 962
|