KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > catalina > core > StandardDefaultContext


1
2
3 /*
4  * The contents of this file are subject to the terms
5  * of the Common Development and Distribution License
6  * (the "License"). You may not use this file except
7  * in compliance with the License.
8  *
9  * You can obtain a copy of the license at
10  * glassfish/bootstrap/legal/CDDLv1.0.txt or
11  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
12  * See the License for the specific language governing
13  * permissions and limitations under the License.
14  *
15  * When distributing Covered Code, include this CDDL
16  * HEADER in each file and include the License file at
17  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
18  * add the following below this CDDL HEADER, with the
19  * fields enclosed by brackets "[]" replaced with your
20  * own identifying information: Portions Copyright [yyyy]
21  * [name of copyright owner]
22  *
23  * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24  *
25  * Portions Copyright Apache Software Foundation.
26  */

27
28
29 package org.apache.catalina.core;
30
31 import java.beans.PropertyChangeListener JavaDoc;
32 import java.beans.PropertyChangeSupport JavaDoc;
33 import java.lang.reflect.Constructor JavaDoc;
34 import java.util.ArrayList JavaDoc;
35 import java.util.Enumeration JavaDoc;
36 import java.util.HashMap JavaDoc;
37 import java.util.Hashtable JavaDoc;
38 import java.util.Vector JavaDoc;
39
40
41 import javax.management.MBeanRegistration JavaDoc;
42 import javax.management.MBeanServer JavaDoc;
43 import javax.management.MalformedObjectNameException JavaDoc;
44 import javax.management.ObjectName JavaDoc;
45 import javax.naming.directory.DirContext JavaDoc;
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 /**
70  * Used to store the default configuration a Host will use
71  * when creating a Context. A Context configured in server.xml
72  * can override these defaults by setting the Context attribute
73  * <CODE>override="true"</CODE>.
74  *
75  * @author Glenn Nielsen
76  * @version $Revision: 1.4 $ $Date: 2006/03/12 01:27:01 $
77  */

