| 1 2 3 27 28 29 package org.apache.catalina.core; 30 31 import java.beans.PropertyChangeListener ; 32 import java.beans.PropertyChangeSupport ; 33 import java.lang.reflect.Constructor ; 34 import java.util.ArrayList ; 35 import java.util.Enumeration ; 36 import java.util.HashMap ; 37 import java.util.Hashtable ; 38 import java.util.Vector ; 39 40 41 import javax.management.MBeanRegistration ; 42 import javax.management.MBeanServer ; 43 import javax.management.MalformedObjectNameException ; 44 import javax.management.ObjectName ; 45 import javax.naming.directory.DirContext ; 46 47 import org.apache.catalina.Container; 48 import org.apache.catalina.Context; 49 import org.apache.catalina.DefaultContext; 50 import org.apache.catalina.Lifecycle; 51 import org.apache.catalina.LifecycleEvent; 52 import org.apache.catalina.LifecycleListener; 53 import org.apache.catalina.Loader; 54 import org.apache.catalina.Manager; 55 import org.apache.catalina.deploy.ApplicationParameter; 56 import org.apache.catalina.deploy.ContextEjb; 57 import org.apache.catalina.deploy.ContextEnvironment; 58 import org.apache.catalina.deploy.ContextResource; 59 import org.apache.catalina.deploy.ContextResourceLink; 60 import org.apache.catalina.deploy.NamingResources; 61 import org.apache.catalina.deploy.ResourceParams; 62 import org.apache.catalina.loader.WebappLoader; 63 import org.apache.catalina.mbeans.MBeanUtils; 64 import org.apache.catalina.util.StringManager; 65 import com.sun.org.apache.commons.modeler.ManagedBean; 66 import com.sun.org.apache.commons.modeler.Registry; 67 import org.apache.naming.ContextAccessController; 68 69 78 79 public class StandardDefaultContext 80 implements DefaultContext, LifecycleListener, MBeanRegistration { 81 82 83 85 86 89 public StandardDefaultContext() { 90 91 namingResources.setContainer(this); 92 93 } 94 95 96 98 99 102 private Hashtable contexts = new Hashtable (); 103 104 105 109 private String applicationListeners[] = new String [0]; 110 111 112 115 private ApplicationParameter applicationParameters[] = 116 new ApplicationParameter[0]; 117 118 119 122 private boolean cookies = true; 123 124 125 129 private boolean crossContext = true; 130 131 132 135 private static final String info = 136 "org.apache.catalina.core.DefaultContext/1.0"; 137 138 139 143 private String instanceListeners[] = new String [0]; 144 145 146 149 private String mapperClass = 150 "org.apache.catalina.core.StandardContextMapper"; 151 152 153 156 private NamingResources namingResources = new NamingResources(); 157 158 159 163 private HashMap parameters = new HashMap (); 164 165 166 169 private boolean reloadable = false; 170 171 172 175 private boolean swallowOutput = false; 176 177 178 182 private String wrapperLifecycles[] = new String [0]; 183 184 185 189 private String wrapperListeners[] = new String [0]; 190 191 192 195 private String wrapperClass = "org.apache.catalina.core.StandardWrapper"; 196 197 198 201 private boolean useNaming = true; 202 203 204 209 DirContext dirContext = null; 210 211 212 215 protected String name = "defaultContext"; 216 217 218 221 protected Container parent = null; 222 223 224 227 protected Vector lifecycle = new Vector (); 228 229 230 233 protected Loader loader = null; 234 235 236 239 protected Manager manager = null; 240 241 242 245 protected boolean caseSensitive = true; 246 247 248 251 protected boolean allowLinking = false; 252 253 254 257 protected int cacheMaxSize = 10240; 259 260 263 protected int cacheTTL = 5000; 264 265 266 269 protected boolean cachingAllowed = true; 270 271 272 275 protected int managerChecksFrequency = 6; 276 277 278 281 protected static final StringManager sm = 282 StringManager.getManager(Constants.Package); 283 284 285 288 protected PropertyChangeSupport support = new PropertyChangeSupport (this); 289 290 291 293 294 297 public void setCaseSensitive(boolean caseSensitive) { 298 this.caseSensitive = caseSensitive; 299 } 300 301 302 305 public boolean isCaseSensitive() { 306 return caseSensitive; 307 } 308 309 310 313 public void setAllowLinking(boolean allowLinking) { 314 this.allowLinking = allowLinking; 315 } 316 317 318 321 public boolean isAllowLinking() { 322 return allowLinking; 323 } 324 325 326 329 public void setCacheTTL(int cacheTTL) { 330 this.cacheTTL = cacheTTL; 331 } 332 333 334 337 public int getCacheTTL() { 338 return cacheTTL; 339 } 340 341 342 345 public int getCacheMaxSize() { 346 return cacheMaxSize; 347 } 348 349 350 353 public void setCacheMaxSize(int cacheMaxSize) { 354 this.cacheMaxSize = cacheMaxSize; 355 } 356 357 358 361 public void setCachingAllowed(boolean cachingAllowed) { 362 this.cachingAllowed = cachingAllowed; 363 } 364 365 366 369 public boolean isCachingAllowed() { 370 return cachingAllowed; 371 } 372 373 374 377 public void setManagerChecksFrequency(int managerChecksFrequency) { 378 this.managerChecksFrequency = managerChecksFrequency; 379 } 380 381 382 385 public int getManagerChecksFrequency() { 386 return managerChecksFrequency; 387 } 388 389 390 393 public boolean isUseNaming() { 394 395 return (useNaming); 396 397 } 398 399 400 403 public void setUseNaming(boolean useNaming) { 404 this.useNaming = useNaming; 405 } 406 407 408 411 public boolean getCookies() { 412 413 return (this.cookies); 414 415 } 416 417 418 423 public void setCookies(boolean cookies) { 424 boolean oldCookies = this.cookies; 425 this.cookies = cookies; 426 427 } 428 429 430 433 public boolean getCrossContext() { 434 435 return (this.crossContext); 436 437 } 438 439 440 445 public void setCrossContext(boolean crossContext) { 446 boolean oldCrossContext = this.crossContext; 447 this.crossContext = crossContext; 448 449 } 450 451 452 457 public String getInfo() { 458 459 return (info); 460 461 } 462 463 464 467 public boolean getReloadable() { 468 469 return (this.reloadable); 470 471 } 472 473 474 479 public void setReloadable(boolean reloadable) { 480 boolean oldReloadable = this.reloadable; 481 this.reloadable = reloadable; 482 483 } 484 485 486 489 public boolean getSwallowOutput() { 490 491 return (this.swallowOutput); 492 493 } 494 495 496 501 public void setSwallowOutput(boolean swallowOutput) { 502 boolean oldSwallowOutput = this.swallowOutput; 503 this.swallowOutput = swallowOutput; 504 505 } 506 507 508 512 public String getWrapperClass() { 513 514 return (this.wrapperClass); 515 516 } 517 518 519 525 public void setWrapperClass(String wrapperClass) { 526 this.wrapperClass = wrapperClass; 527 528 } 529 530 531 537 public void setResources(DirContext resources) { 538 this.dirContext = resources; 539 540 } 541 542 548 public DirContext getResources() { 549 550 return this.dirContext; 551 552 } 553 554 555 559 public Loader getLoader() { 560 561 return loader; 562 563 } 564 565 566 571 public void setLoader(Loader loader) { 572 Loader oldLoader = this.loader; 573 this.loader = loader; 574 575 support.firePropertyChange("loader", oldLoader, this.loader); 577 } 578 579 580 584 public Manager getManager() { 585 586 return manager; 587 588 } 589 590 591 596 public void setManager(Manager manager) { 597 Manager oldManager = this.manager; 598 this.manager = manager; 599 600 support.firePropertyChange("manager", oldManager, this.manager); 602 } 603 604 605 607 608 613 public void addLifecycleListener(LifecycleListener listener) { 614 lifecycle.add(listener); 615 } 616 617 618 620 623 624 public String getName() { 625 return (this.name); 626 } 627 628 public void setName(String name) { 629 this.name = name; 630 } 631 632 633 637 public Container getParent() { 638 639 return (parent); 640 641 } 642 643 644 655 public void setParent(Container container) { 656 Container oldParent = this.parent; 657 this.parent = container; 658 support.firePropertyChange("parent", oldParent, this.parent); 659 660 } 661 662 664 665 671 public void addApplicationListener(String listener) { 672 673 synchronized (applicationListeners) { 674 String results[] =new String [applicationListeners.length + 1]; 675 for (int i = 0; i < applicationListeners.length; i++) 676 results[i] = applicationListeners[i]; 677 results[applicationListeners.length] = listener; 678 applicationListeners = results; 679 } 680 681 } 682 683 684 689 public void addApplicationParameter(ApplicationParameter parameter) { 690 691 synchronized (applicationParameters) { 692 ApplicationParameter results[] = 693 new ApplicationParameter[applicationParameters.length + 1]; 694 System.arraycopy(applicationParameters, 0, results, 0, 695 applicationParameters.length); 696 results[applicationParameters.length] = parameter; 697 applicationParameters = results; 698 } 699 700 } 701 702 703 708 public void addEjb(ContextEjb ejb) { 709 710 namingResources.addEjb(ejb); 711 712 } 713 714 715 720 public void addEnvironment(ContextEnvironment environment) { 721 722 namingResources.addEnvironment(environment); 723 724 } 725 726 727 732 public void addResourceParams(ResourceParams resourceParameters) { 733 734 namingResources.addResourceParams(resourceParameters); 735 736 } 737 738 739 745 public void addInstanceListener(String listener) { 746 747 synchronized (instanceListeners) { 748 String results[] =new String [instanceListeners.length + 1]; 749 for (int i = 0; i < instanceListeners.length; i++) 750 results[i] = instanceListeners[i]; 751 results[instanceListeners.length] = listener; 752 instanceListeners = results; 753 } 754 755 } 756 757 758 769 public void addParameter(String name, String value) { 770 if ((name == null) || (value == null)) 772 throw new IllegalArgumentException  773 (sm.getString("standardContext.parameter.required")); 774 if (parameters.get(name) != null) 775 throw new IllegalArgumentException  776 (sm.getString("standardContext.parameter.duplicate", name)); 777 778 synchronized (parameters) { 780 parameters.put(name, value); 781 } 782 783 } 784 785 786 791 public void addPropertyChangeListener(PropertyChangeListener listener) { 792 793 support.addPropertyChangeListener(listener); 794 795 } 796 797 798 803 public void addResource(ContextResource resource) { 804 805 namingResources.addResource(resource); 806 807 } 808 809 810 816 public void addResourceEnvRef(String name, String type) { 817 818 namingResources.addResourceEnvRef(name, type); 819 820 } 821 822 823 828 public void addResourceLink(ContextResourceLink resourceLink) { 829 830 namingResources.addResourceLink(resourceLink); 831 832 } 833 834 835 841 public void addWrapperLifecycle(String listener) { 842 843 synchronized (wrapperLifecycles) { 844 String results[] =new String [wrapperLifecycles.length + 1]; 845 for (int i = 0; i < wrapperLifecycles.length; i++) 846 results[i] = wrapperLifecycles[i]; 847 results[wrapperLifecycles.length] = listener; 848 wrapperLifecycles = results; 849 } 850 851 } 852 853 854 860 public void addWrapperListener(String listener) { 861 862 synchronized (wrapperListeners) { 863 String results[] =new String [wrapperListeners.length + 1]; 864 for (int i = 0; i < wrapperListeners.length; i++) 865 results[i] = wrapperListeners[i]; 866 results[wrapperListeners.length] = listener; 867 wrapperListeners = results; 868 } 869 870 } 871 872 873 877 public String [] findApplicationListeners() { 878 879 return (applicationListeners); 880 881 } 882 883 884 887 public ApplicationParameter[] findApplicationParameters() { 888 889 return (applicationParameters); 890 891 } 892 893 894 900 public ContextEjb findEjb(String name) { 901 902 return namingResources.findEjb(name); 903 904 } 905 906 907 911 public ContextEjb[] findEjbs() { 912 913 return namingResources.findEjbs(); 914 915 } 916 917 918 924 public ContextEnvironment findEnvironment(String name) { 925 926 return namingResources.findEnvironment(name); 927 928 } 929 930 931 936 public ContextEnvironment[] findEnvironments() { 937 938 return namingResources.findEnvironments(); 939 940 } 941 942 943 948 public ResourceParams[] findResourceParams() { 949 950 return namingResources.findResourceParams(); 951 952 } 953 954 955 959 public String [] findInstanceListeners() { 960 961 return (instanceListeners); 962 963 } 964 965 966 972 public String findParameter(String name) { 973 974 synchronized (parameters) { 975 return ((String ) parameters.get(name)); 976 } 977 978 } 979 980 981 986 public String [] findParameters() { 987 988 synchronized (parameters) { 989 String results[] = new String [parameters.size()]; 990 return ((String []) parameters.keySet().toArray(results)); 991 } 992 993 } 994 995 996 1002 public ContextResource findResource(String name) { 1003 1004 return namingResources.findResource(name); 1005 1006 } 1007 1008 1009 1015 public String findResourceEnvRef(String name) { 1016 1017 return namingResources.findResourceEnvRef(name); 1018 1019 } 1020 1021 1022 1027 public String [] findResourceEnvRefs() { 1028 1029 return namingResources.findResourceEnvRefs(); 1030 1031 } 1032 1033 1034 1040 public ContextResourceLink findResourceLink(String name) { 1041 1042 return namingResources.findResourceLink(name); 1043 1044 } 1045 1046 1047 1051 public ContextResourceLink[] findResourceLinks() { 1052 1053 return namingResources.findResourceLinks(); 1054 1055 } 1056 1057 1058 1062 public ContextResource[] findResources() { 1063 1064 return namingResources.findResources(); 1065 1066 } 1067 1068 1069 1073 public String [] findWrapperLifecycles() { 1074 1075 return (wrapperLifecycles); 1076 1077 } 1078 1079 1080 1084 public String [] findWrapperListeners() { 1085 1086 return (wrapperListeners); 1087 1088 } 1089 1090 1091 1094 public NamingResources getNamingResources() { 1095 1096 return (this.namingResources); 1097 1098 } 1099 1100 1101 1107 public void removeApplicationListener(String |