1 23 24 package com.sun.enterprise.deployment; 25 26 import java.util.*; 27 import java.io.File ; 28 import java.util.logging.*; 29 import com.sun.logging.*; 30 31 import com.sun.enterprise.deployment.Role; 32 import com.sun.enterprise.util.LocalStringManagerImpl; 33 34 import com.sun.enterprise.deployment.node.ejb.EjbBundleNode; 35 import com.sun.enterprise.deployment.runtime.common.SecurityRoleMapping; 36 import com.sun.enterprise.deployment.runtime.IASPersistenceManagerDescriptor; 37 import com.sun.enterprise.deployment.runtime.PersistenceManagerInUse; 38 import com.sun.enterprise.deployment.util.DescriptorVisitor; 39 import com.sun.enterprise.deployment.util.DOLUtils; 40 import com.sun.enterprise.deployment.util.EjbBundleVisitor; 41 import com.sun.enterprise.deployment.util.EjbVisitor; 42 import com.sun.enterprise.deployment.util.LogDomains; 43 import com.sun.enterprise.deployment.xml.ApplicationTagNames; 44 import javax.enterprise.deploy.shared.ModuleType ; 45 46 52 53 public class EjbBundleDescriptor extends BundleDescriptor { 54 55 public final static String SPEC_VERSION = "2.1"; 56 57 private long uniqueId; 58 private Set ejbs = new HashSet(); 59 private Set relationships = new HashSet(); 60 private String relationshipsDescription; 61 private String ejbClientJarUri; 62 63 private Vector configured_pms = null; 65 private PersistenceManagerInUse pm_inuse = null; 66 67 private ResourceReferenceDescriptor cmpResourceReference; 70 71 private Set<EjbApplicationExceptionInfo> applicationExceptions = 73 new HashSet<EjbApplicationExceptionInfo>(); 74 75 private static LocalStringManagerImpl localStrings = 76 new LocalStringManagerImpl(EjbBundleDescriptor.class); 77 78 static Logger _logger = DOLUtils.getDefaultLogger(); 79 80 private List<SecurityRoleMapping> roleMaps = new ArrayList<SecurityRoleMapping>(); 81 82 private Map<String , EjbInterceptor> interceptors = 85 new HashMap<String , EjbInterceptor>(); 86 87 private LinkedList<InterceptorBindingDescriptor> interceptorBindings = 88 new LinkedList<InterceptorBindingDescriptor>(); 89 90 93 public EjbBundleDescriptor() { 94 } 95 96 100 public boolean isEJB20() { 105 return !isEJB11(); 106 } 107 108 111 public boolean isEJB11() { 112 return getSpecVersion().startsWith("1"); 113 } 114 115 119 public String getDefaultSpecVersion() { 120 return EjbBundleNode.SPEC_VERSION; 121 } 122 123 127 public String getEjbClientJarUri() { 128 if (this.ejbClientJarUri == null) { 129 this.ejbClientJarUri = ""; 130 } 131 return this.ejbClientJarUri; 132 } 133 134 137 138 public void setEjbClientJarUri(String ejbClientJarUri) { 139 this.ejbClientJarUri = ejbClientJarUri; 140 this.changed(); 141 } 142 143 public void addApplicationException(EjbApplicationExceptionInfo appExc) { 144 applicationExceptions.add(appExc); 145 } 146 147 public Set<EjbApplicationExceptionInfo> getApplicationExceptions() { 148 return new HashSet<EjbApplicationExceptionInfo>(applicationExceptions); 149 } 150 151 public void addEjbBundleDescriptor(EjbBundleDescriptor ejbBundleDescriptor) { 152 super.addBundleDescriptor(ejbBundleDescriptor); 153 154 for (Iterator ejbs = ejbBundleDescriptor.getEjbs().iterator(); ejbs.hasNext();) { 157 EjbDescriptor ejbDescriptor = (EjbDescriptor)ejbs.next(); 158 ejbDescriptor.setEjbBundleDescriptor(this); 159 this.getEjbs().add(ejbDescriptor); 160 } 161 162 WebServicesDescriptor thisWebServices = this.getWebServices(); 164 WebServicesDescriptor otherWebServices = ejbBundleDescriptor.getWebServices(); 165 for (Iterator i = otherWebServices.getWebServices().iterator(); i.hasNext();) { 166 WebService ws = (WebService)i.next(); 167 thisWebServices.addWebService(new WebService(ws)); 168 } 169 170 this.changed(); 171 } 172 173 176 public Collection getNamedDescriptors() { 177 Collection namedDescriptors = new Vector(); 178 for (Iterator ejbs = this.getEjbs().iterator(); ejbs.hasNext();) { 179 EjbDescriptor ejbDescriptor = (EjbDescriptor) ejbs.next(); 180 namedDescriptors.add(ejbDescriptor); 181 namedDescriptors.addAll(super.getNamedDescriptorsFrom(ejbDescriptor)); 182 } 183 return namedDescriptors; 184 } 185 186 190 191 public Vector getNamedReferencePairs() { 192 Vector pairs = new Vector(); 193 for (Iterator ejbs = this.getEjbs().iterator(); ejbs.hasNext();) { 194 EjbDescriptor ejbDescriptor = (EjbDescriptor) ejbs.next(); 195 pairs.add(NamedReferencePair.createEjbPair(ejbDescriptor, 196 ejbDescriptor)); 197 pairs.addAll(super.getNamedReferencePairsFrom(ejbDescriptor)); 198 } 199 return pairs; 200 } 201 202 205 public Set getResourceReferenceDescriptors() { 206 Set resourceReferences = new HashSet(); 207 for (Iterator itr = this.getEjbs().iterator(); itr.hasNext();) { 208 EjbDescriptor ejbDescriptor = (EjbDescriptor) itr.next(); 209 resourceReferences.addAll(ejbDescriptor.getResourceReferenceDescriptors()); 210 } 211 return resourceReferences; 212 } 213 214 217 public boolean hasEjbReferences() { 218 for (Iterator itr = this.getEjbs().iterator(); itr.hasNext();) { 219 EjbDescriptor nextEjbDescriptor = (EjbDescriptor) itr.next(); 220 if (!nextEjbDescriptor.getEjbReferenceDescriptors().isEmpty()) { 221 return true; 222 } 223 } 224 return false; 225 } 226 227 230 public Set getEjbs() { 231 return this.ejbs; 232 } 233 234 237 public boolean hasEjbByName(String name) { 238 for (Iterator itr = this.getEjbs().iterator(); itr.hasNext();) { 239 Descriptor next = (Descriptor) itr.next(); 240 if (next.getName().equals(name)) { 241 return true; 242 } 243 } 244 return false; 245 } 246 247 251 public EjbDescriptor getEjbByName(String name) { 252 for (Iterator itr = this.getEjbs().iterator(); itr.hasNext();) { 253 Descriptor next = (Descriptor) itr.next(); 254 if (next.getName().equals(name)) { 255 return (EjbDescriptor) next; 256 } 257 } 258 throw new IllegalArgumentException (localStrings.getLocalString( 259 "enterprise.deployment.exceptionbeanbundle", 260 "Referencing error: this bundle has no bean of name: {0}", 261 new Object [] {name})); 262 } 263 264 268 public EjbDescriptor[] getEjbByClassName(String className) { 269 ArrayList<EjbDescriptor> ejbList = new ArrayList<EjbDescriptor>(); 270 for (Object ejb : this.getEjbs()) { 271 if (ejb instanceof EjbDescriptor) { 272 EjbDescriptor ejbDesc = (EjbDescriptor)ejb; 273 if (className.equals(ejbDesc.getEjbClassName())) { 274 ejbList.add(ejbDesc); 275 } 276 } 277 } 278 return ejbList.toArray(new EjbDescriptor[ejbList.size()]); 279 } 280 281 284 public void addEjb(EjbDescriptor ejbDescriptor) { 285 ejbDescriptor.setEjbBundleDescriptor(this); 286 this.getEjbs().add(ejbDescriptor); 287 super.changed(); 288 } 289 290 293 294 public void removeEjb(EjbDescriptor ejbDescriptor) { 295 ejbDescriptor.setEjbBundleDescriptor(null); 296 this.getEjbs().remove(ejbDescriptor); 297 super.changed(); 298 } 299 300 301 304 void replaceEjb(EjbDescriptor oldEjbDescriptor, EjbDescriptor newEjbDescriptor) { 305 oldEjbDescriptor.setEjbBundleDescriptor(null); 306 this.getEjbs().remove(oldEjbDescriptor); 307 newEjbDescriptor.setEjbBundleDescriptor(this); 308 this.getEjbs().add(newEjbDescriptor); 309 } 311 312 316 public boolean containsCMPEntity() { 317 318 Set ejbs = getEjbs(); 319 if (ejbs==null) 320 return false; 321 for (Iterator ejbsItr = ejbs.iterator();ejbsItr.hasNext();) { 322 if (ejbsItr.next() instanceof EjbCMPEntityDescriptor) { 323 return true; 324 } 325 } 326 return false; 327 } 328 329 public void addInterceptor(EjbInterceptor interceptor) { 330 EjbInterceptor ic = 331 getInterceptorByClassName(interceptor.getInterceptorClassName()); 332 if (ic == null) { 333 interceptor.setEjbBundleDescriptor(this); 334 interceptors.put(interceptor.getInterceptorClassName(), interceptor); 335 } 336 } 337 338 public EjbInterceptor getInterceptorByClassName(String className) { 339 340 return interceptors.get(className); 341 342 } 343 344 public boolean hasInterceptors() { 345 346 return (interceptors.size() > 0); 347 348 } 349 350 public Set<EjbInterceptor> getInterceptors() { 351 352 return new HashSet<EjbInterceptor>(interceptors.values()); 353 354 } 355 356 public void prependInterceptorBinding(InterceptorBindingDescriptor binding) 357 { 358 interceptorBindings.addFirst(binding); 359 } 360 361 public void appendInterceptorBinding(InterceptorBindingDescriptor binding) 362 { 363 interceptorBindings.addLast(binding); 364 } 365 366 public List<InterceptorBindingDescriptor> getInterceptorBindings() { 367 return new LinkedList<InterceptorBindingDescriptor> 368 (interceptorBindings); 369 } 370 371 public void setInterceptorBindings(List<InterceptorBindingDescriptor> 372 bindings) { 373 interceptorBindings = new LinkedList<InterceptorBindingDescriptor>(); 374 interceptorBindings.addAll(bindings); 375 } 376 377 380 381 public boolean areResourceReferencesValid() { 382 for (Iterator itr = this.getEjbs().iterator(); itr.hasNext();) { 384 EjbDescriptor ejbDescriptor = (EjbDescriptor) itr.next(); 385 for (Iterator roleRefs = ejbDescriptor.getRoleReferences().iterator(); roleRefs.hasNext();) { 386 RoleReference roleReference = (RoleReference) roleRefs.next(); 387 Role referredRole = roleReference.getRole(); 388 if (!referredRole.getName().equals("") 389 && !super.getRoles().contains(referredRole) ) { 390 391 _logger.log(Level.FINE,localStrings.getLocalString( 392 "enterprise.deployment.badrolereference", 393 "Warning: Bad role reference to {0}", new Object [] {referredRole})); 394 _logger.log(Level.FINE,"Roles: "+ this.getRoles()); 395 return false; 396 } 397 } 398 } 399 return true; 400 } 401 402 405 public void removeRole(Role role) { 406 if (super.getRoles().contains(role)) { 407 for (Iterator itr = this.getEjbs().iterator(); itr.hasNext();) { 408 EjbDescriptor ejbDescriptor = (EjbDescriptor) itr.next(); 409 ejbDescriptor.removeRole(role); 410 } 411 super.removeRole(role); 412 } 413 } 414 415 418 public boolean hasPermissionedRoles() { 419 for (Iterator itr = this.getEjbs().iterator(); itr.hasNext();) { 420 EjbDescriptor nextEjbDescriptor = (EjbDescriptor) itr.next(); 421 if (!nextEjbDescriptor.getPermissionedMethodsByPermission().isEmpty()) { 422 return true; 423 } 424 } 425 return false; 426 } 427 428 431 public boolean hasContainerTransactions() { 432 for (Iterator itr = this.getEjbs().iterator(); itr.hasNext();) { 433 EjbDescriptor nextEjbDescriptor = (EjbDescriptor) itr.next(); 434 if (!nextEjbDescriptor.getMethodContainerTransactions().isEmpty()) { 435 return true; 436 } 437 } 438 return false; 439 } 440 441 444 public boolean hasAssemblyInformation() { 445 return (!this.getRoles().isEmpty()) 446 || this.hasPermissionedRoles() 447 || this.hasContainerTransactions(); 448 449 } 450 451 455 public void addRelationship(RelationshipDescriptor relDesc) 456 { 457 relationships.add(relDesc); 458 super.changed(); 459 } 460 461 465 public void removeRelationship(RelationshipDescriptor relDesc) 466 { 467 relationships.remove(relDesc); 468 super.changed(); 469 } 470 471 472 475 public String getRelationshipsDescription() { 476 if ( relationshipsDescription == null ) 477 relationshipsDescription = ""; 478 return relationshipsDescription; 479 } 480 481 484 public void setRelationshipsDescription(String relationshipsDescription) { 485 this.relationshipsDescription = relationshipsDescription; 486 } 487 488 489 493 public Set getRelationships() 494 { 495 return relationships; 496 } 497 498 public boolean hasRelationships() 499 { 500 return (relationships.size() > 0); 501 } 502 503 507 public boolean hasRelationship(RelationshipDescriptor rd) { 508 return relationships.contains(rd); 509 } 510 511 514 public ResourceReferenceDescriptor getCMPResourceReference() { 515 return this.cmpResourceReference; 516 } 517 518 521 public void setCMPResourceReference(ResourceReferenceDescriptor resourceReference) { 522 this.cmpResourceReference = resourceReference; 523 this.changed(); 524 } 525 526 527 528 public Descriptor getDescriptorByName(String name) 529 { 530 try { 531 return getEjbByName(name); 532 } catch(IllegalArgumentException iae) { 533 return null; 535 } 536 } 537 538 541 542 public String getName() { 543 if ("".equals(super.getName())) { 544 super.setName("Ejb1"); 545 } 546 return super.getName(); 547 } 548 549 private void doMethodDescriptorConversions() throws Exception { 550 for (Iterator itr = this.getEjbs().iterator(); itr.hasNext();) { 551 EjbDescriptor ejbDescriptor = (EjbDescriptor) itr.next(); 552 ejbDescriptor.doMethodDescriptorConversions(); 553 } 554 } 555 556 566 public void setUniqueId(long id) 567 { 568 this.uniqueId = id; 569 570 EjbDescriptor[] descs = (EjbDescriptor[])ejbs.toArray( 572 new EjbDescriptor[ejbs.size()]); 573 574 575 Arrays.sort(descs, 579 new Comparator() { 580 public int compare(Object o1, Object o2) { 581 return (((EjbDescriptor)o1).getName()).compareTo( 582 ((EjbDescriptor)o2).getName()); 583 } 584 } 585 ); 586 587 for (int i=0; i<descs.length; i++) 588 { 589 descs[i].setUniqueId( (id | i) ); 591 } 592 } 593 594 600 public long getUniqueId() 601 { 602 return uniqueId; 603 } 604 605 public static int getIdFromEjbId(long ejbId) 606 { 607 long id = ejbId >> 32; 608 return (int)id; 609 } 610 611 614 public boolean hasWebServiceClients() { 615 for(Iterator ejbs = getEjbs().iterator();ejbs.hasNext();) { 616 EjbDescriptor next = (EjbDescriptor) ejbs.next(); 617 Collection serviceRefs = next.getServiceReferenceDescriptors(); 618 if( !(serviceRefs.isEmpty()) ) { 619 return true; 620 } 621 } 622 return false; 623 } 624 625 629 public Set getServiceReferenceDescriptors() { 630 Set serviceRefs = new OrderedSet(); 631 for(Iterator ejbs = getEjbs().iterator();ejbs.hasNext();) { 632 EjbDescriptor next = (EjbDescriptor) ejbs.next(); 633 serviceRefs.addAll(next.getServiceReferenceDescriptors()); 634 } 635 return serviceRefs; 636 } 637 638 641 public void print(StringBuffer toStringBuffer) { 642 toStringBuffer.append("EjbBundleDescriptor\n"); 643 super.print(toStringBuffer); 644 if (cmpResourceReference!=null) { 645 toStringBuffer.append("\ncmp resource "); 646 ((Descriptor)cmpResourceReference).print(toStringBuffer); 647 } 648 toStringBuffer.append("\nclient JAR ").append(this.getEjbClientJarUri()); 649 for (Iterator itr = this.getEjbs().iterator(); itr.hasNext();) { 650 toStringBuffer.append("\n------------\n"); 651 ((Descriptor)itr.next()).print(toStringBuffer); 652 toStringBuffer.append("\n------------") ; 653 } 654 } 655 656 661 public void visit(DescriptorVisitor aVisitor) { 662 if (aVisitor instanceof EjbBundleVisitor) { 663 visit((EjbBundleVisitor) aVisitor); 664 } else { 665 super.visit(aVisitor); 666 } 667 } 668 669 674 public void visit(EjbBundleVisitor aVisitor) { 675 aVisitor.accept(this); 676 EjbVisitor ejbVisitor = aVisitor.getEjbVisitor(); 677 if (ejbVisitor != null) { 678 for (Iterator itr = this.getEjbs().iterator(); itr.hasNext();) { 679 EjbDescriptor anEjb = (EjbDescriptor) itr.next(); 680 anEjb.visit(ejbVisitor); 681 } 682 } 683 if (hasRelationships()) { 684 for (Iterator itr = getRelationships().iterator();itr.hasNext();) { 685 RelationshipDescriptor rd = (RelationshipDescriptor) itr.next(); 686 aVisitor.accept(rd); 687 } 688 } 689 for (Iterator itr=getWebServices().getWebServices().iterator(); 690 itr.hasNext(); ) { 691 WebService aWebService = (WebService) itr.next(); 692 aVisitor.accept(aWebService); 693 } 694 for (Iterator itr = getMessageDestinations().iterator(); 695 itr.hasNext();) { 696 MessageDestinationDescriptor msgDestDescriptor = 697 (MessageDestinationDescriptor)itr.next(); 698 aVisitor.accept(msgDestDescriptor); 699 } 700 } 701 702 705 public ModuleType getModuleType() { 706 return ModuleType.EJB; 707 } 708 709 public void setPersistenceManagerInuse(String id,String ver) 710 { 711 pm_inuse=new PersistenceManagerInUse(id, ver); 712 if (_logger.isLoggable(Level.FINE)) 713 _logger.fine("***IASEjbBundleDescriptor" 714 + ".setPersistenceManagerInUse done -#- "); 715 } 716 717 public void setPersistenceManagerInUse(PersistenceManagerInUse inuse) { 718 pm_inuse = inuse; 719 } 720 721 public PersistenceManagerInUse getPersistenceManagerInUse() 722 { 723 return pm_inuse; 724 } 725 726 public void addPersistenceManager(IASPersistenceManagerDescriptor pmDesc) 727 { 728 if (configured_pms==null) { 729 configured_pms=new Vector(); 730 } 731 configured_pms.add(pmDesc); 732 if (_logger.isLoggable(Level.FINE)) 733 _logger.fine("***IASEjbBundleDescriptor" 734 + ".addPersistenceManager done -#- "); 735 } 736 737 public IASPersistenceManagerDescriptor getPreferredPersistenceManager() 738 { 739 boolean debug = _logger.isLoggable(Level.FINE); 740 741 if (configured_pms == null || configured_pms.size() == 0) { 742 return null; 744 } 745 746 String pminuse_id = pm_inuse.get_pm_identifier().trim(); 747 String pminuse_ver = pm_inuse.get_pm_version().trim(); 748 if (debug) { 749 _logger.fine("IASPersistenceManagerDescriptor.getPreferred - inid*" + 750 pminuse_id.trim() + "*"); 751 _logger.fine("IASPersistenceManagerDescriptor.getPreferred - inver*" + 752 pminuse_ver.trim() + "*"); 753 } 754 755 int size = configured_pms.size(); 756 for(int i = 0; i < size; i++) { 757 IASPersistenceManagerDescriptor pmdesc=(IASPersistenceManagerDescriptor)configured_pms.elementAt(i); 758 String pmdesc_id = pmdesc.getPersistenceManagerIdentifier(); 759 String pmdesc_ver = pmdesc.getPersistenceManagerVersion(); 760 761 if (debug) { 762 _logger.fine("IASPersistenceManagerDescriptor.getPreferred - pmid*" + 763 pmdesc_id.trim() + "*"); 764 _logger.fine("IASPersistenceManagerDescriptor.getPreferred - pmver*" + 765 pmdesc_ver.trim() + "*"); 766 } 767 768 769 if( ((pmdesc_id.trim()).equals(pminuse_id)) && 770 ((pmdesc_ver.trim()).equals(pminuse_ver)) ) { 771 772 if (debug) 773 _logger.fine("***IASEjbBundleDescriptor.getPreferredPersistenceManager done -#- "); 774 775 return (IASPersistenceManagerDescriptor)pmdesc; 776 } 777 } 778 throw new IllegalArgumentException (localStrings.getLocalString( 779 "enterprise.deployment.nomatchingpminusefound", 780 "No PersistenceManager found that matches specified PersistenceManager in use.")); 781 } 782 783 public Vector getPersistenceManagers() 784 { 785 if (_logger.isLoggable(Level.FINE)) 786 _logger.fine("***IASEjbBundleDescriptor.getPersistenceManagers done -#- "); 787 return configured_pms; 788 } 789 790 public void addSecurityRoleMapping(SecurityRoleMapping roleMapping) { 791 roleMaps.add(roleMapping); 792 } 793 794 public List<SecurityRoleMapping> getSecurityRoleMappings() { 795 return roleMaps; 796 } 797 } 798 | Popular Tags |