78
79 public class StandardDefaultContext
80     implements DefaultContext, LifecycleListener, MBeanRegistration JavaDoc {
81
82
83     // ----------------------------------------------------------- Constructors
84

85
86     /**
87      * Create the DefaultContext
88      */

89     public StandardDefaultContext() {
90
91         namingResources.setContainer(this);
92
93     }
94
95
96     // ----------------------------------------------------- Instance Variables
97

98
99     /**
100      * Contexts we are currently associated with.
101      */

102     private Hashtable JavaDoc contexts = new Hashtable JavaDoc();
103
104
105     /**
106      * The set of application listener class names configured for this
107      * application, in the order they were encountered in the web.xml file.
108      */

109     private String JavaDoc applicationListeners[] = new String JavaDoc[0];
110
111
112     /**
113      * The set of application parameters defined for this application.
114      */

115     private ApplicationParameter applicationParameters[] =
116         new ApplicationParameter[0];
117
118
119     /**
120      * Should we attempt to use cookies for session id communication?
121      */

122     private boolean cookies = true;
123
124
125     /**
126      * Should we allow the <code>ServletContext.getContext()</code> method
127      * to access the context of other web applications in this server?
128      */

129     private boolean crossContext = true;
130
131
132     /**
133      * The descriptive information string for this implementation.
134      */

135     private static final String JavaDoc info =
136         "org.apache.catalina.core.DefaultContext/1.0";
137
138
139     /**
140      * The set of classnames of InstanceListeners that will be added
141      * to each newly created Wrapper by <code>createWrapper()</code>.
142      */

143     private String JavaDoc instanceListeners[] = new String JavaDoc[0];
144
145
146     /**
147      * The Java class name of the default Mapper class for this Container.
148      */

149     private String JavaDoc mapperClass =
150         "org.apache.catalina.core.StandardContextMapper";
151
152
153     /**
154      * The associated naming resources.
155      */

156     private NamingResources namingResources = new NamingResources();
157
158
159     /**
160      * The context initialization parameters for this web application,
161      * keyed by name.
162      */

163     private HashMap JavaDoc parameters = new HashMap JavaDoc();
164
165
166     /**
167      * The reloadable flag for this web application.
168      */

169     private boolean reloadable = false;
170
171
172     /**
173      * The swallowOutput flag for this web application.
174      */

175     private boolean swallowOutput = false;
176
177
178     /**
179      * The set of classnames of LifecycleListeners that will be added
180      * to each newly created Wrapper by <code>createWrapper()</code>.
181      */

182     private String JavaDoc wrapperLifecycles[] = new String JavaDoc[0];
183
184
185     /**
186      * The set of classnames of ContainerListeners that will be added
187      * to each newly created Wrapper by <code>createWrapper()</code>.
188      */

189     private String JavaDoc wrapperListeners[] = new String JavaDoc[0];
190
191
192     /**
193      * Java class name of the Wrapper class implementation we use.
194      */

195     private String JavaDoc wrapperClass = "org.apache.catalina.core.StandardWrapper";
196
197
198     /**
199      * JNDI use flag.
200      */

201     private boolean useNaming = true;
202
203
204     /**
205      * The resources DirContext object with which this Container is
206      * associated.
207      *
208      */

209     DirContext JavaDoc dirContext = null;
210
211
212     /**
213      * The human-readable name of this Container.
214      */

215     protected String JavaDoc name = "defaultContext";
216
217
218     /**
219      * The parent Container to which this Container is a child.
220      */

221     protected Container parent = null;
222
223
224     /**
225      * The Context LifecycleListener's
226      */

227     protected Vector JavaDoc lifecycle = new Vector JavaDoc();
228
229
230     /**
231      * The Loader implementation with which this Container is associated.
232      */

233     protected Loader loader = null;
234
235
236     /**
237      * The Manager implementation with which this Container is associated.
238      */

239     protected Manager manager = null;
240
241
242     /**
243      * Case sensitivity.
244      */

245     protected boolean caseSensitive = true;
246
247
248     /**
249      * Allow linking.
250      */

251     protected boolean allowLinking = false;
252
253
254     /**
255      * Cache max size in KB.
256      */

257     protected int cacheMaxSize = 10240; // 10 MB
258

259
260     /**
261      * Cache TTL in ms.
262      */

263     protected int cacheTTL = 5000;
264
265
266     /**
267      * CachingAllowed.
268      */

269     protected boolean cachingAllowed = true;
270
271
272     /**
273      * Frequency of manager checks.
274      */

275     protected int managerChecksFrequency = 6;
276
277
278     /**
279      * The string manager for this package.
280      */

281     protected static final StringManager sm =
282         StringManager.getManager(Constants.Package);
283
284
285     /**
286      * The property change support for this component.
287      */

288     protected PropertyChangeSupport JavaDoc support = new PropertyChangeSupport JavaDoc(this);
289
290
291     // ----------------------------------------------------- Context Properties
292

293
294     /**
295      * Set case sensitivity.
296      */

297     public void setCaseSensitive(boolean caseSensitive) {
298         this.caseSensitive = caseSensitive;
299     }
300
301
302     /**
303      * Is case sensitive ?
304      */

305     public boolean isCaseSensitive() {
306         return caseSensitive;
307     }
308
309
310     /**
311      * Set allow linking.
312      */

313     public void setAllowLinking(boolean allowLinking) {
314         this.allowLinking = allowLinking;
315     }
316
317
318     /**
319      * Is linking allowed.
320      */

321     public boolean isAllowLinking() {
322         return allowLinking;
323     }
324
325
326     /**
327      * Set cache TTL.
328      */

329     public void setCacheTTL(int cacheTTL) {
330         this.cacheTTL = cacheTTL;
331     }
332
333
334     /**
335      * Get cache TTL.
336      */

337     public int getCacheTTL() {
338         return cacheTTL;
339     }
340
341
342     /**
343      * Return the maximum size of the cache in KB.
344      */

345     public int getCacheMaxSize() {
346         return cacheMaxSize;
347     }
348
349
350     /**
351      * Set the maximum size of the cache in KB.
352      */

353     public void setCacheMaxSize(int cacheMaxSize) {
354         this.cacheMaxSize = cacheMaxSize;
355     }
356
357
358     /**
359      * Set cachingAllowed.
360      */

361     public void setCachingAllowed(boolean cachingAllowed) {
362         this.cachingAllowed = cachingAllowed;
363     }
364
365
366     /**
367      * Is cachingAllowed ?
368      */

369     public boolean isCachingAllowed() {
370         return cachingAllowed;
371     }
372
373
374     /**
375      * Set the manager checks frequency.
376      */

377     public void setManagerChecksFrequency(int managerChecksFrequency) {
378         this.managerChecksFrequency = managerChecksFrequency;
379     }
380
381
382     /**
383      * Get manager checks frquency.
384      */

385     public int getManagerChecksFrequency() {
386         return managerChecksFrequency;
387     }
388  
389
390     /**
391      * Returns true if the internal naming support is used.
392      */

393     public boolean isUseNaming() {
394
395         return (useNaming);
396
397     }
398
399
400     /**
401      * Enables or disables naming.
402      */

403     public void setUseNaming(boolean useNaming) {
404         this.useNaming = useNaming;
405     }
406
407
408     /**
409      * Return the "use cookies for session ids" flag.
410      */

411     public boolean getCookies() {
412
413         return (this.cookies);
414
415     }
416
417
418     /**
419      * Set the "use cookies for session ids" flag.
420      *
421      * @param cookies The new flag
422      */

423     public void setCookies(boolean cookies) {
424         boolean oldCookies = this.cookies;
425         this.cookies = cookies;
426
427     }
428
429
430     /**
431      * Return the "allow crossing servlet contexts" flag.
432      */

433     public boolean getCrossContext() {
434
435         return (this.crossContext);
436
437     }
438
439
440     /**
441      * Set the "allow crossing servlet contexts" flag.
442      *
443      * @param crossContext The new cross contexts flag
444      */

445     public void setCrossContext(boolean crossContext) {
446         boolean oldCrossContext = this.crossContext;
447         this.crossContext = crossContext;
448
449     }
450
451
452     /**
453      * Return descriptive information about this Container implementation and
454      * the corresponding version number, in the format
455      * <code>&lt;description&gt;/&lt;version&gt;</code>.
456      */

457     public String JavaDoc getInfo() {
458
459         return (info);
460
461     }
462
463
464     /**
465      * Return the reloadable flag for this web application.
466      */

467     public boolean getReloadable() {
468
469         return (this.reloadable);
470
471     }
472
473
474     /**
475      * Set the reloadable flag for this web application.
476      *
477      * @param reloadable The new reloadable flag
478      */

479     public void setReloadable(boolean reloadable) {
480         boolean oldReloadable = this.reloadable;
481         this.reloadable = reloadable;
482
483     }
484
485
486     /**
487      * Return the swallowOutput flag for this web application.
488      */

489     public boolean getSwallowOutput() {
490
491         return (this.swallowOutput);
492
493     }
494
495
496     /**
497      * Set the swallowOutput flag for this web application.
498      *
499      * @param swallowOutput The new swallowOutput flag
500      */

501     public void setSwallowOutput(boolean swallowOutput) {
502         boolean oldSwallowOutput = this.swallowOutput;
503         this.swallowOutput = swallowOutput;
504
505     }
506
507
508     /**
509      * Return the Java class name of the Wrapper implementation used
510      * for servlets registered in this Context.
511      */

512     public String JavaDoc getWrapperClass() {
513
514         return (this.wrapperClass);
515
516     }
517
518
519     /**
520      * Set the Java class name of the Wrapper implementation used
521      * for servlets registered in this Context.
522      *
523      * @param wrapperClass The new wrapper class
524      */

525     public void setWrapperClass(String JavaDoc wrapperClass) {
526         this.wrapperClass = wrapperClass;
527
528     }
529
530
531     /**
532      * Set the resources DirContext object with which this Container is
533      * associated.
534      *
535      * @param resources The newly associated DirContext
536      */

537     public void setResources(DirContext JavaDoc resources) {
538         this.dirContext = resources;
539
540     }
541
542     /**
543      * Get the resources DirContext object with which this Container is
544      * associated.
545      *
546      * @param resources The new associated DirContext
547      */

548     public DirContext JavaDoc getResources() {
549
550         return this.dirContext;
551
552     }
553
554
555     /**
556      * Return the Loader with which this Container is associated. If there is
557      * no associated Loader return <code>null</code>.
558      */

559     public Loader getLoader() {
560
561         return loader;
562
563     }
564
565
566     /**
567      * Set the Loader with which this Context is associated.
568      *
569      * @param loader The newly associated loader
570      */

571     public void setLoader(Loader loader) {
572         Loader oldLoader = this.loader;
573         this.loader = loader;
574
575         // Report this property change to interested listeners
576
support.firePropertyChange("loader", oldLoader, this.loader);
577     }
578
579
580     /**
581      * Return the Manager with which this Container is associated. If there is
582      * no associated Manager return <code>null</code>.
583      */

584     public Manager getManager() {
585
586         return manager;
587
588     }
589
590
591     /**
592      * Set the Manager with which this Container is associated.
593      *
594      * @param manager The newly associated Manager
595      */

596     public void setManager(Manager manager) {
597         Manager oldManager = this.manager;
598         this.manager = manager;
599         
600         // Report this property change to interested listeners
601
support.firePropertyChange("manager", oldManager, this.manager);
602     }
603
604
605     // ------------------------------------------------------ Lifecycle Methods
606

607
608     /**
609      * Add a lifecycle event listener to this component.
610      *
611      * @param listener The listener to add
612      */

613     public void addLifecycleListener(LifecycleListener listener) {
614         lifecycle.add(listener);
615     }
616
617
618     // ------------------------------------------------------ Public Properties
619

620     /**
621      * The name of this DefaultContext
622      */

623
624     public String JavaDoc getName() {
625         return (this.name);
626     }
627
628     public void setName(String JavaDoc name) {
629         this.name = name;
630     }
631
632
633     /**
634      * Return the Container for which this Container is a child, if there is
635      * one. If there is no defined parent, return <code>null</code>.
636      */

637     public Container getParent() {
638
639         return (parent);
640
641     }
642
643
644     /**
645      * Set the parent Container to which this Container is being added as a
646      * child. This Container may refuse to become attached to the specified
647      * Container by throwing an exception.
648      *
649      * @param container Container to which this Container is being added
650      * as a child
651      *
652      * @exception IllegalArgumentException if this Container refuses to become
653      * attached to the specified Container
654      */

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     // -------------------------------------------------------- Context Methods
663

664
665     /**
666      * Add a new Listener class name to the set of Listeners
667      * configured for this application.
668      *
669      * @param listener Java class name of a listener class
670      */

671     public void addApplicationListener(String JavaDoc listener) {
672
673         synchronized (applicationListeners) {
674             String JavaDoc results[] =new String JavaDoc[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     /**
685      * Add a new application parameter for this application.
686      *
687      * @param parameter The new application parameter
688      */

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     /**
704      * Add an EJB resource reference for this web application.
705      *
706      * @param ejb New EJB resource reference
707      */

708     public void addEjb(ContextEjb ejb) {
709
710         namingResources.addEjb(ejb);
711
712     }
713
714
715     /**
716      * Add an environment entry for this web application.
717      *
718      * @param environment New environment entry
719      */

720     public void addEnvironment(ContextEnvironment environment) {
721
722         namingResources.addEnvironment(environment);
723
724     }
725
726
727     /**
728      * Add resource parameters for this web application.
729      *
730      * @param resourceParameters New resource parameters
731      */

732     public void addResourceParams(ResourceParams resourceParameters) {
733
734         namingResources.addResourceParams(resourceParameters);
735
736     }
737
738
739     /**
740      * Add the classname of an InstanceListener to be added to each
741      * Wrapper appended to this Context.
742      *
743      * @param listener Java class name of an InstanceListener class
744      */

745     public void addInstanceListener(String JavaDoc listener) {
746
747         synchronized (instanceListeners) {
748             String JavaDoc results[] =new String JavaDoc[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     /**
759      * Add a new context initialization parameter, replacing any existing
760      * value for the specified name.
761      *
762      * @param name Name of the new parameter
763      * @param value Value of the new parameter
764      *
765      * @exception IllegalArgumentException if the name or value is missing,
766      * or if this context initialization parameter has already been
767      * registered
768      */

769     public void addParameter(String JavaDoc name, String JavaDoc value) {
770         // Validate the proposed context initialization parameter
771
if ((name == null) || (value == null))
772             throw new IllegalArgumentException JavaDoc
773                 (sm.getString("standardContext.parameter.required"));
774         if (parameters.get(name) != null)
775             throw new IllegalArgumentException JavaDoc
776                 (sm.getString("standardContext.parameter.duplicate", name));
777
778         // Add this parameter to our defined set
779
synchronized (parameters) {
780             parameters.put(name, value);
781         }
782
783     }
784
785
786     /**
787      * Add a property change listener to this component.
788      *
789      * @param listener The listener to add
790      */

791     public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
792
793         support.addPropertyChangeListener(listener);
794
795     }
796     
797     
798     /**
799      * Add a resource reference for this web application.
800      *
801      * @param resource New resource reference
802      */

803     public void addResource(ContextResource resource) {
804
805         namingResources.addResource(resource);
806
807     }
808
809
810     /**
811      * Add a resource environment reference for this web application.
812      *
813      * @param name The resource environment reference name
814      * @param type The resource environment reference type
815      */

816     public void addResourceEnvRef(String JavaDoc name, String JavaDoc type) {
817
818         namingResources.addResourceEnvRef(name, type);
819
820     }
821
822
823     /**
824      * Add a resource link for this web application.
825      *
826      * @param resource New resource link
827      */

828     public void addResourceLink(ContextResourceLink resourceLink) {
829
830         namingResources.addResourceLink(resourceLink);
831
832     }
833
834
835     /**
836      * Add the classname of a LifecycleListener to be added to each
837      * Wrapper appended to this Context.
838      *
839      * @param listener Java class name of a LifecycleListener class
840      */

841     public void addWrapperLifecycle(String JavaDoc listener) {
842
843         synchronized (wrapperLifecycles) {
844             String JavaDoc results[] =new String JavaDoc[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     /**
855      * Add the classname of a ContainerListener to be added to each
856      * Wrapper appended to this Context.
857      *
858      * @param listener Java class name of a ContainerListener class
859      */

860     public void addWrapperListener(String JavaDoc listener) {
861
862         synchronized (wrapperListeners) {
863             String JavaDoc results[] =new String JavaDoc[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     /**
874      * Return the set of application listener class names configured
875      * for this application.
876      */

877     public String JavaDoc[] findApplicationListeners() {
878
879         return (applicationListeners);
880
881     }
882
883
884     /**
885      * Return the set of application parameters for this application.
886      */

887     public ApplicationParameter[] findApplicationParameters() {
888
889         return (applicationParameters);
890
891     }
892
893
894     /**
895      * Return the EJB resource reference with the specified name, if any;
896      * otherwise, return <code>null</code>.
897      *
898      * @param name Name of the desired EJB resource reference
899      */

900     public ContextEjb findEjb(String JavaDoc name) {
901
902         return namingResources.findEjb(name);
903
904     }
905
906
907     /**
908      * Return the defined EJB resource references for this application.
909      * If there are none, a zero-length array is returned.
910      */

911     public ContextEjb[] findEjbs() {
912
913         return namingResources.findEjbs();
914
915     }
916
917
918     /**
919      * Return the environment entry with the specified name, if any;
920      * otherwise, return <code>null</code>.
921      *
922      * @param name Name of the desired environment entry
923      */

924     public ContextEnvironment findEnvironment(String JavaDoc name) {
925
926         return namingResources.findEnvironment(name);
927
928     }
929
930
931     /**
932      * Return the set of defined environment entries for this web
933      * application. If none have been defined, a zero-length array
934      * is returned.
935      */

936     public ContextEnvironment[] findEnvironments() {
937
938         return namingResources.findEnvironments();
939
940     }
941
942
943     /**
944      * Return the set of defined resource parameters for this web
945      * application. If none have been defined, a zero-length array
946      * is returned.
947      */

948     public ResourceParams[] findResourceParams() {
949
950         return namingResources.findResourceParams();
951
952     }
953
954
955     /**
956      * Return the set of InstanceListener classes that will be added to
957      * newly created Wrappers automatically.
958      */

959     public String JavaDoc[] findInstanceListeners() {
960
961         return (instanceListeners);
962
963     }
964
965
966     /**
967      * Return the value for the specified context initialization
968      * parameter name, if any; otherwise return <code>null</code>.
969      *
970      * @param name Name of the parameter to return
971      */

972     public String JavaDoc findParameter(String JavaDoc name) {
973
974         synchronized (parameters) {
975             return ((String JavaDoc) parameters.get(name));
976         }
977
978     }
979
980
981     /**
982      * Return the names of all defined context initialization parameters
983      * for this Context. If no parameters are defined, a zero-length
984      * array is returned.
985      */

986     public String JavaDoc[] findParameters() {
987
988         synchronized (parameters) {
989             String JavaDoc results[] = new String JavaDoc[parameters.size()];
990             return ((String JavaDoc[]) parameters.keySet().toArray(results));
991         }
992
993     }
994
995
996     /**
997      * Return the resource reference with the specified name, if any;
998      * otherwise return <code>null</code>.
999      *
1000     * @param name Name of the desired resource reference
1001     */

1002    public ContextResource findResource(String JavaDoc name) {
1003
1004        return namingResources.findResource(name);
1005
1006    }
1007
1008
1009    /**
1010     * Return the resource environment reference type for the specified
1011     * name, if any; otherwise return <code>null</code>.
1012     *
1013     * @param name Name of the desired resource environment reference
1014     */

1015    public String JavaDoc findResourceEnvRef(String JavaDoc name) {
1016
1017        return namingResources.findResourceEnvRef(name);
1018
1019    }
1020
1021
1022    /**
1023     * Return the set of resource environment reference names for this
1024     * web application. If none have been specified, a zero-length
1025     * array is returned.
1026     */

1027    public String JavaDoc[] findResourceEnvRefs() {
1028
1029        return namingResources.findResourceEnvRefs();
1030
1031    }
1032
1033
1034    /**
1035     * Return the resource link with the specified name, if any;
1036     * otherwise return <code>null</code>.
1037     *
1038     * @param name Name of the desired resource link
1039     */

1040    public ContextResourceLink findResourceLink(String JavaDoc name) {
1041
1042        return namingResources.findResourceLink(name);
1043
1044    }
1045
1046
1047    /**
1048     * Return the defined resource links for this application. If
1049     * none have been defined, a zero-length array is returned.
1050     */

1051    public ContextResourceLink[] findResourceLinks() {
1052
1053        return namingResources.findResourceLinks();
1054
1055    }
1056
1057
1058    /**
1059     * Return the defined resource references for this application. If
1060     * none have been defined, a zero-length array is returned.
1061     */

1062    public ContextResource[] findResources() {
1063
1064        return namingResources.findResources();
1065
1066    }
1067
1068
1069    /**
1070     * Return the set of LifecycleListener classes that will be added to
1071     * newly created Wrappers automatically.
1072     */

1073    public String JavaDoc[] findWrapperLifecycles() {
1074
1075        return (wrapperLifecycles);
1076
1077    }
1078
1079
1080    /**
1081     * Return the set of ContainerListener classes that will be added to
1082     * newly created Wrappers automatically.
1083     */

1084    public String JavaDoc[] findWrapperListeners() {
1085
1086        return (wrapperListeners);
1087
1088    }
1089
1090
1091    /**
1092     * Return the naming resources associated with this web application.
1093     */

1094    public NamingResources getNamingResources() {
1095
1096        return (this.namingResources);
1097
1098    }
1099
1100
1101    /**
1102     * Remove the specified application listener class from the set of
1103     * listeners for this application.
1104     *
1105     * @param listener Java class name of the listener to be removed
1106     */

1107    public void removeApplicationListener(String JavaDoc listener) {
1108
1109        synchronized (applicationListeners) {
1110
1111            // Make sure this application listener is currently present
1112
int n = -1;
1113            for (int i = 0; i < applicationListeners.length; i++) {
1114                if (applicationListeners[i].equals(listener)) {
1115                    n = i;
1116                    break;
1117                }
1118            }
1119            if (n < 0)
1120                return;
1121
1122            // Remove the specified application listener
1123
int j = 0;
1124            String JavaDoc results[] = new String JavaDoc[applicationListeners.length - 1];
1125            for (int i = 0; i < applicationListeners.length; i++) {
1126                if (i != n)
1127                    results[j++] = applicationListeners[i];
1128            }
1129            applicationListeners = results;
1130
1131        }
1132
1133
1134    }
1135
1136
1137    /**
1138     * Remove the application parameter with the specified name from
1139     * the set for this application.
1140     *
1141     * @param name Name of the application parameter to remove
1142     */

1143    public void removeApplicationParameter(String JavaDoc name) {
1144
1145        synchronized (applicationParameters) {
1146
1147            // Make sure this parameter is currently present
1148
int n = -1;
1149            for (int i = 0; i < applicationParameters.length; i++) {
1150                if (name.equals(applicationParameters[i].getName())) {
1151                    n = i;
1152                    break;
1153                }
1154            }
1155            if (n < 0)
1156                return;
1157
1158            // Remove the specified parameter
1159
int j = 0;
1160            ApplicationParameter results[] =
1161                new ApplicationParameter[applicationParameters.length - 1];
1162            for (int i = 0; i < applicationParameters.length; i++) {
1163                if (i != n)
1164                    results[j++] = applicationParameters[i];
1165            }
1166            applicationParameters = results;
1167
1168        }
1169
1170    }
1171
1172
1173    /**
1174     * Remove any EJB resource reference with the specified name.
1175     *
1176     * @param name Name of the EJB resource reference to remove
1177     */

1178    public void removeEjb(String JavaDoc name) {
1179
1180        namingResources.removeEjb(name);
1181
1182    }
1183
1184
1185    /**
1186     * Remove a class name from the set of InstanceListener classes that
1187     * will be added to newly created Wrappers.
1188     *
1189     * @param listener Class name of an InstanceListener class to be removed
1190     */

1191    public void removeInstanceListener(String JavaDoc listener) {
1192
1193        synchronized (instanceListeners) {
1194
1195            // Make sure this InstanceListener is currently present
1196
int n = -1;
1197            for (int i = 0; i < instanceListeners.length; i++) {
1198                if (instanceListeners[i].equals(listener)) {
1199                    n = i;
1200                    break;
1201                }
1202            }
1203            if (n < 0)
1204                return;
1205
1206            // Remove the specified InstanceListener
1207
int j = 0;
1208            String JavaDoc results[] = new String JavaDoc[instanceListeners.length - 1];
1209            for (int i = 0; i < instanceListeners.length; i++) {
1210                if (i != n)
1211                    results[j++] = instanceListeners[i];
1212            }
1213            instanceListeners = results;
1214
1215        }
1216
1217    }
1218
1219
1220    /**
1221     * Remove the context initialization parameter with the specified
1222     * name, if it exists; otherwise, no action is taken.
1223     *
1224     * @param name Name of the parameter to remove
1225     */

1226    public void removeParameter(String JavaDoc name) {
1227
1228        synchronized (parameters) {
1229            parameters.remove(name);
1230        }
1231
1232    }
1233
1234
1235    /**
1236     * Remove a property change listener from this component.
1237     *
1238     * @param listener The listener to remove
1239     */

1240    public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {
1241
1242        support.removePropertyChangeListener(listener);
1243
1244    }
1245
1246    /**
1247     * Remove any environment entry with the specified name.
1248     *
1249     * @param name Name of the environment entry to remove
1250     */

1251    public void removeEnvironment(String JavaDoc envName) {
1252
1253        NamingResources nresources = getNamingResources();
1254        if (nresources == null) {
1255            return;
1256        }
1257        ContextEnvironment env = nresources.findEnvironment(envName);
1258        if (env == null) {
1259            throw new IllegalArgumentException JavaDoc
1260                ("Invalid environment name '" + envName + "'");
1261        }
1262        nresources.removeEnvironment(envName);
1263    }
1264
1265
1266    /**
1267     * Remove any resource reference with the specified name.
1268     *
1269     * @param resourceName Name of the resource reference to remove
1270     */

1271    public void removeResource(String JavaDoc resourceName) {
1272
1273        // That should be done in the UI
1274
// resourceName = URLDecoder.decode(resourceName);
1275
NamingResources nresources = getNamingResources();
1276        if (nresources == null) {
1277            return;
1278        }
1279        ContextResource resource = nresources.findResource(resourceName);
1280        if (resource == null) {
1281            throw new IllegalArgumentException JavaDoc
1282                ("Invalid resource name '" + resourceName + "'");
1283        }
1284        nresources.removeResource(resourceName);
1285    }
1286
1287
1288    /**
1289     * Remove any resource link with the specified name.
1290     *
1291     * @param resourceName Name of the resource reference to remove
1292     */

1293    public void removeResourceLink(String JavaDoc resourceLinkName) {
1294
1295        //resourceLinkName = URLDecoder.decode(resourceLinkName);
1296
NamingResources nresources = getNamingResources();
1297        if (nresources == null) {
1298            return;
1299        }
1300        ContextResourceLink resource = nresources.findResourceLink(resourceLinkName);
1301        if (resource == null) {
1302            throw new IllegalArgumentException JavaDoc
1303                ("Invalid resource name '" + resourceLinkName + "'");
1304        }
1305        nresources.removeResourceLink(resourceLinkName);
1306    }
1307
1308
1309    /**
1310     * Remove any resource environment reference with the specified name.
1311     *
1312     * @param name Name of the resource environment reference to remove
1313     */

1314    public void removeResourceEnvRef(String JavaDoc name) {
1315
1316        namingResources.removeResourceEnvRef(name);
1317
1318    }
1319
1320    /**
1321     * Remove a class name from the set of LifecycleListener classes that
1322     * will be added to newly created Wrappers.
1323     *
1324     * @param listener Class name of a LifecycleListener class to be removed
1325     */

1326    public void removeWrapperLifecycle(String JavaDoc listener) {
1327
1328
1329        synchronized (wrapperLifecycles) {
1330
1331            // Make sure this LifecycleListener is currently present
1332
int n = -1;
1333            for (int i = 0; i < wrapperLifecycles.length; i++) {
1334                if (wrapperLifecycles[i].equals(listener)) {
1335                    n = i;
1336                    break;
1337                }
1338            }
1339            if (n < 0)
1340                return;
1341
1342            // Remove the specified LifecycleListener
1343
int j = 0;
1344            String JavaDoc results[] = new String JavaDoc[wrapperLifecycles.length - 1];
1345            for (int i = 0; i < wrapperLifecycles.length; i++) {
1346                if (i != n)
1347                    results[j++] = wrapperLifecycles[i];
1348            }
1349            wrapperLifecycles = results;
1350
1351        }
1352
1353    }
1354
1355
1356    /**
1357     * Remove a class name from the set of ContainerListener classes that
1358     * will be added to newly created Wrappers.
1359     *
1360     * @param listener Class name of a ContainerListener class to be removed
1361     */

1362    public void removeWrapperListener(String JavaDoc listener) {
1363
1364
1365        synchronized (wrapperListeners) {
1366
1367            // Make sure this ContainerListener is currently present
1368
int n = -1;
1369            for (int i = 0; i < wrapperListeners.length; i++) {
1370                if (wrapperListeners[i].equals(listener)) {
1371                    n = i;
1372                    break;
1373                }
1374            }
1375            if (n < 0)
1376                return;
1377
1378            // Remove the specified ContainerListener
1379
int j = 0;
1380            String JavaDoc results[] = new String JavaDoc[wrapperListeners.length - 1];
1381            for (int i = 0; i < wrapperListeners.length; i++) {
1382                if (i != n)
1383                    results[j++] = wrapperListeners[i];
1384            }
1385            wrapperListeners = results;
1386
1387        }
1388
1389    }
1390
1391
1392    // --------------------------------------------------------- Public Methods
1393

1394
1395    /**
1396     * Process the START event for an associated Context.
1397     *
1398     * @param event The lifecycle event that has occurred
1399     */

1400    public void lifecycleEvent(LifecycleEvent event) {
1401
1402        StandardContext context = null;
1403        NamingContextListener listener = null;
1404
1405        if (event.getLifecycle() instanceof StandardContext) {
1406            context = (StandardContext) event.getLifecycle();
1407            LifecycleListener[] listeners = context.findLifecycleListeners();
1408            for (int i = 0; i < listeners.length; i++) {
1409                if (listeners[i] instanceof NamingContextListener) {
1410                    listener = (NamingContextListener) listeners[i];
1411                    break;
1412                }
1413            }
1414        }
1415
1416        if (listener == null) {
1417            return;
1418        }
1419
1420        if ((event.getType().equals(Lifecycle.BEFORE_STOP_EVENT))
1421            || (event.getType().equals(Context.RELOAD_EVENT))) {
1422
1423            // Remove context
1424
contexts.remove(context);
1425
1426            // Remove listener from the NamingResource listener list
1427
namingResources.removePropertyChangeListener(listener);
1428
1429            // Remove listener from lifecycle listeners
1430
if (!(event.getType().equals(Context.RELOAD_EVENT))) {
1431                context.removeLifecycleListener(this);
1432            }
1433
1434        }
1435
1436        if ((event.getType().equals(Lifecycle.AFTER_START_EVENT))
1437            || (event.getType().equals(Context.RELOAD_EVENT))) {
1438
1439            // Add context
1440
contexts.put(context, context);
1441
1442            NamingResources contextResources = context.getNamingResources();
1443
1444            // Setting the context in read/write mode
1445
ContextAccessController.setWritable(listener.getName(), context);
1446
1447            // Send notifications to the listener to add the appropriate
1448
// resources
1449
ContextEjb [] contextEjb = findEjbs();
1450            for (int i = 0; i < contextEjb.length; i++) {
1451                ContextEjb contextEntry = contextEjb[i];
1452                if (contextResources.exists(contextEntry.getName())) {
1453                    listener.removeEjb(contextEntry.getName());
1454                }
1455                listener.addEjb(contextEntry);
1456            }
1457            ContextEnvironment [] contextEnv = findEnvironments();
1458            for (int i = 0; i < contextEnv.length; i++) {
1459                ContextEnvironment contextEntry = contextEnv[i];
1460                if (contextResources.exists(contextEntry.getName())) {
1461                    listener.removeEnvironment(contextEntry.getName());
1462                }
1463                listener.addEnvironment(contextEntry);
1464            }
1465            ContextResource [] resources = findResources();
1466            for (int i = 0; i < resources.length; i++) {
1467                ContextResource contextEntry = resources[i];
1468                if (contextResources.exists(contextEntry.getName())) {
1469                    listener.removeResource(contextEntry.getName());
1470                }
1471                listener.addResource(contextEntry);
1472            }
1473            ContextResourceLink [] resourceLinks = findResourceLinks();
1474            for (int i = 0; i < resourceLinks.length; i++) {
1475                ContextResourceLink contextEntry = resourceLinks[i];
1476                if (contextResources.exists(contextEntry.getName())) {
1477                    listener.removeResourceLink(contextEntry.getName());
1478                }
1479                listener.addResourceLink(contextEntry);
1480            }
1481            String JavaDoc [] envRefs = findResourceEnvRefs();
1482            for (int i = 0; i < envRefs.length; i++) {
1483                if (contextResources.exists(envRefs[i])) {
1484                    listener.removeResourceEnvRef(envRefs[i]);
1485                }
1486                listener.addResourceEnvRef
1487                    (envRefs[i], findResourceEnvRef(envRefs[i]));
1488            }
1489
1490            // Setting the context in read only mode
1491
ContextAccessController.setReadOnly(listener.getName());
1492
1493            // Add listener to the NamingResources listener list
1494
namingResources.addPropertyChangeListener(listener);
1495
1496        }
1497
1498    }
1499
1500
1501    /**
1502     * Install the StandardContext portion of the DefaultContext
1503     * configuration into current Context.
1504     *
1505     * @param context current web application context
1506     */

1507    public void installDefaultContext(Context JavaDoc context) {
1508  
1509        if (context instanceof StandardContext) {
1510            ((StandardContext)context).setUseNaming(isUseNaming());
1511            ((StandardContext)context).setSwallowOutput(getSwallowOutput());
1512            ((StandardContext)context).setCachingAllowed(isCachingAllowed());
1513            ((StandardContext)context).setCacheTTL(getCacheTTL());
1514            ((StandardContext)context).setCacheMaxSize(getCacheMaxSize());
1515            ((StandardContext)context).setAllowLinking(isAllowLinking());
1516            ((StandardContext)context).setCaseSensitive(isCaseSensitive());
1517            ((StandardContext)context).setManagerChecksFrequency
1518                (getManagerChecksFrequency());
1519            if (!contexts.containsKey(context)) {
1520                ((StandardContext) context).addLifecycleListener(this);
1521            }
1522            Enumeration JavaDoc lifecycleListeners = lifecycle.elements();
1523            while (lifecycleListeners.hasMoreElements()) {
1524                ((StandardContext)context).addLifecycleListener(
1525                    (LifecycleListener)lifecycleListeners.nextElement());
1526              }
1527        }
1528
1529        if (!context.getPrivileged() && loader != null) {
1530            ClassLoader JavaDoc parentClassLoader = context.getParent().getParentClassLoader();
1531            Class JavaDoc clazz = loader.getClass();
1532            Class JavaDoc types[] = { ClassLoader JavaDoc.class };
1533            Object JavaDoc args[] = { parentClassLoader };
1534            try {
1535                Constructor JavaDoc constructor = clazz.getDeclaredConstructor(types);
1536                Loader context_loader = (Loader) constructor.newInstance(args);
1537                context_loader.setDelegate(loader.getDelegate());
1538                context_loader.setReloadable(loader.getReloadable());
1539                if (loader instanceof WebappLoader) {
1540                    ((WebappLoader)context_loader).setDebug
1541                        (((WebappLoader)loader).getDebug());
1542                    ((WebappLoader)context_loader).setLoaderClass
1543                        (((WebappLoader)loader).getLoaderClass());
1544                }
1545                context.setLoader(context_loader);
1546            } catch(Exception JavaDoc e) {
1547                IllegalArgumentException JavaDoc iae = new IllegalArgumentException JavaDoc
1548                   ("DefaultContext custom Loader install failed");
1549                iae.initCause(e);
1550                throw iae;
1551            }
1552        }
1553    }
1554
1555
1556    /**
1557     * Import the configuration from the DefaultContext into
1558     * current Context.
1559     *
1560     * @param context current web application context
1561     */

1562    public void importDefaultContext(Context JavaDoc context) {
1563
1564        context.setCookies(getCookies());
1565        context.setCrossContext(getCrossContext());
1566        context.setReloadable(getReloadable());
1567
1568        String JavaDoc [] listeners = findApplicationListeners();
1569        for( int i = 0; i < listeners.length; i++ ) {
1570            context.addApplicationListener(listeners[i]);
1571        }
1572        listeners = findInstanceListeners();
1573        for( int i = 0; i < listeners.length; i++ ) {
1574            context.addInstanceListener(listeners[i]);
1575        }
1576        String JavaDoc [] wrapper = findWrapperListeners();
1577        for( int i = 0; i < wrapper.length; i++ ) {
1578            context.addWrapperListener(wrapper[i]);
1579        }
1580        wrapper = findWrapperLifecycles();
1581        for( int i = 0; i < wrapper.length; i++ ) {
1582            context.addWrapperLifecycle(wrapper[i]);
1583        }
1584        String JavaDoc [] parameters = findParameters();
1585        for( int i = 0; i < parameters.length; i++ ) {
1586            context.addParameter(parameters[i],findParameter(parameters[i]));
1587        }
1588        ApplicationParameter [] appParam = findApplicationParameters();
1589        for( int i = 0; i < appParam.length; i++ ) {
1590            context.addApplicationParameter(appParam[i]);
1591        }
1592
1593        if (!(context instanceof StandardContext)) {
1594            ContextEjb [] contextEjb = findEjbs();
1595            for( int i = 0; i < contextEjb.length; i++ ) {
1596                context.addEjb(contextEjb[i]);
1597            }
1598            ContextEnvironment [] contextEnv = findEnvironments();
1599            for( int i = 0; i < contextEnv.length; i++ ) {
1600                context.addEnvironment(contextEnv[i]);
1601            }
1602            /*
1603            if (context instanceof StandardContext) {
1604                ResourceParams [] resourceParams = findResourceParams();
1605                for( int i = 0; i < resourceParams.length; i++ ) {
1606                    ((StandardContext)context).addResourceParams
1607                        (resourceParams[i]);
1608                }
1609            }
1610            */

1611            ContextResource [] resources = findResources();
1612            for( int i = 0; i < resources.length; i++ ) {
1613                context.addResource(resources[i]);
1614            }
1615            ContextResourceLink [] resourceLinks = findResourceLinks();
1616            for( int i = 0; i < resourceLinks.length; i++ ) {
1617                context.addResourceLink(resourceLinks[i]);
1618            }
1619            String JavaDoc [] envRefs = findResourceEnvRefs();
1620            for( int i = 0; i < envRefs.length; i++ ) {
1621                context.addResourceEnvRef
1622                    (envRefs[i],findResourceEnvRef(envRefs[i]));
1623            }
1624        }
1625
1626    }
1627
1628    /**
1629     * Return a String representation of this component.
1630     */

1631    public String JavaDoc toString() {
1632
1633        StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
1634        if (getParent() != null) {
1635            sb.append(getParent().toString());
1636            sb.append(".");
1637        }
1638        sb.append("DefaultContext[");
1639        sb.append("]");
1640        return (sb.toString());
1641
1642    }
1643
1644    // -------------------- JMX stuff --------------------
1645
protected String JavaDoc type;
1646    protected String JavaDoc domain;
1647    protected String JavaDoc suffix;
1648    protected ObjectName JavaDoc oname;
1649    protected MBeanServer JavaDoc mserver;
1650
1651    public ObjectName JavaDoc getObjectName() {
1652        return oname;
1653    }
1654
1655    public String JavaDoc getDomain() {
1656        return domain;
1657    }
1658
1659    public String JavaDoc getType() {
1660        return type;
1661    }
1662
1663    protected String JavaDoc getJSR77Suffix() {
1664        return suffix;
1665    }
1666
1667    public ObjectName JavaDoc preRegister(MBeanServer JavaDoc server,
1668                                  ObjectName JavaDoc name) throws Exception JavaDoc {
1669        oname=name;
1670        mserver=server;
1671        domain=name.getDomain();
1672
1673        type=name.getKeyProperty("type");
1674        if( type==null ) {
1675            type=name.getKeyProperty("j2eeType");
1676        }
1677
1678        String JavaDoc j2eeApp=name.getKeyProperty("J2EEApplication");
1679        String JavaDoc j2eeServer=name.getKeyProperty("J2EEServer");
1680        if( j2eeApp==null ) {
1681            j2eeApp="none";
1682        }
1683        if( j2eeServer==null ) {
1684            j2eeServer="none";
1685        }
1686        suffix=",J2EEApplication=" + j2eeApp + ",J2EEServer=" + j2eeServer;
1687        return name;
1688    }
1689
1690    public void postRegister(Boolean JavaDoc registrationDone) {
1691    }
1692
1693    public void preDeregister() throws Exception JavaDoc {
1694    }
1695
1696    public void postDeregister() {
1697    }
1698
1699    /**
1700     * Return the MBean Names of the set of defined environment entries for
1701     * this web application
1702     */

1703    public String JavaDoc[] getEnvironments() {
1704        ContextEnvironment[] envs = getNamingResources().findEnvironments();
1705        ArrayList JavaDoc results = new ArrayList JavaDoc();
1706        for (int i = 0; i < envs.length; i++) {
1707            try {
1708                ObjectName JavaDoc oname =
1709                    MBeanUtils.createObjectName(this.getDomain(), envs[i]);
1710                results.add(oname.toString());
1711            } catch (MalformedObjectNameException JavaDoc e) {
1712                IllegalArgumentException JavaDoc iae = new IllegalArgumentException JavaDoc
1713                    ("Cannot create object name for environment " + envs[i]);
1714                iae.initCause(e);
1715                throw iae;
1716            }
1717        }
1718        return ((String JavaDoc[]) results.toArray(new String JavaDoc[results.size()]));
1719
1720    }
1721
1722
1723    /**
1724     * Return the MBean Names of all the defined resource references for this
1725     * application.
1726     * XXX This changed - due to conflict
1727     */

1728    public String JavaDoc[] getResourceNames() {
1729
1730        ContextResource[] resources = getNamingResources().findResources();
1731        ArrayList JavaDoc results = new ArrayList JavaDoc();
1732        for (int i = 0; i < resources.length; i++) {
1733            try {
1734                ObjectName JavaDoc oname =
1735                    MBeanUtils.createObjectName(getDomain(), resources[i]);
1736                results.add(oname.toString());
1737            } catch (MalformedObjectNameException JavaDoc e) {
1738                IllegalArgumentException JavaDoc iae = new IllegalArgumentException JavaDoc
1739                    ("Cannot create object name for resource " + resources[i]);
1740                iae.initCause(e);
1741                throw iae;
1742            }
1743        }
1744        return ((String JavaDoc[]) results.toArray(new String JavaDoc[results.size()]));
1745
1746    }
1747
1748
1749    /**
1750     * Return the MBean Names of all the defined resource links for this
1751     * application
1752     */

1753    public String JavaDoc[] getResourceLinks() {
1754
1755        ContextResourceLink[] links = getNamingResources().findResourceLinks();
1756        ArrayList JavaDoc results = new ArrayList JavaDoc();
1757        for (int i = 0; i < links.length; i++) {
1758            try {
1759                ObjectName JavaDoc oname =
1760                    MBeanUtils.createObjectName(getDomain(), links[i]);
1761                results.add(oname.toString());
1762            } catch (MalformedObjectNameException JavaDoc e) {
1763                IllegalArgumentException JavaDoc iae = new IllegalArgumentException JavaDoc
1764                    ("Cannot create object name for resource " + links[i]);
1765                iae.initCause(e);
1766                throw iae;
1767            }
1768        }
1769        return ((String JavaDoc[]) results.toArray(new String JavaDoc[results.size()]));
1770
1771    }
1772
1773    // ------------------------------------------------------------- Operations
1774

1775
1776    /**
1777     * Add an environment entry for this web application.
1778     *
1779     * @param envName New environment entry name
1780     */

1781    public String JavaDoc addEnvironment(String JavaDoc envName, String JavaDoc type)
1782        throws MalformedObjectNameException JavaDoc {
1783
1784        NamingResources nresources = getNamingResources();
1785        if (nresources == null) {
1786            return null;
1787        }
1788        ContextEnvironment env = nresources.findEnvironment(envName);
1789        if (env != null) {
1790            throw new IllegalArgumentException JavaDoc
1791                ("Invalid environment name - already exists '" + envName + "'");
1792        }
1793        env = new ContextEnvironment();
1794        env.setName(envName);
1795        env.setType(type);
1796        nresources.addEnvironment(env);
1797
1798        // Return the corresponding MBean name
1799
ManagedBean managed = Registry.getRegistry().findManagedBean("ContextEnvironment");
1800        ObjectName JavaDoc oname =
1801            MBeanUtils.createObjectName(managed.getDomain(), env);
1802        return (oname.toString());
1803
1804    }
1805
1806
1807    /**
1808     * Add a resource reference for this web application.
1809     *
1810     * @param resourceName New resource reference name
1811     */

1812    public String JavaDoc addResource(String JavaDoc resourceName, String JavaDoc type)
1813        throws MalformedObjectNameException JavaDoc {
1814
1815        NamingResources nresources = getNamingResources();
1816        if (nresources == null) {
1817            return null;
1818        }
1819        ContextResource resource = nresources.findResource(resourceName);
1820        if (resource != null) {
1821            throw new IllegalArgumentException JavaDoc
1822                ("Invalid resource name - already exists'" + resourceName + "'");
1823        }
1824        resource = new ContextResource();
1825        resource.setName(resourceName);
1826        resource.setType(type);
1827        nresources.addResource(resource);
1828
1829        // Return the corresponding MBean name
1830
ManagedBean managed = Registry.getRegistry().findManagedBean("ContextResource");
1831        ObjectName JavaDoc oname =
1832            MBeanUtils.createObjectName(managed.getDomain(), resource);
1833
1834        return (oname.toString());
1835    }
1836
1837
1838    /**
1839     * Add a resource link for this web application.
1840     *
1841     * @param resourceLinkName New resource link name
1842     */

1843    public String JavaDoc addResourceLink(String JavaDoc resourceLinkName, String JavaDoc global,
1844                String JavaDoc name, String JavaDoc type) throws MalformedObjectNameException JavaDoc {
1845
1846        NamingResources nresources = getNamingResources();
1847        if (nresources == null) {
1848            return null;
1849        }
1850        ContextResourceLink resourceLink =
1851                                nresources.findResourceLink(resourceLinkName);
1852        if (resourceLink != null) {
1853            throw new IllegalArgumentException JavaDoc
1854                ("Invalid resource link name - already exists'" +
1855                                                        resourceLinkName + "'");
1856        }
1857        resourceLink = new ContextResourceLink();
1858        resourceLink.setGlobal(global);
1859        resourceLink.setName(resourceLinkName);
1860        resourceLink.setType(type);
1861        nresources.addResourceLink(resourceLink);
1862
1863        // Return the corresponding MBean name
1864
ManagedBean managed = Registry.getRegistry().findManagedBean("ContextResourceLink");
1865        ObjectName JavaDoc oname =
1866            MBeanUtils.createObjectName(managed.getDomain(), resourceLink);
1867        return (oname.toString());
1868    }
1869}
1870
Popular Tags