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 } 879 880 if (!(hasRemoteReturnType(entity, finder) 881 || isMultiObjectFinder(finder))) 882 { 883 fireSpecViolationEvent(entity, finder, new Section("9.2.8.k")); 884 status = false; 885 } 886 887 if ((entity.isBMP()) && (hasMatchingEJBFind(bean, finder))) 888 { 889 Method ejbFind = getMatchingEJBFind(bean, finder); 890 if (!(hasMatchingExceptions(ejbFind, finder))) 891 { 892 fireSpecViolationEvent(entity, finder, new Section("9.2.8.l")); 893 status = false; 894 } 895 } 896 897 if (!throwsFinderException(finder)) 898 { 899 fireSpecViolationEvent(entity, finder, new Section("9.2.8.m")); 900 status = false; 901 } 902 } 903 } 904 catch (ClassNotFoundException ignored) 905 { 906 } 907 } 908 catch (ClassNotFoundException e) 909 { 910 916 fireSpecViolationEvent(entity, new Section("16.2.c")); 917 status = false; 918 } 919 920 return status; 921 } 922 923 924 931 932 private boolean verifyEntityRemote(EntityMetaData entity) 933 { 934 boolean status = true; 935 936 String name = entity.getRemote(); 937 if (name == null) 938 return false; 939 940 try 941 { 942 Class remote = classloader.loadClass(name); 943 944 950 if (!hasEJBObjectInterface(remote)) 951 { 952 fireSpecViolationEvent(entity, new Section("9.2.7.a")); 953 status = false; 954 } 955 956 968 Iterator remoteMethods = Arrays.asList(remote.getMethods()).iterator(); 969 while (remoteMethods.hasNext()) 970 { 971 Method method = (Method )remoteMethods.next(); 972 973 if (!hasLegalRMIIIOPArguments(method)) 974 { 975 fireSpecViolationEvent(entity, method, new Section("9.2.7.b")); 976 status = false; 977 } 978 979 if (!hasLegalRMIIIOPReturnType(method)) 980 { 981 fireSpecViolationEvent(entity, method, new Section("9.2.7.c")); 982 status = false; 983 } 984 985 if (!hasLegalRMIIIOPExceptionTypes(method)) 986 { 987 fireSpecViolationEvent(entity, method, new Section("9.2.7.h")); 988 status = false; 989 } 990 991 if (!throwsRemoteException(method)) 992 { 993 fireSpecViolationEvent(entity, method, new Section("9.2.7.d")); 994 status = false; 995 } 996 } 998 1013 1014 try 1015 { 1016 String beanClass = entity.getEjbClass(); 1017 Class bean = classloader.loadClass(beanClass); 1018 1019 remoteMethods = Arrays.asList(remote.getMethods()).iterator(); 1020 while (remoteMethods.hasNext()) 1021 { 1022 Method method = (Method )remoteMethods.next(); 1023 1024 if (method.getDeclaringClass().getName().equals(EJB_OBJECT_INTERFACE)) 1026 continue; 1027 1028 if (!hasMatchingMethod(bean, method)) 1029 { 1030 fireSpecViolationEvent(entity, method, new Section("9.2.7.e")); 1031 status = false; 1032 } 1033 1034 if (hasMatchingMethod(bean, method)) 1035 { 1036 try 1037 { 1038 Method beanMethod = bean.getMethod(method.getName(), method.getParameterTypes()); 1039 1040 if (!hasMatchingReturnType(beanMethod, method)) 1041 { 1042 fireSpecViolationEvent(entity, method, new Section("9.2.7.f")); 1043 status = false; 1044 } 1045 1046 if (!hasMatchingExceptions(beanMethod, method)) 1047 { 1048 fireSpecViolationEvent(entity, method, new Section("9.2.7.g")); 1049 status = false; 1050 } 1051 } 1052 catch (NoSuchMethodException ignored) 1053 { 1054 } 1055 } 1056 } 1057 } 1058 catch (ClassNotFoundException ignored) 1059 { 1060 } 1061 } 1062 catch (ClassNotFoundException e) 1063 { 1064 1070 fireSpecViolationEvent(entity, new Section("16.2.d")); 1071 status = false; 1072 } 1073 1074 return status; 1075 } 1076 1077 1084 1085 private boolean verifyEntityBean(EntityMetaData entity) 1086 { 1087 boolean status = true; 1088 1089 String name = entity.getEjbClass(); 1090 1091 try 1092 { 1093 Class bean = classloader.loadClass(name); 1094 1095 1101 if (!hasEntityBeanInterface(bean)) 1102 { 1103 fireSpecViolationEvent(entity, new Section("9.2.2.a")); 1104 status = false; 1105 } 1106 1107 1112 if (!isPublic(bean)) 1113 { 1114 fireSpecViolationEvent(entity, new Section("9.2.2.b")); 1115 status = false; 1116 } 1117 1118 1123 if (isAbstract(bean)) 1124 { 1125 fireSpecViolationEvent(entity, new Section("9.2.2.c")); 1126 status = false; 1127 } 1128 1129 1134 if (isFinal(bean)) 1135 { 1136 fireSpecViolationEvent(entity, new Section("9.2.2.d")); 1137 status = false; 1138 } 1139 1140 1146 if (!hasDefaultConstructor(bean)) 1147 { 1148 fireSpecViolationEvent(entity, new Section("9.2.2.e")); 1149 status = false; 1150 } 1151 1152 1157 if (hasFinalizer(bean)) 1158 { 1159 fireSpecViolationEvent(entity, new Section("9.2.2.f")); 1160 status = false; 1161 } 1162 1163 1174 if (hasEJBCreateMethod(bean, false)) 1175 { 1176 Iterator it = getEJBCreateMethods(bean); 1177 while (it.hasNext()) 1178 { 1179 Method ejbCreate = (Method )it.next(); 1180 1181 if (!isPublic(ejbCreate)) 1182 { 1183 fireSpecViolationEvent(entity, ejbCreate, new Section("9.2.3.a")); 1184 status = false; 1185 } 1186 1187 if ((isFinal(ejbCreate)) || (isStatic(ejbCreate))) 1188 { 1189 fireSpecViolationEvent(entity, ejbCreate, new Section("9.2.3.b")); 1190 status = false; 1191 } 1192 1193 if (!hasPrimaryKeyReturnType(entity, ejbCreate)) 1194 { 1195 fireSpecViolationEvent(entity, ejbCreate, new Section("9.2.3.c")); 1196 status = false; 1197 } 1198 1199 if (!hasLegalRMIIIOPArguments(ejbCreate)) 1200 { 1201 fireSpecViolationEvent(entity, ejbCreate, new Section("9.2.3.d")); 1202 status = false; 1203 } 1204 1205 if (!hasLegalRMIIIOPReturnType(ejbCreate)) 1206 { 1207 fireSpecViolationEvent(entity, ejbCreate, new Section("9.2.3.e")); 1208 status = false; 1209 } 1210 } 1211 } 1212 1213 1227 if (hasEJBCreateMethod(bean, false)) 1228 { 1229 Iterator it = getEJBCreateMethods(bean); 1230 while (it.hasNext()) 1231 { 1232 Method ejbCreate = (Method )it.next(); 1233 1234 if (!hasMatchingEJBPostCreate(bean, ejbCreate)) 1235 { 1236 fireSpecViolationEvent(entity, ejbCreate, new Section("9.2.4.a")); 1237 status = false; 1238 } 1239 1240 if (hasMatchingEJBPostCreate(bean, ejbCreate)) 1241 { 1242 Method ejbPostCreate = getMatchingEJBPostCreate(bean, ejbCreate); 1243 1244 if (!isPublic(ejbPostCreate)) 1245 { 1246 fireSpecViolationEvent(entity, ejbPostCreate, new Section("9.2.4.b")); 1247 status = false; 1248 } 1249 1250 if (isStatic(ejbPostCreate)) 1251 { 1252 fireSpecViolationEvent(entity, ejbPostCreate, new Section("9.2.4.c")); 1253 status = false; 1254 } 1255 1256 if (isFinal(ejbPostCreate)) 1257 { 1258 fireSpecViolationEvent(entity, ejbPostCreate, new Section("9.2.4.d")); 1259 status = false; 1260 } 1261 1262 if (!hasVoidReturnType(ejbPostCreate)) 1263 { 1264 fireSpecViolationEvent(entity, ejbPostCreate, new Section("9.2.4.e")); 1265 status = false; 1266 } 1267 } 1268 } 1269 } 1270 1271 1281 if (entity.isBMP() && (!hasEJBFindByPrimaryKey(bean))) 1282 { 1283 fireSpecViolationEvent(entity, new Section("9.2.5.a")); 1284 status = false; 1285 } 1286 1287 if (hasEJBFindByPrimaryKey(bean)) 1288 { 1289 Method ejbFindByPrimaryKey = getEJBFindByPrimaryKey(bean); 1290 1291 if (!hasPrimaryKeyReturnType(entity, ejbFindByPrimaryKey)) 1292 { 1293 fireSpecViolationEvent(entity, ejbFindByPrimaryKey, new Section("9.2.5.b")); 1294 status = false; 1295 } 1296 1297 if (!isSingleObjectFinder(entity, ejbFindByPrimaryKey)) 1298 { 1299 fireSpecViolationEvent(entity, ejbFindByPrimaryKey, new Section("9.2.5.c")); 1300 status = false; 1301 } 1302 } 1303 1304 1320 if (hasFinderMethod(bean)) 1321 { 1322 Iterator it = getEJBFindMethods(bean); 1323 while (it.hasNext()) 1324 { 1325 Method finder = (Method )it.next(); 1326 1327 if (!isPublic(finder)) 1328 { 1329 fireSpecViolationEvent(entity, finder, new Section("9.2.5.d")); 1330 status = false; 1331 } 1332 1333 if (isFinal(finder)) 1334 { 1335 fireSpecViolationEvent(entity, finder, new Section("9.2.5.e")); 1336 status = false; 1337 } 1338 1339 if (isStatic(finder)) 1340 { 1341 fireSpecViolationEvent(entity, finder, new Section("9.2.5.f")); 1342 status = false; 1343 } 1344 1345 if (!hasLegalRMIIIOPArguments(finder)) 1346 { 1347 fireSpecViolationEvent(entity, finder, new Section("9.2.5.g")); 1348 status = false; 1349 } 1350 1351 if (!(isSingleObjectFinder(entity, finder) 1352 || isMultiObjectFinder(finder))) 1353 { 1354 fireSpecViolationEvent(entity, finder, new Section("9.2.5.h")); 1355 status = false; 1356 } 1357 } 1358 } 1359 } 1360 catch (ClassNotFoundException e) 1361 { 1362 1369 fireSpecViolationEvent(entity, new Section("16.2.b")); 1370 status = false; 1371 } 1372 1373 return status; 1374 } 1375 1376 private boolean verifyPrimaryKey(EntityMetaData entity) 1377 { 1378 boolean status = true; 1379 1380 if (entity.getPrimaryKeyClass() == null 1381 || entity.getPrimaryKeyClass().length() == 0) 1382 { 1383 fireSpecViolationEvent(entity, new Section("16.5.a")); 1384 return false; } 1386 1387 if (entity.getPrimKeyField() == null 1388 || entity.getPrimKeyField().length() == 0) 1389 { 1390 Class cls = null; 1391 1392 try 1393 { 1394 cls = classloader.loadClass(entity.getPrimaryKeyClass()); 1395 1396 if (entity.isCMP()) 1397 { 1398 if (!isPublic(cls)) 1399 { 1400 fireSpecViolationEvent(entity, new Section("9.4.7.2.a")); 1401 status = false; 1402 } 1403 1404 if (!isAllFieldsPublic(cls)) 1405 { 1406 fireSpecViolationEvent(entity, new Section("9.4.7.2.b")); 1407 status = false; 1408 } 1409 1410 if (!hasANonStaticField(cls)) 1411 { 1412 fireSpecViolationEvent(entity, new Section("9.4.7.2.c")); 1413 status = false; 1414 } 1415 } 1416 1417 if (!cls.getName().equals("java.lang.Object")) 1418 { 1419 Object one, two; 1420 try 1421 { 1422 one = cls.newInstance(); 1423 two = cls.newInstance(); 1424 try 1425 { 1426 if (!one.equals(two)) 1427 { 1428 fireSpecViolationEvent(entity, new Section("9.2.9.b")); 1429 status = false; 1430 } 1431 } 1432 catch (NullPointerException e) 1433 { 1434 } try 1436 { 1437 if (one.hashCode() != two.hashCode()) 1438 { 1439 fireSpecViolationEvent(entity, new Section("9.2.9.c")); 1440 status = false; 1441 } 1442 } 1443 catch (NullPointerException e) 1444 { 1445 } } 1447 catch (IllegalAccessException e) 1448 { 1449 } 1457 catch (InstantiationException e) 1458 { 1459 } 1462 } 1463 } 1464 catch (ClassNotFoundException e) 1465 { 1466 fireSpecViolationEvent(entity, new Section("16.2.e")); 1467 status = false; } 1469 } 1470 else 1471 { 1472 if (entity.isBMP()) 1473 { 1474 fireSpecViolationEvent(entity, new Section("9.4.7.1.a")); 1475 status = false; 1476 } 1477 1478 try 1479 { 1480 Class fieldClass = classloader.loadClass(entity.getEjbClass()); 1481 Field field = null; 1482 try 1483 { 1484 field = fieldClass.getField(entity.getPrimKeyField()); 1485 if (!entity.getPrimaryKeyClass().equals(field.getType().getName())) 1486 { 1487 fireSpecViolationEvent(entity, new Section("9.4.7.1.c")); 1488 status = false; 1489 } 1490 1491 Iterator it = entity.getCMPFields(); 1492 boolean found = false; 1493 while (it.hasNext()) 1494 { 1495 String fieldName = (String )it.next(); 1496 if (fieldName.equals(entity.getPrimKeyField())) 1497 { 1498 found = true; 1499 break; 1500 } 1501 } 1502 1503 if (!found) 1504 { 1505 fireSpecViolationEvent(entity, new Section("9.4.7.1.d")); 1506 status = false; 1507 } 1508 } 1509 catch (NoSuchFieldException e) 1510 { 1511 fireSpecViolationEvent(entity, new Section("9.4.7.1.b")); 1512 status = false; 1513 } 1514 } 1515 catch (ClassNotFoundException e) 1516 { 1517 } } 1519 1520 return status; 1521 } 1522 1523} 1524 1525 1528 | Popular Tags |