1 23 package com.sun.enterprise.deployment; 24 25 import com.sun.enterprise.deployment.archivist.AppClientArchivist; 26 import com.sun.enterprise.deployment.archivist.ApplicationArchivist; 27 import com.sun.enterprise.deployment.archivist.EjbArchivist; 28 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive; 29 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 30 import com.sun.enterprise.deployment.deploy.shared.InputJarArchive; 31 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapper; 32 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapperFactory; 33 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapperFactoryMgr; 34 import com.sun.enterprise.deployment.node.ApplicationNode; 35 import com.sun.enterprise.deployment.Role; 36 import com.sun.enterprise.deployment.runtime.common.SecurityRoleMapping; 37 import com.sun.enterprise.deployment.types.RoleMappingContainer; 38 import com.sun.enterprise.deployment.util.AppClientVisitor; 39 import com.sun.enterprise.deployment.util.ApplicationVisitor; 40 import com.sun.enterprise.deployment.util.ConnectorVisitor; 41 import com.sun.enterprise.deployment.util.DescriptorVisitor; 42 import com.sun.enterprise.deployment.util.DOLUtils; 43 import com.sun.enterprise.deployment.util.EjbBundleVisitor; 44 import com.sun.enterprise.deployment.util.EjbComponentAnnotationDetector; 45 import com.sun.enterprise.deployment.util.ModuleDescriptor; 46 import com.sun.enterprise.deployment.util.WebBundleVisitor; 47 import com.sun.enterprise.util.LocalStringManagerImpl; 48 import com.sun.enterprise.util.NotificationEvent; 49 import com.sun.enterprise.util.NotificationListener; 50 import com.sun.enterprise.util.io.FileUtils; 51 52 import java.io.File ; 53 import java.io.FilenameFilter ; 54 import java.io.IOException ; 55 import java.net.URI ; 56 import java.net.URISyntaxException ; 57 import java.util.ArrayList ; 58 import java.util.Arrays ; 59 import java.util.Collection ; 60 import java.util.Comparator ; 61 import java.util.Enumeration ; 62 import java.util.HashMap ; 63 import java.util.HashSet ; 64 import java.util.Hashtable ; 65 import java.util.Iterator ; 66 import java.util.List ; 67 import java.util.logging.Level ; 68 import java.util.logging.Logger ; 69 import java.util.Map ; 70 import java.util.Set ; 71 import java.util.StringTokenizer ; 72 import java.util.Vector ; 73 74 import javax.enterprise.deploy.shared.ModuleType ; 75 import javax.persistence.EntityManagerFactory; 76 77 82 83 public class Application extends RootDeploymentDescriptor 84 implements NotificationListener, Roles, RoleMappingContainer { 85 86 87 private static final String LIBRARY_DIRECTORY_DEFAULT_VALUE = "lib"; 88 89 private static final String PERSISTENCE_UNIT_NAME_SEPARATOR = "#"; 90 91 94 private String generatedXMLDir; 95 96 private Set modules = new HashSet (); 98 99 101 private long uniqueId; 102 103 105 private boolean virtual = false; 106 107 110 private Boolean passByReference = null; 111 112 private Hashtable cmpDescriptors = null; 115 116 private boolean isDirty; 119 120 private SecurityRoleMapper roleMapper; 122 123 125 private String registrationName; 126 127 private String realm; 129 130 private Map <String , EntityManagerFactory> entityManagerFactories = 133 new HashMap <String , EntityManagerFactory>(); 134 135 private Set <String > entityManagerFactoryUnitNames = 136 new HashSet <String >(); 137 138 private static LocalStringManagerImpl localStrings= 140 new LocalStringManagerImpl(Application.class); 141 142 private Set appRoles; 143 144 private String libraryDirectory; 145 146 private List <SecurityRoleMapping> roleMaps = new ArrayList <SecurityRoleMapping>(); 147 148 private boolean loadedFromApplicationXml = true; 149 150 private List resourceList = null; 151 152 159 public Application(String name, File jar) { 160 super(name, localStrings.getLocalString( 161 "enterprise.deployment.application.description", 162 "Application description")); 163 } 164 165 public Application() { 166 super("", localStrings.getLocalString( 167 "enterprise.deployment.application.description", 168 "Application description")); 169 } 170 171 172 175 static Logger _logger = com.sun.enterprise.deployment.util.LogDomains.getLogger(com.sun.enterprise.deployment.util.LogDomains.DPL_LOGGER); 176 177 178 182 public String getDefaultSpecVersion() { 183 return ApplicationNode.SPEC_VERSION; 184 } 185 186 192 public static Application createApplication(String name, ModuleDescriptor newModule) { 193 194 Application application = new Application(); 196 application.setVirtual(true); 197 if (name==null && newModule.getDescriptor()!=null) { 198 name = newModule.getDescriptor().getDisplayName(); 199 200 } 201 if (name!=null) { 202 application.setDisplayName(name); 203 application.setName(name); 204 } 205 206 newModule.setStandalone(true); 208 newModule.setArchiveUri(name); 209 if (newModule.getDescriptor()!=null) { 210 newModule.getDescriptor().setApplication(application); 211 } 212 application.addModule(newModule); 213 214 return application; 215 } 216 217 226 public static Application createApplication( 227 AbstractArchive archive, boolean introspect) { 228 return createApplication(archive, introspect, false); 229 } 230 231 241 public static Application createApplication( 242 AbstractArchive archive, boolean introspect, boolean directory) { 243 if (introspect) { 244 return getApplicationFromIntrospection(archive, directory); 245 } else { 246 return getApplicationFromAppXml(archive); 247 } 248 } 249 250 private static Application getApplicationFromAppXml(AbstractArchive archive) { 251 ApplicationArchivist archivist = new ApplicationArchivist(); 252 archivist.setXMLValidation(false); 253 254 Application application = null; 256 try { 257 application = 258 (Application) archivist.readStandardDeploymentDescriptor(archive); 259 } catch (Exception ex) { 260 _logger.log(Level.SEVERE, 262 "Error loading application.xml from " + archive.getArchiveUri()); 263 _logger.log(Level.SEVERE, ex.getMessage()); 264 } 265 266 return application; 267 } 268 269 276 private static Application getApplicationFromIntrospection( 277 AbstractArchive archive, boolean directory) { 278 String appRoot = archive.getArchiveUri(); Application app = new Application(); 280 app.setLoadedFromApplicationXml(false); 281 app.setVirtual(false); 282 283 String appName = appRoot.substring( 285 appRoot.lastIndexOf(File.separatorChar)+1); 286 app.setName(appName); 287 288 List <AbstractArchive> unknowns = new ArrayList (); 289 File [] files = getEligibleEntries(new File (appRoot), directory); 290 for (File subModule : files) { 291 AbstractArchive subArchive = null; 292 try { 293 try { 294 if (!directory) { 295 subArchive = new InputJarArchive(); 296 ((InputJarArchive)subArchive).open(subModule.getAbsolutePath()); 297 } else { 298 subArchive = new FileArchive(); 299 ((FileArchive)subArchive).open(subModule.getAbsolutePath()); 300 } 301 } catch (IOException ex) { 302 _logger.log(Level.WARNING, ex.getMessage()); 303 } 304 305 309 String name = subModule.getName(); 311 String uri = deriveArchiveUri(appRoot, subModule, directory); 312 if ( (!directory && name.endsWith(".war")) 313 || (directory && name.endsWith("_war")) ) { 314 String contextRoot = 315 uri.substring(uri.lastIndexOf('/')+1, uri.lastIndexOf('.')); 316 ModuleDescriptor md = new ModuleDescriptor(); 317 md.setArchiveUri(uri); 318 md.setModuleType(ModuleType.WAR); 319 md.setContextRoot(contextRoot); 320 app.addModule(md); 321 } 322 else if ( (!directory && name.endsWith(".rar")) 324 || (directory && name.endsWith("_rar")) ) { 325 ModuleDescriptor md = new ModuleDescriptor(); 326 md.setArchiveUri(uri); 327 md.setModuleType(ModuleType.RAR); 328 app.addModule(md); 329 } 330 else if ( (!directory && name.endsWith(".jar")) 331 || (directory && name.endsWith("_jar")) ) { 332 try { 333 AppClientArchivist acArchivist = new AppClientArchivist(); 335 if (acArchivist.hasStandardDeploymentDescriptor(subArchive) 336 || acArchivist.hasRuntimeDeploymentDescriptor(subArchive) 337 || acArchivist.getMainClassName(subArchive.getManifest()) != null) { 338 339 ModuleDescriptor md = new ModuleDescriptor(); 340 md.setArchiveUri(uri); 341 md.setModuleType(ModuleType.CAR); 342 md.setManifest(subArchive.getManifest()); 343 app.addModule(md); 344 continue; 345 } 346 347 EjbArchivist ejbArchivist = new EjbArchivist(); 349 if (ejbArchivist.hasStandardDeploymentDescriptor(subArchive) 350 || ejbArchivist.hasRuntimeDeploymentDescriptor(subArchive)) { 351 352 ModuleDescriptor md = new ModuleDescriptor(); 353 md.setArchiveUri(uri); 354 md.setModuleType(ModuleType.EJB); 355 app.addModule(md); 356 continue; 357 } 358 } catch (IOException ex) { 359 _logger.log(Level.WARNING, ex.getMessage()); 360 } 361 362 unknowns.add(subArchive); 364 } else { 365 } 367 } finally { 368 if (subArchive != null) { 369 try { 370 subArchive.close(); 371 } catch (IOException ioe) { 372 _logger.log(Level.WARNING, localStrings.getLocalString("enterprise.deployment.errorClosingSubArch", "Error closing subarchive {0}", new Object [] {subModule.getAbsolutePath()}), ioe); 373 } 374 } 375 } 376 } 377 378 if (unknowns.size() > 0) { 379 EjbComponentAnnotationDetector detector = 380 new EjbComponentAnnotationDetector(); 381 for (int i = 0; i < unknowns.size(); i++) { 382 File jarFile = new File (unknowns.get(i).getArchiveUri()); 383 try { 384 if (detector.hasAnnotationInArchive(unknowns.get(i))) { 385 String uri = deriveArchiveUri(appRoot, jarFile, directory); 386 ModuleDescriptor md = new ModuleDescriptor(); 388 md.setArchiveUri(uri); 389 md.setModuleType(ModuleType.EJB); 390 app.addModule(md); 391 } 392 } catch (IOException ex) { 393 _logger.log(Level.WARNING, ex.getMessage()); 394 } 395 } 396 } 397 398 return app; 399 } 400 401 public void setGeneratedXMLDirectory(String xmlDir) { 402 generatedXMLDir = xmlDir; 403 } 404 405 409 public String getGeneratedXMLDirectory() { 410 return generatedXMLDir; 411 } 412 413 421 public void setRegistrationName(String appId) { 422 423 SecurityRoleMapper roleMapper=null; 425 try { 426 roleMapper = getRoleMapper(); 427 } catch(IllegalArgumentException ignore) {}; 428 429 if (roleMapper!=null) { 430 SecurityRoleMapperFactory factory = SecurityRoleMapperFactoryMgr.getFactory(); 431 if (factory==null) { 432 throw new IllegalArgumentException (localStrings.getLocalString( 433 "enterprise.deployment.norolemapperfactorydefine", 434 "This application has no role mapper factory defined")); 435 } 436 factory.removeRoleMapper(getName()); 437 roleMapper.setName(appId); 438 factory.setRoleMapper(appId, roleMapper); 439 } 440 441 this.registrationName = appId; 442 } 443 444 449 public String getRegistrationName() { 450 if (registrationName!=null) { 451 return registrationName; 452 } else { 453 return getName(); 454 } 455 } 456 458 472 public void addEntityManagerFactory( 473 String unitName, 474 String persistenceRootUri, 475 EntityManagerFactory emf) { 476 477 String fullyQualifiedUnitName = persistenceRootUri + 478 PERSISTENCE_UNIT_NAME_SEPARATOR + unitName; 479 480 entityManagerFactories.put(fullyQualifiedUnitName, emf); 482 483 if( entityManagerFactoryUnitNames.contains(unitName) ) { 490 entityManagerFactories.remove(unitName); 491 } else { 492 entityManagerFactories.put(unitName, emf); 493 entityManagerFactoryUnitNames.add(unitName); 494 } 495 } 496 497 502 public EntityManagerFactory getEntityManagerFactory 503 (String unitName, BundleDescriptor declaringModule) { 504 505 String lookupString = unitName; 506 507 int separatorIndex = 508 unitName.lastIndexOf(PERSISTENCE_UNIT_NAME_SEPARATOR); 509 510 if( separatorIndex != -1 ) { 511 String unqualifiedUnitName = 512 unitName.substring(separatorIndex + 1); 513 String path = unitName.substring(0, separatorIndex); 514 515 String persistenceRootUri = getTargetUri(declaringModule, path); 516 517 lookupString = persistenceRootUri + 518 PERSISTENCE_UNIT_NAME_SEPARATOR + unqualifiedUnitName; 519 } 520 521 return entityManagerFactories.get(lookupString); 522 } 523 524 528 public Set <EntityManagerFactory> getEntityManagerFactories() { 529 530 return new HashSet <EntityManagerFactory> 531 (entityManagerFactories.values()); 532 533 } 534 535 540 public Set getRoles() { 541 Set roles = new HashSet (); 542 for (Iterator itr = this.getWebBundleDescriptors().iterator(); itr.hasNext();) { 543 WebBundleDescriptor wbd = (WebBundleDescriptor) itr.next(); 544 if (wbd!=null) { 545 roles.addAll(wbd.getRoles()); 546 } 547 } 548 for (Iterator itr = this.getEjbBundleDescriptors().iterator(); itr.hasNext();) { 549 EjbBundleDescriptor ejbd = (EjbBundleDescriptor) itr.next(); 550 if (ejbd != null) { 551 roles.addAll(ejbd.getRoles()); 552 } 553 } 554 return roles; 555 } 556 557 561 public Set getAppRoles() { 562 if (this.appRoles == null) { 563 this.appRoles = new OrderedSet(); 564 } 565 return this.appRoles; 566 } 567 568 public void addAppRole(SecurityRoleDescriptor descriptor) { 569 Role role = new Role(descriptor.getName()); 570 role.setDescription(descriptor.getDescription()); 571 getAppRoles().add(role); 572 } 573 574 575 577 public void addRole(Role role) { 578 for (Iterator itr = this.getWebBundleDescriptors().iterator(); itr.hasNext();){ 579 WebBundleDescriptor wbd = (WebBundleDescriptor) itr.next(); 580 wbd.addRole(role); 581 } 582 for (Iterator itr = this.getEjbBundleDescriptors().iterator(); itr.hasNext();){ 583 EjbBundleDescriptor ejbd = (EjbBundleDescriptor) itr.next(); 584 ejbd.addRole(role); 585 } 586 changed(); 587 } 588 589 592 public void removeRole(Role role) { 593 getAppRoles().remove(role); 594 for (Iterator itr = this.getWebBundleDescriptors().iterator(); itr.hasNext();){ 595 WebBundleDescriptor wbd = (WebBundleDescriptor) itr.next(); 596 wbd.removeRole(role); 597 } 598 for (Iterator itr = this.getEjbBundleDescriptors().iterator(); itr.hasNext();){ 599 EjbBundleDescriptor ejbd = (EjbBundleDescriptor) itr.next(); 600 ejbd.removeRole(role); 601 } 602 changed(); 603 } 604 605 608 609 public Set getResourceReferenceDescriptors() { 610 Set resourceReferences = new HashSet (); 611 for (Iterator itr = this.getEjbBundleDescriptors().iterator(); itr.hasNext();) { 612 EjbBundleDescriptor ejbd = (EjbBundleDescriptor) itr.next(); 613 resourceReferences.addAll(ejbd.getResourceReferenceDescriptors()); 614 } 615 return resourceReferences; 616 } 617 618 623 public void setName(String name) { 624 name = name.replace('/', '-'); 625 name = name.replace('\\', '-'); setDirty(true); 628 super.setName(name); 629 if (this.getRoleMapper() != null) { 630 this.getRoleMapper().setName(name); 631 } 632 } 633 634 public void setDescription(String description) { 635 setDirty(true); 636 super.setDescription(description); 637 } 638 639 public void setLargeIconUri(String largeIconUri) { 640 setDirty(true); 641 super.setLargeIconUri(largeIconUri); 642 } 643 644 public void setSmallIconUri(String smallIconUri) { 645 setDirty(true); 646 super.setSmallIconUri(smallIconUri); 647 } 648 649 public void setLibraryDirectory(String value) 650 { 651 libraryDirectory = value; 652 } 653 654 661 public String getLibraryDirectory() 662 { 663 if (libraryDirectory != null) { 664 return (libraryDirectory.length() == 0) ? null : libraryDirectory; 665 } else { 666 return LIBRARY_DIRECTORY_DEFAULT_VALUE; 667 } 668 } 669 670 public String getLibraryDirectoryRawValue() { 671 return libraryDirectory; 672 } 673 674 682 public int getWebComponentCount() { 683 int count = 0; 684 for (Iterator itr = this.getWebBundleDescriptors().iterator(); itr.hasNext();) { 685 WebBundleDescriptor wbd = (WebBundleDescriptor) itr.next(); 686 count = count + wbd.getWebDescriptors().size(); 687 } 688 return count; 689 } 690 691 public void removeModule(ModuleDescriptor descriptor) { 692 if (modules.contains(descriptor)) { 693 if (descriptor.getDescriptor() != null) { 694 descriptor.getDescriptor().removeNotificationListener(this); 695 descriptor.getDescriptor().setApplication(null); 696 } 697 modules.remove(descriptor); 698 this.changed(true); 699 } 700 } 701 702 public void addModule(ModuleDescriptor descriptor) { 703 modules.add(descriptor); 704 if (descriptor.getDescriptor()!=null) { 705 descriptor.getDescriptor().addNotificationListener(this); 706 descriptor.getDescriptor().setApplication(this); 707 } 708 this.changed(true); 709 } 710 711 716 public Iterator getModules() { 717 return modules.iterator(); 718 } 719 720 726 public Iterator getModulesByType(ModuleType type) { 727 if (type==null) { 728 return null; 729 } 730 Set moduleSet = new HashSet (); 731 for (Iterator bundles = getModules();bundles.hasNext();) { 732 ModuleDescriptor aModule = (ModuleDescriptor) bundles.next(); 733 if (type.equals(aModule.getModuleType())) { 734 moduleSet.add(aModule); 735 } 736 } 737 return moduleSet.iterator(); 738 } 739 740 public void addDescriptor(Object descriptor) { 741 if (descriptor instanceof EjbBundleDescriptor) { 742 addEjbBundleDescriptor((EjbBundleDescriptor) descriptor); 743 } 744 if (descriptor instanceof WebBundleDescriptor) { 745 addWebBundleDescriptor((WebBundleDescriptor) descriptor); 746 } 747 if (descriptor instanceof ConnectorDescriptor) { 748 addRarDescriptor((ConnectorDescriptor) descriptor); 749 } 750 } 751 752 757 public int getEjbComponentCount() { 758 int count = 0; 759 for (Iterator itr = this.getEjbBundleDescriptors().iterator(); itr.hasNext();) { 760 EjbBundleDescriptor ejbd = (EjbBundleDescriptor) itr.next(); 761 count = count + ejbd.getEjbs().size(); 762 } 763 return count; 764 } 765 766 767 public int getRarComponentCount() { 768 return this.getRarDescriptors().size(); 769 } 770 771 772 777 778 779 public Vector getEjbReferenceDescriptors() { 780 Vector ejbReferenceDescriptors = new Vector (); 781 for (Iterator itr = this.getNamedDescriptors().iterator(); itr.hasNext();) { 782 Object next = itr.next(); 783 if (next instanceof EjbReferenceDescriptor) { 784 ejbReferenceDescriptors.addElement(next); 785 } 786 } 787 return ejbReferenceDescriptors; 788 } 789 790 791 798 public EjbBundleDescriptor getEjbBundleByName(String name) { 799 for (Iterator itr = this.getEjbBundleDescriptors().iterator(); itr.hasNext();) { 800 EjbBundleDescriptor ejbBundleDescriptor = (EjbBundleDescriptor) itr.next(); 801 if (ejbBundleDescriptor.getDisplayName().equals(name)) 802 return ejbBundleDescriptor; 803 } 804 throw new IllegalArgumentException (localStrings.getLocalString( 805 "enterprise.deployment.exceptionapphasnoejbjarnamed", 806 "This application has no ejb jars of name {0}", 807 new Object []{name})); 808 } 809 810 819 public String getTargetUri(BundleDescriptor origin, 820 String relativeTargetUri) { 821 String targetUri = null; 822 823 try { 824 String archiveUri = origin.getModuleDescriptor().getArchiveUri(); 825 URI originUri = new URI (archiveUri); 826 URI resolvedUri = originUri.resolve(relativeTargetUri); 827 targetUri = resolvedUri.getPath(); 828 } catch(URISyntaxException use) { 829 _logger.log(Level.FINE, "origin " + origin + " has invalid syntax", 830 use); 831 } 832 833 return targetUri; 834 } 835 836 846 public BundleDescriptor getRelativeBundle(BundleDescriptor origin, 847 String relativeTargetUri) { 848 String targetBundleUri = getTargetUri(origin, relativeTargetUri); 849 850 BundleDescriptor targetBundle = null; 851 852 if( targetBundleUri != null ) { 853 Descriptor module = getModuleByUri(targetBundleUri); 854 targetBundle = (module instanceof BundleDescriptor) ? 855 (BundleDescriptor) module : null; 856 } 857 858 return targetBundle; 859 } 860 861 867 public String getRelativeUri(BundleDescriptor origin, 868 BundleDescriptor target) { 869 870 String originUri = origin.getModuleDescriptor().getArchiveUri(); 871 String targetUri = target.getModuleDescriptor().getArchiveUri(); 872 873 StringTokenizer tokenizer = new StringTokenizer (originUri, "/"); 874 int numTokens = tokenizer.countTokens(); 875 int numSeparators = (numTokens > 0) ? (numTokens - 1) : 0; 876 877 StringBuffer relativeUri = new StringBuffer (); 878 879 for(int i = 0; i < numSeparators; i++) { 886 relativeUri.append("../"); 887 } 888 889 relativeUri.append(targetUri); 890 891 return relativeUri.toString(); 892 } 893 894 897 public EjbBundleDescriptor getEjbBundleByUri(String name) { 898 Descriptor desc = getModuleByTypeAndUri(ModuleType.EJB, name); 899 if (desc!=null && desc instanceof EjbBundleDescriptor) { 900 return (EjbBundleDescriptor) desc; 901 } 902 throw new IllegalArgumentException (localStrings.getLocalString( 903 "enterprise.deployment.exceptionapphasnoejbjarnamed", 904 "This application has no ejb jars of name {0}", 905 new Object []{name})); 906 } 907 908 917 public ModuleDescriptor getModuleDescriptorByUri(String uri) { 918 for (Iterator itr = getModules();itr.hasNext();) { 919 ModuleDescriptor aModule = (ModuleDescriptor) itr.next(); 920 if (aModule.getArchiveUri().equals(uri)) { 921 return aModule; 922 } 923 } 924 return null; 925 } 926 927 936 public Descriptor getModuleByUri(String uri) { 937 ModuleDescriptor md = getModuleDescriptorByUri(uri); 938 if (md!=null) { 939 return md.getDescriptor(); 940 } 941 return null; 942 } 943 944 951 public Descriptor getModuleByTypeAndUri(ModuleType type, String uri) { 952 for (Iterator itr = getModules();itr.hasNext();) { 953 ModuleDescriptor aModule = (ModuleDescriptor) itr.next(); 954 if (aModule.getModuleType().equals(type)) { 955 if (aModule.getArchiveUri().equals(uri)) { 956 return aModule.getDescriptor(); 957 } 958 } 959 } 960 return null; 961 } 962 963 970 public EjbDescriptor getEjbByName(String ejbName) { 971 EjbDescriptor ejbDescriptor = null; 972 for (Iterator itr = this.getEjbBundleDescriptors().iterator(); itr.hasNext();) { 973 EjbBundleDescriptor ejbBundleDescriptor = (EjbBundleDescriptor) itr.next(); 974 if (ejbBundleDescriptor.hasEjbByName(ejbName)) { 975 return ejbBundleDescriptor.getEjbByName(ejbName); 976 } 977 } 978 throw new IllegalArgumentException (localStrings.getLocalString( 979 "enterprise.deployment.exceptionapphasnobeannamed", 980 "This application has no beans of name {0}", new Object []{ejbName})); 981 } 982 983 989 public boolean hasEjbByName(String ejbName) { 990 EjbDescriptor ejbDescriptor = null; 991 for (Iterator itr = this.getEjbBundleDescriptors().iterator(); itr.hasNext();) { 992 EjbBundleDescriptor ejbBundleDescriptor = (EjbBundleDescriptor) itr.next(); 993 if (ejbBundleDescriptor.hasEjbByName(ejbName)) { 994 return true; 995 } 996 } 997 return false; 998 } 999 1000 1006 public ApplicationClientDescriptor getApplicationClientByName(String name) { 1007 for (Iterator itr = this.getApplicationClientDescriptors().iterator(); itr.hasNext();) { 1008 ApplicationClientDescriptor next = (ApplicationClientDescriptor) itr.next(); 1009 if (next.getDisplayName().equals(name)) { 1010 return next; 1011 } 1012 } 1013 throw new IllegalArgumentException (localStrings.getLocalString( 1014 "enterprise.deployment.exceptionapphasnoappclientname", 1015 "This application has no application clients of name {0}", new Object []{name})); 1016 } 1017 1018 1023 public ApplicationClientDescriptor getApplicationClientByUri(String name) { 1024 Descriptor desc = getModuleByTypeAndUri(ModuleType.CAR, name); 1025 if (desc!=null && desc instanceof ApplicationClientDescriptor) { 1026 return (ApplicationClientDescriptor) desc; 1027 } 1028 throw new IllegalArgumentException (name); 1029 } 1030 1031 1037 public WebBundleDescriptor getWebBundleDescriptorByName(String name) { 1038 for (Iterator itr = this.getWebBundleDescriptors().iterator(); itr.hasNext();) { 1039 WebBundleDescriptor next = (WebBundleDescriptor) itr.next(); 1040 if (next.getDisplayName().equals(name)) { 1041 return next; 1042 } 1043 } 1044 throw new IllegalArgumentException (localStrings.getLocalString( 1045 "enterprise.deployment.exceptionapphasnowebappname", 1046 "This application has no web app of name {0}", new Object []{name})); 1047 } 1048 1049 1052 public WebBundleDescriptor getWebBundleDescriptorByUri(String name) { 1053 Descriptor desc = getModuleByTypeAndUri(ModuleType.WAR, name); 1054 if (desc!=null && desc instanceof WebBundleDescriptor) { 1055 return (WebBundleDescriptor) desc; 1056 } 1057 throw new IllegalArgumentException (localStrings.getLocalString( 1058 "enterprise.deployment.exceptionapphasnowebappname", 1059 "This application has no web app of name {0}", new Object []{name})); 1060 } 1061 1062 1063 1068 public ConnectorDescriptor getRarDescriptorByUri(String name) { 1069 Descriptor desc = getModuleByTypeAndUri(ModuleType.RAR, name); 1070 if (desc!=null && desc instanceof ConnectorDescriptor) { 1071 return (ConnectorDescriptor) desc; 1072 } 1073 throw new IllegalArgumentException (name); 1074 } 1075 1076 1077 1083 public Set getJndiNameEnvironments() { 1084 Set jndiNameEnvironments = new HashSet (); 1085 jndiNameEnvironments.addAll(this.getWebBundleDescriptors()); 1086 jndiNameEnvironments.addAll(this.getApplicationClientDescriptors()); 1087 jndiNameEnvironments.addAll(this.getEjbDescriptors()); 1088 return jndiNameEnvironments; 1089 } 1090 1091 1095 public Set getServiceReferenceDescriptors() { 1096 Set serviceRefs = new HashSet (); 1097 Set jndiNameEnvironments = this.getJndiNameEnvironments(); 1098 for(Iterator iter = jndiNameEnvironments.iterator(); iter.hasNext();) { 1099 JndiNameEnvironment next = (JndiNameEnvironment) iter.next(); 1100 serviceRefs.addAll(next.getServiceReferenceDescriptors()); 1101 } 1102 return serviceRefs; 1103 } 1104 1105 1109 public Set getWebServiceDescriptors() { 1110 Set webServiceDescriptors = new HashSet (); 1111 Set bundles = new HashSet (); 1112 bundles.addAll(getEjbBundleDescriptors()); 1113 bundles.addAll(getWebBundleDescriptors()); 1114 for(Iterator iter = bundles.iterator(); iter.hasNext();) { 1115 BundleDescriptor next = (BundleDescriptor) iter.next(); 1116 WebServicesDescriptor webServicesDesc = 1117 next.getWebServices(); 1118 webServiceDescriptors.addAll(webServicesDesc.getWebServices()); 1119 } 1120 return webServiceDescriptors; 1121 } 1122 1123 1128 public Set getWebBundleDescriptors() { 1129 return getBundleDescriptors(ModuleType.WAR); 1130 } 1131 1132 1138 public BundleDescriptor getStandaloneBundleDescriptor() { 1139 if (isVirtual()) { 1140 Iterator modules = getModules(); 1141 if (modules.hasNext()) { 1142 ModuleDescriptor module = (ModuleDescriptor) modules.next(); 1143 if (modules.hasNext()) { 1144 throw new IllegalStateException ("Virtual application contains more than one module"); 1148 } 1149 return module.getDescriptor(); 1150 } 1151 return null; 1152 } else { 1153 return null; 1154 } 1155 } 1156 1157 1158 1164 public Set getBundleDescriptors(ModuleType type) { 1165 if (type==null) { 1166 return null; 1167 } 1168 Set bundleSet = new HashSet (); 1169 for (Iterator bundles = getModules();bundles.hasNext();) { 1170 ModuleDescriptor aModule = (ModuleDescriptor) bundles.next(); 1171 if (type.equals(aModule.getModuleType())) { 1172 if (aModule.getDescriptor()!=null) { 1173 bundleSet.add(aModule.getDescriptor()); 1174 } else { 1175 DOLUtils.getDefaultLogger().fine("Null descriptor for module " + aModule.getArchiveUri()); 1176 } 1177 } 1178 } 1179 return bundleSet; 1180 } 1181 1182 1187 public Set getBundleDescriptors() { 1188 Set bundleSet = new HashSet (); 1189 for (Iterator bundles = getModules();bundles.hasNext();) { 1190 ModuleDescriptor aModule = (ModuleDescriptor) bundles.next(); 1191 if (aModule.getDescriptor()!=null) { 1192 bundleSet.add(aModule.getDescriptor()); 1193 } else { 1194 DOLUtils.getDefaultLogger().fine("Null descriptor for module " + aModule.getArchiveUri()); 1195 } 1196 } 1197 return bundleSet; 1198 } 1199 1200 1205 public void addWebBundleDescriptor(WebBundleDescriptor webBundleDescriptor) { 1206 addBundleDescriptor(webBundleDescriptor); 1207 } 1208 1209 private void addBundleDescriptor(BundleDescriptor bundleDescriptor) { 1210 ModuleDescriptor newModule = bundleDescriptor.getModuleDescriptor(); 1211 addModule(newModule); 1212 } 1213 1214 1219 public void removeWebBundleDescriptor(WebBundleDescriptor webBundleDescriptor) { 1220 webBundleDescriptor.removeNotificationListener(this); 1221 webBundleDescriptor.setApplication(null); 1222 this.getWebBundleDescriptors().remove(webBundleDescriptor); 1223 this.changed(true); 1224 } 1225 1226 1231 public Set getRarDescriptors() { 1232 return getBundleDescriptors(ModuleType.RAR); 1233 } 1234 1235 1240 public void addRarDescriptor(ConnectorDescriptor rarDescriptor) { 1241 addBundleDescriptor(rarDescriptor); 1242 } 1243 1244 1249 public void removeRarDescriptor(ConnectorDescriptor rarDescriptor) { 1250 rarDescriptor.removeNotificationListener(this); 1251 rarDescriptor.setApplication(null); 1252 this.getRarDescriptors().remove(rarDescriptor); 1253 this.changed(true); 1254 } 1255 1256 1257 1258 1263 public Set getEjbBundleDescriptors() { 1264 return getBundleDescriptors(ModuleType.EJB); 1265 } 1266 1267 1269 public void addEjbBundleDescriptor(EjbBundleDescriptor ejbBundleDescriptor) { 1270 addBundleDescriptor(ejbBundleDescriptor); 1271 } 1272 1273 1275 public void removeEjbBundleDescriptor(EjbBundleDescriptor ejbBundleDescriptor) { 1276 this.getEjbBundleDescriptors().remove(ejbBundleDescriptor); 1277 ejbBundleDescriptor.removeNotificationListener(this); 1278 ejbBundleDescriptor.setApplication(null); 1279 this.changed(true); 1280 } 1281 1282 1283 public Set getApplicationClientDescriptors() { 1284 return getBundleDescriptors(ModuleType.CAR); 1285 } 1286 1287 1288 public void addApplicationClientDescriptor(ApplicationClientDescriptor applicationClientDescriptor) { 1289 addBundleDescriptor(applicationClientDescriptor); 1290 } 1291 1292 1293 public void removeApplicationClientDescriptor(ApplicationClientDescriptor applicationClientDescriptor) { 1294 this.getApplicationClientDescriptors().remove(applicationClientDescriptor); 1295 applicationClientDescriptor.removeNotificationListener(this); 1296 applicationClientDescriptor.setApplication(null); 1297 this.changed(true); 1298 } 1299 1300 1307 public EjbCMPEntityDescriptor getCMPDescriptorFor(String className) 1308 { 1309 if ( cmpDescriptors == null ) { 1310 cmpDescriptors = new Hashtable (); 1311 Iterator ejbBundles = getEjbBundleDescriptors().iterator(); 1312 while ( ejbBundles.hasNext() ) { 1313 EjbBundleDescriptor bundle = (EjbBundleDescriptor)ejbBundles.next(); 1314 Iterator ejbs = bundle.getEjbs().iterator(); 1315 while ( ejbs.hasNext() ) { 1316 EjbDescriptor ejb = (EjbDescriptor)ejbs.next(); 1317 if ( ejb instanceof EjbCMPEntityDescriptor ) 1318 cmpDescriptors.put(ejb.getEjbImplClassName(), ejb); 1319 } 1320 } 1321 } 1322 return (EjbCMPEntityDescriptor)cmpDescriptors.get(className); 1323 } 1324 1325 1326 1327 1328 1336 public Vector getNamedReferencePairs() { 1337 Vector pairs = new Vector (); 1338 for (Iterator itr = this.getEjbBundleDescriptors().iterator(); itr.hasNext();) { 1339 EjbBundleDescriptor ejbBundleDescriptor = (EjbBundleDescriptor) itr.next(); 1340 pairs.addAll(ejbBundleDescriptor.getNamedReferencePairs()); 1341 } 1342 for (Iterator itr = this.getWebBundleDescriptors().iterator(); itr.hasNext();) { 1343 WebBundleDescriptor webBundleDescriptor = (WebBundleDescriptor) itr.next(); 1344 pairs.addAll(webBundleDescriptor.getNamedReferencePairs()); 1345 } 1346 for (Iterator itr = this.getApplicationClientDescriptors().iterator(); itr.hasNext();) { 1347 ApplicationClientDescriptor applicationClientDescriptor = (ApplicationClientDescriptor) itr.next(); 1348 pairs.addAll(applicationClientDescriptor.getNamedReferencePairs()); 1349 } 1350 return pairs; 1351 } 1352 1353 1356 public Collection getNamedDescriptors() { 1357 Collection namedDescriptors = new Vector (); 1358 for (Iterator itr = this.getEjbBundleDescriptors().iterator(); itr.hasNext();) { 1359 EjbBundleDescriptor ejbBundleDescriptor = (EjbBundleDescriptor) itr.next(); 1360 namedDescriptors.addAll(ejbBundleDescriptor.getNamedDescriptors()); 1361 } 1362 for (Iterator itr = this.getWebBundleDescriptors().iterator(); itr.hasNext();) { 1363 WebBundleDescriptor webBundleDescriptor = (WebBundleDescriptor) itr.next(); 1364 namedDescriptors.addAll(webBundleDescriptor.getNamedDescriptors()); 1365 } 1366 for (Iterator itr = this.getApplicationClientDescriptors().iterator(); itr.hasNext();) { 1367 ApplicationClientDescriptor applicationClientDescriptor = (ApplicationClientDescriptor) itr.next(); 1368 namedDescriptors.addAll(applicationClientDescriptor.getNamedDescriptors()); 1369 } 1370 return namedDescriptors; 1371 1372 } 1373 1374 1375 public Vector getEjbDescriptors() { 1376 Vector ejbDescriptors = new Vector (); 1377 for (Iterator itr = this.getEjbBundleDescriptors().iterator(); itr.hasNext();) { 1378 EjbBundleDescriptor ejbBundleDescriptor = (EjbBundleDescriptor) itr.next(); 1379 ejbDescriptors.addAll(ejbBundleDescriptor.getEjbs()); 1380 } 1381 1382 return ejbDescriptors; 1383 } 1384 1385 1389 public boolean containsCMPEntity() { 1390 for (Iterator itr = this.getEjbBundleDescriptors().iterator(); itr.hasNext();) { 1391 if (((EjbBundleDescriptor) itr.next()).containsCMPEntity()) 1392 return true; 1393 } 1394 return false; 1395 } 1396 1397 1398 1401 1407 public EjbDescriptor[] getSortedEjbDescriptors() 1408 { 1409 Vector ejbDesc = getEjbDescriptors(); 1410 EjbDescriptor[] descs = (EjbDescriptor[])ejbDesc.toArray( 1411 new EjbDescriptor[ejbDesc.size()]); 1412 1413 1417 Arrays.sort(descs, 1420 new Comparator () { 1421 public int compare(Object o1, Object o2) { 1422 EjbDescriptor desc1 = (EjbDescriptor)o1; 1423 EjbDescriptor desc2 = (EjbDescriptor)o2; 1424 String moduleUri1 = desc1.getEjbBundleDescriptor().getModuleDescriptor().getArchiveUri(); 1425 String moduleUri2 = desc2.getEjbBundleDescriptor().getModuleDescriptor().getArchiveUri(); 1426 return (moduleUri1 + desc1.getName()).compareTo( 1427 moduleUri2 + desc2.getName()); 1428 } 1429 } 1430 ); 1431 1432 return descs; 1433 } 1434 1435 1437 1445 public void setVirtual(boolean virtual) 1446 { 1447 this.virtual = virtual; 1448 } 1449 1450 1455 public boolean isVirtual() 1456 { 1457 return this.virtual; 1458 } 1459 1460 1467 public void setUniqueId(long id) 1468 { 1469 _logger.log(Level.FINE,"[Application]uid: " + id); 1470 this.uniqueId = id; 1471 1472 EjbDescriptor[] descs = getSortedEjbDescriptors(); 1473 1474 for (int i=0; i<descs.length; i++) 1475 { 1476 descs[i].setUniqueId( (id | i) ); 1478 if(_logger.isLoggable(Level.FINE)){ 1479 _logger.log(Level.FINE,"[Application]desc name: " + descs[i].getName()); 1480 _logger.log(Level.FINE,"[Application]desc id: "+descs[i].getUniqueId()); 1481 } 1482 } 1483 } 1484 1485 1490 public long getUniqueId() 1491 { 1492 return this.uniqueId; 1493 } 1494 1496 1509 public void setPassByReference(boolean passByReference) 1510 { 1511 this.passByReference = Boolean.valueOf(passByReference); 1512 } 1513 1514 1524 public boolean getPassByReference() 1525 { 1526 boolean passByReference = false; 1527 1528 if (this.isPassByReferenceDefined()) { 1529 passByReference = this.passByReference.booleanValue(); 1530 } 1531 return passByReference; 1532 } 1533 1535 1543 public boolean isPassByReferenceDefined() 1544 { 1545 boolean passByReferenceDefined = false; 1546 if (this.passByReference != null) { 1547 passByReferenceDefined = true; 1548 } 1549 return passByReferenceDefined; 1550 } 1551 1553 1556 public void addApplication(Application application) { 1557 for (Iterator itr = application.getEjbBundleDescriptors().iterator(); itr.hasNext();) { 1558 EjbBundleDescriptor ejbBundleDescriptor = (EjbBundleDescriptor) itr.next(); 1559 this.addEjbBundleDescriptor(ejbBundleDescriptor); 1560 } 1561 for (Iterator itr = application.getWebBundleDescriptors().iterator(); itr.hasNext();) { 1562 WebBundleDescriptor webBundleDescriptor = (WebBundleDescriptor) itr.next(); 1563 this.addWebBundleDescriptor(webBundleDescriptor); 1564 } 1565 for (Iterator itr = application.getApplicationClientDescriptors().iterator(); itr.hasNext();) { 1566 ApplicationClientDescriptor acd = (ApplicationClientDescriptor) itr.next(); 1567 this.addApplicationClientDescriptor(acd); 1568 } 1569 for (Iterator itr = application.getRarDescriptors().iterator(); itr.hasNext();) { 1570 ConnectorDescriptor rarDescriptor = (ConnectorDescriptor) itr.next(); 1571 this.addRarDescriptor(rarDescriptor); 1572 } 1573 } 1574 1575 1579 public Set getArchivableDescriptors() { 1580 Set archivableDescriptors = new HashSet (); 1581 archivableDescriptors.addAll(this.getEjbBundleDescriptors()); 1582 archivableDescriptors.addAll(this.getWebBundleDescriptors()); 1583 archivableDescriptors.addAll(this.getApplicationClientDescriptors()); 1584 archivableDescriptors.addAll(this.getRarDescriptors()); 1585 return archivableDescriptors; 1586 } 1587 1588 1591 public void setRoleMapper(SecurityRoleMapper roleMapper) { 1592 this.roleMapper = roleMapper; 1594 this.changed(true); 1595 } 1596 1597 1601 public boolean hasRuntimeInformation() { 1602 return true; 1603 } 1604 1605 1609 public SecurityRoleMapper getRoleMapper() { 1610 if (this.roleMapper == null) { 1611 SecurityRoleMapperFactory factory = SecurityRoleMapperFactoryMgr.getFactory(); 1612 if (factory==null) { 1613 _logger.log(Level.FINE, "SecurityRoleMapperFactory NOT set."); 1614 } else { 1615 this.roleMapper = factory.getRoleMapper(this.getName()); 1616 } 1617 } 1618 return this.roleMapper; 1619 } 1620 1621 1624 public void setRealm(String realm) { 1625 this.realm=realm; 1626 } 1627 1628 1631 public String getRealm() { 1632 return realm; 1633 } 1634 1635 1638 public boolean isDirty() { 1639 return this.isDirty; 1640 } 1641 1642 1643 public void notification(NotificationEvent ne) { 1644 1647 this.changed(true); 1648 } 1649 1650 1653 public ClassLoader getClassLoader() { 1654 if (classLoader==null) { 1655 throw new RuntimeException ("No class loader associated with application " + getName()); 1656 } 1657 return classLoader; 1658 } 1659 1660 1663 public void changed() { 1664 NotificationEvent ne = new NotificationEvent(this, DESCRIPTOR_CHANGED, this); 1665 1666 Vector listenersClone = null; 1667 synchronized (listeners) { 1668 listenersClone = (Vector ) listeners.clone(); 1669 } 1670 for (Enumeration e = listenersClone.elements(); e.hasMoreElements();) { 1671 NotificationListener nl = (NotificationListener) e.nextElement(); 1672 nl.notification(ne); 1673 } 1674 } 1675 1676 1679 public void print(StringBuffer toStringBuffer) { 1680 toStringBuffer.append("Application"); 1681 toStringBuffer.append("\n"); 1682 super.print(toStringBuffer); 1683 toStringBuffer.append("\n smallIcon ").append(super.getSmallIconUri()); 1684 for (Iterator itr = getModules();itr.hasNext();) { 1685 toStringBuffer.append("\n Module : "); 1686 ((Descriptor)itr.next()).print(toStringBuffer); 1687 } 1688 toStringBuffer.append("\n EjbBundles: \n"); 1689 if(this.getEjbBundleDescriptors() != null) 1690 printDescriptorSet(this.getEjbBundleDescriptors(),toStringBuffer); 1691 toStringBuffer.append("\n WebBundleDescriptors "); 1692 if(this.getWebBundleDescriptors() != null) 1693 printDescriptorSet(this.getWebBundleDescriptors(),toStringBuffer); 1694 toStringBuffer.append("\n applicationClientDescriptors "); 1695 if(this.getApplicationClientDescriptors() != null) 1696 printDescriptorSet(this.getApplicationClientDescriptors(),toStringBuffer); 1697 toStringBuffer.append("\n roles ").append(getRoles()); 1698 toStringBuffer.append("\n RoleMapper ").append(this.getRoleMapper()); 1699 toStringBuffer.append("\n Realm ").append(realm); 1700 } 1701 private void printDescriptorSet(Set descSet, StringBuffer sbuf){ 1702 for(Iterator itr = descSet.iterator(); itr.hasNext();){ 1703 Object obj = itr.next(); 1704 if(obj instanceof Descriptor) 1705 ((Descriptor)obj).print(sbuf); 1706 else 1707 sbuf.append(obj); 1708 } 1709 } 1710 1715 public void visit(DescriptorVisitor aVisitor) { 1716 if (aVisitor instanceof ApplicationVisitor) { 1717 visit((ApplicationVisitor) aVisitor); 1718 } else { 1719 super.visit(aVisitor); 1720 } 1721 } 1722 1723 1728 public void visit(ApplicationVisitor aVisitor) { 1729 aVisitor.accept(this); 1730 EjbBundleVisitor ejbBundleVisitor = aVisitor.getEjbBundleVisitor(); 1731 if (ejbBundleVisitor != null) { 1732 for (Iterator ejbBundles = getEjbBundleDescriptors().iterator();ejbBundles.hasNext();) { 1733 EjbBundleDescriptor anEjbBundle = (EjbBundleDescriptor) ejbBundles.next(); 1734 anEjbBundle.visit(ejbBundleVisitor); 1735 } 1736 } 1737 WebBundleVisitor webVisitor = aVisitor.getWebBundleVisitor(); 1738 if (webVisitor != null) { 1739 for (Iterator webBundles = getWebBundleDescriptors().iterator();webBundles.hasNext();) { 1740 WebBundleDescriptor aWebBundle = (WebBundleDescriptor) webBundles.next(); 1741 if( aWebBundle != null ) { 1747 aWebBundle.visit(webVisitor); 1748 } 1749 } 1750 } 1751 ConnectorVisitor connectorVisitor = aVisitor.getConnectorVisitor(); 1752 if (connectorVisitor != null) { 1753 for (Iterator connectors = getRarDescriptors().iterator();connectors.hasNext();) { 1754 ConnectorDescriptor aConnector = (ConnectorDescriptor) connectors.next(); 1755 aConnector.visit(connectorVisitor); 1756 } 1757 } 1758 1759 AppClientVisitor appclientVisitor = aVisitor.getAppClientVisitor(); 1760 if (appclientVisitor != null) { 1761 for (Iterator appclients = getApplicationClientDescriptors().iterator();appclients.hasNext();) { 1762 ApplicationClientDescriptor appclient = (ApplicationClientDescriptor) appclients.next(); 1763 appclient.visit(appclientVisitor); 1764 } 1765 } 1766 } 1767 1768 void doneSaving() { 1769 this.isDirty = false; 1770 this.changed(false); 1771 } 1772 1773 1775 public void doneOpening() { 1776 this.isDirty = false; 1777 this.changed(false); 1778 } 1779 1780 private void setDirty(boolean dirty) { 1781 this.isDirty = dirty; 1782 } 1783 1784 1787 public String getModuleID() { 1788 return moduleID; 1789 } 1790 1791 1794 public boolean isApplication() { 1795 return true; 1796 } 1797 1798 1800 1801 public void changed(boolean dirtyChange) { 1802 if (dirtyChange) { 1803 this.isDirty = true; 1804 } 1805 super.changed(); 1806 } 1807 1808 1811 public ModuleType getModuleType() { 1812 return ModuleType.EAR; 1813 } 1814 1815 public void addSecurityRoleMapping(SecurityRoleMapping roleMapping) { 1816 roleMaps.add(roleMapping); 1817 } 1818 1819 public List <SecurityRoleMapping> getSecurityRoleMappings() { 1820 return roleMaps; 1821 } 1822 1823 1829 public void setLoadedFromApplicationXml(boolean bool) { 1830 loadedFromApplicationXml = bool; 1831 } 1832 1833 1838 public boolean isLoadedFromApplicationXml() { 1839 return loadedFromApplicationXml; 1840 } 1841 1842 public void setResourceList(List rList) { 1844 resourceList = rList; 1845 } 1846 1847 public List getResourceList() { 1848 return resourceList; 1849 } 1850 1851 private static String deriveArchiveUri( 1852 String appRoot, File subModule, boolean deploydir) { 1853 1854 if (deploydir) { 1857 return FileUtils.revertFriendlyFilename(subModule.getName()); 1858 } 1859 1860 String uri = subModule.getAbsolutePath().substring(appRoot.length()+1); 1863 return uri.replace(File.separatorChar, '/'); 1864 } 1865 1866 private static File [] getEligibleEntries(File appRoot, boolean deploydir) { 1867 1868 if (deploydir) { 1870 return appRoot.listFiles(new DirectoryIntrospectionFilter()); 1871 } 1872 1873 Vector files = new Vector (); 1875 getListOfFiles(appRoot, files, 1876 new ArchiveIntrospectionFilter(appRoot.getAbsolutePath())); 1877 return (File []) files.toArray(new File [files.size()]); 1878 } 1879 1880 private static void getListOfFiles( 1881 File directory, Vector files, FilenameFilter filter) { 1882 1883 File [] list = directory.listFiles(filter); 1884 for (int i=0;i<list.length;i++) { 1885 if (!list[i].isDirectory()) { 1886 files.add(list[i]); 1887 } else { 1888 getListOfFiles(list[i], files, filter); 1889 } 1890 } 1891 } 1892 1893 private static class ArchiveIntrospectionFilter implements FilenameFilter { 1894 private String libDir; 1895 ArchiveIntrospectionFilter(String root) { 1896 libDir = root + File.separator + "lib" + File.separator; 1897 } 1898 1899 public boolean accept(File dir, String name) { 1900 1901 File currentFile = new File (dir, name); 1902 if (currentFile.isDirectory()) { 1903 return true; 1904 } 1905 1906 if (name.endsWith(".war") || name.endsWith(".rar")) { 1908 return true; 1909 } 1910 1911 String path = currentFile.getAbsolutePath(); 1912 if (!path.startsWith(libDir) && path.endsWith(".jar")) { 1913 return true; 1914 } 1915 1916 return false; 1917 } 1918 } 1919 1920 private static class DirectoryIntrospectionFilter implements FilenameFilter { 1921 1922 DirectoryIntrospectionFilter() { } 1923 1924 public boolean accept(File dir, String name) { 1925 1926 File currentFile = new File (dir, name); 1927 if (!currentFile.isDirectory()) { 1928 return false; 1929 } 1930 1931 if (name.endsWith("_war") 1932 || name.endsWith("_rar") 1933 || name.endsWith("_jar")) { 1934 return true; 1935 } 1936 1937 return false; 1938 } 1939 } 1940} 1941 | Popular Tags |