1 25 26 package org.objectweb.easybeans.deployment.annotations.metadata; 27 28 import static javax.ejb.TransactionAttributeType.REQUIRED ; 29 import static javax.ejb.TransactionManagementType.CONTAINER ; 30 31 import java.util.ArrayList ; 32 import java.util.Collection ; 33 import java.util.HashMap ; 34 import java.util.LinkedList ; 35 import java.util.List ; 36 import java.util.Map ; 37 38 import javax.ejb.ApplicationException ; 39 import javax.ejb.TransactionAttributeType ; 40 import javax.ejb.TransactionManagementType ; 41 42 import org.objectweb.easybeans.deployment.annotations.ClassType; 43 import org.objectweb.easybeans.deployment.annotations.InterceptorType; 44 import org.objectweb.easybeans.deployment.annotations.JClassInterceptor; 45 import org.objectweb.easybeans.deployment.annotations.JField; 46 import org.objectweb.easybeans.deployment.annotations.JMethod; 47 import org.objectweb.easybeans.deployment.annotations.exceptions.InterceptorsValidationException; 48 import org.objectweb.easybeans.deployment.annotations.impl.JAnnotationResource; 49 import org.objectweb.easybeans.deployment.annotations.impl.JCommonBean; 50 import org.objectweb.easybeans.deployment.annotations.impl.JEjbEJB; 51 import org.objectweb.easybeans.deployment.annotations.impl.JInterceptors; 52 import org.objectweb.easybeans.deployment.annotations.impl.JLocal; 53 import org.objectweb.easybeans.deployment.annotations.impl.JMessageDriven; 54 import org.objectweb.easybeans.deployment.annotations.impl.JRemote; 55 import org.objectweb.easybeans.deployment.annotations.impl.JStateful; 56 import org.objectweb.easybeans.deployment.annotations.impl.JStateless; 57 import org.objectweb.easybeans.deployment.annotations.impl.JavaxPersistenceContext; 58 import org.objectweb.easybeans.deployment.annotations.impl.JavaxPersistenceUnit; 59 import org.objectweb.easybeans.deployment.annotations.metadata.interfaces.IAnnotationSecurityPermitAll; 60 import org.objectweb.easybeans.deployment.annotations.metadata.interfaces.IAnnotationSecurityRolesAllowed; 61 import org.objectweb.easybeans.deployment.annotations.metadata.interfaces.IEJBInterceptors; 62 import org.objectweb.easybeans.deployment.annotations.metadata.interfaces.ITransactionAttribute; 63 import org.objectweb.easybeans.log.JLog; 64 import org.objectweb.easybeans.log.JLogFactory; 65 66 67 72 public class ClassAnnotationMetadata extends CommonAnnotationMetadata implements ITransactionAttribute, IEJBInterceptors, 73 IAnnotationSecurityRolesAllowed, IAnnotationSecurityPermitAll { 74 75 78 private static JLog logger = JLogFactory.getLog(ClassAnnotationMetadata.class); 79 80 83 private Map <JMethod, MethodAnnotationMetadata> methodsAnnotationMetadata = null; 84 85 88 private Map <JField, FieldAnnotationMetadata> fieldsAnnotationMetadata = null; 89 90 93 private EjbJarAnnotationMetadata ejbJarAnnotationMetadata = null; 94 95 98 private JLocal jLocal = null; 99 100 103 private JRemote jRemote = null; 104 105 108 private JCommonBean jCommonBean = null; 109 110 113 private JMessageDriven jMessageDriven = null; 114 115 118 private JStateless jStateless = null; 119 120 123 private JStateful jStateful = null; 124 125 126 129 private String localHome = null; 130 131 134 private String remoteHome = null; 135 136 139 private JInterceptors annotationInterceptors = null; 140 141 146 private List <JClassInterceptor> globalEasyBeansInterceptors = null; 147 148 153 private Map <InterceptorType, List <JClassInterceptor>> externalUserInterceptors = null; 154 155 160 private Map <InterceptorType, List <JClassInterceptor>> internalUserInterceptors = null; 161 162 163 166 private TransactionManagementType transactionManagementType = CONTAINER; 167 168 171 private TransactionAttributeType transactionAttributeType = REQUIRED; 172 173 176 private ApplicationException applicationException = null; 177 178 181 private String superName = null; 182 183 186 private String [] interfaces = null; 187 188 192 private ClassType classType = null; 193 194 197 private String className = null; 198 199 203 private List <MethodAnnotationMetadata> aroundInvokeMethodsMetadata = null; 204 205 208 private List <JEjbEJB> jEjbEJBs = null; 209 210 213 private List <JAnnotationResource> jAnnotationResources = null; 214 215 218 private List <JavaxPersistenceContext> javaxPersistencePersistenceContexts = null; 219 220 223 private List <JavaxPersistenceUnit> javaxPersistencePersistenceUnits = null; 224 225 229 private LinkedList <MethodAnnotationMetadata> postConstructMethodsMetadata = null; 230 231 235 private LinkedList <MethodAnnotationMetadata> preDestroyMethodsMetadata = null; 236 237 241 private LinkedList <MethodAnnotationMetadata> postActivateMethodsMetadata = null; 242 243 247 private LinkedList <MethodAnnotationMetadata> prePassivateMethodsMetadata = null; 248 249 252 private boolean modified = false; 253 254 257 private List <String > declareRoles = null; 258 259 262 private List <String > rolesAllowed = null; 263 264 267 private boolean permitAll = false; 268 269 272 private String runAs = null; 273 274 279 public ClassAnnotationMetadata(final String className, final EjbJarAnnotationMetadata ejbJarAnnotationMetadata) { 280 this.className = className; 281 this.methodsAnnotationMetadata = new HashMap <JMethod, MethodAnnotationMetadata>(); 282 this.fieldsAnnotationMetadata = new HashMap <JField, FieldAnnotationMetadata>(); 283 this.ejbJarAnnotationMetadata = ejbJarAnnotationMetadata; 284 this.postConstructMethodsMetadata = new LinkedList <MethodAnnotationMetadata>(); 285 this.preDestroyMethodsMetadata = new LinkedList <MethodAnnotationMetadata>(); 286 this.postActivateMethodsMetadata = new LinkedList <MethodAnnotationMetadata>(); 287 this.prePassivateMethodsMetadata = new LinkedList <MethodAnnotationMetadata>(); 288 } 289 290 293 public String getClassName() { 294 return className; 295 } 296 297 301 public void addMethodAnnotationMetadata(final MethodAnnotationMetadata methodAnnotationMetadata) { 302 JMethod key = methodAnnotationMetadata.getJMethod(); 303 if (methodsAnnotationMetadata.containsKey(key)) { 305 String msg = logger.getI18n().getMessage("BeanAnnotationMetadata.addMethodAnnotationMetadata.alreadyPresent", key); 306 logger.debug(msg); 307 throw new IllegalStateException (msg); 308 } 309 methodsAnnotationMetadata.put(key, methodAnnotationMetadata); 310 } 311 312 316 public MethodAnnotationMetadata getMethodAnnotationMetadata(final JMethod jMethod) { 317 return methodsAnnotationMetadata.get(jMethod); 318 } 319 320 324 public Collection <MethodAnnotationMetadata> getMethodAnnotationMetadataCollection() { 325 return methodsAnnotationMetadata.values(); 326 } 327 328 329 333 public void addFieldAnnotationMetadata(final FieldAnnotationMetadata fieldAnnotationMetadata) { 334 JField key = fieldAnnotationMetadata.getJField(); 335 if (fieldsAnnotationMetadata.containsKey(key)) { 337 String msg = logger.getI18n().getMessage("BeanAnnotationMetadata.addFieldAnnotationMetadata.alreadyPresent", key); 338 logger.debug(msg); 339 throw new IllegalStateException (msg); 340 } 341 fieldsAnnotationMetadata.put(key, fieldAnnotationMetadata); 342 } 343 344 348 public FieldAnnotationMetadata getFieldAnnotationMetadata(final JField jField) { 349 return fieldsAnnotationMetadata.get(jField); 350 } 351 352 356 public Collection <FieldAnnotationMetadata> getFieldAnnotationMetadataCollection() { 357 return fieldsAnnotationMetadata.values(); 358 } 359 360 361 365 public void setLocalInterfaces(final JLocal jLocal) { 366 this.jLocal = jLocal; 367 } 368 369 373 public void setRemoteInterfaces(final JRemote jRemote) { 374 this.jRemote = jRemote; 375 } 376 377 378 381 public JLocal getLocalInterfaces() { 382 return jLocal; 383 } 384 385 388 public JRemote getRemoteInterfaces() { 389 return jRemote; 390 } 391 392 395 public boolean isStateless() { 396 return (classType != null && classType == ClassType.STATELESS); 397 } 398 399 402 public boolean isStateful() { 403 return (classType != null && classType == ClassType.STATEFUL); 404 } 405 406 409 public boolean isSession() { 410 return (classType != null && (classType == ClassType.STATELESS || classType == ClassType.STATEFUL)); 411 } 412 413 416 public boolean isMdb() { 417 return (classType != null && classType == ClassType.MDB); 418 } 419 420 425 public void setClassType(final ClassType cType) { 426 this.classType = cType; 427 } 428 429 432 public JMessageDriven getJMessageDriven() { 433 return jMessageDriven; 434 } 435 436 440 public void setJMessageDriven(final JMessageDriven messageDriven) { 441 jMessageDriven = messageDriven; 442 } 443 444 445 448 @Override 449 public String toString() { 450 StringBuilder sb = new StringBuilder (); 451 sb.append(this.getClass().getName().substring(this.getClass().getPackage().getName().length() + 1)); 453 sb.append("[\n"); 454 455 sb.append(super.toString()); 457 458 concatStringBuilder("className", className, sb); 460 461 concatStringBuilder("superName", superName, sb); 463 464 concatStringBuilder("interfaces", interfaces, sb); 466 467 concatStringBuilder("classType", classType, sb); 469 470 concatStringBuilder("jLocal", jLocal, sb); 472 473 concatStringBuilder("aroundInvokeMethodsMetadata", aroundInvokeMethodsMetadata, sb); 475 476 concatStringBuilder("jRemote", jRemote, sb); 478 479 concatStringBuilder("jMessageDriven", jMessageDriven, sb); 481 482 concatStringBuilder("remoteHome", remoteHome, sb); 484 485 concatStringBuilder("localHome", localHome, sb); 487 488 concatStringBuilder("transactionManagementType", transactionManagementType, sb); 490 491 concatStringBuilder("transactionAttributeType", transactionAttributeType, sb); 493 494 concatStringBuilder("annotationInterceptors", annotationInterceptors, sb); 496 497 concatStringBuilder("jAnnotationEJBs", jEjbEJBs, sb); 499 500 concatStringBuilder("jAnnotationResources", jAnnotationResources, sb); 502 503 concatStringBuilder("javaxPersistencePersistenceContexts", javaxPersistencePersistenceContexts, sb); 505 506 concatStringBuilder("javaxPersistencePersistenceUnits", javaxPersistencePersistenceUnits, sb); 508 509 510 for (MethodAnnotationMetadata methodAnnotationMetadata : getMethodAnnotationMetadataCollection()) { 512 concatStringBuilder("methods", methodAnnotationMetadata, sb); 513 } 514 515 concatStringBuilder("modified", Boolean.valueOf(modified), sb); 517 518 concatStringBuilder("declareRoles", declareRoles, sb); 520 521 concatStringBuilder("rolesAllowed", rolesAllowed, sb); 523 524 concatStringBuilder("permitAll", Boolean.valueOf(permitAll), sb); 526 527 concatStringBuilder("runAs", runAs, sb); 529 530 sb.append("]"); 531 return sb.toString(); 532 } 533 534 537 public String getRemoteHome() { 538 return remoteHome; 539 } 540 541 545 public void setRemoteHome(final String remoteHome) { 546 this.remoteHome = remoteHome; 547 } 548 549 552 public String getLocalHome() { 553 return localHome; 554 } 555 556 560 public void setLocalHome(final String localHome) { 561 this.localHome = localHome; 562 } 563 564 567 public TransactionManagementType getTransactionManagementType() { 568 return transactionManagementType; 569 } 570 571 577 public void setTransactionManagementType(final TransactionManagementType transactionManagementType) { 578 this.transactionManagementType = transactionManagementType; 579 } 580 581 585 public TransactionAttributeType getTransactionAttributeType() { 586 return transactionAttributeType; 587 } 588 589 594 public void setTransactionAttributeType(final TransactionAttributeType transactionAttributeType) { 595 this.transactionAttributeType = transactionAttributeType; 596 } 597 598 601 public JInterceptors getAnnotationInterceptors() { 602 return annotationInterceptors; 603 } 604 605 609 public void setAnnotationsInterceptors(final JInterceptors annotationInterceptors) { 610 this.annotationInterceptors = annotationInterceptors; 611 } 612 613 616 public ApplicationException getApplicationException() { 617 return applicationException; 618 } 619 620 624 public void setApplicationException(final ApplicationException applicationException) { 625 this.applicationException = applicationException; 626 } 627 628 631 public boolean isBean() { 632 return isStateless() || isStateful() || isMdb(); 633 } 634 635 638 public String [] getInterfaces() { 639 return interfaces; 640 } 641 642 646 public void setInterfaces(final String [] interfaces) { 647 this.interfaces = interfaces; 648 } 649 650 653 public String getSuperName() { 654 return superName; 655 } 656 657 661 public void setSuperName(final String superName) { 662 this.superName = superName; 663 } 664 665 668 public EjbJarAnnotationMetadata getEjbJarAnnotationMetadata() { 669 return ejbJarAnnotationMetadata; 670 } 671 672 676 public Map <InterceptorType, List <JClassInterceptor>> getExternalUserEasyBeansInterceptors() { 677 return externalUserInterceptors; 678 } 679 680 685 public void setExternalUserInterceptors(final Map <InterceptorType, List <JClassInterceptor>> externalUserInterceptors) { 686 this.externalUserInterceptors = externalUserInterceptors; 687 } 688 689 690 694 public Map <InterceptorType, List <JClassInterceptor>> getInternalUserEasyBeansInterceptors() { 695 return internalUserInterceptors; 696 } 697 698 703 public void setInternalUserInterceptors(final Map <InterceptorType, List <JClassInterceptor>> internalUserInterceptors) { 704 this.internalUserInterceptors = internalUserInterceptors; 705 } 706 707 710 public List <JClassInterceptor> getGlobalEasyBeansInterceptors() { 711 return globalEasyBeansInterceptors; 712 } 713 714 718 public void setGlobalEasyBeansInterceptors(final List <JClassInterceptor> globalEasyBeansInterceptors) { 719 this.globalEasyBeansInterceptors = globalEasyBeansInterceptors; 720 } 721 722 725 public boolean isAroundInvokeMethodMetadata() { 726 return (aroundInvokeMethodsMetadata != null); 727 } 728 729 730 733 public List <MethodAnnotationMetadata> getAroundInvokeMethodMetadatas() { 734 return aroundInvokeMethodsMetadata; 735 } 736 737 741 public void addAroundInvokeMethodMetadata(final MethodAnnotationMetadata aroundInvokeMethodMetadata) { 742 if (aroundInvokeMethodsMetadata == null) { 743 this.aroundInvokeMethodsMetadata = new ArrayList <MethodAnnotationMetadata>(); 744 } 745 aroundInvokeMethodsMetadata.add(aroundInvokeMethodMetadata); 746 } 747 748 751 public LinkedList <MethodAnnotationMetadata> getPostConstructMethodsMetadata() { 752 return postConstructMethodsMetadata; 753 } 754 755 759 public void addPostConstructMethodMetadata(final MethodAnnotationMetadata postConstructMethodMetadata) { 760 checkLifeCycleDuplicate(postConstructMethodMetadata, InterceptorType.POST_CONSTRUCT, getPostConstructMethodsMetadata()); 761 this.postConstructMethodsMetadata.addFirst(postConstructMethodMetadata); 762 } 763 764 770 private void checkLifeCycleDuplicate(final MethodAnnotationMetadata postConstructMethodMetadata, 771 final InterceptorType itcType, final List <MethodAnnotationMetadata> existingList) { 772 ClassAnnotationMetadata wantToAddClassMetadata = postConstructMethodMetadata.getClassAnnotationMetadata(); 774 if (postConstructMethodMetadata.isInherited()) { 775 wantToAddClassMetadata = postConstructMethodMetadata.getOriginalClassAnnotationMetadata(); 776 } 777 for (MethodAnnotationMetadata method : existingList) { 778 ClassAnnotationMetadata compareMetaData; 779 if (method.isInherited()) { 780 compareMetaData = method.getOriginalClassAnnotationMetadata(); 781 } else { 782 compareMetaData = method.getClassAnnotationMetadata(); 783 } 784 if (compareMetaData.equals(wantToAddClassMetadata)) { 785 throw new InterceptorsValidationException("Class " + getClassName() 786 + " has already a " + itcType + " method which is " 787 + method.getMethodName() + ", cannot set new method " 788 + postConstructMethodMetadata.getMethodName()); 789 } 790 } 791 } 792 793 794 797 public LinkedList <MethodAnnotationMetadata> getPreDestroyMethodsMetadata() { 798 return preDestroyMethodsMetadata; 799 } 800 801 805 public void addPreDestroyMethodMetadata(final MethodAnnotationMetadata preDestroyMethodMetadata) { 806 checkLifeCycleDuplicate(preDestroyMethodMetadata, InterceptorType.PRE_DESTROY, getPreDestroyMethodsMetadata()); 807 this.preDestroyMethodsMetadata.addFirst(preDestroyMethodMetadata); 808 } 809 810 811 814 public LinkedList <MethodAnnotationMetadata> getPostActivateMethodsMetadata() { 815 return postActivateMethodsMetadata; 816 } 817 818 822 public void addPostActivateMethodMetadata(final MethodAnnotationMetadata postActivateMethodMetadata) { 823 checkLifeCycleDuplicate(postActivateMethodMetadata, InterceptorType.POST_ACTIVATE, getPostActivateMethodsMetadata()); 824 this.postActivateMethodsMetadata.addFirst(postActivateMethodMetadata); 825 } 826 827 828 831 public LinkedList <MethodAnnotationMetadata> getPrePassivateMethodsMetadata() { 832 return prePassivateMethodsMetadata; 833 } 834 835 839 public void addPrePassivateMethodMetadata(final MethodAnnotationMetadata prePassivateMethodMetadata) { 840 checkLifeCycleDuplicate(prePassivateMethodMetadata, InterceptorType.PRE_PASSIVATE, getPrePassivateMethodsMetadata()); 841 this.prePassivateMethodsMetadata.addFirst(prePassivateMethodMetadata); 842 } 843 844 845 849 public boolean isInterceptor() { 850 return (aroundInvokeMethodsMetadata != null && aroundInvokeMethodsMetadata.size() > 0) 851 || (postConstructMethodsMetadata != null && postConstructMethodsMetadata.size() > 0) 852 || (preDestroyMethodsMetadata != null && preDestroyMethodsMetadata.size() > 0) 853 || (prePassivateMethodsMetadata != null && prePassivateMethodsMetadata.size() > 0) 854 || (postActivateMethodsMetadata != null && postActivateMethodsMetadata.size() > 0); 855 } 856 857 858 861 public List <JEjbEJB> getJEjbEJBs() { 862 return jEjbEJBs; 863 } 864 865 869 public void setJEjbEJBs(final List <JEjbEJB> jEjbEJBs) { 870 this.jEjbEJBs = jEjbEJBs; 871 } 872 873 874 877 public List <JAnnotationResource> getJAnnotationResources() { 878 return jAnnotationResources; 879 } 880 881 885 public void setJAnnotationResources(final List <JAnnotationResource> jAnnotationResources) { 886 this.jAnnotationResources = jAnnotationResources; 887 } 888 889 893 public List <JavaxPersistenceContext> getJavaxPersistencePersistenceContexts() { 894 return javaxPersistencePersistenceContexts; 895 } 896 897 901 public void setJavaxPersistencePersistenceContexts(final List <JavaxPersistenceContext> javaxPersistencePersistenceContexts) { 902 this.javaxPersistencePersistenceContexts = javaxPersistencePersistenceContexts; 903 } 904 905 908 public List <JavaxPersistenceUnit> getJavaxPersistencePersistenceUnits() { 909 return javaxPersistencePersistenceUnits; 910 } 911 912 916 public void setJavaxPersistencePersistenceUnits(final List <JavaxPersistenceUnit> javaxPersistencePersistenceUnits) { 917 this.javaxPersistencePersistenceUnits = javaxPersistencePersistenceUnits; 918 } 919 920 923 public JCommonBean getJCommonBean() { 924 return jCommonBean; 925 } 926 927 931 public void setJCommonBean(final JCommonBean commonBean) { 932 String ejbName = commonBean.getName(); 934 if (ejbName == null || "".equals(ejbName)) { 935 commonBean.setName(className.substring(className.lastIndexOf("/") + 1)); 937 } 938 jCommonBean = commonBean; 939 } 940 941 944 public JStateful getJStateful() { 945 return jStateful; 946 } 947 948 952 public void setJStateful(final JStateful jStateful) { 953 this.jStateful = jStateful; 954 } 955 956 959 public JStateless getJStateless() { 960 return jStateless; 961 } 962 963 967 public void setJStateless(final JStateless jStateless) { 968 this.jStateless = jStateless; 969 } 970 971 974 public boolean wasModified() { 975 return modified; 976 } 977 978 981 public void setModified() { 982 this.modified = true; 983 } 984 985 989 public void setDeclareRoles(final List <String > declareRoles) { 990 this.declareRoles = declareRoles; 991 } 992 993 996 public List <String > getDeclareRoles() { 997 return declareRoles; 998 } 999 1000 1004 public void setRolesAllowed(final List <String > rolesAllowed) { 1005 this.rolesAllowed = rolesAllowed; 1006 } 1007 1008 1011 public List <String > getRolesAllowed() { 1012 return rolesAllowed; 1013 } 1014 1015 1019 public void setPermitAll(final boolean permitAll) { 1020 this.permitAll = permitAll; 1021 } 1022 1023 1026 public boolean hasPermitAll() { 1027 return permitAll; 1028 } 1029 1030 1034 public void setRunAs(final String runAs) { 1035 this.runAs = runAs; 1036 } 1037 1038 1041 public String getRunAs() { 1042 return runAs; 1043 } 1044} 1045 | Popular Tags |