Source Code Cross Referenced for StandardDefaultContext.java in  » Web-Server » Rimfaxe-Web-Server » org » apache » catalina » core » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Server » Rimfaxe Web Server » org.apache.catalina.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardDefaultContext.java,v 1.6 2002/06/25 22:29:23 remm Exp $
0003:         * $Revision: 1.6 $
0004:         * $Date: 2002/06/25 22:29:23 $
0005:         *
0006:         * ====================================================================
0007:         *
0008:         * The Apache Software License, Version 1.1
0009:         *
0010:         * Copyright (c) 1999 The Apache Software Foundation.  All rights
0011:         * reserved.
0012:         *
0013:         * Redistribution and use in source and binary forms, with or without
0014:         * modification, are permitted provided that the following conditions
0015:         * are met:
0016:         *
0017:         * 1. Redistributions of source code must retain the above copyright
0018:         *    notice, this list of conditions and the following disclaimer.
0019:         *
0020:         * 2. Redistributions in binary form must reproduce the above copyright
0021:         *    notice, this list of conditions and the following disclaimer in
0022:         *    the documentation and/or other materials provided with the
0023:         *    distribution.
0024:         *
0025:         * 3. The end-user documentation included with the redistribution, if
0026:         *    any, must include the following acknowlegement:
0027:         *       "This product includes software developed by the
0028:         *        Apache Software Foundation (http://www.apache.org/)."
0029:         *    Alternately, this acknowlegement may appear in the software itself,
0030:         *    if and wherever such third-party acknowlegements normally appear.
0031:         *
0032:         * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
0033:         *    Foundation" must not be used to endorse or promote products derived
0034:         *    from this software without prior written permission. For written
0035:         *    permission, please contact apache@apache.org.
0036:         *
0037:         * 5. Products derived from this software may not be called "Apache"
0038:         *    nor may "Apache" appear in their names without prior written
0039:         *    permission of the Apache Group.
0040:         *
0041:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
0042:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0043:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0044:         * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
0045:         * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0046:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0047:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
0048:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
0049:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
0050:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
0051:         * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0052:         * SUCH DAMAGE.
0053:         * ====================================================================
0054:         *
0055:         * This software consists of voluntary contributions made by many
0056:         * individuals on behalf of the Apache Software Foundation.  For more
0057:         * information on the Apache Software Foundation, please see
0058:         * <http://www.apache.org/>.
0059:         *
0060:         * [Additional notices, if required by prior licensing conditions]
0061:         *
0062:         */
0063:
0064:        package org.apache.catalina.core;
0065:
0066:        import java.beans.PropertyChangeListener;
0067:        import java.beans.PropertyChangeSupport;
0068:        import java.util.Enumeration;
0069:        import java.util.HashMap;
0070:        import java.util.Hashtable;
0071:        import java.util.Iterator;
0072:        import javax.naming.directory.DirContext;
0073:        import org.apache.naming.ContextAccessController;
0074:        import org.apache.catalina.Container;
0075:        import org.apache.catalina.ContainerListener;
0076:        import org.apache.catalina.Context;
0077:        import org.apache.catalina.DefaultContext;
0078:        import org.apache.catalina.InstanceListener;
0079:        import org.apache.catalina.Lifecycle;
0080:        import org.apache.catalina.LifecycleEvent;
0081:        import org.apache.catalina.LifecycleException;
0082:        import org.apache.catalina.LifecycleListener;
0083:        import org.apache.catalina.Loader;
0084:        import org.apache.catalina.Manager;
0085:        import org.apache.catalina.Wrapper;
0086:        import org.apache.catalina.deploy.ApplicationParameter;
0087:        import org.apache.catalina.deploy.ContextEjb;
0088:        import org.apache.catalina.deploy.ContextEnvironment;
0089:        import org.apache.catalina.deploy.ContextResource;
0090:        import org.apache.catalina.deploy.ContextResourceLink;
0091:        import org.apache.catalina.deploy.NamingResources;
0092:        import org.apache.catalina.deploy.ResourceParams;
0093:        import org.apache.catalina.util.StringManager;
0094:
0095:        /**
0096:         * Used to store the default configuration a Host will use
0097:         * when creating a Context.  A Context configured in server.xml
0098:         * can override these defaults by setting the Context attribute
0099:         * <CODE>override="true"</CODE>.
0100:         *
0101:         * @author Glenn Nielsen
0102:         * @version $Revision: 1.6 $ $Date: 2002/06/25 22:29:23 $
0103:         */
0104:
0105:        public class StandardDefaultContext implements  DefaultContext,
0106:                LifecycleListener {
0107:
0108:            // ----------------------------------------------------------- Constructors
0109:
0110:            /**
0111:             * Create the DefaultContext
0112:             */
0113:            public StandardDefaultContext() {
0114:
0115:                namingResources.setContainer(this );
0116:
0117:            }
0118:
0119:            // ----------------------------------------------------- Instance Variables
0120:
0121:            /**
0122:             * Contexts we are currently associated with.
0123:             */
0124:            private Hashtable contexts = new Hashtable();
0125:
0126:            /**
0127:             * The set of application listener class names configured for this
0128:             * application, in the order they were encountered in the web.xml file.
0129:             */
0130:            private String applicationListeners[] = new String[0];
0131:
0132:            /**
0133:             * The set of application parameters defined for this application.
0134:             */
0135:            private ApplicationParameter applicationParameters[] = new ApplicationParameter[0];
0136:
0137:            /**
0138:             * Should we attempt to use cookies for session id communication?
0139:             */
0140:            private boolean cookies = true;
0141:
0142:            /**
0143:             * Should we allow the <code>ServletContext.getContext()</code> method
0144:             * to access the context of other web applications in this server?
0145:             */
0146:            private boolean crossContext = true;
0147:
0148:            /**
0149:             * The descriptive information string for this implementation.
0150:             */
0151:            private static final String info = "org.apache.catalina.core.DefaultContext/1.0";
0152:
0153:            /**
0154:             * The set of classnames of InstanceListeners that will be added
0155:             * to each newly created Wrapper by <code>createWrapper()</code>.
0156:             */
0157:            private String instanceListeners[] = new String[0];
0158:
0159:            /**
0160:             * The Java class name of the default Mapper class for this Container.
0161:             */
0162:            private String mapperClass = "org.apache.catalina.core.StandardContextMapper";
0163:
0164:            /**
0165:             * The associated naming resources.
0166:             */
0167:            private NamingResources namingResources = new NamingResources();
0168:
0169:            /**
0170:             * The context initialization parameters for this web application,
0171:             * keyed by name.
0172:             */
0173:            private HashMap parameters = new HashMap();
0174:
0175:            /**
0176:             * The reloadable flag for this web application.
0177:             */
0178:            private boolean reloadable = false;
0179:
0180:            /**
0181:             * The set of classnames of LifecycleListeners that will be added
0182:             * to each newly created Wrapper by <code>createWrapper()</code>.
0183:             */
0184:            private String wrapperLifecycles[] = new String[0];
0185:
0186:            /**
0187:             * The set of classnames of ContainerListeners that will be added
0188:             * to each newly created Wrapper by <code>createWrapper()</code>.
0189:             */
0190:            private String wrapperListeners[] = new String[0];
0191:
0192:            /**
0193:             * Java class name of the Wrapper class implementation we use.
0194:             */
0195:            private String wrapperClass = "org.apache.catalina.core.StandardWrapper";
0196:
0197:            /**
0198:             * JNDI use flag.
0199:             */
0200:            private boolean useNaming = true;
0201:
0202:            /**
0203:             * The resources DirContext object with which this Container is
0204:             * associated.
0205:             *
0206:             */
0207:            DirContext dirContext = null;
0208:
0209:            /**
0210:             * The human-readable name of this Container.
0211:             */
0212:            protected String name = "defaultContext";
0213:
0214:            /**
0215:             * The parent Container to which this Container is a child.
0216:             */
0217:            protected Container parent = null;
0218:
0219:            /**
0220:             * The Loader implementation with which this Container is associated.
0221:             */
0222:            protected Loader loader = null;
0223:
0224:            /**
0225:             * The Manager implementation with which this Container is associated.
0226:             */
0227:            protected Manager manager = null;
0228:
0229:            /**
0230:             * The string manager for this package.
0231:             */
0232:            protected static StringManager sm = StringManager
0233:                    .getManager(Constants.Package);
0234:
0235:            /**
0236:             * The property change support for this component.
0237:             */
0238:            protected PropertyChangeSupport support = new PropertyChangeSupport(
0239:                    this );
0240:
0241:            // ----------------------------------------------------- Context Properties
0242:
0243:            /**
0244:             * Returns true if the internal naming support is used.
0245:             */
0246:            public boolean isUseNaming() {
0247:
0248:                return (useNaming);
0249:
0250:            }
0251:
0252:            /**
0253:             * Enables or disables naming.
0254:             */
0255:            public void setUseNaming(boolean useNaming) {
0256:                this .useNaming = useNaming;
0257:            }
0258:
0259:            /**
0260:             * Return the "use cookies for session ids" flag.
0261:             */
0262:            public boolean getCookies() {
0263:
0264:                return (this .cookies);
0265:
0266:            }
0267:
0268:            /**
0269:             * Set the "use cookies for session ids" flag.
0270:             *
0271:             * @param cookies The new flag
0272:             */
0273:            public void setCookies(boolean cookies) {
0274:                boolean oldCookies = this .cookies;
0275:                this .cookies = cookies;
0276:
0277:            }
0278:
0279:            /**
0280:             * Return the "allow crossing servlet contexts" flag.
0281:             */
0282:            public boolean getCrossContext() {
0283:
0284:                return (this .crossContext);
0285:
0286:            }
0287:
0288:            /**
0289:             * Set the "allow crossing servlet contexts" flag.
0290:             *
0291:             * @param crossContext The new cross contexts flag
0292:             */
0293:            public void setCrossContext(boolean crossContext) {
0294:                boolean oldCrossContext = this .crossContext;
0295:                this .crossContext = crossContext;
0296:
0297:            }
0298:
0299:            /**
0300:             * Return descriptive information about this Container implementation and
0301:             * the corresponding version number, in the format
0302:             * <code>&lt;description&gt;/&lt;version&gt;</code>.
0303:             */
0304:            public String getInfo() {
0305:
0306:                return (info);
0307:
0308:            }
0309:
0310:            /**
0311:             * Return the reloadable flag for this web application.
0312:             */
0313:            public boolean getReloadable() {
0314:
0315:                return (this .reloadable);
0316:
0317:            }
0318:
0319:            /**
0320:             * Set the reloadable flag for this web application.
0321:             *
0322:             * @param reloadable The new reloadable flag
0323:             */
0324:            public void setReloadable(boolean reloadable) {
0325:                boolean oldReloadable = this .reloadable;
0326:                this .reloadable = reloadable;
0327:
0328:            }
0329:
0330:            /**
0331:             * Return the Java class name of the Wrapper implementation used
0332:             * for servlets registered in this Context.
0333:             */
0334:            public String getWrapperClass() {
0335:
0336:                return (this .wrapperClass);
0337:
0338:            }
0339:
0340:            /**
0341:             * Set the Java class name of the Wrapper implementation used
0342:             * for servlets registered in this Context.
0343:             *
0344:             * @param wrapperClass The new wrapper class
0345:             */
0346:            public void setWrapperClass(String wrapperClass) {
0347:                this .wrapperClass = wrapperClass;
0348:
0349:            }
0350:
0351:            /**
0352:             * Set the resources DirContext object with which this Container is
0353:             * associated.
0354:             *
0355:             * @param resources The newly associated DirContext
0356:             */
0357:            public void setResources(DirContext resources) {
0358:                this .dirContext = resources;
0359:
0360:            }
0361:
0362:            /**
0363:             * Get the resources DirContext object with which this Container is
0364:             * associated.
0365:             *
0366:             * @param resources The new associated DirContext
0367:             */
0368:            public DirContext getResources() {
0369:
0370:                return this .dirContext;
0371:
0372:            }
0373:
0374:            /**
0375:             * Return the Loader with which this Container is associated.  If there is
0376:             * no associated Loader return <code>null</code>.
0377:             */
0378:            public Loader getLoader() {
0379:
0380:                return loader;
0381:
0382:            }
0383:
0384:            /**
0385:             * Set the Loader with which this Context is associated.
0386:             *
0387:             * @param loader The newly associated loader
0388:             */
0389:            public void setLoader(Loader loader) {
0390:                Loader oldLoader = this .loader;
0391:                this .loader = loader;
0392:
0393:                // Report this property change to interested listeners
0394:                support.firePropertyChange("loader", oldLoader, this .loader);
0395:            }
0396:
0397:            /**
0398:             * Return the Manager with which this Container is associated.  If there is
0399:             * no associated Manager return <code>null</code>.
0400:             */
0401:            public Manager getManager() {
0402:
0403:                return manager;
0404:
0405:            }
0406:
0407:            /**
0408:             * Set the Manager with which this Container is associated.
0409:             *
0410:             * @param manager The newly associated Manager
0411:             */
0412:            public void setManager(Manager manager) {
0413:                Manager oldManager = this .manager;
0414:                this .manager = manager;
0415:
0416:                // Report this property change to interested listeners
0417:                support.firePropertyChange("manager", oldManager, this .manager);
0418:            }
0419:
0420:            // ------------------------------------------------------ Public Properties
0421:
0422:            /**
0423:             * The name of this DefaultContext
0424:             */
0425:
0426:            public String getName() {
0427:                return (this .name);
0428:            }
0429:
0430:            public void setName(String name) {
0431:                this .name = name;
0432:            }
0433:
0434:            /**
0435:             * Return the Container for which this Container is a child, if there is
0436:             * one.  If there is no defined parent, return <code>null</code>.
0437:             */
0438:            public Container getParent() {
0439:
0440:                return (parent);
0441:
0442:            }
0443:
0444:            /**
0445:             * Set the parent Container to which this Container is being added as a
0446:             * child.  This Container may refuse to become attached to the specified
0447:             * Container by throwing an exception.
0448:             *
0449:             * @param container Container to which this Container is being added
0450:             *  as a child
0451:             *
0452:             * @exception IllegalArgumentException if this Container refuses to become
0453:             *  attached to the specified Container
0454:             */
0455:            public void setParent(Container container) {
0456:                Container oldParent = this .parent;
0457:                this .parent = container;
0458:                support.firePropertyChange("parent", oldParent, this .parent);
0459:
0460:            }
0461:
0462:            // -------------------------------------------------------- Context Methods
0463:
0464:            /**
0465:             * Add a new Listener class name to the set of Listeners
0466:             * configured for this application.
0467:             *
0468:             * @param listener Java class name of a listener class
0469:             */
0470:            public void addApplicationListener(String listener) {
0471:
0472:                synchronized (applicationListeners) {
0473:                    String results[] = new String[applicationListeners.length + 1];
0474:                    for (int i = 0; i < applicationListeners.length; i++)
0475:                        results[i] = applicationListeners[i];
0476:                    results[applicationListeners.length] = listener;
0477:                    applicationListeners = results;
0478:                }
0479:
0480:            }
0481:
0482:            /**
0483:             * Add a new application parameter for this application.
0484:             *
0485:             * @param parameter The new application parameter
0486:             */
0487:            public void addApplicationParameter(ApplicationParameter parameter) {
0488:
0489:                synchronized (applicationParameters) {
0490:                    ApplicationParameter results[] = new ApplicationParameter[applicationParameters.length + 1];
0491:                    System.arraycopy(applicationParameters, 0, results, 0,
0492:                            applicationParameters.length);
0493:                    results[applicationParameters.length] = parameter;
0494:                    applicationParameters = results;
0495:                }
0496:
0497:            }
0498:
0499:            /**
0500:             * Add an EJB resource reference for this web application.
0501:             *
0502:             * @param ejb New EJB resource reference
0503:             */
0504:            public void addEjb(ContextEjb ejb) {
0505:
0506:                namingResources.addEjb(ejb);
0507:
0508:            }
0509:
0510:            /**
0511:             * Add an environment entry for this web application.
0512:             *
0513:             * @param environment New environment entry
0514:             */
0515:            public void addEnvironment(ContextEnvironment environment) {
0516:
0517:                namingResources.addEnvironment(environment);
0518:
0519:            }
0520:
0521:            /**
0522:             * Add resource parameters for this web application.
0523:             *
0524:             * @param resourceParameters New resource parameters
0525:             */
0526:            public void addResourceParams(ResourceParams resourceParameters) {
0527:
0528:                namingResources.addResourceParams(resourceParameters);
0529:
0530:            }
0531:
0532:            /**
0533:             * Add the classname of an InstanceListener to be added to each
0534:             * Wrapper appended to this Context.
0535:             *
0536:             * @param listener Java class name of an InstanceListener class
0537:             */
0538:            public void addInstanceListener(String listener) {
0539:
0540:                synchronized (instanceListeners) {
0541:                    String results[] = new String[instanceListeners.length + 1];
0542:                    for (int i = 0; i < instanceListeners.length; i++)
0543:                        results[i] = instanceListeners[i];
0544:                    results[instanceListeners.length] = listener;
0545:                    instanceListeners = results;
0546:                }
0547:
0548:            }
0549:
0550:            /**
0551:             * Add a new context initialization parameter, replacing any existing
0552:             * value for the specified name.
0553:             *
0554:             * @param name Name of the new parameter
0555:             * @param value Value of the new  parameter
0556:             *
0557:             * @exception IllegalArgumentException if the name or value is missing,
0558:             *  or if this context initialization parameter has already been
0559:             *  registered
0560:             */
0561:            public void addParameter(String name, String value) {
0562:                // Validate the proposed context initialization parameter
0563:                if ((name == null) || (value == null))
0564:                    throw new IllegalArgumentException(sm
0565:                            .getString("standardContext.parameter.required"));
0566:                if (parameters.get(name) != null)
0567:                    throw new IllegalArgumentException(sm.getString(
0568:                            "standardContext.parameter.duplicate", name));
0569:
0570:                // Add this parameter to our defined set
0571:                synchronized (parameters) {
0572:                    parameters.put(name, value);
0573:                }
0574:
0575:            }
0576:
0577:            /**
0578:             * Add a resource reference for this web application.
0579:             *
0580:             * @param resource New resource reference
0581:             */
0582:            public void addResource(ContextResource resource) {
0583:
0584:                namingResources.addResource(resource);
0585:
0586:            }
0587:
0588:            /**
0589:             * Add a resource environment reference for this web application.
0590:             *
0591:             * @param name The resource environment reference name
0592:             * @param type The resource environment reference type
0593:             */
0594:            public void addResourceEnvRef(String name, String type) {
0595:
0596:                namingResources.addResourceEnvRef(name, type);
0597:
0598:            }
0599:
0600:            /**
0601:             * Add a resource link for this web application.
0602:             *
0603:             * @param resource New resource link
0604:             */
0605:            public void addResourceLink(ContextResourceLink resourceLink) {
0606:
0607:                namingResources.addResourceLink(resourceLink);
0608:
0609:            }
0610:
0611:            /**
0612:             * Add the classname of a LifecycleListener to be added to each
0613:             * Wrapper appended to this Context.
0614:             *
0615:             * @param listener Java class name of a LifecycleListener class
0616:             */
0617:            public void addWrapperLifecycle(String listener) {
0618:
0619:                synchronized (wrapperLifecycles) {
0620:                    String results[] = new String[wrapperLifecycles.length + 1];
0621:                    for (int i = 0; i < wrapperLifecycles.length; i++)
0622:                        results[i] = wrapperLifecycles[i];
0623:                    results[wrapperLifecycles.length] = listener;
0624:                    wrapperLifecycles = results;
0625:                }
0626:
0627:            }
0628:
0629:            /**
0630:             * Add the classname of a ContainerListener to be added to each
0631:             * Wrapper appended to this Context.
0632:             *
0633:             * @param listener Java class name of a ContainerListener class
0634:             */
0635:            public void addWrapperListener(String listener) {
0636:
0637:                synchronized (wrapperListeners) {
0638:                    String results[] = new String[wrapperListeners.length + 1];
0639:                    for (int i = 0; i < wrapperListeners.length; i++)
0640:                        results[i] = wrapperListeners[i];
0641:                    results[wrapperListeners.length] = listener;
0642:                    wrapperListeners = results;
0643:                }
0644:
0645:            }
0646:
0647:            /**
0648:             * Return the set of application listener class names configured
0649:             * for this application.
0650:             */
0651:            public String[] findApplicationListeners() {
0652:
0653:                return (applicationListeners);
0654:
0655:            }
0656:
0657:            /**
0658:             * Return the set of application parameters for this application.
0659:             */
0660:            public ApplicationParameter[] findApplicationParameters() {
0661:
0662:                return (applicationParameters);
0663:
0664:            }
0665:
0666:            /**
0667:             * Return the EJB resource reference with the specified name, if any;
0668:             * otherwise, return <code>null</code>.
0669:             *
0670:             * @param name Name of the desired EJB resource reference
0671:             */
0672:            public ContextEjb findEjb(String name) {
0673:
0674:                return namingResources.findEjb(name);
0675:
0676:            }
0677:
0678:            /**
0679:             * Return the defined EJB resource references for this application.
0680:             * If there are none, a zero-length array is returned.
0681:             */
0682:            public ContextEjb[] findEjbs() {
0683:
0684:                return namingResources.findEjbs();
0685:
0686:            }
0687:
0688:            /**
0689:             * Return the environment entry with the specified name, if any;
0690:             * otherwise, return <code>null</code>.
0691:             *
0692:             * @param name Name of the desired environment entry
0693:             */
0694:            public ContextEnvironment findEnvironment(String name) {
0695:
0696:                return namingResources.findEnvironment(name);
0697:
0698:            }
0699:
0700:            /**
0701:             * Return the set of defined environment entries for this web
0702:             * application.  If none have been defined, a zero-length array
0703:             * is returned.
0704:             */
0705:            public ContextEnvironment[] findEnvironments() {
0706:
0707:                return namingResources.findEnvironments();
0708:
0709:            }
0710:
0711:            /**
0712:             * Return the set of defined resource parameters for this web
0713:             * application.  If none have been defined, a zero-length array
0714:             * is returned.
0715:             */
0716:            public ResourceParams[] findResourceParams() {
0717:
0718:                return namingResources.findResourceParams();
0719:
0720:            }
0721:
0722:            /**
0723:             * Return the set of InstanceListener classes that will be added to
0724:             * newly created Wrappers automatically.
0725:             */
0726:            public String[] findInstanceListeners() {
0727:
0728:                return (instanceListeners);
0729:
0730:            }
0731:
0732:            /**
0733:             * Return the value for the specified context initialization
0734:             * parameter name, if any; otherwise return <code>null</code>.
0735:             *
0736:             * @param name Name of the parameter to return
0737:             */
0738:            public String findParameter(String name) {
0739:
0740:                synchronized (parameters) {
0741:                    return ((String) parameters.get(name));
0742:                }
0743:
0744:            }
0745:
0746:            /**
0747:             * Return the names of all defined context initialization parameters
0748:             * for this Context.  If no parameters are defined, a zero-length
0749:             * array is returned.
0750:             */
0751:            public String[] findParameters() {
0752:
0753:                synchronized (parameters) {
0754:                    String results[] = new String[parameters.size()];
0755:                    return ((String[]) parameters.keySet().toArray(results));
0756:                }
0757:
0758:            }
0759:
0760:            /**
0761:             * Return the resource reference with the specified name, if any;
0762:             * otherwise return <code>null</code>.
0763:             *
0764:             * @param name Name of the desired resource reference
0765:             */
0766:            public ContextResource findResource(String name) {
0767:
0768:                return namingResources.findResource(name);
0769:
0770:            }
0771:
0772:            /**
0773:             * Return the resource environment reference type for the specified
0774:             * name, if any; otherwise return <code>null</code>.
0775:             *
0776:             * @param name Name of the desired resource environment reference
0777:             */
0778:            public String findResourceEnvRef(String name) {
0779:
0780:                return namingResources.findResourceEnvRef(name);
0781:
0782:            }
0783:
0784:            /**
0785:             * Return the set of resource environment reference names for this
0786:             * web application.  If none have been specified, a zero-length
0787:             * array is returned.
0788:             */
0789:            public String[] findResourceEnvRefs() {
0790:
0791:                return namingResources.findResourceEnvRefs();
0792:
0793:            }
0794:
0795:            /**
0796:             * Return the resource link with the specified name, if any;
0797:             * otherwise return <code>null</code>.
0798:             *
0799:             * @param name Name of the desired resource link
0800:             */
0801:            public ContextResourceLink findResourceLink(String name) {
0802:
0803:                return namingResources.findResourceLink(name);
0804:
0805:            }
0806:
0807:            /**
0808:             * Return the defined resource links for this application.  If
0809:             * none have been defined, a zero-length array is returned.
0810:             */
0811:            public ContextResourceLink[] findResourceLinks() {
0812:
0813:                return namingResources.findResourceLinks();
0814:
0815:            }
0816:
0817:            /**
0818:             * Return the defined resource references for this application.  If
0819:             * none have been defined, a zero-length array is returned.
0820:             */
0821:            public ContextResource[] findResources() {
0822:
0823:                return namingResources.findResources();
0824:
0825:            }
0826:
0827:            /**
0828:             * Return the set of LifecycleListener classes that will be added to
0829:             * newly created Wrappers automatically.
0830:             */
0831:            public String[] findWrapperLifecycles() {
0832:
0833:                return (wrapperLifecycles);
0834:
0835:            }
0836:
0837:            /**
0838:             * Return the set of ContainerListener classes that will be added to
0839:             * newly created Wrappers automatically.
0840:             */
0841:            public String[] findWrapperListeners() {
0842:
0843:                return (wrapperListeners);
0844:
0845:            }
0846:
0847:            /**
0848:             * Return the naming resources associated with this web application.
0849:             */
0850:            public NamingResources getNamingResources() {
0851:
0852:                return (this .namingResources);
0853:
0854:            }
0855:
0856:            /**
0857:             * Remove the specified application listener class from the set of
0858:             * listeners for this application.
0859:             *
0860:             * @param listener Java class name of the listener to be removed
0861:             */
0862:            public void removeApplicationListener(String listener) {
0863:
0864:                synchronized (applicationListeners) {
0865:
0866:                    // Make sure this application listener is currently present
0867:                    int n = -1;
0868:                    for (int i = 0; i < applicationListeners.length; i++) {
0869:                        if (applicationListeners[i].equals(listener)) {
0870:                            n = i;
0871:                            break;
0872:                        }
0873:                    }
0874:                    if (n < 0)
0875:                        return;
0876:
0877:                    // Remove the specified application listener
0878:                    int j = 0;
0879:                    String results[] = new String[applicationListeners.length - 1];
0880:                    for (int i = 0; i < applicationListeners.length; i++) {
0881:                        if (i != n)
0882:                            results[j++] = applicationListeners[i];
0883:                    }
0884:                    applicationListeners = results;
0885:
0886:                }
0887:
0888:            }
0889:
0890:            /**
0891:             * Remove the application parameter with the specified name from
0892:             * the set for this application.
0893:             *
0894:             * @param name Name of the application parameter to remove
0895:             */
0896:            public void removeApplicationParameter(String name) {
0897:
0898:                synchronized (applicationParameters) {
0899:
0900:                    // Make sure this parameter is currently present
0901:                    int n = -1;
0902:                    for (int i = 0; i < applicationParameters.length; i++) {
0903:                        if (name.equals(applicationParameters[i].getName())) {
0904:                            n = i;
0905:                            break;
0906:                        }
0907:                    }
0908:                    if (n < 0)
0909:                        return;
0910:
0911:                    // Remove the specified parameter
0912:                    int j = 0;
0913:                    ApplicationParameter results[] = new ApplicationParameter[applicationParameters.length - 1];
0914:                    for (int i = 0; i < applicationParameters.length; i++) {
0915:                        if (i != n)
0916:                            results[j++] = applicationParameters[i];
0917:                    }
0918:                    applicationParameters = results;
0919:
0920:                }
0921:
0922:            }
0923:
0924:            /**
0925:             * Remove any EJB resource reference with the specified name.
0926:             *
0927:             * @param name Name of the EJB resource reference to remove
0928:             */
0929:            public void removeEjb(String name) {
0930:
0931:                namingResources.removeEjb(name);
0932:
0933:            }
0934:
0935:            /**
0936:             * Remove any environment entry with the specified name.
0937:             *
0938:             * @param name Name of the environment entry to remove
0939:             */
0940:            public void removeEnvironment(String name) {
0941:
0942:                namingResources.removeEnvironment(name);
0943:
0944:            }
0945:
0946:            /**
0947:             * Remove a class name from the set of InstanceListener classes that
0948:             * will be added to newly created Wrappers.
0949:             *
0950:             * @param listener Class name of an InstanceListener class to be removed
0951:             */
0952:            public void removeInstanceListener(String listener) {
0953:
0954:                synchronized (instanceListeners) {
0955:
0956:                    // Make sure this InstanceListener is currently present
0957:                    int n = -1;
0958:                    for (int i = 0; i < instanceListeners.length; i++) {
0959:                        if (instanceListeners[i].equals(listener)) {
0960:                            n = i;
0961:                            break;
0962:                        }
0963:                    }
0964:                    if (n < 0)
0965:                        return;
0966:
0967:                    // Remove the specified InstanceListener
0968:                    int j = 0;
0969:                    String results[] = new String[instanceListeners.length - 1];
0970:                    for (int i = 0; i < instanceListeners.length; i++) {
0971:                        if (i != n)
0972:                            results[j++] = instanceListeners[i];
0973:                    }
0974:                    instanceListeners = results;
0975:
0976:                }
0977:
0978:            }
0979:
0980:            /**
0981:             * Remove the context initialization parameter with the specified
0982:             * name, if it exists; otherwise, no action is taken.
0983:             *
0984:             * @param name Name of the parameter to remove
0985:             */
0986:            public void removeParameter(String name) {
0987:
0988:                synchronized (parameters) {
0989:                    parameters.remove(name);
0990:                }
0991:
0992:            }
0993:
0994:            /**
0995:             * Remove any resource reference with the specified name.
0996:             *
0997:             * @param name Name of the resource reference to remove
0998:             */
0999:            public void removeResource(String name) {
1000:
1001:                namingResources.removeResource(name);
1002:
1003:            }
1004:
1005:            /**
1006:             * Remove any resource environment reference with the specified name.
1007:             *
1008:             * @param name Name of the resource environment reference to remove
1009:             */
1010:            public void removeResourceEnvRef(String name) {
1011:
1012:                namingResources.removeResourceEnvRef(name);
1013:
1014:            }
1015:
1016:            /**
1017:             * Remove any resource link with the specified name.
1018:             *
1019:             * @param name Name of the resource link to remove
1020:             */
1021:            public void removeResourceLink(String name) {
1022:
1023:                namingResources.removeResourceLink(name);
1024:
1025:            }
1026:
1027:            /**
1028:             * Remove a class name from the set of LifecycleListener classes that
1029:             * will be added to newly created Wrappers.
1030:             *
1031:             * @param listener Class name of a LifecycleListener class to be removed
1032:             */
1033:            public void removeWrapperLifecycle(String listener) {
1034:
1035:                synchronized (wrapperLifecycles) {
1036:
1037:                    // Make sure this LifecycleListener is currently present
1038:                    int n = -1;
1039:                    for (int i = 0; i < wrapperLifecycles.length; i++) {
1040:                        if (wrapperLifecycles[i].equals(listener)) {
1041:                            n = i;
1042:                            break;
1043:                        }
1044:                    }
1045:                    if (n < 0)
1046:                        return;
1047:
1048:                    // Remove the specified LifecycleListener
1049:                    int j = 0;
1050:                    String results[] = new String[wrapperLifecycles.length - 1];
1051:                    for (int i = 0; i < wrapperLifecycles.length; i++) {
1052:                        if (i != n)
1053:                            results[j++] = wrapperLifecycles[i];
1054:                    }
1055:                    wrapperLifecycles = results;
1056:
1057:                }
1058:
1059:            }
1060:
1061:            /**
1062:             * Remove a class name from the set of ContainerListener classes that
1063:             * will be added to newly created Wrappers.
1064:             *
1065:             * @param listener Class name of a ContainerListener class to be removed
1066:             */
1067:            public void removeWrapperListener(String listener) {
1068:
1069:                synchronized (wrapperListeners) {
1070:
1071:                    // Make sure this ContainerListener is currently present
1072:                    int n = -1;
1073:                    for (int i = 0; i < wrapperListeners.length; i++) {
1074:                        if (wrapperListeners[i].equals(listener)) {
1075:                            n = i;
1076:                            break;
1077:                        }
1078:                    }
1079:                    if (n < 0)
1080:                        return;
1081:
1082:                    // Remove the specified ContainerListener
1083:                    int j = 0;
1084:                    String results[] = new String[wrapperListeners.length - 1];
1085:                    for (int i = 0; i < wrapperListeners.length; i++) {
1086:                        if (i != n)
1087:                            results[j++] = wrapperListeners[i];
1088:                    }
1089:                    wrapperListeners = results;
1090:
1091:                }
1092:
1093:            }
1094:
1095:            // --------------------------------------------------------- Public Methods
1096:
1097:            /**
1098:             * Process the START event for an associated Context.
1099:             *
1100:             * @param event The lifecycle event that has occurred
1101:             */
1102:            public void lifecycleEvent(LifecycleEvent event) {
1103:
1104:                StandardContext context = null;
1105:                NamingContextListener listener = null;
1106:
1107:                if (event.getLifecycle() instanceof  StandardContext) {
1108:                    context = (StandardContext) event.getLifecycle();
1109:                    LifecycleListener[] listeners = context
1110:                            .findLifecycleListeners();
1111:                    for (int i = 0; i < listeners.length; i++) {
1112:                        if (listeners[i] instanceof  NamingContextListener) {
1113:                            listener = (NamingContextListener) listeners[i];
1114:                            break;
1115:                        }
1116:                    }
1117:                }
1118:
1119:                if (listener == null) {
1120:                    return;
1121:                }
1122:
1123:                if (event.getType().equals(Lifecycle.AFTER_START_EVENT)) {
1124:
1125:                    // Add context
1126:                    contexts.put(context, context);
1127:
1128:                    NamingResources contextResources = context
1129:                            .getNamingResources();
1130:
1131:                    // Setting the context in read/write mode
1132:                    ContextAccessController.setWritable(listener.getName(),
1133:                            context);
1134:
1135:                    // Send notifications to the listener to add the appropriate 
1136:                    // resources
1137:                    ContextEjb[] contextEjb = findEjbs();
1138:                    for (int i = 0; i < contextEjb.length; i++) {
1139:                        ContextEjb contextEntry = contextEjb[i];
1140:                        if (contextResources.exists(contextEntry.getName())) {
1141:                            listener.removeEjb(contextEntry.getName());
1142:                        }
1143:                        listener.addEjb(contextEntry);
1144:                    }
1145:                    ContextEnvironment[] contextEnv = findEnvironments();
1146:                    for (int i = 0; i < contextEnv.length; i++) {
1147:                        ContextEnvironment contextEntry = contextEnv[i];
1148:                        if (contextResources.exists(contextEntry.getName())) {
1149:                            listener.removeEnvironment(contextEntry.getName());
1150:                        }
1151:                        listener.addEnvironment(contextEntry);
1152:                    }
1153:                    ContextResource[] resources = findResources();
1154:                    for (int i = 0; i < resources.length; i++) {
1155:                        ContextResource contextEntry = resources[i];
1156:                        if (contextResources.exists(contextEntry.getName())) {
1157:                            listener.removeResource(contextEntry.getName());
1158:                        }
1159:                        listener.addResource(contextEntry);
1160:                    }
1161:                    String[] envRefs = findResourceEnvRefs();
1162:                    for (int i = 0; i < envRefs.length; i++) {
1163:                        if (contextResources.exists(envRefs[i])) {
1164:                            listener.removeResourceEnvRef(envRefs[i]);
1165:                        }
1166:                        listener.addResourceEnvRef(envRefs[i],
1167:                                findResourceEnvRef(envRefs[i]));
1168:                    }
1169:
1170:                    // Setting the context in read only mode
1171:                    ContextAccessController.setReadOnly(listener.getName());
1172:
1173:                    // Add listener to the NamingResources listener list
1174:                    namingResources.addPropertyChangeListener(listener);
1175:
1176:                } else if (event.getType().equals(Lifecycle.BEFORE_STOP_EVENT)) {
1177:
1178:                    // Remove context
1179:                    contexts.remove(context);
1180:
1181:                    // Remove listener from the NamingResource listener list
1182:                    namingResources.removePropertyChangeListener(listener);
1183:
1184:                    // Remove listener from lifecycle listeners
1185:                    context.removeLifecycleListener(this );
1186:
1187:                }
1188:
1189:            }
1190:
1191:            /**
1192:             * Import the configuration from the DefaultContext into
1193:             * current Context.
1194:             *
1195:             * @param context current web application context
1196:             */
1197:            public void importDefaultContext(Context context) {
1198:
1199:                if (context instanceof  StandardContext) {
1200:                    ((StandardContext) context).setUseNaming(isUseNaming());
1201:                    if (!contexts.containsKey(context)) {
1202:                        ((StandardContext) context).addLifecycleListener(this );
1203:                    }
1204:                }
1205:
1206:                context.setCookies(getCookies());
1207:                context.setCrossContext(getCrossContext());
1208:                context.setReloadable(getReloadable());
1209:
1210:                String[] listeners = findApplicationListeners();
1211:                for (int i = 0; i < listeners.length; i++) {
1212:                    context.addApplicationListener(listeners[i]);
1213:                }
1214:                listeners = findInstanceListeners();
1215:                for (int i = 0; i < listeners.length; i++) {
1216:                    context.addInstanceListener(listeners[i]);
1217:                }
1218:                String[] wrapper = findWrapperListeners();
1219:                for (int i = 0; i < wrapper.length; i++) {
1220:                    context.addWrapperListener(wrapper[i]);
1221:                }
1222:                wrapper = findWrapperLifecycles();
1223:                for (int i = 0; i < wrapper.length; i++) {
1224:                    context.addWrapperLifecycle(wrapper[i]);
1225:                }
1226:                String[] parameters = findParameters();
1227:                for (int i = 0; i < parameters.length; i++) {
1228:                    context.addParameter(parameters[i],
1229:                            findParameter(parameters[i]));
1230:                }
1231:                ApplicationParameter[] appParam = findApplicationParameters();
1232:                for (int i = 0; i < appParam.length; i++) {
1233:                    context.addApplicationParameter(appParam[i]);
1234:                }
1235:
1236:                if (!(context instanceof  StandardContext)) {
1237:                    ContextEjb[] contextEjb = findEjbs();
1238:                    for (int i = 0; i < contextEjb.length; i++) {
1239:                        context.addEjb(contextEjb[i]);
1240:                    }
1241:                    ContextEnvironment[] contextEnv = findEnvironments();
1242:                    for (int i = 0; i < contextEnv.length; i++) {
1243:                        context.addEnvironment(contextEnv[i]);
1244:                    }
1245:                    /*
1246:                    if (context instanceof StandardContext) {
1247:                        ResourceParams [] resourceParams = findResourceParams();
1248:                        for( int i = 0; i < resourceParams.length; i++ ) {
1249:                            ((StandardContext)context).addResourceParams
1250:                                (resourceParams[i]);
1251:                        }
1252:                    }
1253:                     */
1254:                    ContextResource[] resources = findResources();
1255:                    for (int i = 0; i < resources.length; i++) {
1256:                        context.addResource(resources[i]);
1257:                    }
1258:                    String[] envRefs = findResourceEnvRefs();
1259:                    for (int i = 0; i < envRefs.length; i++) {
1260:                        context.addResourceEnvRef(envRefs[i],
1261:                                findResourceEnvRef(envRefs[i]));
1262:                    }
1263:                }
1264:
1265:            }
1266:
1267:            /**
1268:             * Return a String representation of this component.
1269:             */
1270:            public String toString() {
1271:
1272:                StringBuffer sb = new StringBuffer();
1273:                if (getParent() != null) {
1274:                    sb.append(getParent().toString());
1275:                    sb.append(".");
1276:                }
1277:                sb.append("DefaultContext[");
1278:                sb.append("]");
1279:                return (sb.toString());
1280:
1281:            }
1282:
1283:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.