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 fireSpecViolationEvent(session, ejbCreate, 963 new Section("7.11.3.d")); 964 status = false; 965 } 966 967 if (!hasLegalRMIIIOPArguments(ejbCreate)) 968 { 969 fireSpecViolationEvent(session, ejbCreate, 970 new Section("7.11.3.e")); 971 status = false; 972 } 973 } 974 } 975 976 return status; 977 } 978 979 982 private boolean verifyEntityHome(EntityMetaData entity) 983 { 984 boolean status = true; 985 986 if (!hasEJBHomeInterface(home)) 992 { 993 fireSpecViolationEvent(entity, new Section("12.2.9.a")); 994 status = false; 995 } 996 997 Iterator methods = Arrays.asList(home.getMethods()).iterator(); 1009 while (methods.hasNext()) 1010 { 1011 Method method = (Method )methods.next(); 1012 1013 if (!hasLegalRMIIIOPArguments(method)) 1014 { 1015 fireSpecViolationEvent(entity, method, 1016 new Section("12.2.9.b1")); 1017 status = false; 1018 } 1019 1020 if (!hasLegalRMIIIOPReturnType(method)) 1021 { 1022 fireSpecViolationEvent(entity, method, 1023 new Section("12.2.9.b2")); 1024 status = false; 1025 } 1026 1027 if (!throwsRemoteException(method)) 1028 { 1029 fireSpecViolationEvent(entity, method, 1030 new Section("12.2.9.b3")); 1031 status = false; 1032 } 1033 } 1034 1035 methods = Arrays.asList(home.getMethods()).iterator(); 1045 while (methods.hasNext()) 1046 { 1047 Method method = (Method )methods.next(); 1048 1049 if (method.getDeclaringClass().getName().equals(EJB_HOME_INTERFACE)) 1051 continue; 1052 1053 if (isCreateMethod(method)) 1054 { 1055 if (!hasMatchingEJBCreate(bean, method)) 1077 { 1078 fireSpecViolationEvent(entity, method, new Section("12.2.9.d")); 1079 status = false; 1080 } 1081 1082 if (!hasRemoteReturnType(entity, method)) 1083 { 1084 fireSpecViolationEvent(entity, method, new Section("12.2.9.e")); 1085 status = false; 1086 } 1087 1088 if (hasMatchingEJBCreate(bean, method) 1089 && hasMatchingEJBPostCreate(bean, method)) 1090 { 1091 Method ejbCreate = getMatchingEJBCreate(bean, method); 1092 Method ejbPostCreate = getMatchingEJBPostCreate(bean, method); 1093 1094 if (!(hasMatchingExceptions(ejbCreate, method) 1095 && hasMatchingExceptions(ejbPostCreate, method))) 1096 { 1097 fireSpecViolationEvent(entity, method, 1098 new Section("12.2.9.f")); 1099 } 1100 } 1101 1102 if (!throwsCreateException(method)) 1103 { 1104 fireSpecViolationEvent(entity, method, new Section("12.2.9.g")); 1105 status = false; 1106 } 1107 } 1108 else if (isFinderMethod(method)) 1109 { 1110 if (entity.isBMP()) 1132 { if ((!hasMatchingEJBFind(bean, method))) 1134 { 1135 fireSpecViolationEvent(entity, method, 1136 new Section("12.2.9.h")); 1137 status = false; 1138 } 1139 1140 if (!(hasRemoteReturnType(entity, method) 1141 || isMultiObjectFinder(method))) 1142 { 1143 fireSpecViolationEvent(entity, method, 1144 new Section("12.2.9.j")); 1145 status = false; 1146 } 1147 1148 if ((hasMatchingEJBFind(bean, method))) 1149 { 1150 Method ejbFind = getMatchingEJBFind(bean, method); 1151 if (!(hasMatchingExceptions(ejbFind, method))) 1152 { 1153 fireSpecViolationEvent(entity, method, 1154 new Section("12.2.9.k")); 1155 status = false; 1156 } 1157 } 1158 1159 if (!throwsFinderException(method)) 1160 { 1161 fireSpecViolationEvent(entity, method, 1162 new Section("12.2.9.l")); 1163 status = false; 1164 } 1165 } 1167 if (entity.isCMP()) 1168 { 1169 1170 if (!(hasRemoteReturnType(entity, method) 1171 || isMultiObjectFinder(method))) 1172 { 1173 fireSpecViolationEvent(entity, method, 1174 new Section("10.6.10.a")); 1175 status = false; 1176 } 1177 1178 if (!throwsFinderException(method)) 1179 { 1180 fireSpecViolationEvent(entity, method, 1181 new Section("10.6.10.b")); 1182 status = false; 1183 } 1184 1185 if (!method.getName().equals("findByPrimaryKey") 1192 && !method.getName().equals("findAll") 1193 && !hasMatchingQuery(method, entity)) 1194 { 1195 fireSpecViolationEvent(entity, method, 1196 new Section("10.5.6")); 1197 status = false; 1198 } 1199 } } 1201 else { 1203 if (!hasMatchingEJBHome(bean, method)) 1213 { 1214 fireSpecViolationEvent(entity, method, 1215 new Section("12.2.9.m")); 1216 status = false; 1217 } 1218 } 1219 } 1221 1222 return status; 1223 } 1224 1225 1228 private boolean verifyEntityLocalHome(EntityMetaData entity) 1229 { 1230 boolean status = true; 1231 1232 if (!hasEJBLocalHomeInterface(localHome)) 1238 { 1239 fireSpecViolationEvent(entity, new Section("12.2.11.a")); 1240 status = false; 1241 } 1242 1243 Iterator homeMethods = Arrays.asList(localHome.getMethods()).iterator(); 1249 while (homeMethods.hasNext()) 1250 { 1251 Method method = (Method )homeMethods.next(); 1252 1253 if (throwsRemoteException(method)) 1254 { 1255 fireSpecViolationEvent(entity, method, new Section("12.2.11.b")); 1256 status = false; 1257 } 1258 } 1259 1260 homeMethods = Arrays.asList(localHome.getMethods()).iterator(); 1270 while (homeMethods.hasNext()) 1271 { 1272 Method method = (Method )homeMethods.next(); 1273 1274 if (method.getDeclaringClass().getName().equals(EJB_LOCAL_HOME_INTERFACE)) 1276 continue; 1277 1278 if (isCreateMethod(method)) 1279 { 1280 if (!hasMatchingEJBCreate(bean, method)) 1302 { 1303 fireSpecViolationEvent(entity, method, 1304 new Section("12.2.11.e")); 1305 status = false; 1306 } 1307 1308 if (!hasLocalReturnType(entity, method)) 1309 { 1310 fireSpecViolationEvent(entity, method, 1311 new Section("12.2.11.f")); 1312 status = false; 1313 } 1314 1315 if (hasMatchingEJBCreate(bean, method) 1316 && hasMatchingEJBPostCreate(bean, method)) 1317 { 1318 Method ejbCreate = getMatchingEJBCreate(bean, method); 1319 Method ejbPostCreate = getMatchingEJBPostCreate(bean, method); 1320 1321 if (!(hasMatchingExceptions(ejbCreate, method) 1322 && hasMatchingExceptions(ejbPostCreate, method))) 1323 { 1324 fireSpecViolationEvent(entity, method, 1325 new Section("12.2.11.g")); 1326 } 1327 } 1328 1329 if (!throwsCreateException(method)) 1330 { 1331 fireSpecViolationEvent(entity, method, 1332 new Section("12.2.11.h")); 1333 status = false; 1334 } 1335 } 1336 else if (isFinderMethod(method)) 1337 { 1338 if (!(hasLocalReturnType(entity, method) 1359 || isMultiObjectFinder(method))) 1360 { 1361 fireSpecViolationEvent(entity, method, 1362 new Section("12.2.11.j")); 1363 status = false; 1364 } 1365 1366 if (!throwsFinderException(method)) 1367 { 1368 fireSpecViolationEvent(entity, method, 1369 new Section("12.2.11.k")); 1370 status = false; 1371 } 1372 1373 if (entity.isCMP()) 1374 { 1375 if (hasMatchingEJBFind(bean, method)) 1382 { 1383 fireSpecViolationEvent(entity, method, 1384 new Section("10.6.2.j")); 1385 status = false; 1386 } 1387 1388 if (!method.getName().equals("findByPrimaryKey") 1397 && !method.getName().equals("findAll") 1398 && !hasMatchingQuery(method, entity)) 1399 { 1400 fireSpecViolationEvent(entity, method, 1401 new Section("10.5.6")); 1402 status = false; 1403 } 1404 } 1405 1406 if (entity.isBMP()) 1407 { 1408 if (!hasMatchingEJBFind(bean, method)) 1409 { 1410 fireSpecViolationEvent(entity, method, 1411 new Section("12.2.11.i")); 1412 status = false; 1413 } 1414 else 1415 { 1416 Method ejbFind = getMatchingEJBFind(bean, method); 1417 1418 if (!(hasMatchingExceptions(ejbFind, method))) 1419 { 1420 fireSpecViolationEvent(entity, method, 1421 new Section("12.2.11.l")); 1422 } 1423 } 1424 } 1425 } 1426 else 1427 { 1428 if (!hasMatchingEJBHome(bean, method)) 1438 { 1439 fireSpecViolationEvent(entity, method, 1440 new Section("12.2.11.m")); 1441 status = false; 1442 } 1443 } 1444 } 1446 return status; 1447 } 1448 1449 1452 private boolean verifyEntityLocal(EntityMetaData entity) 1453 { 1454 boolean status = true; 1455 1456 if (!hasEJBLocalObjectInterface(local)) 1462 { 1463 fireSpecViolationEvent(entity, new Section("12.2.10.a")); 1464 status = false; 1465 } 1466 1467 Iterator localMethods = Arrays.asList(local.getMethods()).iterator(); 1473 while (localMethods.hasNext()) 1474 { 1475 Method method = (Method )localMethods.next(); 1476 1477 if (throwsRemoteException(method)) 1478 { 1479 fireSpecViolationEvent(entity, method, new Section("12.2.10.b")); 1480 status = false; 1481 } 1482 } 1483 1484 localMethods = Arrays.asList(local.getMethods()).iterator(); 1499 while (localMethods.hasNext()) 1500 { 1501 Method method = (Method )localMethods.next(); 1502 1503 if (method.getDeclaringClass().getName().equals(EJB_LOCAL_OBJECT_INTERFACE)) 1506 continue; 1507 1508 if (!hasMatchingMethod(bean, method)) 1509 { 1510 fireSpecViolationEvent(entity, method, new Section("12.2.10.c")); 1511 status = false; 1512 } 1513 1514 if (hasMatchingMethod(bean, method)) 1515 { 1516 try 1517 { 1518 Method beanMethod = bean.getMethod(method.getName(), 1519 method.getParameterTypes()); 1520 1521 if (!hasMatchingReturnType(beanMethod, method)) 1522 { 1523 fireSpecViolationEvent(entity, method, 1524 new Section("12.2.10.d")); 1525 status = false; 1526 } 1527 1528 if (!hasMatchingExceptions(beanMethod, method)) 1529 { 1530 fireSpecViolationEvent(entity, method, 1531 new Section("12.2.10.e")); 1532 1533 status = false; 1534 } 1535 } 1536 catch (NoSuchMethodException ignored) 1537 { 1538 } 1539 } 1540 } 1541 1542 return status; 1543 } 1544 1545 1548 private boolean verifyEntityRemote(EntityMetaData entity) 1549 { 1550 boolean status = true; 1551 1552 if (!hasEJBObjectInterface(remote)) 1558 { 1559 fireSpecViolationEvent(entity, new Section("9.2.7.a")); 1560 status = false; 1561 } 1562 1563 Iterator it = Arrays.asList(remote.getMethods()).iterator(); 1575 while (it.hasNext()) 1576 { 1577 Method method = (Method )it.next(); 1578 1579 if (!hasLegalRMIIIOPArguments(method)) 1580 { 1581 fireSpecViolationEvent(entity, method, new Section("9.2.7.b")); 1582 status = false; 1583 } 1584 1585 if (!hasLegalRMIIIOPReturnType(method)) 1586 { 1587 fireSpecViolationEvent(entity, method, new Section("9.2.7.c")); 1588 status = false; 1589 } 1590 1591 if (!hasLegalRMIIIOPExceptionTypes(method)) 1592 { 1593 fireSpecViolationEvent(entity, method, new Section("9.2.7.h")); 1594 status = false; 1595 } 1596 1597 if (!throwsRemoteException(method)) 1598 { 1599 fireSpecViolationEvent(entity, method, new Section("9.2.7.d")); 1600 status = false; 1601 } 1602 } 1603 1604 it = Arrays.asList(remote.getMethods()).iterator(); 1619 while (it.hasNext()) 1620 { 1621 Method method = (Method )it.next(); 1622 1623 if (method.getDeclaringClass().getName().equals(EJB_OBJECT_INTERFACE)) 1625 continue; 1626 1627 if (!hasMatchingMethod(bean, method)) 1628 { 1629 fireSpecViolationEvent(entity, method, new Section("9.2.7.e")); 1630 status = false; 1631 } 1632 1633 if (hasMatchingMethod(bean, method)) 1634 { 1635 try 1636 { 1637 Method beanMethod = bean.getMethod(method.getName(), 1638 method.getParameterTypes()); 1639 1640 if (!hasMatchingReturnType(beanMethod, method)) 1641 { 1642 fireSpecViolationEvent(entity, method, 1643 new Section("9.2.7.f")); 1644 status = false; 1645 } 1646 1647 if (!hasMatchingExceptions(beanMethod, method)) 1648 { 1649 fireSpecViolationEvent(entity, method, 1650 new Section("9.2.7.g")); 1651 status = false; 1652 } 1653 } 1654 catch (NoSuchMethodException ignored) 1655 { 1656 } 1657 } 1658 } 1659 1660 return status; 1661 } 1662 1663 1666 private boolean verifyCMPEntityBean(EntityMetaData entity) 1667 { 1668 boolean status = true; 1669 1670 if (!hasEntityBeanInterface(bean)) 1676 { 1677 fireSpecViolationEvent(entity, new Section("10.6.2.a")); 1678 status = false; 1679 } 1680 1681 if (!isPublic(bean) || !isAbstract(bean)) 1686 { 1687 fireSpecViolationEvent(entity, new Section("10.6.2.b")); 1688 status = false; 1689 } 1690 1691 if (!hasDefaultConstructor(bean)) 1697 { 1698 fireSpecViolationEvent(entity, new Section("10.6.2.c")); 1699 status = false; 1700 } 1701 1702 if (hasFinalizer(bean)) 1707 { 1708 fireSpecViolationEvent(entity, new Section("10.6.2.d")); 1709 status = false; 1710 } 1711 1712 if (hasEJBCreateMethod(bean, false)) 1726 { 1727 Iterator it = getEJBCreateMethods(bean); 1728 while (it.hasNext()) 1729 { 1730 Method ejbCreate = (Method )it.next(); 1731 if (!isPublic(ejbCreate)) 1732 { 1733 fireSpecViolationEvent(entity, ejbCreate, 1734 new Section("10.6.4.b")); 1735 status = false; 1736 } 1737 1738 if ((isFinal(ejbCreate)) || (isStatic(ejbCreate))) 1739 { 1740 fireSpecViolationEvent(entity, ejbCreate, 1741 new Section("10.6.4.c")); 1742 status = false; 1743 } 1744 1745 if (!hasPrimaryKeyReturnType(entity, ejbCreate)) 1746 { 1747 fireSpecViolationEvent(entity, ejbCreate, 1748 new Section("10.6.4.d")); 1749 status = false; 1750 } 1751 1752 1765 1766 if (!throwsCreateException(ejbCreate)) 1767 { 1768 fireSpecViolationEvent(entity, ejbCreate, 1769 new Section("10.6.4.g")); 1770 status = false; 1771 } 1772 } 1773 } 1774 1775 if (hasEJBCreateMethod(bean, false)) 1789 { 1790 Iterator it = getEJBCreateMethods(bean); 1791 1792 while (it.hasNext()) 1793 { 1794 Method ejbCreate = (Method )it.next(); 1795 1796 if (!hasMatchingEJBPostCreate(bean, ejbCreate)) 1797 { 1798 fireSpecViolationEvent(entity, ejbCreate, 1799 new Section("10.6.5.a")); 1800 status = false; 1801 } 1802 1803 if (hasMatchingEJBPostCreate(bean, ejbCreate)) 1804 { 1805 Method ejbPostCreate = getMatchingEJBPostCreate(bean, 1806 ejbCreate); 1807 1808 if (!isPublic(ejbPostCreate)) 1809 { 1810 fireSpecViolationEvent(entity, ejbPostCreate, 1811 new Section("10.6.5.b")); 1812 status = false; 1813 } 1814 1815 if (isStatic(ejbPostCreate)) 1816 { 1817 fireSpecViolationEvent(entity, ejbPostCreate, 1818 new Section("10.6.5.c")); 1819 status = false; 1820 } 1821 1822 if (isFinal(ejbPostCreate)) 1823 { 1824 fireSpecViolationEvent(entity, ejbPostCreate, 1825 new Section("10.6.5.d")); 1826 status = false; 1827 } 1828 1829 if (!hasVoidReturnType(ejbPostCreate)) 1830 { 1831 fireSpecViolationEvent(entity, ejbPostCreate, 1832 new Section("10.6.5.e")); 1833 status = false; 1834 } 1835 } 1836 } 1837 } 1838 1839 Iterator it = getEjbHomeMethods(bean); 1849 while (it.hasNext()) 1850 { 1851 Method ejbHome = (Method )it.next(); 1852 if (!isPublic(ejbHome)) 1853 { 1854 fireSpecViolationEvent(entity, ejbHome, new Section("10.6.6.a")); 1855 status = false; 1856 } 1857 1858 if (isStatic(ejbHome)) 1859 { 1860 fireSpecViolationEvent(entity, ejbHome, new Section("10.6.6.b")); 1861 status = false; 1862 } 1863 1864 if (throwsRemoteException(ejbHome)) 1865 { 1866 fireSpecViolationEvent(entity, ejbHome, new Section("10.6.6.c")); 1867 status = false; 1868 } 1869 } 1870 1871 it = entity.getCMPFields(); 1877 while (it.hasNext()) 1878 { 1879 String fieldName = (String )it.next(); 1880 String getName = "get" + fieldName.substring(0, 1).toUpperCase() + 1881 fieldName.substring(1); 1882 Class fieldType = null; 1883 1884 try 1885 { 1886 Method m = bean.getMethod(getName, new Class [0]); 1887 fieldType = m.getReturnType(); 1888 1889 if (fieldType == Void.TYPE) 1892 { 1893 fireSpecViolationEvent(entity, 1894 new Section("jb.7.1.b", "Field: " + fieldName)); 1895 } 1896 } 1897 catch (NoSuchMethodException nsme) 1898 { 1899 fireSpecViolationEvent(entity, 1900 new Section("10.6.2.g", "Field: " + fieldName)); 1901 status = false; 1902 } 1903 1904 String setName = "set" + fieldName.substring(0, 1).toUpperCase() + 1905 fieldName.substring(1); 1906 Class [] args = new Class [1]; 1907 args[0] = fieldType; 1908 1909 try 1910 { 1911 Method m = bean.getMethod(setName, args); 1912 fieldType = m.getReturnType(); 1913 1914 if (fieldType != Void.TYPE) 1917 { 1918 fireSpecViolationEvent(entity, 1919 new Section("jb.7.1.a", "Field: " + fieldName)); 1920 } 1921 } 1922 catch (NoSuchMethodException nsme) 1923 { 1924 try 1929 { 1930 args[0] = classloader.loadClass("java.util.Collection"); 1931 Method m = bean.getMethod(setName, args); 1932 } 1933 catch (NoSuchMethodException nsme2) 1934 { 1935 fireSpecViolationEvent(entity, 1936 new Section("10.6.2.h", "Field: " + fieldName)); 1937 status = false; 1938 } 1939 catch (ClassNotFoundException cnfe) 1940 { 1941 } 1943 } 1944 } 1945 1946 it = getEjbSelectMethods(bean); 1956 while (it.hasNext()) 1957 { 1958 Method ejbSelect = (Method )it.next(); 1959 1960 if (!isPublic(ejbSelect)) 1961 { 1962 fireSpecViolationEvent(entity, ejbSelect, new Section("10.6.7.a")); 1963 status = false; 1964 } 1965 1966 if (!isAbstract(ejbSelect)) 1967 { 1968 fireSpecViolationEvent(entity, ejbSelect, new Section("10.6.7.b")); 1969 status = false; 1970 } 1971 1972 if (!throwsFinderException(ejbSelect)) 1973 { 1974 fireSpecViolationEvent(entity, ejbSelect, new Section("10.6.7.c")); 1975 status = false; 1976 } 1977 1978 if (!hasMatchingQuery(ejbSelect, entity)) 1979 { 1980 fireSpecViolationEvent(entity, ejbSelect, new Section("10.5.7")); 1981 status = false; 1982 } 1983 } 1984 1985 if (hasFinderMethod(bean)) 1990 { 1991 fireSpecViolationEvent(entity, new Section("10.6.2.i")); 1992 status = false; 1993 } 1994 1995 return status; 1996 } 1997 1998 2001 private boolean verifyBMPEntityBean(EntityMetaData entity) 2002 { 2003 boolean status = true; 2004 2005 if (!hasEntityBeanInterface(bean)) 2011 { 2012 fireSpecViolationEvent(entity, new Section("12.2.2.a")); 2013 status = false; 2014 } 2015 2016 if (!isPublic(bean) || isAbstract(bean)) 2021 { 2022 fireSpecViolationEvent(entity, new Section("12.2.2.b")); 2023 status = false; 2024 } 2025 2026 if (isFinal(bean)) 2031 { 2032 fireSpecViolationEvent(entity, new Section("12.2.2.c")); 2033 status = false; 2034 } 2035 2036 if (!hasDefaultConstructor(bean)) 2042 { 2043 fireSpecViolationEvent(entity, new Section("12.2.2.d")); 2044 status = false; 2045 } 2046 2047 if (hasFinalizer(bean)) 2052 { 2053 fireSpecViolationEvent(entity, new Section("12.2.2.e")); 2054 status = false; 2055 } 2056 2057 if (hasEJBCreateMethod(bean, false)) 2070 { 2071 Iterator it = getEJBCreateMethods(bean); 2072 while (it.hasNext()) 2073 { 2074 Method ejbCreate = (Method )it.next(); 2075 if (!isPublic(ejbCreate)) 2076 { 2077 fireSpecViolationEvent(entity, ejbCreate, 2078 new Section("12.2.3.a")); 2079 status = false; 2080 } 2081 2082 if ((isFinal(ejbCreate)) || (isStatic(ejbCreate))) 2083 { 2084 fireSpecViolationEvent(entity, ejbCreate, 2085 new Section("12.2.3.b")); 2086 status = false; 2087 } 2088 2089 if (!hasPrimaryKeyReturnType(entity, ejbCreate)) 2090 { 2091 fireSpecViolationEvent(entity, ejbCreate, 2092 new Section("12.2.3.c")); 2093 status = false; 2094 } 2095 2096 2108 } 2109 } 2110 2111 if (hasEJBCreateMethod(bean, false)) 2125 { 2126 Iterator it = getEJBCreateMethods(bean); 2127 while (it.hasNext()) 2128 { 2129 Method ejbCreate = (Method )it.next(); 2130 2131 if (!hasMatchingEJBPostCreate(bean, ejbCreate)) 2132 { 2133 fireSpecViolationEvent(entity, ejbCreate, 2134 new Section("12.2.4.a")); 2135 status = false; 2136 } 2137 2138 if (hasMatchingEJBPostCreate(bean, ejbCreate)) 2139 { 2140 Method ejbPostCreate = getMatchingEJBPostCreate(bean, 2141 ejbCreate); 2142 2143 if (!isPublic(ejbPostCreate)) 2144 { 2145 fireSpecViolationEvent(entity, ejbPostCreate, 2146 new Section("12.2.4.b")); 2147 status = false; 2148 } 2149 2150 if (isStatic(ejbPostCreate) || isFinal(ejbPostCreate)) 2151 { 2152 fireSpecViolationEvent(entity, ejbPostCreate, 2153 new Section("12.2.4.c")); 2154 status = false; 2155 } 2156 2157 if (!hasVoidReturnType(ejbPostCreate)) 2158 { 2159 fireSpecViolationEvent(entity, ejbPostCreate, 2160 new Section("12.2.4.d")); 2161 status = false; 2162 } 2163 } 2164 } 2165 } 2166 2167 if (!hasEJBFindByPrimaryKey(bean)) 2177 { 2178 fireSpecViolationEvent(entity, new Section("12.2.5.e")); 2179 status = false; 2180 } 2181 2182 if (hasEJBFindByPrimaryKey(bean)) 2183 { 2184 Method ejbFindByPrimaryKey = getEJBFindByPrimaryKey(bean); 2185 2186 if (!hasPrimaryKeyReturnType(entity, ejbFindByPrimaryKey)) 2187 { 2188 fireSpecViolationEvent(entity, ejbFindByPrimaryKey, 2189 new Section("12.2.5.e1")); 2190 status = false; 2191 } 2192 2193 if (!isSingleObjectFinder(entity, ejbFindByPrimaryKey)) 2194 { 2195 fireSpecViolationEvent(entity, ejbFindByPrimaryKey, 2196 new Section("12.2.5.e2")); 2197 status = false; 2198 } 2199 } 2200 2201 if (hasFinderMethod(bean)) 2217 { 2218 Iterator it = getEJBFindMethods(bean); 2219 while (it.hasNext()) 2220 { 2221 Method finder = (Method )it.next(); 2222 2223 if (!isPublic(finder)) 2224 { 2225 fireSpecViolationEvent(entity, finder, new Section("12.2.5.a")); 2226 status = false; 2227 } 2228 2229 if (isFinal(finder) || isStatic(finder)) 2230 { 2231 fireSpecViolationEvent(entity, finder, new Section("12.2.5.b")); 2232 status = false; 2233 } 2234 2235 2243 2244 if (!(isSingleObjectFinder(entity, finder) 2245 || isMultiObjectFinder(finder))) 2246 { 2247 fireSpecViolationEvent(entity, finder, new Section("12.2.5.d")); 2248 status = false; 2249 } 2250 } 2251 } 2252 2253 Iterator it = getEjbHomeMethods(bean); 2263 while (it.hasNext()) 2264 { 2265 Method ejbHome = (Method )it.next(); 2266 2267 if (!isPublic(ejbHome)) 2268 { 2269 fireSpecViolationEvent(entity, ejbHome, new Section("10.6.6.a")); 2270 status = false; 2271 } 2272 2273 if (isStatic(ejbHome)) 2274 { 2275 fireSpecViolationEvent(entity, ejbHome, new Section("10.6.6.b")); 2276 status = false; 2277 } 2278 2279 if (throwsRemoteException(ejbHome)) 2280 { 2281 fireSpecViolationEvent(entity, ejbHome, new Section("10.6.6.c")); 2282 status = false; 2283 } 2284 } 2285 2286 return status; 2287 } 2288 2289 2292 private boolean verifyPrimaryKey(EntityMetaData entity) 2293 { 2294 boolean status = true; 2295 boolean cmp = entity.isCMP(); 2296 2297 if (entity.getPrimaryKeyClass() == null 2298 || entity.getPrimaryKeyClass().length() == 0) 2299 { 2300 if (cmp) 2301 fireSpecViolationEvent(entity, new Section("10.6.1.a")); 2302 else 2303 fireSpecViolationEvent(entity, new Section("12.2.1.a")); 2304 2305 return false; 2307 } 2308 2309 Class cls = null; 2315 try 2316 { 2317 cls = classloader.loadClass(entity.getPrimaryKeyClass()); 2318 } 2319 catch (ClassNotFoundException e) 2320 { 2321 if (cmp) 2322 fireSpecViolationEvent(entity, new Section("10.6.13.a")); 2323 else 2324 fireSpecViolationEvent(entity, new Section("12.2.12.a")); 2325 2326 return false; 2328 } 2329 2330 if (!isRMIIDLValueType(cls)) 2335 { 2336 if (cmp) 2337 fireSpecViolationEvent(entity, new Section("10.6.13.b")); 2338 else 2339 fireSpecViolationEvent(entity, new Section("12.2.12.b")); 2340 status = false; 2341 } 2342 2343 if (entity.getPrimKeyField() == null || 2345 entity.getPrimKeyField().length() == 0) 2346 { 2347 if (!cls.getName().equals("java.lang.Object")) 2352 { 2353 Object one, two; 2354 2355 try 2356 { 2357 one = cls.newInstance(); 2358 two = cls.newInstance(); 2359 try 2360 { 2361 if (!one.equals(two)) 2362 { 2363 if (cmp) 2364 { 2365 log.warn("Default instances of primary key: " + cls 2367 + " do not equate, check your equals method"); 2368 } 2369 else 2370 { 2371 log.warn("Default instances of primary key: " + cls 2373 + " do not equate, check your equals method"); 2374 } 2375 status = true; 2376 } 2377 } 2378 catch (NullPointerException e) 2379 { 2380 } 2383 2384 try 2385 { 2386 if (one.hashCode() != two.hashCode()) 2387 { 2388 if (cmp) 2389 { 2390 log.warn("Default instances of primary key: " + cls 2392 + " do not have the same hash, check your hashCode method"); 2393 } 2394 else 2395 { 2396 log.warn("Default instances of primary key: " + cls 2398 + " do not have the same hash, check your hashCode method"); 2399 } 2400 status = true; 2401 } 2402 } 2403 catch (NullPointerException e) 2404 { 2405 } 2407 } 2408 catch (IllegalAccessException e) 2409 { 2410 if (cmp) 2414 { 2415 fireSpecViolationEvent(entity, new Section("10.8.2.a")); 2416 status = false; 2417 } 2418 } 2419 catch (InstantiationException e) 2420 { 2421 } 2425 } 2426 } 2427 else 2428 { 2429 if (entity.isBMP()) 2433 { 2434 fireSpecViolationEvent(entity, new Section("dd.a")); 2435 status = false; 2436 } 2437 2438 boolean found = false; 2444 Iterator it = entity.getCMPFields(); 2445 while (it.hasNext()) 2446 { 2447 String fieldName = (String )it.next(); 2448 if (fieldName.equals(entity.getPrimKeyField())) 2449 { 2450 found = true; 2451 break; 2452 } 2453 } 2454 2455 if (!found) 2456 { 2457 status = false; 2458 fireSpecViolationEvent(entity, new Section("10.8.1.b")); 2459 } 2460 2461 try 2462 { 2463 String pkField = entity.getPrimKeyField(); 2471 String methodName = "get" + 2472 pkField.substring(0, 1).toUpperCase() + pkField.substring(1); 2473 2474 Method method = bean.getMethod(methodName, new Class [0]); 2475 if (!entity.getPrimaryKeyClass().equals(method.getReturnType().getName()) 2476 ) 2477 { 2478 status = false; 2479 fireSpecViolationEvent(entity, new Section("10.8.1.a")); 2480 } 2481 2482 } 2483 catch (NoSuchMethodException e) 2484 { 2485 status = false; 2491 fireSpecViolationEvent(entity, new Section("10.8.1.b")); 2492 } 2493 } 2494 2495 return status; 2496 } 2497 2498 2501 protected boolean verifyMessageDrivenBean(MessageDrivenMetaData mdBean) 2502 { 2503 boolean status = true; 2504 2505 if (!hasMessageDrivenBeanInterface(bean)) 2511 { 2512 fireSpecViolationEvent(mdBean, new Section("15.7.2.a")); 2513 status = false; 2514 } 2515 2516 if (!isAssignableFrom(mdBean.getMessagingType(), bean)) 2522 { 2523 fireSpecViolationEvent(mdBean, new Section("15.7.2.b")); 2524 status = false; 2525 } 2526 2527 if (!isPublic(bean)) 2532 { 2533 fireSpecViolationEvent(mdBean, new Section("15.7.2.c1")); 2534 status = false; 2535 } 2536 2537 if (isFinal(bean)) 2542 { 2543 fireSpecViolationEvent(mdBean, new Section("15.7.2.c2")); 2544 status = false; 2545 } 2546 2547 if (isAbstract(bean)) 2552 { 2553 fireSpecViolationEvent(mdBean, new Section("15.7.2.c3")); 2554 status = false; 2555 } 2556 2557 if (!hasDefaultConstructor(bean)) 2563 { 2564 fireSpecViolationEvent(mdBean, new Section("15.7.2.d")); 2565 status = false; 2566 } 2567 2568 if (hasFinalizer(bean)) 2573 { 2574 fireSpecViolationEvent(mdBean, new Section("15.7.2.e")); 2575 status = false; 2576 } 2577 2578 if (hasEJBCreateMethod(bean, false)) 2591 { 2592 Iterator it = getEJBCreateMethods(bean); 2593 Method ejbCreate = (Method )it.next(); 2594 2595 if (!isPublic(ejbCreate)) 2596 { 2597 fireSpecViolationEvent(mdBean, ejbCreate, new Section("15.7.3.b")); 2598 status = false; 2599 } 2600 2601 if ((isFinal(ejbCreate)) || (isStatic(ejbCreate))) 2602 { 2603 fireSpecViolationEvent(mdBean, ejbCreate, new Section("15.7.3.c")); 2604 status = false; 2605 } 2606 2607 if (!hasVoidReturnType(ejbCreate)) 2608 { 2609 fireSpecViolationEvent(mdBean, ejbCreate, new Section("15.7.3.d")); 2610 status = false; 2611 } 2612 2613 if (!hasNoArguments(ejbCreate)) 2614 { 2615 fireSpecViolationEvent(mdBean, ejbCreate, new Section("15.7.3.e")); 2616 status = false; 2617 } 2618 2619 if (!throwsNoException(ejbCreate)) 2620 { 2621 fireSpecViolationEvent(mdBean, ejbCreate, new Section("15.7.3.f")); 2622 status = false; 2623 } 2624 2625 if (it.hasNext()) 2626 { 2627 fireSpecViolationEvent(mdBean, new Section("15.7.3.a")); 2628 status = false; 2629 } 2630 } 2631 else 2632 { 2633 fireSpecViolationEvent(mdBean, new Section("15.7.3.a")); 2634 status = false; 2635 } 2636 2637 2646 Class messageListener = null; 2647 try 2648 { 2649 messageListener = classloader.loadClass(mdBean.getMessagingType()); 2650 } 2651 catch (ClassNotFoundException cnfe) 2652 { 2653 fireSpecViolationEvent(mdBean, 2654 new Section("15.7.2.b", 2655 "Class not found on '" + mdBean.getMessagingType() + "': " + cnfe.getMessage())); 2656 status = false; 2657 2658 } 2659 2660 if (messageListener != null) 2661 { 2662 Method [] methods = bean.getMethods(); 2663 for (int i = 0; i < methods.length; ++i) 2664 { 2665 if (methods[i].getDeclaringClass().equals(messageListener)) 2666 { 2667 if (!isPublic(methods[i])) 2668 { 2669 fireSpecViolationEvent(mdBean, methods[i], new Section("15.7.4.b")); 2670 status = false; 2671 } 2672 2673 if ((isFinal(methods[i])) || (isStatic(methods[i]))) 2674 { 2675 fireSpecViolationEvent(mdBean, methods[i], new Section("15.7.4.c")); 2676 status = false; 2677 } 2678 } 2679 } 2680 } 2681 2682 if (hasEJBRemoveMethod(bean)) 2695 { 2696 Iterator it = getEJBRemoveMethods(bean); 2697 Method ejbRemove = (Method )it.next(); 2698 2699 if (!isPublic(ejbRemove)) 2700 { 2701 fireSpecViolationEvent(mdBean, ejbRemove, new Section("15.7.5.b")); 2702 status = false; 2703 } 2704 2705 if ((isFinal(ejbRemove)) || (isStatic(ejbRemove))) 2706 { 2707 fireSpecViolationEvent(mdBean, ejbRemove, new Section("15.7.5.c")); 2708 status = false; 2709 } 2710 2711 if (!hasVoidReturnType(ejbRemove)) 2712 { 2713 fireSpecViolationEvent(mdBean, ejbRemove, new Section("15.7.5.d")); 2714 status = false; 2715 } 2716 2717 if (!hasNoArguments(ejbRemove)) 2718 { 2719 fireSpecViolationEvent(mdBean, ejbRemove, new Section("15.7.5.e")); 2720 status = false; 2721 } 2722 2723 if (!throwsNoException(ejbRemove)) 2724 { 2725 fireSpecViolationEvent(mdBean, ejbRemove, new Section("15.7.5.f")); 2726 status = false; 2727 } 2728 2729 if (it.hasNext()) 2730 { 2731 fireSpecViolationEvent(mdBean, new Section("15.7.5.a")); 2732 status = false; 2733 } 2734 } 2735 else 2736 { 2737 fireSpecViolationEvent(mdBean, new Section("15.7.5.a")); 2738 status = false; 2739 } 2740 2741 return status; 2742 } 2743 2744 2749 protected boolean verifyServiceEndpoint(SessionMetaData session) 2750 { 2751 boolean status = true; 2752 2753 if (!hasRemoteInterface(serviceEndpointInterface)) 2759 { 2760 fireSpecViolationEvent(session, new Section("7.11.9.a")); 2761 status = false; 2762 } 2763 2764 Iterator it = Arrays.asList(serviceEndpointInterface.getMethods()).iterator(); 2776 while (it.hasNext()) 2777 { 2778 Method method = (Method )it.next(); 2779 2780 if (!hasLegalJAXRPCArguments(method)) 2781 { 2782 fireSpecViolationEvent(session, method, new Section("7.11.9.b1")); 2783 status = false; 2784 } 2785 2786 if (!hasLegalJAXRPCReturnType(method)) 2787 { 2788 fireSpecViolationEvent(session, method, new Section("7.11.9.b2")); 2789 status = false; 2790 } 2791 2792 if (!throwsRemoteException(method)) 2793 { 2794 fireSpecViolationEvent(session, method, new Section("7.11.9.b3")); 2795 status = false; 2796 } 2797 } 2798 2799 it = Arrays.asList(serviceEndpointInterface.getDeclaredMethods()).iterator(); 2813 while (it.hasNext()) 2814 { 2815 Method seiMethod = (Method )it.next(); 2816 2817 if (!hasMatchingMethod(bean, seiMethod)) 2818 { 2819 fireSpecViolationEvent(session, seiMethod, new Section("7.11.9.c")); 2820 status = false; 2821 } 2822 else 2823 { 2824 try 2825 { 2826 Method beanMethod = bean.getMethod(seiMethod.getName(), seiMethod.getParameterTypes()); 2827 if (!hasMatchingReturnType(seiMethod, beanMethod)) 2828 { 2829 fireSpecViolationEvent(session, seiMethod, new Section("7.11.9.c1")); 2830 status = false; 2831 } 2832 2833 if (!hasMatchingExceptions(beanMethod, seiMethod)) 2834 { 2835 fireSpecViolationEvent(session, seiMethod, new Section("7.11.59.c2")); 2836 status = false; 2837 } 2838 } 2839 catch (NoSuchMethodException ignored) 2840 { 2841 } 2842 } 2843 } 2844 2845 return status; 2846 } 2847 2848 2852 protected boolean hasLegalJAXRPCReturnType(Method method) 2853 { 2854 return isJAXRPCType(method.getReturnType()); 2855 } 2856 2857 2861 protected boolean isJAXRPCType(Class class1) 2862 { 2863 return isRMIIDLValueType(class1); 2865 } 2866 2867 2871 protected boolean hasLegalJAXRPCArguments(Method method) 2872 { 2873 Class [] params = method.getParameterTypes(); 2874 2875 for (int i = 0; i < params.length; ++i) 2876 { 2877 if (!isJAXRPCType(params[i])) 2878 return false; 2879 } 2880 2881 return true; 2882 } 2883 2884 2890 protected boolean hasServiceEndpointInterfaces(SessionMetaData bean) 2891 { 2892 boolean status = true; 2893 String seiName = bean.getServiceEndpoint(); 2894 2895 if (seiName == null) 2896 return false; 2897 2898 try 2900 { 2901 serviceEndpointInterface = classloader.loadClass(seiName); 2902 } 2903 catch (ClassNotFoundException cnfe) 2904 { 2905 fireSpecViolationEvent(bean, 2906 new Section("23.2", "Class not found on '" + seiName + "': " + cnfe.getMessage())); 2907 status = false; 2908 } 2909 2910 return status; 2911 } 2912 2913} 2914 | Popular Tags |