1 23 24 package com.sun.enterprise.deployment; 25 26 import java.util.*; 27 import java.lang.reflect.Method ; 28 import java.lang.reflect.Field ; 29 import java.util.logging.*; 30 import com.sun.logging.*; 31 32 import static com.sun.enterprise.deployment.LifecycleCallbackDescriptor.CallbackType; 33 import static com.sun.enterprise.deployment.LifecycleCallbackDescriptor.CallbackType.*; 34 import com.sun.enterprise.deployment.types.EjbReference; 35 import com.sun.enterprise.deployment.types.EjbReferenceContainer; 36 import com.sun.enterprise.deployment.types.ResourceEnvReferenceContainer; 37 import com.sun.enterprise.deployment.types.ResourceReferenceContainer; 38 import com.sun.enterprise.deployment.types.ServiceReferenceContainer; 39 import com.sun.enterprise.deployment.types.MessageDestinationReference; 40 import com.sun.enterprise.deployment.types.MessageDestinationReferencer; 41 import com.sun.enterprise.deployment.types.MessageDestinationReferenceContainer; 42 43 import com.sun.enterprise.util.BeanMethodCalculator; 44 import com.sun.enterprise.util.LocalStringManagerImpl; 45 import com.sun.enterprise.deployment.util.LogDomains; 46 47 import com.sun.enterprise.deployment.runtime.IASEjbExtraDescriptors; 50 51 52 import com.sun.enterprise.deployment.util.EjbVisitor; 53 import com.sun.enterprise.deployment.util.DescriptorVisitor; 54 import com.sun.enterprise.deployment.util.InterceptorBindingTranslator; 55 import com.sun.enterprise.deployment.util.InterceptorBindingTranslator.TranslationResults; 56 57 64 65 public abstract class EjbDescriptor extends EjbAbstractDescriptor 66 implements WritableJndiNameEnvironment, 67 EjbReferenceContainer, 68 ResourceEnvReferenceContainer, 69 ResourceReferenceContainer, 70 ServiceReferenceContainer, 71 MessageDestinationReferenceContainer 72 { 73 74 final public static String BEAN_TRANSACTION_TYPE = "Bean"; 75 76 final public static String CONTAINER_TRANSACTION_TYPE = "Container"; 77 78 final public static String LOCAL_TRANSACTION_SCOPE = "Local"; 80 final public static String DISTRIBUTED_TRANSACTION_SCOPE = "Distributed"; 81 82 protected String transactionType = null; 83 protected boolean usesDefaultTransaction = false; 84 private Hashtable methodContainerTransactions = null; 85 private Hashtable permissionedMethodsByPermission = null; 86 private HashMap methodPermissionsFromDD = null; 87 private Set<EnvironmentProperty> environmentProperties = 88 new HashSet<EnvironmentProperty>(); 89 private Set<EjbReference> ejbReferences = 90 new HashSet<EjbReference>(); 91 private Set<JmsDestinationReferenceDescriptor> jmsDestReferences = 92 new HashSet<JmsDestinationReferenceDescriptor>(); 93 private Set<MessageDestinationReferenceDescriptor> messageDestReferences = 94 new HashSet<MessageDestinationReferenceDescriptor>(); 95 private Set<ResourceReferenceDescriptor> resourceReferences = 96 new HashSet<ResourceReferenceDescriptor>(); 97 private Set<ServiceReferenceDescriptor> serviceReferences = 98 new HashSet<ServiceReferenceDescriptor>(); 99 100 private Set<LifecycleCallbackDescriptor> postConstructDescs = 101 new HashSet<LifecycleCallbackDescriptor>(); 102 private Set<LifecycleCallbackDescriptor> preDestroyDescs = 103 new HashSet<LifecycleCallbackDescriptor>(); 104 private Set<LifecycleCallbackDescriptor> aroundInvokeDescs = 105 new HashSet<LifecycleCallbackDescriptor>(); 106 107 private Set<EntityManagerFactoryReferenceDescriptor> 108 entityManagerFactoryReferences = 109 new HashSet<EntityManagerFactoryReferenceDescriptor>(); 110 111 private Set<EntityManagerReferenceDescriptor> 112 entityManagerReferences = 113 new HashSet<EntityManagerReferenceDescriptor>(); 114 115 private Set roleReferences = new HashSet(); 116 private EjbBundleDescriptor bundleDescriptor; 117 private Set iorConfigDescriptors = new OrderedSet(); 119 private String ejbClassName; 121 122 private Set ejbReferencersPointingToMe = new HashSet(); 124 125 protected Boolean usesCallerIdentity = null; 127 protected String securityIdentityDescription; 128 protected boolean isDistributedTxScope = true; 129 protected RunAsIdentityDescriptor runAsIdentity = null; 130 131 private Map styledMethodDescriptors = new HashMap(); 135 136 private long uniqueId; 137 private String remoteHomeImplClassName; 138 private String ejbObjectImplClassName; 139 private String localHomeImplClassName; 140 private String ejbLocalObjectImplClassName; 141 142 private MethodDescriptor timedObjectMethod; 143 144 145 private Set<EjbInterceptor> allInterceptorClasses = 151 new HashSet<EjbInterceptor>(); 152 153 private List<EjbInterceptor> interceptorChain = 155 new LinkedList<EjbInterceptor>(); 156 157 private Map<MethodDescriptor, List<EjbInterceptor>> methodInterceptorsMap = 169 new HashMap<MethodDescriptor, List<EjbInterceptor>>(); 170 171 private static LocalStringManagerImpl localStrings = 172 new LocalStringManagerImpl(EjbDescriptor.class); 173 174 static Logger _logger = LogDomains.getLogger(LogDomains.DPL_LOGGER); 175 176 private IASEjbExtraDescriptors iASEjbExtraDescriptors= new IASEjbExtraDescriptors(); 178 183 public IASEjbExtraDescriptors getIASEjbExtraDescriptors(){ 184 return iASEjbExtraDescriptors; 185 } 186 187 190 protected EjbDescriptor() { 191 } 192 193 public EjbDescriptor(EjbDescriptor other) { 194 super(other); 195 this.transactionType = other.transactionType; 196 this.methodContainerTransactions = new Hashtable(other.getMethodContainerTransactions()); 197 this.permissionedMethodsByPermission = new Hashtable(other.getPermissionedMethodsByPermission()); 198 this.getEnvironmentProperties().addAll(other.getEnvironmentProperties()); 199 this.getEjbReferenceDescriptors().addAll(other.getEjbReferenceDescriptors()); 200 this.getJmsDestinationReferenceDescriptors().addAll(other.getJmsDestinationReferenceDescriptors()); 201 this.getMessageDestinationReferenceDescriptors().addAll(other.getMessageDestinationReferenceDescriptors()); 202 this.getResourceReferenceDescriptors().addAll(other.getResourceReferenceDescriptors()); 203 this.getServiceReferenceDescriptors().addAll(other.getServiceReferenceDescriptors()); 204 this.getRoleReferences().addAll(other.getRoleReferences()); 205 this.getIORConfigurationDescriptors().addAll(other.getIORConfigurationDescriptors()); 206 this.transactionType = other.transactionType; 207 this.ejbClassName = other.ejbClassName; 208 this.usesCallerIdentity = other.usesCallerIdentity; 209 this.bundleDescriptor = other.bundleDescriptor; 210 } 211 212 215 public void setEjbClassName(String ejbClassName) { 216 this.ejbClassName = ejbClassName; 217 } 218 221 public String getEjbClassName() { 222 return this.ejbClassName; 223 } 224 232 public String getEjbImplClassName() { 233 return this.getEjbClassName(); 234 } 235 236 239 public void setRemoteHomeImplClassName(String name) { 240 this.remoteHomeImplClassName = name; 241 } 242 245 public String getRemoteHomeImplClassName() { 246 return this.remoteHomeImplClassName; 247 } 248 249 252 public void setLocalHomeImplClassName(String name) { 253 this.localHomeImplClassName = name; 254 } 255 258 public String getLocalHomeImplClassName() { 259 return this.localHomeImplClassName; 260 } 261 262 263 266 public void setEJBLocalObjectImplClassName(String name) { 267 this.ejbLocalObjectImplClassName = name; 268 } 269 272 public String getEJBLocalObjectImplClassName() { 273 return this.ejbLocalObjectImplClassName; 274 } 275 276 277 280 public void setEJBObjectImplClassName(String name) { 281 this.ejbObjectImplClassName = name; 282 } 283 286 public String getEJBObjectImplClassName() { 287 return this.ejbObjectImplClassName; 288 } 289 290 293 public String getTransactionType() { 294 return this.transactionType; 295 } 296 297 300 public abstract void setTransactionType(String transactionType); 301 302 308 public Vector getPossibleTransactionAttributes() { 309 Vector txAttributes = new Vector(); 310 txAttributes.add(new ContainerTransaction 311 (ContainerTransaction.MANDATORY, "")); 312 txAttributes.add(new ContainerTransaction 313 (ContainerTransaction.NEVER, "")); 314 txAttributes.add(new ContainerTransaction 315 (ContainerTransaction.NOT_SUPPORTED, "")); 316 txAttributes.add(new ContainerTransaction 317 (ContainerTransaction.REQUIRED, "")); 318 txAttributes.add(new ContainerTransaction 319 (ContainerTransaction.REQUIRES_NEW, "")); 320 txAttributes.add(new ContainerTransaction 321 (ContainerTransaction.SUPPORTS, "")); 322 return txAttributes; 323 } 324 325 public boolean isTimedObject() { 326 return (timedObjectMethod != null); 327 } 328 329 public MethodDescriptor getEjbTimeoutMethod() { 330 return timedObjectMethod; 331 } 332 333 public void setEjbTimeoutMethod(MethodDescriptor method) { 334 timedObjectMethod = method; 335 } 336 337 public Set<LifecycleCallbackDescriptor> 338 getPostConstructDescriptors() { 339 if (postConstructDescs == null) { 340 postConstructDescs = 341 new HashSet<LifecycleCallbackDescriptor>(); 342 } 343 return postConstructDescs; 344 } 345 346 public void addPostConstructDescriptor(LifecycleCallbackDescriptor 347 postConstructDesc) { 348 String className = postConstructDesc.getLifecycleCallbackClass(); 349 boolean found = false; 350 for (LifecycleCallbackDescriptor next : 351 getPostConstructDescriptors()) { 352 if (next.getLifecycleCallbackClass().equals(className)) { 353 found = true; 354 break; 355 } 356 } 357 if (!found) { 358 getPostConstructDescriptors().add(postConstructDesc); 359 } 360 } 361 362 public LifecycleCallbackDescriptor 363 getPostConstructDescriptorByClass(String className) { 364 return bundleDescriptor.getPostConstructDescriptorByClass 365 (className, this); 366 } 367 368 public boolean hasPostConstructMethod() { 369 return (getPostConstructDescriptors().size() > 0); 370 } 371 372 public Set<LifecycleCallbackDescriptor> 373 getPreDestroyDescriptors() { 374 if (preDestroyDescs == null) { 375 preDestroyDescs = 376 new HashSet<LifecycleCallbackDescriptor>(); 377 } 378 return preDestroyDescs; 379 } 380 381 public void addPreDestroyDescriptor(LifecycleCallbackDescriptor 382 preDestroyDesc) { 383 String className = preDestroyDesc.getLifecycleCallbackClass(); 384 boolean found = false; 385 for (LifecycleCallbackDescriptor next : 386 getPreDestroyDescriptors()) { 387 if (next.getLifecycleCallbackClass().equals(className)) { 388 found = true; 389 break; 390 } 391 } 392 if (!found) { 393 getPreDestroyDescriptors().add(preDestroyDesc); 394 } 395 } 396 397 public LifecycleCallbackDescriptor 398 getPreDestroyDescriptorByClass(String className) { 399 return bundleDescriptor.getPreDestroyDescriptorByClass 400 (className, this); 401 } 402 403 public boolean hasPreDestroyMethod() { 404 return (getPreDestroyDescriptors().size() > 0); 405 } 406 407 public Set<LifecycleCallbackDescriptor> getAroundInvokeDescriptors() { 408 if (aroundInvokeDescs == null) { 409 aroundInvokeDescs = 410 new HashSet<LifecycleCallbackDescriptor>(); 411 } 412 return aroundInvokeDescs; 413 } 414 415 public void addAroundInvokeDescriptor(LifecycleCallbackDescriptor 416 aroundInvokeDesc) { 417 String className = aroundInvokeDesc.getLifecycleCallbackClass(); 418 boolean found = false; 419 for (LifecycleCallbackDescriptor next : 420 getAroundInvokeDescriptors()) { 421 if (next.getLifecycleCallbackClass().equals(className)) { 422 found = true; 423 break; 424 } 425 } 426 if (!found) { 427 getAroundInvokeDescriptors().add(aroundInvokeDesc); 428 } 429 } 430 431 public LifecycleCallbackDescriptor 432 getAroundInvokeDescriptorByClass(String className) { 433 434 for (LifecycleCallbackDescriptor next : 435 getAroundInvokeDescriptors()) { 436 if (next.getLifecycleCallbackClass().equals(className)) { 437 return next; 438 } 439 } 440 return null; 441 } 442 443 public boolean hasAroundInvokeMethod() { 444 return (getAroundInvokeDescriptors().size() > 0); 445 } 446 447 454 public void applyDefaultClassToLifecycleMethods() { 455 Set<LifecycleCallbackDescriptor> lifecycleMethods = 456 new HashSet<LifecycleCallbackDescriptor>(); 457 lifecycleMethods.addAll(getAroundInvokeDescriptors()); 458 lifecycleMethods.addAll(getPostConstructDescriptors()); 459 lifecycleMethods.addAll(getPreDestroyDescriptors()); 460 if( getType().equals(EjbSessionDescriptor.TYPE) ) { 461 EjbSessionDescriptor sfulDesc = (EjbSessionDescriptor) this; 462 lifecycleMethods.addAll(sfulDesc.getPrePassivateDescriptors()); 463 lifecycleMethods.addAll(sfulDesc.getPostActivateDescriptors()); 464 } 465 for(LifecycleCallbackDescriptor next : lifecycleMethods) { 466 if( next.getLifecycleCallbackClass() == null ) { 467 next.setLifecycleCallbackClass(getEjbClassName()); 468 } 469 } 470 } 471 472 475 public void applyInterceptors(InterceptorBindingTranslator 476 bindingTranslator) { 477 478 TranslationResults results = bindingTranslator.apply(getName()); 487 488 allInterceptorClasses.clear(); 489 allInterceptorClasses.addAll(results.allInterceptorClasses); 490 491 interceptorChain.clear(); 492 interceptorChain.addAll(results.classInterceptorChain); 493 494 methodInterceptorsMap.clear(); 495 methodInterceptorsMap.putAll(results.methodInterceptorsMap); 496 497 for (EjbInterceptor interceptor : allInterceptorClasses) { 498 for (Object ejbRefObj : interceptor.getEjbReferenceDescriptors()) { 499 addEjbReferenceDescriptor((EjbReference)ejbRefObj); 500 } 501 502 for (Object msgDestRefObj : 503 interceptor.getMessageDestinationReferenceDescriptors()) { 504 addMessageDestinationReferenceDescriptor( 505 (MessageDestinationReferenceDescriptor)msgDestRefObj); 506 } 507 508 for (Object envPropObj : interceptor.getEnvironmentProperties()) { 509 addEnvironmentProperty((EnvironmentProperty)envPropObj); 510 } 511 512 for (Object servRefObj : 513 interceptor.getServiceReferenceDescriptors()) { 514 addServiceReferenceDescriptor( 515 (ServiceReferenceDescriptor)servRefObj); 516 } 517 518 for (Object resRefObj : 519 interceptor.getResourceReferenceDescriptors()) { 520 addResourceReferenceDescriptor( 521 (ResourceReferenceDescriptor)resRefObj); 522 } 523 524 for (Object jmsDestRefObj: 525 interceptor.getJmsDestinationReferenceDescriptors()) { 526 addJmsDestinationReferenceDescriptor( 527 (JmsDestinationReferenceDescriptor)jmsDestRefObj); 528 } 529 530 for (EntityManagerFactoryReferenceDescriptor entMgrFacRef : 531 interceptor.getEntityManagerFactoryReferenceDescriptors()) { 532 addEntityManagerFactoryReferenceDescriptor(entMgrFacRef); 533 } 534 535 for (EntityManagerReferenceDescriptor entMgrRef : 536 interceptor.getEntityManagerReferenceDescriptors()) { 537 addEntityManagerReferenceDescriptor(entMgrRef); 538 } 539 } 540 } 541 542 548 public Set<EjbInterceptor> getInterceptorClasses() { 549 return new HashSet<EjbInterceptor>(allInterceptorClasses); 550 } 551 552 558 public Set<String > getInterceptorClassNames() { 559 560 HashSet<String > classNames = new HashSet<String >(); 561 562 for (EjbInterceptor ei : getInterceptorClasses()) { 563 classNames.add(ei.getInterceptorClassName()); 564 } 565 566 return classNames; 567 } 568 569 public Map<MethodDescriptor, List<EjbInterceptor>> 570 getMethodInterceptorsMap() { 571 return new HashMap<MethodDescriptor, List<EjbInterceptor>> 572 (methodInterceptorsMap); 573 } 574 575 public List<EjbInterceptor> getInterceptorChain() { 576 return new LinkedList<EjbInterceptor>( interceptorChain ); 577 } 578 579 585 public List<EjbInterceptor> getAroundInvokeInterceptors 586 (MethodDescriptor businessMethod) 587 { 588 589 LinkedList<EjbInterceptor> aroundInvokeInterceptors = 590 new LinkedList<EjbInterceptor>(); 591 592 List<EjbInterceptor> classOrMethodInterceptors = 593 methodInterceptorsMap.get(businessMethod); 594 if( classOrMethodInterceptors == null ) { 595 classOrMethodInterceptors = interceptorChain; 596 } 597 598 for (EjbInterceptor next : classOrMethodInterceptors) { 599 if (next.getAroundInvokeDescriptors().size() > 0) { 600 aroundInvokeInterceptors.add(next); 601 } 602 } 603 604 if( hasAroundInvokeMethod() ) { 605 606 EjbInterceptor interceptorInfo = new EjbInterceptor(); 607 interceptorInfo.setFromBeanClass(true); 608 interceptorInfo.addAroundInvokeDescriptors(getAroundInvokeDescriptors()); 609 interceptorInfo.setInterceptorClassName(getEjbImplClassName()); 610 611 aroundInvokeInterceptors.add(interceptorInfo); 612 } 613 614 return aroundInvokeInterceptors; 615 } 616 617 623 public List<EjbInterceptor> getCallbackInterceptors(CallbackType type) { 624 625 LinkedList<EjbInterceptor> callbackInterceptors = 626 new LinkedList<EjbInterceptor>(); 627 628 for (EjbInterceptor next : interceptorChain) { 629 if (next.getCallbackDescriptors(type).size() > 0) { 630 callbackInterceptors.add(next); 631 } 632 } 633 634 EjbInterceptor beanClassCallbackInfo = null; 635 636 switch(type) { 637 case POST_CONSTRUCT : 638 639 if( hasPostConstructMethod() ) { 640 beanClassCallbackInfo = new EjbInterceptor(); 641 beanClassCallbackInfo.setFromBeanClass(true); 642 beanClassCallbackInfo.addCallbackDescriptors 643 (type, getPostConstructDescriptors()); 644 } 645 break; 646 647 case PRE_DESTROY : 648 649 if( hasPreDestroyMethod() ) { 650 beanClassCallbackInfo = new EjbInterceptor(); 651 beanClassCallbackInfo.setFromBeanClass(true); 652 beanClassCallbackInfo.addCallbackDescriptors 653 (type, getPreDestroyDescriptors()); 654 } 655 break; 656 657 case PRE_PASSIVATE : 658 659 if( ((EjbSessionDescriptor)this).hasPrePassivateMethod() ) { 660 beanClassCallbackInfo = new EjbInterceptor(); 661 beanClassCallbackInfo.setFromBeanClass(true); 662 beanClassCallbackInfo.addCallbackDescriptors(type, 663 ((EjbSessionDescriptor)this).getPrePassivateDescriptors()); 664 } 665 666 break; 667 668 case POST_ACTIVATE : 669 670 if( ((EjbSessionDescriptor)this).hasPostActivateMethod() ) { 671 beanClassCallbackInfo = new EjbInterceptor(); 672 beanClassCallbackInfo.setFromBeanClass(true); 673 beanClassCallbackInfo.addCallbackDescriptors(type, 674 ((EjbSessionDescriptor)this).getPostActivateDescriptors()); 675 } 676 677 break; 678 679 } 680 681 if( beanClassCallbackInfo != null ) { 682 683 beanClassCallbackInfo.setInterceptorClassName 684 (getEjbImplClassName()); 685 callbackInterceptors.add(beanClassCallbackInfo); 686 687 } 688 689 return callbackInterceptors; 690 } 691 692 693 697 public boolean isDistributedTransactionScope() { 698 return isDistributedTxScope; 699 } 700 701 704 public void setDistributedTransactionScope(boolean scope) 705 { 706 isDistributedTxScope = scope; 707 } 708 709 710 713 public void setUsesCallerIdentity(boolean flag) 714 { 715 usesCallerIdentity = flag; 716 } 717 718 723 public Boolean getUsesCallerIdentity() 724 { 725 return usesCallerIdentity; 726 } 727 728 729 732 public String getSecurityIdentityDescription() 733 { 734 if ( securityIdentityDescription == null ) 735 securityIdentityDescription = ""; 736 return securityIdentityDescription; 737 } 738 739 742 public void setSecurityIdentityDescription(String s) 743 { 744 securityIdentityDescription = s; 745 } 746 747 748 public void setRunAsIdentity(RunAsIdentityDescriptor desc) 749 { 750 if ( usesCallerIdentity == null || usesCallerIdentity ) 751 throw new IllegalStateException ("Cannot set RunAs identity when using caller identity"); 752 this.runAsIdentity = desc; 753 } 754 755 public RunAsIdentityDescriptor getRunAsIdentity() 756 { 757 if ( usesCallerIdentity == null || usesCallerIdentity ) 758 throw new IllegalStateException ("Cannot get RunAs identity when using caller identity"); 759 return runAsIdentity; 760 } 761 762 765 public void setUsesDefaultTransaction() { 766 usesDefaultTransaction = true; 767 } 768 769 773 public boolean isUsesDefaultTransaction() { 774 return usesDefaultTransaction; 775 } 776 777 780 public Hashtable getMethodContainerTransactions() { 781 if (this.methodContainerTransactions == null) { 782 this.methodContainerTransactions = new Hashtable(); 783 } 784 return methodContainerTransactions; 785 } 786 787 791 public void setContainerTransactionFor(MethodDescriptor methodDescriptor, ContainerTransaction containerTransaction) { 792 ContainerTransaction oldValue = this.getContainerTransactionFor(methodDescriptor); 793 if (oldValue == null || (oldValue != null && !(oldValue.equals(containerTransaction)))) { 794 String transactionType = this.getTransactionType(); 795 if (transactionType == null) { 796 setTransactionType(CONTAINER_TRANSACTION_TYPE); 797 transactionType = CONTAINER_TRANSACTION_TYPE; 798 } else if (BEAN_TRANSACTION_TYPE.equals(transactionType)) { 799 throw new IllegalArgumentException (localStrings.getLocalString( 800 "enterprise.deployment.exceptiontxattrbtnotspecifiedinbeanwithtxtype", 801 "Method level transaction attributes may not be specified on a bean with transaction type {0}", new Object [] {EjbSessionDescriptor.BEAN_TRANSACTION_TYPE})); 802 } 803 getMethodContainerTransactions().put(methodDescriptor, containerTransaction); 805 } 806 } 807 808 private void removeContainerTransactionFor(MethodDescriptor methodDescriptor) { 809 getMethodContainerTransactions().remove(methodDescriptor); 810 } 811 812 817 public void setMethodContainerTransactions(Hashtable methodContainerTransactions) { 818 if (methodContainerTransactions == null || methodContainerTransactions.isEmpty()) { 819 methodContainerTransactions = null; 820 } else { 821 for (Enumeration e = methodContainerTransactions.keys(); e.hasMoreElements();) { 822 MethodDescriptor methodDescriptor = (MethodDescriptor) e.nextElement(); 823 ContainerTransaction containerTransaction = 824 (ContainerTransaction) methodContainerTransactions.get(methodDescriptor); 825 setContainerTransactionFor(methodDescriptor, containerTransaction); 826 } 827 } 828 } 829 830 Set getAllMethodDescriptors() { 831 Set allMethodDescriptors = new HashSet(); 832 for (Enumeration e = getMethodContainerTransactions().keys(); e.hasMoreElements();) { 833 allMethodDescriptors.add(e.nextElement()); 834 } 835 for (Iterator e = this.getPermissionedMethodsByPermission().keySet().iterator(); e.hasNext();) { 836 MethodPermission nextPermission = (MethodPermission) e.next(); 837 Set permissionedMethods = (Set) this.getPermissionedMethodsByPermission().get(nextPermission); 838 for (Iterator itr = permissionedMethods.iterator(); itr.hasNext();) { 839 allMethodDescriptors.add(itr.next()); 840 } 841 } 842 return allMethodDescriptors; 843 } 844 845 846 849 public ContainerTransaction getContainerTransactionFor(MethodDescriptor methodDescriptor) { 850 ContainerTransaction containerTransaction = null; 851 if (this.needToConvertMethodContainerTransactions()) { 852 this.convertMethodContainerTransactions(); 853 } 854 containerTransaction = (ContainerTransaction) this.getMethodContainerTransactions().get(methodDescriptor); 855 if (containerTransaction == null) { 856 if (this.isBoundsChecking() && usesDefaultTransaction) { 857 containerTransaction = new ContainerTransaction(ContainerTransaction.REQUIRED, ""); 858 this.getMethodContainerTransactions().put(methodDescriptor, containerTransaction); 859 } else { 860 containerTransaction = null; 861 } 862 } 863 return containerTransaction; 864 } 865 866 private boolean needToConvertMethodContainerTransactions() { 867 if (this.getEjbBundleDescriptor() != null) { 868 for (Enumeration e = this.getMethodContainerTransactions().keys(); e.hasMoreElements();) { 869 MethodDescriptor md = (MethodDescriptor) e.nextElement(); 870 if (!md.isExact()) { 871 return true; 872 } 873 } 874 } 875 return false; 876 } 877 878 879 private void convertMethodContainerTransactions() { 880 Hashtable convertedTransactions = new Hashtable(); 884 convertMethodContainerTransactionsOfStyle(1, convertedTransactions); 885 convertMethodContainerTransactionsOfStyle(2, convertedTransactions); 886 convertMethodContainerTransactionsOfStyle(3, convertedTransactions); 887 this.methodContainerTransactions = convertedTransactions; 889 } 890 891 private void convertMethodContainerTransactionsOfStyle( int requestedStyleForConversion, Hashtable convertedMethods) { 892 893 Collection transactionMethods = this.getTransactionMethodDescriptors(); 894 Hashtable transactions = this.getMethodContainerTransactions(); 895 for (Enumeration e=transactions.keys();e.hasMoreElements();) { 896 MethodDescriptor md = (MethodDescriptor) e.nextElement(); 897 if (md.getStyle()==requestedStyleForConversion) { 898 ContainerTransaction ct = (ContainerTransaction) getMethodContainerTransactions().get(md); 899 for (Enumeration mds = md.doStyleConversion(this, transactionMethods).elements(); mds.hasMoreElements();) { 900 MethodDescriptor next = (MethodDescriptor) mds.nextElement(); 901 convertedMethods.put(next, new ContainerTransaction(ct)); 902 } 903 } 904 } 905 } 906 907 911 public ContainerTransaction getContainerTransaction() { 912 Vector transactionalMethods = new Vector(this.getTransactionMethodDescriptors()); 913 MethodDescriptor md = (MethodDescriptor) transactionalMethods.firstElement(); 914 if (md != null) { 915 ContainerTransaction first = this.getContainerTransactionFor(md); 916 for (Enumeration e = transactionalMethods.elements(); e.hasMoreElements();) { 917 MethodDescriptor next = (MethodDescriptor) e.nextElement(); 918 ContainerTransaction nextCt = this.getContainerTransactionFor(next); 919 if (nextCt != null && !nextCt.equals(first)) { 920 return null; 921 } 922 } 923 return first; 924 } 925 return null; 926 } 927 928 public Set getIORConfigurationDescriptors() { 929 return iorConfigDescriptors; 930 } 931 932 public void addIORConfigurationDescriptor(EjbIORConfigurationDescriptor val) 933 { 934 iorConfigDescriptors.add(val); 935 this.changed(); 936 } 937 938 941 public Set getPermissionedRoles() { 942 if (needToConvertMethodPermissions()) { 943 convertMethodPermissions(); 944 } 945 Set allPermissionedRoles = new HashSet(); 946 for (Iterator i = this.getPermissionedMethodsByPermission().keySet().iterator(); i.hasNext();) { 947 MethodPermission pm = (MethodPermission) i.next(); 948 if (pm.isRoleBased()) { 949 allPermissionedRoles.add(pm.getRole()); 950 } 951 } 952 return allPermissionedRoles; 953 } 954 955 959 public Map getPermissionedMethodsByPermission() { 960 if (permissionedMethodsByPermission==null) { 961 permissionedMethodsByPermission = new Hashtable(); 962 } 963 return permissionedMethodsByPermission; 964 } 965 966 972 public void addPermissionedMethod(MethodPermission mp, MethodDescriptor md) { 973 if (getEjbBundleDescriptor() == null) { 974 throw new IllegalArgumentException (localStrings.getLocalString( 975 "enterprise.deployment.exceptioncannotaddrolesdescriptor", 976 "Cannot add roles when the descriptor is not part of a bundle")); 977 } 978 if (mp.isRoleBased()) { 979 if (!getEjbBundleDescriptor().getRoles().contains(mp.getRole())) { 980 throw new IllegalArgumentException (localStrings.getLocalString( 981 "enterprise.deployment.exceptioncannotaddrolesbundle", 982 "Cannot add roles when the bundle does not have them")); 983 } 984 } 985 986 if (md.isExact()) { 987 updateMethodPermissionForMethod(mp, md); 988 } else { 989 addMethodPermissionForStyledMethodDescriptor(mp, md); 990 } 991 992 saveMethodPermissionFromDD(mp,md); 993 } 994 995 998 private void saveMethodPermissionFromDD(MethodPermission mp, 999 MethodDescriptor md) { 1000 1001 if (methodPermissionsFromDD==null) { 1002 methodPermissionsFromDD = new HashMap(); 1003 } 1004 1005 ArrayList descriptors = (ArrayList) methodPermissionsFromDD.get(mp); 1010 if (descriptors == null) 1011 descriptors = new ArrayList(); 1012 descriptors.add(md); 1013 methodPermissionsFromDD.put(mp, descriptors); 1014 } 1015 1016 1019 public HashMap getMethodPermissionsFromDD() { 1020 return methodPermissionsFromDD; 1021 } 1022 1023 private void addMethodPermissionForMethod(MethodPermission mp, MethodDescriptor md) { 1024 1025 if (getPermissionedMethodsByPermission().containsKey(mp)) { 1026 Set alreadyPermissionedMethodsForThisRole = (Set) getPermissionedMethodsByPermission().get(mp); 1027 alreadyPermissionedMethodsForThisRole.add(md); 1028 this.getPermissionedMethodsByPermission().put(mp, alreadyPermissionedMethodsForThisRole); 1029 } else { 1030 Set permissionedMethodsForThisRole = new HashSet(); 1031 permissionedMethodsForThisRole.add(md); 1032 this.getPermissionedMethodsByPermission().put(mp, permissionedMethodsForThisRole); 1033 } 1034 this.changed(); 1035 } 1036 1037 1043 public void removePermissionedMethod(MethodPermission mp, MethodDescriptor md) { 1044 if (this.getEjbBundleDescriptor() == null) { 1045 throw new IllegalArgumentException (localStrings.getLocalString( 1046 "enterprise.deployment.exceptioncanotaddrolesdescriptor", 1047 "Cannot add roles when the descriptor is not part of a bundle")); 1048 } 1049 if (mp.isRoleBased()) { 1050 if (!getEjbBundleDescriptor().getRoles().contains(mp.getRole())) { 1051 throw new IllegalArgumentException (localStrings.getLocalString( 1052 "enterprise.deployment.exceptioncannotaddrolesbndledoesnothave", 1053 "Cannot add roles when the bundle does not have them")); 1054 } 1055 } 1056 1057 if (this.getPermissionedMethodsByPermission().containsKey(mp)) { 1058 Set alreadyPermissionedMethodsForThisRole = (Set) this.getPermissionedMethodsByPermission().get(mp); 1059 alreadyPermissionedMethodsForThisRole.remove(md); 1060 this.getPermissionedMethodsByPermission().put(mp, alreadyPermissionedMethodsForThisRole); 1061 } 1062 this.changed(); 1063 } 1064 1065 1068 private void addMethodPermissionForStyledMethodDescriptor(MethodPermission mp, MethodDescriptor md) { 1069 1070 if (styledMethodDescriptors==null) { 1071 styledMethodDescriptors = new HashMap(); 1072 } 1073 1074 Set permissions = (Set) styledMethodDescriptors.get(md); 1076 if (permissions==null) 1077 permissions = new HashSet(); 1078 permissions.add(mp); 1079 styledMethodDescriptors.put(md, permissions); 1080 } 1081 1082 1085 public Map getStyledPermissionedMethodsByPermission() { 1086 if (styledMethodDescriptors==null) { 1087 return null; 1088 } 1089 1090 Map styledMethodDescriptorsByPermission = new HashMap(); 1094 for (Iterator mdIterator=styledMethodDescriptors.keySet().iterator();mdIterator.hasNext();) { 1095 MethodDescriptor md = (MethodDescriptor) mdIterator.next(); 1096 Set methodPermissions = (Set) styledMethodDescriptors.get(md); 1097 for (Iterator mpIterator = methodPermissions.iterator(); mpIterator.hasNext();) { 1098 MethodPermission mp = (MethodPermission) mpIterator.next(); 1099 1100 Set methodDescriptors = (Set) styledMethodDescriptorsByPermission.get(mp); 1101 if (methodDescriptors == null) { 1102 methodDescriptors = new HashSet(); 1103 } 1104 methodDescriptors.add(md); 1105 styledMethodDescriptorsByPermission.put(mp, methodDescriptors); 1106 } 1107 } 1108 return styledMethodDescriptorsByPermission; 1109 } 1110 1111 1115 public Set getUncheckedMethodDescriptors (){ 1116 if (needToConvertMethodPermissions()) { 1117 convertMethodPermissions(); 1118 } 1119 return (Set) getPermissionedMethodsByPermission().get(MethodPermission.getUncheckedMethodPermission()); 1120 } 1121 1122 1126 public Set getExcludedMethodDescriptors (){ 1127 if (needToConvertMethodPermissions()) { 1128 convertMethodPermissions(); 1129 } 1130 return (Set) getPermissionedMethodsByPermission().get(MethodPermission.getExcludedMethodPermission()); 1131 } 1132 1133 1137 private void convertMethodPermissions() { 1138 1139 if (styledMethodDescriptors==null) 1140 return; 1141 1142 Set allMethods = getMethodDescriptors(); 1143 Set unpermissionedMethods = getMethodDescriptors(); 1144 1145 Set methodDescriptors = styledMethodDescriptors.keySet(); 1146 for (Iterator styledMdItr = methodDescriptors.iterator();styledMdItr.hasNext();) { 1147 MethodDescriptor styledMd = (MethodDescriptor) styledMdItr.next(); 1148 1149 Set newPermissions = (Set) styledMethodDescriptors.get(styledMd); 1152 1153 Vector mds = styledMd.doStyleConversion(this, allMethods); 1155 for (Iterator mdItr = mds.iterator(); mdItr.hasNext();) { 1156 MethodDescriptor md = (MethodDescriptor) mdItr.next(); 1157 1158 unpermissionedMethods.remove(md); 1162 1163 for (Iterator newPermissionsItr = newPermissions.iterator();newPermissionsItr.hasNext();) { 1166 MethodPermission newMp = (MethodPermission) newPermissionsItr.next(); 1167 updateMethodPermissionForMethod(newMp, md); 1168 } 1169 } 1170 } 1171 1172 MethodPermission mp = MethodPermission.getUncheckedMethodPermission(); 1174 Iterator iterator = unpermissionedMethods.iterator(); 1175 while(iterator.hasNext()) { 1176 MethodDescriptor md = (MethodDescriptor) iterator.next(); 1177 if (getMethodPermissions(md).isEmpty()) { 1178 addMethodPermissionForMethod(mp, md); 1179 } 1180 } 1181 1182 styledMethodDescriptors = null; 1184 } 1185 1186 private void dumpMethodPermissions() { 1187 _logger.log(Level.FINE,"For Bean " + getName()); 1188 Map allPermissions = getPermissionedMethodsByPermission(); 1189 Set permissions = allPermissions.keySet(); 1190 for (Iterator permissionsIterator = permissions.iterator();permissionsIterator.hasNext();) { 1191 MethodPermission mp = (MethodPermission) permissionsIterator.next(); 1192 _logger.log(Level.FINE," Method Permission : " + mp); 1193 Set allMethods = (Set) getPermissionedMethodsByPermission().get(mp); 1194 for (Iterator methodIterator = allMethods.iterator();methodIterator.hasNext();) { 1195 MethodDescriptor md = (MethodDescriptor) methodIterator.next(); 1196 _logger.log(Level.FINE," -> " + md); 1197 } 1198 } 1199 } 1200 1201 1209 private void updateMethodPermissionForMethod(MethodPermission mp, MethodDescriptor md) { 1210 1211 Set oldPermissions = getMethodPermissions(md); 1213 1214 if (oldPermissions.isEmpty()) { 1215 addMethodPermissionForMethod(mp, md); 1217 return; 1218 } 1219 1220 1226 if (mp.isExcluded()) { 1227 for (Iterator oldPermissionsItr = oldPermissions.iterator();oldPermissionsItr.hasNext();) { 1230 MethodPermission oldMp = (MethodPermission) oldPermissionsItr.next(); 1231 removePermissionedMethod(oldMp, md); 1232 } 1233 addMethodPermissionForMethod(mp, md); 1235 } else { 1236 if (mp.isUnchecked()) { 1237 for (Iterator oldPermissionsItr = oldPermissions.iterator();oldPermissionsItr.hasNext();) { 1241 MethodPermission oldMp = (MethodPermission) oldPermissionsItr.next(); 1242 if (!oldMp.isExcluded()) { 1243 removePermissionedMethod(oldMp, md); 1244 addMethodPermissionForMethod(mp, md); 1245 } 1246 } 1247 } else { 1248 for (Iterator oldPermissionsItr = oldPermissions.iterator();oldPermissionsItr.hasNext();) { 1252 MethodPermission oldMp = (MethodPermission) oldPermissionsItr.next(); 1253 if (!oldMp.isExcluded()) { 1254 if (!oldMp.isUnchecked()) { 1255 addMethodPermissionForMethod(mp, md); 1256 } 1257 } 1258 } 1259 } 1260 } 1261 } 1262 1263 1266 private boolean needToConvertMethodPermissions() { 1267 return styledMethodDescriptors!=null; 1268 } 1269 1270 1273 public Set getMethodPermissionsFor(MethodDescriptor methodDescriptor) { 1274 1275 if (needToConvertMethodPermissions()) { 1276 convertMethodPermissions(); 1277 } 1278 return getMethodPermissions(methodDescriptor); 1279 } 1280 1281 private Set getMethodPermissions(MethodDescriptor methodDescriptor) { 1282 1283 Set methodPermissionsForMethod = new HashSet(); 1284 for (Iterator e = this.getPermissionedMethodsByPermission().keySet().iterator(); e.hasNext();) { 1285 MethodPermission nextPermission = (MethodPermission) e.next(); 1286 Set permissionedMethods = (Set) this.getPermissionedMethodsByPermission().get(nextPermission); 1287 for (Iterator itr = permissionedMethods.iterator(); itr.hasNext();) { 1288 MethodDescriptor md = (MethodDescriptor) itr.next(); 1289 if (md.equals(methodDescriptor)) { 1290 methodPermissionsForMethod.add(nextPermission); 1291 } 1292 } 1293 } 1294 return methodPermissionsForMethod; 1295 } 1296 1297 1298 1301 public Set<EjbReference> getEjbReferenceDescriptors() { 1302 return ejbReferences; 1303 } 1304 1307 1308 public void addEjbReferenceDescriptor(EjbReference ejbReference) { 1309 ejbReferences.add(ejbReference); 1310 ejbReference.setReferringBundleDescriptor(getEjbBundleDescriptor()); 1311 } 1312 1313 public void removeEjbReferenceDescriptor(EjbReference ejbReference) { 1314 ejbReferences.remove(ejbReference); 1315 ejbReference.setReferringBundleDescriptor(null); 1316 } 1317 1318 public Set<ServiceReferenceDescriptor> getServiceReferenceDescriptors() { 1319 return serviceReferences; 1320 } 1321 1322 public void addServiceReferenceDescriptor(ServiceReferenceDescriptor 1323 serviceRef) { 1324 serviceRef.setBundleDescriptor(getEjbBundleDescriptor()); 1325 serviceReferences.add(serviceRef); 1326 } 1327 1328 public void removeServiceReferenceDescriptor(ServiceReferenceDescriptor 1329 serviceRef) { 1330 serviceReferences.remove(serviceRef); 1331 } 1332 1333 1337 public ServiceReferenceDescriptor getServiceReferenceByName(String name) { 1338 for (Iterator itr = this.getServiceReferenceDescriptors().iterator(); 1339 itr.hasNext();) { 1340 ServiceReferenceDescriptor srd = (ServiceReferenceDescriptor) 1341 itr.next(); 1342 if (srd.getName().equals(name)) { 1343 return srd; 1344 } 1345 } 1346 throw new IllegalArgumentException ("This ejb has no service refernce by the name " + name); 1347 } 1348 1349 public Set<MessageDestinationReferenceDescriptor> getMessageDestinationReferenceDescriptors() { 1350 return messageDestReferences; 1351 } 1352 1353 public void addMessageDestinationReferenceDescriptor 1354 (MessageDestinationReferenceDescriptor messageDestRef) { 1355 if( getEjbBundleDescriptor() != null ) { 1356 messageDestRef.setReferringBundleDescriptor 1357 (getEjbBundleDescriptor()); 1358 } 1359 messageDestReferences.add(messageDestRef); 1360 } 1361 1362 public void removeMessageDestinationReferenceDescriptor 1363 (MessageDestinationReferenceDescriptor msgDestRef) { 1364 messageDestReferences.remove(msgDestRef); 1365 } 1366 1367 1371 public MessageDestinationReferenceDescriptor 1372 getMessageDestinationReferenceByName(String name) { 1373 1374 for (MessageDestinationReferenceDescriptor mdr : messageDestReferences) { 1375 if (mdr.getName().equals(name)) { 1376 return mdr; 1377 } 1378 } 1379 throw new IllegalArgumentException ("This ejb has no message destination reference by the name " + name); 1380 } 1381 1382 1385 public Set<JmsDestinationReferenceDescriptor> getJmsDestinationReferenceDescriptors() { 1386 return jmsDestReferences; 1387 } 1388 1389 public void addJmsDestinationReferenceDescriptor(JmsDestinationReferenceDescriptor jmsDestReference) { 1390 jmsDestReferences.add(jmsDestReference); 1391 } 1392 1393 public void removeJmsDestinationReferenceDescriptor(JmsDestinationReferenceDescriptor jmsDestReference) { 1394 jmsDestReferences.remove(jmsDestReference); 1395 } 1396 1397 1400 public Set<ResourceReferenceDescriptor> getResourceReferenceDescriptors() { 1401 return resourceReferences; 1402 } 1403 1404 1406 public void addResourceReferenceDescriptor(ResourceReferenceDescriptor resourceReference) { 1407 resourceReferences.add(resourceReference); 1408 } 1409 1410 1413 public void removeResourceReferenceDescriptor(ResourceReferenceDescriptor resourceReference) { 1414 resourceReferences.remove(resourceReference); 1415 } 1416 1417 1418 1421 public Set<ResourceReferenceDescriptor> getResourceReferenceDescriptors(boolean resolved) { 1422 Set<ResourceReferenceDescriptor> toReturn = new HashSet<ResourceReferenceDescriptor>(); 1423 for (Iterator itr = this.getResourceReferenceDescriptors().iterator(); itr.hasNext();) { 1424 ResourceReferenceDescriptor next = (ResourceReferenceDescriptor) itr.next(); 1425 if (next.isResolved() == resolved) { 1426 toReturn.add(next); 1427 } 1428 } 1429 return toReturn; 1430 } 1431 1432 1436 public EnvironmentProperty getEnvironmentPropertyByName(String name) { 1437 for (Iterator itr = this.getEnvironmentProperties().iterator(); itr.hasNext();) { 1438 EnvironmentProperty ev = (EnvironmentProperty) itr.next(); 1439 if (ev.getName().equals(name)) { 1440 return ev; 1441 } 1442 } 1443 throw new IllegalArgumentException (localStrings.getLocalString( 1444 "enterprise.deployment.exceptionbeanhasnoenvpropertybyname", 1445 "This bean {0} has no environment property by the name of {1}", 1446 new Object [] {getName(), name})); 1447 } 1448 1449 1452 public EjbReference getEjbReference(String name) { 1453 for (Iterator itr = this.getEjbReferenceDescriptors().iterator(); itr.hasNext();) { 1454 EjbReference er = (EjbReference) itr.next(); 1455 if (er.getName().equals(name)) { 1456 return er; 1457 } 1458 } 1459 throw new IllegalArgumentException (localStrings.getLocalString( 1460 "enterprise.deployment.exceptionbeanhasnoejbrefbyname", 1461 "This bean {0} has no ejb reference by the name of {1}", 1462 new Object [] {getName(), name})); 1463 } 1464 1465 1466 1469 public EjbReferenceDescriptor getEjbReferenceByName(String name) { 1470 return (EjbReferenceDescriptor) getEjbReference(name); 1471 } 1472 1473 1476 public JmsDestinationReferenceDescriptor getJmsDestinationReferenceByName(String name) { 1477 for (Iterator itr = this.getJmsDestinationReferenceDescriptors().iterator(); itr.hasNext();) { 1478 JmsDestinationReferenceDescriptor jdr = (JmsDestinationReferenceDescriptor) itr.next(); 1479 if (jdr.getName().equals(name)) { 1480 return jdr; 1481 } 1482 } 1483 throw new IllegalArgumentException (localStrings.getLocalString( 1484 "enterprise.deployment.exceptionbeanhasnojmsdestrefbyname", 1485 "This bean {0} has no JMS destination reference by the name of {1}", 1486 new Object [] {getName(), name})); 1487 } 1488 1489 1492 1493 public void replaceEnvironmentProperty(EnvironmentProperty oldOne, EnvironmentProperty newOne) { 1494 environmentProperties.remove(oldOne); 1495 environmentProperties.add(newOne); 1496 } 1497 1498 1501 1502 public void removeEnvironmentProperty(EnvironmentProperty environmentProperty) { 1503 this.getEnvironmentProperties().remove(environmentProperty); 1504 this.changed(); 1505 } 1506 1507 1508 void removeRole(Role role) { 1509 this.getPermissionedMethodsByPermission().remove(new MethodPermission(role)); 1511 Set roleReferences = new HashSet(this.getRoleReferences()); 1512 for (Iterator itr = roleReferences.iterator(); itr.hasNext();) { 1513 RoleReference roleReference = (RoleReference) itr.next(); 1514 if (roleReference.getRole().equals(role)) { 1515 roleReference.setValue(""); 1516 } 1517 } 1518 } 1519 1520 1523 public ResourceReferenceDescriptor getResourceReferenceByName(String name) { 1524 for (Iterator itr = this.getResourceReferenceDescriptors().iterator(); itr.hasNext();) { 1525 ResourceReferenceDescriptor next = (ResourceReferenceDescriptor) itr.next(); 1526 if (next.getName().equals(name)) { 1527 return next; 1528 } 1529 } 1530 throw new IllegalArgumentException (localStrings.getLocalString( 1531 "enterprise.deployment.exceptionbeanhasnoresourcerefbyname", 1532 "This bean {0} has no resource reference by the name of {1}", 1533 new Object [] {getName(), name})); 1534 } 1535 1536 1539 public boolean hasResolvedResourceReferences() { 1540 if (!this.getResourceReferenceDescriptors().isEmpty()) { 1541 return false; 1542 } else { 1543 for (Iterator itr = this.getResourceReferenceDescriptors().iterator(); itr.hasNext();) { 1544 ResourceReferenceDescriptor resourceReference = (ResourceReferenceDescriptor) itr.next(); 1545 if (resourceReference.isResolved()) { 1546 return true; 1547 } 1548 } 1549 } 1550 return false; 1551 } 1552 1553 1554 public Set<EntityManagerFactoryReferenceDescriptor> 1555 getEntityManagerFactoryReferenceDescriptors() { 1556 1557 return entityManagerFactoryReferences; 1558 } 1559 1560 1564 public EntityManagerFactoryReferenceDescriptor 1565 getEntityManagerFactoryReferenceByName(String name) { 1566 for (EntityManagerFactoryReferenceDescriptor next : 1567 getEntityManagerFactoryReferenceDescriptors()) { 1568 1569 if (next.getName().equals(name)) { 1570 return next; 1571 } 1572 } 1573 throw new IllegalArgumentException (localStrings.getLocalString( 1574 "enterprise.deployment.exceptionbeanhasnoentitymgrfactoryrefbyname", 1575 "This ejb {0} has no entity manager factory reference by the name of {1}", 1576 new Object [] {getName(), name})); 1577 } 1578 1579 public void addEntityManagerFactoryReferenceDescriptor 1580 (EntityManagerFactoryReferenceDescriptor reference) { 1581 1582 if( getEjbBundleDescriptor() != null ) { 1583 reference.setReferringBundleDescriptor 1584 (getEjbBundleDescriptor()); 1585 } 1586 entityManagerFactoryReferences.add(reference); 1587 } 1588 1589 public Set<EntityManagerReferenceDescriptor> 1590 getEntityManagerReferenceDescriptors() { 1591 1592 return entityManagerReferences; 1593 } 1594 1595 1599 public EntityManagerReferenceDescriptor 1600 getEntityManagerReferenceByName(String name) { 1601 for (EntityManagerReferenceDescriptor next : 1602 getEntityManagerReferenceDescriptors()) { 1603 1604 if (next.getName().equals(name)) { 1605 return next; 1606 } 1607 } 1608 throw new IllegalArgumentException (localStrings.getLocalString( 1609 "enterprise.deployment.exceptionbeanhasnoentitymgrrefbyname", 1610 "This ejb {0} has no entity manager reference by the name of {1}", 1611 new Object [] {getName(), name})); 1612 } 1613 1614 public void addEntityManagerReferenceDescriptor 1615 (EntityManagerReferenceDescriptor reference) { 1616 if( getEjbBundleDescriptor() != null ) { 1617 reference.setReferringBundleDescriptor 1618 (getEjbBundleDescriptor()); 1619 } 1620 this.getEntityManagerReferenceDescriptors().add(reference); 1621 } 1622 1623 1624 1627 public Set<EnvironmentProperty> getEnvironmentProperties() { 1628 return environmentProperties; 1629 } 1630 1631 1632 1635 public void addEnvironmentProperty(EnvironmentProperty environmentProperty) { 1636 if (environmentProperties.contains(environmentProperty)) { 1637 replaceEnvironmentProperty(environmentProperty, environmentProperty); 1638 } else { 1639 environmentProperties.add(environmentProperty); 1640 } 1641 } 1642 1643 1646 public Set<RoleReference> getRoleReferences() { 1647 if (roleReferences == null) { 1648 roleReferences = new HashSet(); 1649 } 1650 return roleReferences; 1651 } 1652 1653 1656 1657 public void addRoleReference(RoleReference roleReference) { 1658 this.getRoleReferences().add(roleReference); 1660 this.changed(); 1661 } 1662 1663 1666 1667 public void removeRoleReference(RoleReference roleReference) { 1668 this.getRoleReferences().remove(roleReference); 1669 this.changed(); 1670 } 1671 1672 1675 public RoleReference getRoleReferenceByName(String roleReferenceName) { 1676 for (Iterator itr = this.getRoleReferences().iterator(); itr.hasNext();) { 1677 RoleReference nextRR = (RoleReference) itr.next(); 1678 if (nextRR.getName().equals( roleReferenceName )) { 1679 return nextRR; 1680 } 1681 } 1682 return null; 1683 } 1684 1685 public List<InjectionCapable> 1686 getInjectableResourcesByClass(String className) { 1687 return bundleDescriptor.getInjectableResourcesByClass 1688 (className, this); 1689 } 1690 1691 public InjectionInfo getInjectionInfoByClass(String className) { 1692 return bundleDescriptor.getInjectionInfoByClass(className, this); 1693 } 1694 1695 1698 public EjbBundleDescriptor getEjbBundleDescriptor() { 1699 return bundleDescriptor; 1700 } 1701 1702 public void setEjbBundleDescriptor(EjbBundleDescriptor bundleDescriptor) { 1703 this.bundleDescriptor = bundleDescriptor; 1704 } 1705 1706 1709 public Application getApplication() { 1710 if (getEjbBundleDescriptor() != null) { 1711 return getEjbBundleDescriptor().getApplication(); 1712 } 1713 return null; 1714 } 1715 1716 1720 public Set getMethodDescriptors() { 1721 1722 ClassLoader classLoader = getEjbBundleDescriptor().getClassLoader(); 1723 Set methods = new HashSet(); 1724 1725 try { 1726 if (isRemoteInterfacesSupported()) { 1727 addAllInterfaceMethodsIn(methods, classLoader.loadClass(getHomeClassName()), MethodDescriptor.EJB_HOME); 1728 addAllInterfaceMethodsIn(methods, classLoader.loadClass(getRemoteClassName()), MethodDescriptor.EJB_REMOTE); 1729 } 1730 1731 if (isRemoteBusinessInterfacesSupported()) { 1732 for(String intf : getRemoteBusinessClassNames()) { 1733 addAllInterfaceMethodsIn(methods, classLoader.loadClass(intf), MethodDescriptor.EJB_REMOTE); 1734 } 1735 } 1736 1737 if (isLocalInterfacesSupported()) { 1738 addAllInterfaceMethodsIn(methods, classLoader.loadClass(getLocalHomeClassName()), MethodDescriptor.EJB_LOCALHOME); 1739 addAllInterfaceMethodsIn(methods, classLoader.loadClass(getLocalClassName()), MethodDescriptor.EJB_LOCAL); 1740 } 1741 1742 if (isLocalBusinessInterfacesSupported()) { 1743 for(String intf : getLocalBusinessClassNames()) { 1744 addAllInterfaceMethodsIn(methods, classLoader.loadClass(intf), MethodDescriptor.EJB_LOCAL); 1745 } 1746 } 1747 1748 if (hasWebServiceEndpointInterface()) { 1749 addAllInterfaceMethodsIn(methods, classLoader.loadClass(getWebServiceEndpointInterfaceName()), MethodDescriptor.EJB_WEB_SERVICE); 1750 } 1751 } catch (Throwable t) { 1752 1758 _logger.log(Level.SEVERE,"enterprise.deployment.backend.methodClassLoadFailure",new Object [] {"(EjbDescriptor.getMethods())"}); 1759 1760 throw new RuntimeException (t); 1761 } 1762 return methods; 1763 } 1764 1765 1768 public Set getTxBusinessMethodDescriptors() { 1769 Set txBusMethods = getBusinessMethodDescriptors(); 1770 if (isTimedObject()) { 1771 txBusMethods.add(getEjbTimeoutMethod()); 1772 } 1773 return txBusMethods; 1774 } 1775 1776 1779 public Set getSecurityBusinessMethodDescriptors() { 1780 return getBusinessMethodDescriptors(); 1781 } 1782 1783 1786 private Set getBusinessMethodDescriptors() { 1787 1788 ClassLoader classLoader = getEjbBundleDescriptor().getClassLoader(); 1789 1790 Set methods = new HashSet(); 1791 1792 try { 1793 if (isRemoteInterfacesSupported()) { 1794 addAllInterfaceMethodsIn(methods, classLoader.loadClass(getRemoteClassName()), MethodDescriptor.EJB_REMOTE); 1795 } 1796 1797 if (isRemoteBusinessInterfacesSupported()) { 1798 for(String intf : getRemoteBusinessClassNames()) { 1799 addAllInterfaceMethodsIn(methods, classLoader.loadClass(intf), MethodDescriptor.EJB_REMOTE); 1800 } 1801 } 1802 1803 if (isLocalInterfacesSupported()) { 1804 addAllInterfaceMethodsIn(methods, classLoader.loadClass(getLocalClassName()), MethodDescriptor.EJB_LOCAL); 1805 } 1806 1807 if (isLocalBusinessInterfacesSupported()) { 1808 for(String intf : getLocalBusinessClassNames()) { 1809 addAllInterfaceMethodsIn(methods, classLoader.loadClass(intf), MethodDescriptor.EJB_LOCAL); 1810 } 1811 } 1812 1813 if (hasWebServiceEndpointInterface()) { 1814 addAllInterfaceMethodsIn(methods, classLoader.loadClass(getWebServiceEndpointInterfaceName()), MethodDescriptor.EJB_WEB_SERVICE); 1815 } 1816 } catch (Throwable t) { 1817 _logger.log(Level.SEVERE,"enterprise.deployment.backend.methodClassLoadFailure",new Object [] {"(EjbDescriptor.getBusinessMethodDescriptors())"}); 1818 1819 throw new RuntimeException (t); 1820 } 1821 return methods; 1822 } 1823 1824 protected void addAllInterfaceMethodsIn(Collection methodDescriptors, Class c, String methodIntf) { 1825 Method [] methods = c.getMethods(); 1826 for (int i=0;i<methods.length;i++) { 1827 methodDescriptors.add(new MethodDescriptor(methods[i], methodIntf)); 1828 } 1829 } 1830 1831 1835 public Collection getTransactionMethodDescriptors() { 1836 1837 return getTransactionMethods(getEjbBundleDescriptor().getClassLoader()); 1838 } 1839 1840 1844 protected Collection getTransactionMethods(ClassLoader classLoader) { 1845 1846 try { 1847 return BeanMethodCalculator.getTransactionalMethodsFor(this,classLoader); 1848 } catch (Throwable t) { 1849 1850 _logger.log(Level.SEVERE,"enterprise.deployment.backend.methodClassLoadFailure",new Object [] {"(EjbDescriptor.getMethods())"}); 1851 1852 throw new RuntimeException (t); 1853 } 1854 } 1855 1856 1859 1860 public Vector getMethods() { 1861 return getMethods(getEjbBundleDescriptor().getClassLoader()); 1862 } 1863 1864 1865 1868 public Vector getMethods(ClassLoader classLoader) { 1869 try { 1870 return BeanMethodCalculator.getMethodsFor(this, classLoader); 1871 } catch (Throwable t) { 1872 _logger.log(Level.SEVERE,"enterprise.deployment.backend.methodClassLoadFailure",new Object [] {"(EjbDescriptor.getMethods())"}); 1873 throw new RuntimeException (t); 1874 } 1875 } 1876 1877 1880 public Vector getFields() { 1881 Vector fieldsVector = new Vector(); 1882 Class ejb = null; 1883 try { 1884 ClassLoader cl = getEjbBundleDescriptor().getClassLoader(); 1885 ejb = cl.loadClass(this.getEjbClassName()); 1886 } catch (Throwable t) { 1887 _logger.log(Level.SEVERE,"enterprise.deployment.backend.methodClassLoadFailure",new Object [] {this.getEjbClassName()}); 1888 1889 return fieldsVector; 1890 } 1891 Field [] fields = ejb.getFields(); 1892 for (int i = 0; i < fields.length; i++) { 1893 fieldsVector.addElement(fields[i]); 1894 } 1895 return fieldsVector; 1896 1897 } 1898 1899 public Vector getFieldDescriptors() { 1900 Vector fields = this.getFields(); 1901 Vector fieldDescriptors = new Vector(); 1902 for(int fieldIndex = 0; fieldIndex < fields.size(); fieldIndex++) { 1903 Field field = (Field ) fields.elementAt(fieldIndex); 1904 fieldDescriptors.insertElementAt(new FieldDescriptor(field) , fieldIndex); 1905 } 1906 return fieldDescriptors; 1907 } 1908 1909 void doMethodDescriptorConversions() throws Exception { 1910 Hashtable transactions = this.getMethodContainerTransactions(); 1912 Hashtable convertedTransactions = new Hashtable(); 1914 Collection transactionMethods = this.getTransactionMethodDescriptors(); 1915 for (Enumeration e = transactions.keys(); e.hasMoreElements();) { 1916 MethodDescriptor md = (MethodDescriptor) e.nextElement(); 1917 ContainerTransaction ct = (ContainerTransaction) transactions.get(md); 1918 for (Enumeration mds = md.doStyleConversion(this, transactionMethods).elements(); mds.hasMoreElements();) { 1919 MethodDescriptor next = (MethodDescriptor) mds.nextElement(); 1920 convertedTransactions.put(next, new ContainerTransaction(ct)); 1921 } 1922 } 1923 setMethodContainerTransactions(convertedTransactions); 1925 1926 convertMethodPermissions(); 1927 } 1928 1929 public void removeEjbReferencer(EjbReferenceDescriptor ref) 1930 { 1931 ejbReferencersPointingToMe.remove(ref); 1932 } 1933 1934 void addEjbReferencer(EjbReferenceDescriptor ref) 1936 { 1937 ejbReferencersPointingToMe.add(ref); 1938 } 1939 1940 public Set getAllEjbReferencers() 1942 { 1943 return ejbReferencersPointingToMe; 1944 } 1945 1946 1947 public void setUniqueId(long id) 1949 { 1950 uniqueId = id; 1951 } 1952 1953 public long getUniqueId() 1954 { 1955 return uniqueId; 1956 } 1957 1958 1959 1962 1963 public void changed() { 1964 if (this.getEjbBundleDescriptor() != null) { 1965 this.getEjbBundleDescriptor().changed(); 1966 } else { 1967 super.changed(); 1968 } 1969 } 1970 1971 1974 public void print(StringBuffer toStringBuffer) { 1975 super.print(toStringBuffer); 1976 toStringBuffer.append("\n ejbClassName ").append(ejbClassName); 1977 toStringBuffer.append("\n transactionType ").append(transactionType); 1978 toStringBuffer.append("\n methodContainerTransactions ").append(getMethodContainerTransactions()); 1979 toStringBuffer.append("\n environmentProperties "); 1980 if(environmentProperties != null) 1981 printDescriptorSet(environmentProperties,toStringBuffer); 1982 toStringBuffer.append("\n ejbReferences "); 1983 if(ejbReferences != null) 1984 printDescriptorSet(ejbReferences,toStringBuffer); 1985 toStringBuffer.append("\n jmsDestReferences "); 1986 if(jmsDestReferences != null) 1987 printDescriptorSet(jmsDestReferences,toStringBuffer); 1988 toStringBuffer.append("\n messageDestReferences "); 1989 if(messageDestReferences != null) 1990 printDescriptorSet(messageDestReferences,toStringBuffer); 1991 toStringBuffer.append("\n resourceReferences "); 1992 if(resourceReferences != null) 1993 printDescriptorSet(resourceReferences,toStringBuffer); 1994 toStringBuffer.append("\n serviceReferences "); 1995 if(serviceReferences != null) 1996 printDescriptorSet(serviceReferences,toStringBuffer); 1997 toStringBuffer.append("\n roleReferences "); 1998 if(roleReferences != null) 1999 printDescriptorSet(roleReferences,toStringBuffer); 2000 for (Iterator e = this.getPermissionedMethodsByPermission().keySet().iterator(); e.hasNext();) { 2001 MethodPermission nextPermission = (MethodPermission) e.next(); 2002 toStringBuffer.append("\n method-permission->method: "); 2003 nextPermission.print(toStringBuffer); 2004 toStringBuffer.append(" -> ").append(this.getPermissionedMethodsByPermission().get(nextPermission)); 2005 } 2006 } 2007 private void printDescriptorSet(Set descSet, StringBuffer sbuf){ 2008 for(Iterator itr = descSet.iterator(); itr.hasNext();){ 2009 Object obj = itr.next(); 2010 if(obj instanceof Descriptor) 2011 ((Descriptor)obj).print(sbuf); 2012 else 2013 sbuf.append(obj); 2014 } 2015 } 2016 2017 2022 public void visit(DescriptorVisitor aVisitor) { 2023 if (aVisitor instanceof EjbVisitor) { 2024 visit((EjbVisitor) aVisitor); 2025 } else { 2026 super.visit(aVisitor); 2027 } 2028 } 2029 2030 2035 public void visit(EjbVisitor aVisitor) { 2036 aVisitor.accept(this); 2037 2038 for(InjectionCapable injectable : 2041 bundleDescriptor.getInjectableResources(this)) { 2042 aVisitor.accept(injectable); 2043 } 2044 2045 for (Iterator itr = ejbReferences.iterator();itr.hasNext();) { 2046 EjbReference aRef = (EjbReference) itr.next(); 2047 aVisitor.accept(aRef); 2048 } 2049 for (Iterator e = getPermissionedMethodsByPermission().keySet().iterator(); e.hasNext();) { 2050 MethodPermission nextPermission = (MethodPermission) e.next(); 2051 Set methods = (Set) getPermissionedMethodsByPermission().get(nextPermission); 2052 aVisitor.accept( nextPermission, methods.iterator()) ; 2053 } 2054 if (getStyledPermissionedMethodsByPermission()!=null) { 2055 for (Iterator e = getStyledPermissionedMethodsByPermission().keySet().iterator(); e.hasNext();) { 2056 MethodPermission nextPermission = (MethodPermission) e.next(); 2057 Set methods = (Set) getStyledPermissionedMethodsByPermission().get(nextPermission); 2058 aVisitor.accept( nextPermission, methods.iterator()) ; 2059 } 2060 } 2061 for (Iterator e = getRoleReferences().iterator();e.hasNext();) { 2062 RoleReference roleRef = (RoleReference) e.next(); 2063 aVisitor.accept( roleRef); 2064 } 2065 for (Iterator e=getMethodContainerTransactions().keySet().iterator();e.hasNext();) { 2066 MethodDescriptor md = (MethodDescriptor) e.next(); 2067 ContainerTransaction ct = (ContainerTransaction) getMethodContainerTransactions().get(md); 2068 aVisitor.accept(md, ct); 2069 } 2070 for (Iterator e=getEnvironmentProperties().iterator();e.hasNext();) { 2071 EnvironmentProperty envProp = (EnvironmentProperty) e.next(); 2072 aVisitor.accept(envProp); 2073 } 2074 2075 for (Iterator it=getResourceReferenceDescriptors().iterator(); 2076 it.hasNext();) { 2077 ResourceReferenceDescriptor next = 2078 (ResourceReferenceDescriptor) it.next(); 2079 aVisitor.accept(next); 2080 } 2081 2082 for (Iterator it=getJmsDestinationReferenceDescriptors().iterator(); 2083 it.hasNext();) { 2084 JmsDestinationReferenceDescriptor next = 2085 (JmsDestinationReferenceDescriptor) it.next(); 2086 aVisitor.accept(next); 2087 } 2088 2089 for (Iterator it=getMessageDestinationReferenceDescriptors().iterator(); 2090 it.hasNext();) { 2091 MessageDestinationReferencer next = 2092 (MessageDestinationReferencer) it.next(); 2093 aVisitor.accept(next); 2094 } 2095 2096 if( getType().equals(EjbMessageBeanDescriptor.TYPE) ) { 2099 MessageDestinationReferencer msgDestReferencer = 2100 (MessageDestinationReferencer) this; 2101 if( msgDestReferencer.getMessageDestinationLinkName() != null ) { 2102 aVisitor.accept(msgDestReferencer); 2103 } 2104 } 2105 2106 Set serviceRefs = getServiceReferenceDescriptors(); 2107 for (Iterator itr = serviceRefs.iterator();itr.hasNext();) { 2108 aVisitor.accept((ServiceReferenceDescriptor) itr.next()); 2109 } 2110 } 2111 2112 2113 2114 2115} 2116 2117 | Popular Tags |