Source Code Cross Referenced for StandardDefaultContext.java in  » Sevlet-Container » tomcat-catalina » 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 » Sevlet Container » tomcat catalina » org.apache.catalina.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Copyright 1999,2004 The Apache Software Foundation.
0003:         * 
0004:         * Licensed under the Apache License, Version 2.0 (the "License");
0005:         * you may not use this file except in compliance with the License.
0006:         * You may obtain a copy of the License at
0007:         * 
0008:         *      http://www.apache.org/licenses/LICENSE-2.0
0009:         * 
0010:         * Unless required by applicable law or agreed to in writing, software
0011:         * distributed under the License is distributed on an "AS IS" BASIS,
0012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013:         * See the License for the specific language governing permissions and
0014:         * limitations under the License.
0015:         */
0016:
0017:        package org.apache.catalina.core;
0018:
0019:        import java.beans.PropertyChangeListener;
0020:        import java.beans.PropertyChangeSupport;
0021:        import java.lang.reflect.Constructor;
0022:        import java.util.ArrayList;
0023:        import java.util.Enumeration;
0024:        import java.util.HashMap;
0025:        import java.util.Hashtable;
0026:        import java.util.Vector;
0027:
0028:        import javax.management.MBeanRegistration;
0029:        import javax.management.MBeanServer;
0030:        import javax.management.MalformedObjectNameException;
0031:        import javax.management.ObjectName;
0032:        import javax.naming.directory.DirContext;
0033:
0034:        import org.apache.catalina.Container;
0035:        import org.apache.catalina.Context;
0036:        import org.apache.catalina.DefaultContext;
0037:        import org.apache.catalina.Lifecycle;
0038:        import org.apache.catalina.LifecycleEvent;
0039:        import org.apache.catalina.LifecycleListener;
0040:        import org.apache.catalina.Loader;
0041:        import org.apache.catalina.Manager;
0042:        import org.apache.catalina.deploy.ApplicationParameter;
0043:        import org.apache.catalina.deploy.ContextEjb;
0044:        import org.apache.catalina.deploy.ContextEnvironment;
0045:        import org.apache.catalina.deploy.ContextResource;
0046:        import org.apache.catalina.deploy.ContextResourceLink;
0047:        import org.apache.catalina.deploy.NamingResources;
0048:        import org.apache.catalina.deploy.ResourceParams;
0049:        import org.apache.catalina.loader.WebappLoader;
0050:        import org.apache.catalina.mbeans.MBeanUtils;
0051:        import org.apache.catalina.util.StringManager;
0052:        import org.apache.commons.modeler.ManagedBean;
0053:        import org.apache.commons.modeler.Registry;
0054:        import org.apache.naming.ContextAccessController;
0055:        import org.apache.tomcat.util.compat.JdkCompat;
0056:
0057:        /**
0058:         * Used to store the default configuration a Host will use
0059:         * when creating a Context.  A Context configured in server.xml
0060:         * can override these defaults by setting the Context attribute
0061:         * <CODE>override="true"</CODE>.
0062:         *
0063:         * @author Glenn Nielsen
0064:         * @version $Revision: 1.15 $ $Date: 2004/05/26 15:36:35 $
0065:         */
0066:
0067:        public class StandardDefaultContext implements  DefaultContext,
0068:                LifecycleListener, MBeanRegistration {
0069:
0070:            // ----------------------------------------------------------- Constructors
0071:
0072:            /**
0073:             * Create the DefaultContext
0074:             */
0075:            public StandardDefaultContext() {
0076:
0077:                namingResources.setContainer(this );
0078:
0079:            }
0080:
0081:            // ----------------------------------------------------- Class Variables
0082:
0083:            /**
0084:             * The string manager for this package.
0085:             */
0086:            protected static StringManager sm = StringManager
0087:                    .getManager(Constants.Package);
0088:
0089:            /**
0090:             * JDK compatibility support
0091:             */
0092:            private static final JdkCompat jdkCompat = JdkCompat.getJdkCompat();
0093:
0094:            // ----------------------------------------------------- Instance Variables
0095:
0096:            /**
0097:             * Contexts we are currently associated with.
0098:             */
0099:            private Hashtable contexts = new Hashtable();
0100:
0101:            /**
0102:             * The set of application listener class names configured for this
0103:             * application, in the order they were encountered in the web.xml file.
0104:             */
0105:            private String applicationListeners[] = new String[0];
0106:
0107:            /**
0108:             * The set of application parameters defined for this application.
0109:             */
0110:            private ApplicationParameter applicationParameters[] = new ApplicationParameter[0];
0111:
0112:            /**
0113:             * Should we attempt to use cookies for session id communication?
0114:             */
0115:            private boolean cookies = true;
0116:
0117:            /**
0118:             * Should we allow the <code>ServletContext.getContext()</code> method
0119:             * to access the context of other web applications in this server?
0120:             */
0121:            private boolean crossContext = true;
0122:
0123:            /**
0124:             * The descriptive information string for this implementation.
0125:             */
0126:            private static final String info = "org.apache.catalina.core.DefaultContext/1.0";
0127:
0128:            /**
0129:             * The set of classnames of InstanceListeners that will be added
0130:             * to each newly created Wrapper by <code>createWrapper()</code>.
0131:             */
0132:            private String instanceListeners[] = new String[0];
0133:
0134:            /**
0135:             * The Java class name of the default Mapper class for this Container.
0136:             */
0137:            private String mapperClass = "org.apache.catalina.core.StandardContextMapper";
0138:
0139:            /**
0140:             * The associated naming resources.
0141:             */
0142:            private NamingResources namingResources = new NamingResources();
0143:
0144:            /**
0145:             * The context initialization parameters for this web application,
0146:             * keyed by name.
0147:             */
0148:            private HashMap parameters = new HashMap();
0149:
0150:            /**
0151:             * The reloadable flag for this web application.
0152:             */
0153:            private boolean reloadable = false;
0154:
0155:            /**
0156:             * The swallowOutput flag for this web application.
0157:             */
0158:            private boolean swallowOutput = false;
0159:
0160:            /**
0161:             * The set of classnames of LifecycleListeners that will be added
0162:             * to each newly created Wrapper by <code>createWrapper()</code>.
0163:             */
0164:            private String wrapperLifecycles[] = new String[0];
0165:
0166:            /**
0167:             * The set of classnames of ContainerListeners that will be added
0168:             * to each newly created Wrapper by <code>createWrapper()</code>.
0169:             */
0170:            private String wrapperListeners[] = new String[0];
0171:
0172:            /**
0173:             * Java class name of the Wrapper class implementation we use.
0174:             */
0175:            private String wrapperClass = "org.apache.catalina.core.StandardWrapper";
0176:
0177:            /**
0178:             * JNDI use flag.
0179:             */
0180:            private boolean useNaming = true;
0181:
0182:            /**
0183:             * The resources DirContext object with which this Container is
0184:             * associated.
0185:             *
0186:             */
0187:            DirContext dirContext = null;
0188:
0189:            /**
0190:             * The human-readable name of this Container.
0191:             */
0192:            protected String name = "defaultContext";
0193:
0194:            /**
0195:             * The parent Container to which this Container is a child.
0196:             */
0197:            protected Container parent = null;
0198:
0199:            /**
0200:             * The Context LifecycleListener's
0201:             */
0202:            protected Vector lifecycle = new Vector();
0203:
0204:            /**
0205:             * The Loader implementation with which this Container is associated.
0206:             */
0207:            protected Loader loader = null;
0208:
0209:            /**
0210:             * The Manager implementation with which this Container is associated.
0211:             */
0212:            protected Manager manager = null;
0213:
0214:            /**
0215:             * Case sensitivity.
0216:             */
0217:            protected boolean caseSensitive = true;
0218:
0219:            /**
0220:             * Allow linking.
0221:             */
0222:            protected boolean allowLinking = false;
0223:
0224:            /**
0225:             * Cache max size in KB.
0226:             */
0227:            protected int cacheMaxSize = 10240; // 10 MB
0228:
0229:            /**
0230:             * Cache TTL in ms.
0231:             */
0232:            protected int cacheTTL = 5000;
0233:
0234:            /**
0235:             * CachingAllowed.
0236:             */
0237:            protected boolean cachingAllowed = true;
0238:
0239:            /**
0240:             * Frequency of manager checks.
0241:             */
0242:            protected int managerChecksFrequency = 6;
0243:
0244:            /**
0245:             * The property change support for this component.
0246:             */
0247:            protected PropertyChangeSupport support = new PropertyChangeSupport(
0248:                    this );
0249:
0250:            // ----------------------------------------------------- Context Properties
0251:
0252:            /**
0253:             * Set case sensitivity.
0254:             */
0255:            public void setCaseSensitive(boolean caseSensitive) {
0256:                this .caseSensitive = caseSensitive;
0257:            }
0258:
0259:            /**
0260:             * Is case sensitive ?
0261:             */
0262:            public boolean isCaseSensitive() {
0263:                return caseSensitive;
0264:            }
0265:
0266:            /**
0267:             * Set allow linking.
0268:             */
0269:            public void setAllowLinking(boolean allowLinking) {
0270:                this .allowLinking = allowLinking;
0271:            }
0272:
0273:            /**
0274:             * Is linking allowed.
0275:             */
0276:            public boolean isAllowLinking() {
0277:                return allowLinking;
0278:            }
0279:
0280:            /**
0281:             * Set cache TTL.
0282:             */
0283:            public void setCacheTTL(int cacheTTL) {
0284:                this .cacheTTL = cacheTTL;
0285:            }
0286:
0287:            /**
0288:             * Get cache TTL.
0289:             */
0290:            public int getCacheTTL() {
0291:                return cacheTTL;
0292:            }
0293:
0294:            /**
0295:             * Return the maximum size of the cache in KB.
0296:             */
0297:            public int getCacheMaxSize() {
0298:                return cacheMaxSize;
0299:            }
0300:
0301:            /**
0302:             * Set the maximum size of the cache in KB.
0303:             */
0304:            public void setCacheMaxSize(int cacheMaxSize) {
0305:                this .cacheMaxSize = cacheMaxSize;
0306:            }
0307:
0308:            /**
0309:             * Set cachingAllowed.
0310:             */
0311:            public void setCachingAllowed(boolean cachingAllowed) {
0312:                this .cachingAllowed = cachingAllowed;
0313:            }
0314:
0315:            /**
0316:             * Is cachingAllowed ?
0317:             */
0318:            public boolean isCachingAllowed() {
0319:                return cachingAllowed;
0320:            }
0321:
0322:            /**
0323:             * Set the manager checks frequency.
0324:             */
0325:            public void setManagerChecksFrequency(int managerChecksFrequency) {
0326:                this .managerChecksFrequency = managerChecksFrequency;
0327:            }
0328:
0329:            /**
0330:             * Get manager checks frquency.
0331:             */
0332:            public int getManagerChecksFrequency() {
0333:                return managerChecksFrequency;
0334:            }
0335:
0336:            /**
0337:             * Returns true if the internal naming support is used.
0338:             */
0339:            public boolean isUseNaming() {
0340:
0341:                return (useNaming);
0342:
0343:            }
0344:
0345:            /**
0346:             * Enables or disables naming.
0347:             */
0348:            public void setUseNaming(boolean useNaming) {
0349:                this .useNaming = useNaming;
0350:            }
0351:
0352:            /**
0353:             * Return the "use cookies for session ids" flag.
0354:             */
0355:            public boolean getCookies() {
0356:
0357:                return (this .cookies);
0358:
0359:            }
0360:
0361:            /**
0362:             * Set the "use cookies for session ids" flag.
0363:             *
0364:             * @param cookies The new flag
0365:             */
0366:            public void setCookies(boolean cookies) {
0367:                boolean oldCookies = this .cookies;
0368:                this .cookies = cookies;
0369:
0370:            }
0371:
0372:            /**
0373:             * Return the "allow crossing servlet contexts" flag.
0374:             */
0375:            public boolean getCrossContext() {
0376:
0377:                return (this .crossContext);
0378:
0379:            }
0380:
0381:            /**
0382:             * Set the "allow crossing servlet contexts" flag.
0383:             *
0384:             * @param crossContext The new cross contexts flag
0385:             */
0386:            public void setCrossContext(boolean crossContext) {
0387:                boolean oldCrossContext = this .crossContext;
0388:                this .crossContext = crossContext;
0389:
0390:            }
0391:
0392:            /**
0393:             * Return descriptive information about this Container implementation and
0394:             * the corresponding version number, in the format
0395:             * <code>&lt;description&gt;/&lt;version&gt;</code>.
0396:             */
0397:            public String getInfo() {
0398:
0399:                return (info);
0400:
0401:            }
0402:
0403:            /**
0404:             * Return the reloadable flag for this web application.
0405:             */
0406:            public boolean getReloadable() {
0407:
0408:                return (this .reloadable);
0409:
0410:            }
0411:
0412:            /**
0413:             * Set the reloadable flag for this web application.
0414:             *
0415:             * @param reloadable The new reloadable flag
0416:             */
0417:            public void setReloadable(boolean reloadable) {
0418:                boolean oldReloadable = this .reloadable;
0419:                this .reloadable = reloadable;
0420:
0421:            }
0422:
0423:            /**
0424:             * Return the swallowOutput flag for this web application.
0425:             */
0426:            public boolean getSwallowOutput() {
0427:
0428:                return (this .swallowOutput);
0429:
0430:            }
0431:
0432:            /**
0433:             * Set the swallowOutput flag for this web application.
0434:             *
0435:             * @param swallowOutput The new swallowOutput flag
0436:             */
0437:            public void setSwallowOutput(boolean swallowOutput) {
0438:                boolean oldSwallowOutput = this .swallowOutput;
0439:                this .swallowOutput = swallowOutput;
0440:
0441:            }
0442:
0443:            /**
0444:             * Return the Java class name of the Wrapper implementation used
0445:             * for servlets registered in this Context.
0446:             */
0447:            public String getWrapperClass() {
0448:
0449:                return (this .wrapperClass);
0450:
0451:            }
0452:
0453:            /**
0454:             * Set the Java class name of the Wrapper implementation used
0455:             * for servlets registered in this Context.
0456:             *
0457:             * @param wrapperClass The new wrapper class
0458:             */
0459:            public void setWrapperClass(String wrapperClass) {
0460:                this .wrapperClass = wrapperClass;
0461:
0462:            }
0463:
0464:            /**
0465:             * Set the resources DirContext object with which this Container is
0466:             * associated.
0467:             *
0468:             * @param resources The newly associated DirContext
0469:             */
0470:            public void setResources(DirContext resources) {
0471:                this .dirContext = resources;
0472:
0473:            }
0474:
0475:            /**
0476:             * Get the resources DirContext object with which this Container is
0477:             * associated.
0478:             *
0479:             * @return The associated DirContext
0480:             */
0481:            public DirContext getResources() {
0482:
0483:                return this .dirContext;
0484:
0485:            }
0486:
0487:            /**
0488:             * Return the Loader with which this Container is associated.  If there is
0489:             * no associated Loader return <code>null</code>.
0490:             */
0491:            public Loader getLoader() {
0492:
0493:                return loader;
0494:
0495:            }
0496:
0497:            /**
0498:             * Set the Loader with which this Context is associated.
0499:             *
0500:             * @param loader The newly associated loader
0501:             */
0502:            public void setLoader(Loader loader) {
0503:                Loader oldLoader = this .loader;
0504:                this .loader = loader;
0505:
0506:                // Report this property change to interested listeners
0507:                support.firePropertyChange("loader", oldLoader, this .loader);
0508:            }
0509:
0510:            /**
0511:             * Return the Manager with which this Container is associated.  If there is
0512:             * no associated Manager return <code>null</code>.
0513:             */
0514:            public Manager getManager() {
0515:
0516:                return manager;
0517:
0518:            }
0519:
0520:            /**
0521:             * Set the Manager with which this Container is associated.
0522:             *
0523:             * @param manager The newly associated Manager
0524:             */
0525:            public void setManager(Manager manager) {
0526:                Manager oldManager = this .manager;
0527:                this .manager = manager;
0528:
0529:                // Report this property change to interested listeners
0530:                support.firePropertyChange("manager", oldManager, this .manager);
0531:            }
0532:
0533:            // ------------------------------------------------------ Lifecycle Methods
0534:
0535:            /**
0536:             * Add a lifecycle event listener to this component.
0537:             *
0538:             * @param listener The listener to add
0539:             */
0540:            public void addLifecycleListener(LifecycleListener listener) {
0541:                lifecycle.add(listener);
0542:            }
0543:
0544:            // ------------------------------------------------------ Public Properties
0545:
0546:            /**
0547:             * The name of this DefaultContext
0548:             */
0549:
0550:            public String getName() {
0551:                return (this .name);
0552:            }
0553:
0554:            public void setName(String name) {
0555:                this .name = name;
0556:            }
0557:
0558:            /**
0559:             * Return the Container for which this Container is a child, if there is
0560:             * one.  If there is no defined parent, return <code>null</code>.
0561:             */
0562:            public Container getParent() {
0563:
0564:                return (parent);
0565:
0566:            }
0567:
0568:            /**
0569:             * Set the parent Container to which this Container is being added as a
0570:             * child.  This Container may refuse to become attached to the specified
0571:             * Container by throwing an exception.
0572:             *
0573:             * @param container Container to which this Container is being added
0574:             *  as a child
0575:             *
0576:             * @exception IllegalArgumentException if this Container refuses to become
0577:             *  attached to the specified Container
0578:             */
0579:            public void setParent(Container container) {
0580:                Container oldParent = this .parent;
0581:                this .parent = container;
0582:                support.firePropertyChange("parent", oldParent, this .parent);
0583:
0584:            }
0585:
0586:            // -------------------------------------------------------- Context Methods
0587:
0588:            /**
0589:             * Add a new Listener class name to the set of Listeners
0590:             * configured for this application.
0591:             *
0592:             * @param listener Java class name of a listener class
0593:             */
0594:            public void addApplicationListener(String listener) {
0595:
0596:                synchronized (applicationListeners) {
0597:                    String results[] = new String[applicationListeners.length + 1];
0598:                    for (int i = 0; i < applicationListeners.length; i++)
0599:                        results[i] = applicationListeners[i];
0600:                    results[applicationListeners.length] = listener;
0601:                    applicationListeners = results;
0602:                }
0603:
0604:            }
0605:
0606:            /**
0607:             * Add a new application parameter for this application.
0608:             *
0609:             * @param parameter The new application parameter
0610:             */
0611:            public void addApplicationParameter(ApplicationParameter parameter) {
0612:
0613:                synchronized (applicationParameters) {
0614:                    ApplicationParameter results[] = new ApplicationParameter[applicationParameters.length + 1];
0615:                    System.arraycopy(applicationParameters, 0, results, 0,
0616:                            applicationParameters.length);
0617:                    results[applicationParameters.length] = parameter;
0618:                    applicationParameters = results;
0619:                }
0620:
0621:            }
0622:
0623:            /**
0624:             * Add an EJB resource reference for this web application.
0625:             *
0626:             * @param ejb New EJB resource reference
0627:             */
0628:            public void addEjb(ContextEjb ejb) {
0629:
0630:                namingResources.addEjb(ejb);
0631:
0632:            }
0633:
0634:            /**
0635:             * Add an environment entry for this web application.
0636:             *
0637:             * @param environment New environment entry
0638:             */
0639:            public void addEnvironment(ContextEnvironment environment) {
0640:
0641:                namingResources.addEnvironment(environment);
0642:
0643:            }
0644:
0645:            /**
0646:             * Add resource parameters for this web application.
0647:             *
0648:             * @param resourceParameters New resource parameters
0649:             */
0650:            public void addResourceParams(ResourceParams resourceParameters) {
0651:
0652:                namingResources.addResourceParams(resourceParameters);
0653:
0654:            }
0655:
0656:            /**
0657:             * Add the classname of an InstanceListener to be added to each
0658:             * Wrapper appended to this Context.
0659:             *
0660:             * @param listener Java class name of an InstanceListener class
0661:             */
0662:            public void addInstanceListener(String listener) {
0663:
0664:                synchronized (instanceListeners) {
0665:                    String results[] = new String[instanceListeners.length + 1];
0666:                    for (int i = 0; i < instanceListeners.length; i++)
0667:                        results[i] = instanceListeners[i];
0668:                    results[instanceListeners.length] = listener;
0669:                    instanceListeners = results;
0670:                }
0671:
0672:            }
0673:
0674:            /**
0675:             * Add a new context initialization parameter, replacing any existing
0676:             * value for the specified name.
0677:             *
0678:             * @param name Name of the new parameter
0679:             * @param value Value of the new  parameter
0680:             *
0681:             * @exception IllegalArgumentException if the name or value is missing,
0682:             *  or if this context initialization parameter has already been
0683:             *  registered
0684:             */
0685:            public void addParameter(String name, String value) {
0686:                // Validate the proposed context initialization parameter
0687:                if ((name == null) || (value == null))
0688:                    throw new IllegalArgumentException(sm
0689:                            .getString("standardContext.parameter.required"));
0690:                if (parameters.get(name) != null)
0691:                    throw new IllegalArgumentException(sm.getString(
0692:                            "standardContext.parameter.duplicate", name));
0693:
0694:                // Add this parameter to our defined set
0695:                synchronized (parameters) {
0696:                    parameters.put(name, value);
0697:                }
0698:
0699:            }
0700:
0701:            /**
0702:             * Add a property change listener to this component.
0703:             *
0704:             * @param listener The listener to add
0705:             */
0706:            public void addPropertyChangeListener(
0707:                    PropertyChangeListener listener) {
0708:
0709:                support.addPropertyChangeListener(listener);
0710:
0711:            }
0712:
0713:            /**
0714:             * Add a resource reference for this web application.
0715:             *
0716:             * @param resource New resource reference
0717:             */
0718:            public void addResource(ContextResource resource) {
0719:
0720:                namingResources.addResource(resource);
0721:
0722:            }
0723:
0724:            /**
0725:             * Add a resource environment reference for this web application.
0726:             *
0727:             * @param name The resource environment reference name
0728:             * @param type The resource environment reference type
0729:             */
0730:            public void addResourceEnvRef(String name, String type) {
0731:
0732:                namingResources.addResourceEnvRef(name, type);
0733:
0734:            }
0735:
0736:            /**
0737:             * Add a resource link for this web application.
0738:             *
0739:             * @param resourceLink New resource link
0740:             */
0741:            public void addResourceLink(ContextResourceLink resourceLink) {
0742:
0743:                namingResources.addResourceLink(resourceLink);
0744:
0745:            }
0746:
0747:            /**
0748:             * Add the classname of a LifecycleListener to be added to each
0749:             * Wrapper appended to this Context.
0750:             *
0751:             * @param listener Java class name of a LifecycleListener class
0752:             */
0753:            public void addWrapperLifecycle(String listener) {
0754:
0755:                synchronized (wrapperLifecycles) {
0756:                    String results[] = new String[wrapperLifecycles.length + 1];
0757:                    for (int i = 0; i < wrapperLifecycles.length; i++)
0758:                        results[i] = wrapperLifecycles[i];
0759:                    results[wrapperLifecycles.length] = listener;
0760:                    wrapperLifecycles = results;
0761:                }
0762:
0763:            }
0764:
0765:            /**
0766:             * Add the classname of a ContainerListener to be added to each
0767:             * Wrapper appended to this Context.
0768:             *
0769:             * @param listener Java class name of a ContainerListener class
0770:             */
0771:            public void addWrapperListener(String listener) {
0772:
0773:                synchronized (wrapperListeners) {
0774:                    String results[] = new String[wrapperListeners.length + 1];
0775:                    for (int i = 0; i < wrapperListeners.length; i++)
0776:                        results[i] = wrapperListeners[i];
0777:                    results[wrapperListeners.length] = listener;
0778:                    wrapperListeners = results;
0779:                }
0780:
0781:            }
0782:
0783:            /**
0784:             * Return the set of application listener class names configured
0785:             * for this application.
0786:             */
0787:            public String[] findApplicationListeners() {
0788:
0789:                return (applicationListeners);
0790:
0791:            }
0792:
0793:            /**
0794:             * Return the set of application parameters for this application.
0795:             */
0796:            public ApplicationParameter[] findApplicationParameters() {
0797:
0798:                return (applicationParameters);
0799:
0800:            }
0801:
0802:            /**
0803:             * Return the EJB resource reference with the specified name, if any;
0804:             * otherwise, return <code>null</code>.
0805:             *
0806:             * @param name Name of the desired EJB resource reference
0807:             */
0808:            public ContextEjb findEjb(String name) {
0809:
0810:                return namingResources.findEjb(name);
0811:
0812:            }
0813:
0814:            /**
0815:             * Return the defined EJB resource references for this application.
0816:             * If there are none, a zero-length array is returned.
0817:             */
0818:            public ContextEjb[] findEjbs() {
0819:
0820:                return namingResources.findEjbs();
0821:
0822:            }
0823:
0824:            /**
0825:             * Return the environment entry with the specified name, if any;
0826:             * otherwise, return <code>null</code>.
0827:             *
0828:             * @param name Name of the desired environment entry
0829:             */
0830:            public ContextEnvironment findEnvironment(String name) {
0831:
0832:                return namingResources.findEnvironment(name);
0833:
0834:            }
0835:
0836:            /**
0837:             * Return the set of defined environment entries for this web
0838:             * application.  If none have been defined, a zero-length array
0839:             * is returned.
0840:             */
0841:            public ContextEnvironment[] findEnvironments() {
0842:
0843:                return namingResources.findEnvironments();
0844:
0845:            }
0846:
0847:            /**
0848:             * Return the set of defined resource parameters for this web
0849:             * application.  If none have been defined, a zero-length array
0850:             * is returned.
0851:             */
0852:            public ResourceParams[] findResourceParams() {
0853:
0854:                return namingResources.findResourceParams();
0855:
0856:            }
0857:
0858:            /**
0859:             * Return the set of InstanceListener classes that will be added to
0860:             * newly created Wrappers automatically.
0861:             */
0862:            public String[] findInstanceListeners() {
0863:
0864:                return (instanceListeners);
0865:
0866:            }
0867:
0868:            /**
0869:             * Return the value for the specified context initialization
0870:             * parameter name, if any; otherwise return <code>null</code>.
0871:             *
0872:             * @param name Name of the parameter to return
0873:             */
0874:            public String findParameter(String name) {
0875:
0876:                synchronized (parameters) {
0877:                    return ((String) parameters.get(name));
0878:                }
0879:
0880:            }
0881:
0882:            /**
0883:             * Return the names of all defined context initialization parameters
0884:             * for this Context.  If no parameters are defined, a zero-length
0885:             * array is returned.
0886:             */
0887:            public String[] findParameters() {
0888:
0889:                synchronized (parameters) {
0890:                    String results[] = new String[parameters.size()];
0891:                    return ((String[]) parameters.keySet().toArray(results));
0892:                }
0893:
0894:            }
0895:
0896:            /**
0897:             * Return the resource reference with the specified name, if any;
0898:             * otherwise return <code>null</code>.
0899:             *
0900:             * @param name Name of the desired resource reference
0901:             */
0902:            public ContextResource findResource(String name) {
0903:
0904:                return namingResources.findResource(name);
0905:
0906:            }
0907:
0908:            /**
0909:             * Return the resource environment reference type for the specified
0910:             * name, if any; otherwise return <code>null</code>.
0911:             *
0912:             * @param name Name of the desired resource environment reference
0913:             */
0914:            public String findResourceEnvRef(String name) {
0915:
0916:                return namingResources.findResourceEnvRef(name);
0917:
0918:            }
0919:
0920:            /**
0921:             * Return the set of resource environment reference names for this
0922:             * web application.  If none have been specified, a zero-length
0923:             * array is returned.
0924:             */
0925:            public String[] findResourceEnvRefs() {
0926:
0927:                return namingResources.findResourceEnvRefs();
0928:
0929:            }
0930:
0931:            /**
0932:             * Return the resource link with the specified name, if any;
0933:             * otherwise return <code>null</code>.
0934:             *
0935:             * @param name Name of the desired resource link
0936:             */
0937:            public ContextResourceLink findResourceLink(String name) {
0938:
0939:                return namingResources.findResourceLink(name);
0940:
0941:            }
0942:
0943:            /**
0944:             * Return the defined resource links for this application.  If
0945:             * none have been defined, a zero-length array is returned.
0946:             */
0947:            public ContextResourceLink[] findResourceLinks() {
0948:
0949:                return namingResources.findResourceLinks();
0950:
0951:            }
0952:
0953:            /**
0954:             * Return the defined resource references for this application.  If
0955:             * none have been defined, a zero-length array is returned.
0956:             */
0957:            public ContextResource[] findResources() {
0958:
0959:                return namingResources.findResources();
0960:
0961:            }
0962:
0963:            /**
0964:             * Return the set of LifecycleListener classes that will be added to
0965:             * newly created Wrappers automatically.
0966:             */
0967:            public String[] findWrapperLifecycles() {
0968:
0969:                return (wrapperLifecycles);
0970:
0971:            }
0972:
0973:            /**
0974:             * Return the set of ContainerListener classes that will be added to
0975:             * newly created Wrappers automatically.
0976:             */
0977:            public String[] findWrapperListeners() {
0978:
0979:                return (wrapperListeners);
0980:
0981:            }
0982:
0983:            /**
0984:             * Return the naming resources associated with this web application.
0985:             */
0986:            public NamingResources getNamingResources() {
0987:
0988:                return (this .namingResources);
0989:
0990:            }
0991:
0992:            /**
0993:             * Remove the specified application listener class from the set of
0994:             * listeners for this application.
0995:             *
0996:             * @param listener Java class name of the listener to be removed
0997:             */
0998:            public void removeApplicationListener(String listener) {
0999:
1000:                synchronized (applicationListeners) {
1001:
1002:                    // Make sure this application listener is currently present
1003:                    int n = -1;
1004:                    for (int i = 0; i < applicationListeners.length; i++) {
1005:                        if (applicationListeners[i].equals(listener)) {
1006:                            n = i;
1007:                            break;
1008:                        }
1009:                    }
1010:                    if (n < 0)
1011:                        return;
1012:
1013:                    // Remove the specified application listener
1014:                    int j = 0;
1015:                    String results[] = new String[applicationListeners.length - 1];
1016:                    for (int i = 0; i < applicationListeners.length; i++) {
1017:                        if (i != n)
1018:                            results[j++] = applicationListeners[i];
1019:                    }
1020:                    applicationListeners = results;
1021:
1022:                }
1023:
1024:            }
1025:
1026:            /**
1027:             * Remove the application parameter with the specified name from
1028:             * the set for this application.
1029:             *
1030:             * @param name Name of the application parameter to remove
1031:             */
1032:            public void removeApplicationParameter(String name) {
1033:
1034:                synchronized (applicationParameters) {
1035:
1036:                    // Make sure this parameter is currently present
1037:                    int n = -1;
1038:                    for (int i = 0; i < applicationParameters.length; i++) {
1039:                        if (name.equals(applicationParameters[i].getName())) {
1040:                            n = i;
1041:                            break;
1042:                        }
1043:                    }
1044:                    if (n < 0)
1045:                        return;
1046:
1047:                    // Remove the specified parameter
1048:                    int j = 0;
1049:                    ApplicationParameter results[] = new ApplicationParameter[applicationParameters.length - 1];
1050:                    for (int i = 0; i < applicationParameters.length; i++) {
1051:                        if (i != n)
1052:                            results[j++] = applicationParameters[i];
1053:                    }
1054:                    applicationParameters = results;
1055:
1056:                }
1057:
1058:            }
1059:
1060:            /**
1061:             * Remove any EJB resource reference with the specified name.
1062:             *
1063:             * @param name Name of the EJB resource reference to remove
1064:             */
1065:            public void removeEjb(String name) {
1066:
1067:                namingResources.removeEjb(name);
1068:
1069:            }
1070:
1071:            /**
1072:             * Remove a class name from the set of InstanceListener classes that
1073:             * will be added to newly created Wrappers.
1074:             *
1075:             * @param listener Class name of an InstanceListener class to be removed
1076:             */
1077:            public void removeInstanceListener(String listener) {
1078:
1079:                synchronized (instanceListeners) {
1080:
1081:                    // Make sure this InstanceListener is currently present
1082:                    int n = -1;
1083:                    for (int i = 0; i < instanceListeners.length; i++) {
1084:                        if (instanceListeners[i].equals(listener)) {
1085:                            n = i;
1086:                            break;
1087:                        }
1088:                    }
1089:                    if (n < 0)
1090:                        return;
1091:
1092:                    // Remove the specified InstanceListener
1093:                    int j = 0;
1094:                    String results[] = new String[instanceListeners.length - 1];
1095:                    for (int i = 0; i < instanceListeners.length; i++) {
1096:                        if (i != n)
1097:                            results[j++] = instanceListeners[i];
1098:                    }
1099:                    instanceListeners = results;
1100:
1101:                }
1102:
1103:            }
1104:
1105:            /**
1106:             * Remove the context initialization parameter with the specified
1107:             * name, if it exists; otherwise, no action is taken.
1108:             *
1109:             * @param name Name of the parameter to remove
1110:             */
1111:            public void removeParameter(String name) {
1112:
1113:                synchronized (parameters) {
1114:                    parameters.remove(name);
1115:                }
1116:
1117:            }
1118:
1119:            /**
1120:             * Remove a property change listener from this component.
1121:             *
1122:             * @param listener The listener to remove
1123:             */
1124:            public void removePropertyChangeListener(
1125:                    PropertyChangeListener listener) {
1126:
1127:                support.removePropertyChangeListener(listener);
1128:
1129:            }
1130:
1131:            /**
1132:             * Remove any environment entry with the specified name.
1133:             *
1134:             * @param envName Name of the environment entry to remove
1135:             */
1136:            public void removeEnvironment(String envName) {
1137:
1138:                NamingResources nresources = getNamingResources();
1139:                if (nresources == null) {
1140:                    return;
1141:                }
1142:                ContextEnvironment env = nresources.findEnvironment(envName);
1143:                if (env == null) {
1144:                    throw new IllegalArgumentException(
1145:                            "Invalid environment name '" + envName + "'");
1146:                }
1147:                nresources.removeEnvironment(envName);
1148:            }
1149:
1150:            /**
1151:             * Remove any resource reference with the specified name.
1152:             *
1153:             * @param resourceName Name of the resource reference to remove
1154:             */
1155:            public void removeResource(String resourceName) {
1156:
1157:                // That should be done in the UI
1158:                // resourceName = URLDecoder.decode(resourceName);
1159:                NamingResources nresources = getNamingResources();
1160:                if (nresources == null) {
1161:                    return;
1162:                }
1163:                ContextResource resource = nresources
1164:                        .findResource(resourceName);
1165:                if (resource == null) {
1166:                    throw new IllegalArgumentException(
1167:                            "Invalid resource name '" + resourceName + "'");
1168:                }
1169:                nresources.removeResource(resourceName);
1170:            }
1171:
1172:            /**
1173:             * Remove any resource link with the specified name.
1174:             *
1175:             * @param resourceLinkName Name of the resource reference to remove
1176:             */
1177:            public void removeResourceLink(String resourceLinkName) {
1178:
1179:                //resourceLinkName = URLDecoder.decode(resourceLinkName);
1180:                NamingResources nresources = getNamingResources();
1181:                if (nresources == null) {
1182:                    return;
1183:                }
1184:                ContextResourceLink resource = nresources
1185:                        .findResourceLink(resourceLinkName);
1186:                if (resource == null) {
1187:                    throw new IllegalArgumentException(
1188:                            "Invalid resource name '" + resourceLinkName + "'");
1189:                }
1190:                nresources.removeResourceLink(resourceLinkName);
1191:            }
1192:
1193:            /**
1194:             * Remove any resource environment reference with the specified name.
1195:             *
1196:             * @param name Name of the resource environment reference to remove
1197:             */
1198:            public void removeResourceEnvRef(String name) {
1199:
1200:                namingResources.removeResourceEnvRef(name);
1201:
1202:            }
1203:
1204:            /**
1205:             * Remove a class name from the set of LifecycleListener classes that
1206:             * will be added to newly created Wrappers.
1207:             *
1208:             * @param listener Class name of a LifecycleListener class to be removed
1209:             */
1210:            public void removeWrapperLifecycle(String listener) {
1211:
1212:                synchronized (wrapperLifecycles) {
1213:
1214:                    // Make sure this LifecycleListener is currently present
1215:                    int n = -1;
1216:                    for (int i = 0; i < wrapperLifecycles.length; i++) {
1217:                        if (wrapperLifecycles[i].equals(listener)) {
1218:                            n = i;
1219:                            break;
1220:                        }
1221:                    }
1222:                    if (n < 0)
1223:                        return;
1224:
1225:                    // Remove the specified LifecycleListener
1226:                    int j = 0;
1227:                    String results[] = new String[wrapperLifecycles.length - 1];
1228:                    for (int i = 0; i < wrapperLifecycles.length; i++) {
1229:                        if (i != n)
1230:                            results[j++] = wrapperLifecycles[i];
1231:                    }
1232:                    wrapperLifecycles = results;
1233:
1234:                }
1235:
1236:            }
1237:
1238:            /**
1239:             * Remove a class name from the set of ContainerListener classes that
1240:             * will be added to newly created Wrappers.
1241:             *
1242:             * @param listener Class name of a ContainerListener class to be removed
1243:             */
1244:            public void removeWrapperListener(String listener) {
1245:
1246:                synchronized (wrapperListeners) {
1247:
1248:                    // Make sure this ContainerListener is currently present
1249:                    int n = -1;
1250:                    for (int i = 0; i < wrapperListeners.length; i++) {
1251:                        if (wrapperListeners[i].equals(listener)) {
1252:                            n = i;
1253:                            break;
1254:                        }
1255:                    }
1256:                    if (n < 0)
1257:                        return;
1258:
1259:                    // Remove the specified ContainerListener
1260:                    int j = 0;
1261:                    String results[] = new String[wrapperListeners.length - 1];
1262:                    for (int i = 0; i < wrapperListeners.length; i++) {
1263:                        if (i != n)
1264:                            results[j++] = wrapperListeners[i];
1265:                    }
1266:                    wrapperListeners = results;
1267:
1268:                }
1269:
1270:            }
1271:
1272:            // --------------------------------------------------------- Public Methods
1273:
1274:            /**
1275:             * Process the START event for an associated Context.
1276:             *
1277:             * @param event The lifecycle event that has occurred
1278:             */
1279:            public void lifecycleEvent(LifecycleEvent event) {
1280:
1281:                StandardContext context = null;
1282:                NamingContextListener listener = null;
1283:
1284:                if (event.getLifecycle() instanceof  StandardContext) {
1285:                    context = (StandardContext) event.getLifecycle();
1286:                    LifecycleListener[] listeners = context
1287:                            .findLifecycleListeners();
1288:                    for (int i = 0; i < listeners.length; i++) {
1289:                        if (listeners[i] instanceof  NamingContextListener) {
1290:                            listener = (NamingContextListener) listeners[i];
1291:                            break;
1292:                        }
1293:                    }
1294:                }
1295:
1296:                if (listener == null) {
1297:                    return;
1298:                }
1299:
1300:                if ((event.getType().equals(Lifecycle.BEFORE_STOP_EVENT))
1301:                        || (event.getType().equals(Context.RELOAD_EVENT))) {
1302:
1303:                    // Remove context
1304:                    contexts.remove(context);
1305:
1306:                    // Remove listener from the NamingResource listener list
1307:                    namingResources.removePropertyChangeListener(listener);
1308:
1309:                    // Remove listener from lifecycle listeners
1310:                    if (!(event.getType().equals(Context.RELOAD_EVENT))) {
1311:                        context.removeLifecycleListener(this );
1312:                    }
1313:
1314:                }
1315:
1316:                if ((event.getType().equals(Lifecycle.AFTER_START_EVENT))
1317:                        || (event.getType().equals(Context.RELOAD_EVENT))) {
1318:
1319:                    // Add context
1320:                    contexts.put(context, context);
1321:
1322:                    NamingResources contextResources = context
1323:                            .getNamingResources();
1324:
1325:                    // Setting the context in read/write mode
1326:                    ContextAccessController.setWritable(listener.getName(),
1327:                            context);
1328:
1329:                    // Send notifications to the listener to add the appropriate 
1330:                    // resources
1331:                    ContextEjb[] contextEjb = findEjbs();
1332:                    for (int i = 0; i < contextEjb.length; i++) {
1333:                        ContextEjb contextEntry = contextEjb[i];
1334:                        if (contextResources.exists(contextEntry.getName())) {
1335:                            listener.removeEjb(contextEntry.getName());
1336:                        }
1337:                        listener.addEjb(contextEntry);
1338:                    }
1339:                    ContextEnvironment[] contextEnv = findEnvironments();
1340:                    for (int i = 0; i < contextEnv.length; i++) {
1341:                        ContextEnvironment contextEntry = contextEnv[i];
1342:                        if (contextResources.exists(contextEntry.getName())) {
1343:                            listener.removeEnvironment(contextEntry.getName());
1344:                        }
1345:                        listener.addEnvironment(contextEntry);
1346:                    }
1347:                    ContextResource[] resources = findResources();
1348:                    for (int i = 0; i < resources.length; i++) {
1349:                        ContextResource contextEntry = resources[i];
1350:                        if (contextResources.exists(contextEntry.getName())) {
1351:                            listener.removeResource(contextEntry.getName());
1352:                        }
1353:                        listener.addResource(contextEntry);
1354:                    }
1355:                    ContextResourceLink[] resourceLinks = findResourceLinks();
1356:                    for (int i = 0; i < resourceLinks.length; i++) {
1357:                        ContextResourceLink contextEntry = resourceLinks[i];
1358:                        if (contextResources.exists(contextEntry.getName())) {
1359:                            listener.removeResourceLink(contextEntry.getName());
1360:                        }
1361:                        listener.addResourceLink(contextEntry);
1362:                    }
1363:                    String[] envRefs = findResourceEnvRefs();
1364:                    for (int i = 0; i < envRefs.length; i++) {
1365:                        if (contextResources.exists(envRefs[i])) {
1366:                            listener.removeResourceEnvRef(envRefs[i]);
1367:                        }
1368:                        listener.addResourceEnvRef(envRefs[i],
1369:                                findResourceEnvRef(envRefs[i]));
1370:                    }
1371:
1372:                    // Setting the context in read only mode
1373:                    ContextAccessController.setReadOnly(listener.getName());
1374:
1375:                    // Add listener to the NamingResources listener list
1376:                    namingResources.addPropertyChangeListener(listener);
1377:
1378:                }
1379:
1380:            }
1381:
1382:            /**
1383:             * Install the StandardContext portion of the DefaultContext
1384:             * configuration into current Context.
1385:             *
1386:             * @param context current web application context
1387:             */
1388:            public void installDefaultContext(Context context) {
1389:
1390:                if (context instanceof  StandardContext) {
1391:                    ((StandardContext) context).setUseNaming(isUseNaming());
1392:                    ((StandardContext) context)
1393:                            .setSwallowOutput(getSwallowOutput());
1394:                    ((StandardContext) context)
1395:                            .setCachingAllowed(isCachingAllowed());
1396:                    ((StandardContext) context).setCacheTTL(getCacheTTL());
1397:                    ((StandardContext) context)
1398:                            .setCacheMaxSize(getCacheMaxSize());
1399:                    ((StandardContext) context)
1400:                            .setAllowLinking(isAllowLinking());
1401:                    ((StandardContext) context)
1402:                            .setCaseSensitive(isCaseSensitive());
1403:                    ((StandardContext) context)
1404:                            .setManagerChecksFrequency(getManagerChecksFrequency());
1405:                    if (!contexts.containsKey(context)) {
1406:                        ((StandardContext) context).addLifecycleListener(this );
1407:                    }
1408:                    Enumeration lifecycleListeners = lifecycle.elements();
1409:                    while (lifecycleListeners.hasMoreElements()) {
1410:                        ((StandardContext) context)
1411:                                .addLifecycleListener((LifecycleListener) lifecycleListeners
1412:                                        .nextElement());
1413:                    }
1414:                }
1415:
1416:                if (!context.getPrivileged() && loader != null) {
1417:                    ClassLoader parentClassLoader = context.getParent()
1418:                            .getParentClassLoader();
1419:                    Class clazz = loader.getClass();
1420:                    Class types[] = { ClassLoader.class };
1421:                    Object args[] = { parentClassLoader };
1422:                    try {
1423:                        Constructor constructor = clazz
1424:                                .getDeclaredConstructor(types);
1425:                        Loader context_loader = (Loader) constructor
1426:                                .newInstance(args);
1427:                        context_loader.setDelegate(loader.getDelegate());
1428:                        context_loader.setReloadable(loader.getReloadable());
1429:                        if (loader instanceof  WebappLoader) {
1430:                            ((WebappLoader) context_loader)
1431:                                    .setDebug(((WebappLoader) loader)
1432:                                            .getDebug());
1433:                            ((WebappLoader) context_loader)
1434:                                    .setLoaderClass(((WebappLoader) loader)
1435:                                            .getLoaderClass());
1436:                        }
1437:                        context.setLoader(context_loader);
1438:                    } catch (Exception e) {
1439:                        IllegalArgumentException iae = new IllegalArgumentException(
1440:                                "DefaultContext custom Loader install failed");
1441:                        jdkCompat.chainException(iae, e);
1442:                        throw iae;
1443:                    }
1444:                }
1445:            }
1446:
1447:            /**
1448:             * Import the configuration from the DefaultContext into
1449:             * current Context.
1450:             *
1451:             * @param context current web application context
1452:             */
1453:            public void importDefaultContext(Context context) {
1454:                context.setCookies(getCookies());
1455:                context.setCrossContext(getCrossContext());
1456:                context.setReloadable(getReloadable());
1457:
1458:                String[] listeners = findApplicationListeners();
1459:                for (int i = 0; i < listeners.length; i++) {
1460:                    context.addApplicationListener(listeners[i]);
1461:                }
1462:                listeners = findInstanceListeners();
1463:                for (int i = 0; i < listeners.length; i++) {
1464:                    context.addInstanceListener(listeners[i]);
1465:                }
1466:                String[] wrapper = findWrapperListeners();
1467:                for (int i = 0; i < wrapper.length; i++) {
1468:                    context.addWrapperListener(wrapper[i]);
1469:                }
1470:                wrapper = findWrapperLifecycles();
1471:                for (int i = 0; i < wrapper.length; i++) {
1472:                    context.addWrapperLifecycle(wrapper[i]);
1473:                }
1474:                String[] parameters = findParameters();
1475:                for (int i = 0; i < parameters.length; i++) {
1476:                    context.addParameter(parameters[i],
1477:                            findParameter(parameters[i]));
1478:                }
1479:                ApplicationParameter[] appParam = findApplicationParameters();
1480:                for (int i = 0; i < appParam.length; i++) {
1481:                    context.addApplicationParameter(appParam[i]);
1482:                }
1483:
1484:                if (!(context instanceof  StandardContext)) {
1485:                    ContextEjb[] contextEjb = findEjbs();
1486:                    for (int i = 0; i < contextEjb.length; i++) {
1487:                        context.addEjb(contextEjb[i]);
1488:                    }
1489:                    ContextEnvironment[] contextEnv = findEnvironments();
1490:                    for (int i = 0; i < contextEnv.length; i++) {
1491:                        context.addEnvironment(contextEnv[i]);
1492:                    }
1493:                    /*
1494:                    if (context instanceof StandardContext) {
1495:                        ResourceParams [] resourceParams = findResourceParams();
1496:                        for( int i = 0; i < resourceParams.length; i++ ) {
1497:                            ((StandardContext)context).addResourceParams
1498:                                (resourceParams[i]);
1499:                        }
1500:                    }
1501:                     */
1502:                    ContextResource[] resources = findResources();
1503:                    for (int i = 0; i < resources.length; i++) {
1504:                        context.addResource(resources[i]);
1505:                    }
1506:                    ContextResourceLink[] resourceLinks = findResourceLinks();
1507:                    for (int i = 0; i < resourceLinks.length; i++) {
1508:                        context.addResourceLink(resourceLinks[i]);
1509:                    }
1510:                    String[] envRefs = findResourceEnvRefs();
1511:                    for (int i = 0; i < envRefs.length; i++) {
1512:                        context.addResourceEnvRef(envRefs[i],
1513:                                findResourceEnvRef(envRefs[i]));
1514:                    }
1515:                }
1516:
1517:            }
1518:
1519:            /**
1520:             * Return a String representation of this component.
1521:             */
1522:            public String toString() {
1523:
1524:                StringBuffer sb = new StringBuffer();
1525:                if (getParent() != null) {
1526:                    sb.append(getParent().toString());
1527:                    sb.append(".");
1528:                }
1529:                sb.append("DefaultContext[");
1530:                sb.append("]");
1531:                return (sb.toString());
1532:
1533:            }
1534:
1535:            // -------------------- JMX stuff  --------------------
1536:            protected String type;
1537:            protected String domain;
1538:            protected String suffix;
1539:            protected ObjectName oname;
1540:            protected MBeanServer mserver;
1541:
1542:            public ObjectName getObjectName() {
1543:                return oname;
1544:            }
1545:
1546:            public String getDomain() {
1547:                return domain;
1548:            }
1549:
1550:            public String getType() {
1551:                return type;
1552:            }
1553:
1554:            protected String getJSR77Suffix() {
1555:                return suffix;
1556:            }
1557:
1558:            public ObjectName preRegister(MBeanServer server, ObjectName name)
1559:                    throws Exception {
1560:                oname = name;
1561:                mserver = server;
1562:                domain = name.getDomain();
1563:
1564:                type = name.getKeyProperty("type");
1565:                if (type == null) {
1566:                    type = name.getKeyProperty("j2eeType");
1567:                }
1568:
1569:                String j2eeApp = name.getKeyProperty("J2EEApplication");
1570:                String j2eeServer = name.getKeyProperty("J2EEServer");
1571:                if (j2eeApp == null) {
1572:                    j2eeApp = "none";
1573:                }
1574:                if (j2eeServer == null) {
1575:                    j2eeServer = "none";
1576:                }
1577:                suffix = ",J2EEApplication=" + j2eeApp + ",J2EEServer="
1578:                        + j2eeServer;
1579:                return name;
1580:            }
1581:
1582:            public void postRegister(Boolean registrationDone) {
1583:            }
1584:
1585:            public void preDeregister() throws Exception {
1586:            }
1587:
1588:            public void postDeregister() {
1589:            }
1590:
1591:            /**
1592:             * Return the MBean Names of the set of defined environment entries for
1593:             * this web application
1594:             */
1595:            public String[] getEnvironments() {
1596:                ContextEnvironment[] envs = getNamingResources()
1597:                        .findEnvironments();
1598:                ArrayList results = new ArrayList();
1599:                for (int i = 0; i < envs.length; i++) {
1600:                    try {
1601:                        ObjectName oname = MBeanUtils.createObjectName(this 
1602:                                .getDomain(), envs[i]);
1603:                        results.add(oname.toString());
1604:                    } catch (MalformedObjectNameException e) {
1605:                        IllegalArgumentException iae = new IllegalArgumentException(
1606:                                "Cannot create object name for environment "
1607:                                        + envs[i]);
1608:                        jdkCompat.chainException(iae, e);
1609:                        throw iae;
1610:                    }
1611:                }
1612:                return ((String[]) results.toArray(new String[results.size()]));
1613:
1614:            }
1615:
1616:            /**
1617:             * Return the MBean Names of all the defined resource references for this
1618:             * application.
1619:             * XXX This changed - due to conflict
1620:             */
1621:            public String[] getResourceNames() {
1622:
1623:                ContextResource[] resources = getNamingResources()
1624:                        .findResources();
1625:                ArrayList results = new ArrayList();
1626:                for (int i = 0; i < resources.length; i++) {
1627:                    try {
1628:                        ObjectName oname = MBeanUtils.createObjectName(
1629:                                getDomain(), resources[i]);
1630:                        results.add(oname.toString());
1631:                    } catch (MalformedObjectNameException e) {
1632:                        IllegalArgumentException iae = new IllegalArgumentException(
1633:                                "Cannot create object name for resource "
1634:                                        + resources[i]);
1635:                        jdkCompat.chainException(iae, e);
1636:                        throw iae;
1637:                    }
1638:                }
1639:                return ((String[]) results.toArray(new String[results.size()]));
1640:
1641:            }
1642:
1643:            /**
1644:             * Return the MBean Names of all the defined resource links for this
1645:             * application
1646:             */
1647:            public String[] getResourceLinks() {
1648:
1649:                ContextResourceLink[] links = getNamingResources()
1650:                        .findResourceLinks();
1651:                ArrayList results = new ArrayList();
1652:                for (int i = 0; i < links.length; i++) {
1653:                    try {
1654:                        ObjectName oname = MBeanUtils.createObjectName(
1655:                                getDomain(), links[i]);
1656:                        results.add(oname.toString());
1657:                    } catch (MalformedObjectNameException e) {
1658:                        IllegalArgumentException iae = new IllegalArgumentException(
1659:                                "Cannot create object name for resource "
1660:                                        + links[i]);
1661:                        jdkCompat.chainException(iae, e);
1662:                        throw iae;
1663:                    }
1664:                }
1665:                return ((String[]) results.toArray(new String[results.size()]));
1666:
1667:            }
1668:
1669:            // ------------------------------------------------------------- Operations
1670:
1671:            /**
1672:             * Add an environment entry for this web application.
1673:             *
1674:             * @param envName New environment entry name
1675:             */
1676:            public String addEnvironment(String envName, String type)
1677:                    throws MalformedObjectNameException {
1678:
1679:                NamingResources nresources = getNamingResources();
1680:                if (nresources == null) {
1681:                    return null;
1682:                }
1683:                ContextEnvironment env = nresources.findEnvironment(envName);
1684:                if (env != null) {
1685:                    throw new IllegalArgumentException(
1686:                            "Invalid environment name - already exists '"
1687:                                    + envName + "'");
1688:                }
1689:                env = new ContextEnvironment();
1690:                env.setName(envName);
1691:                env.setType(type);
1692:                nresources.addEnvironment(env);
1693:
1694:                // Return the corresponding MBean name
1695:                ManagedBean managed = Registry.getRegistry(null, null)
1696:                        .findManagedBean("ContextEnvironment");
1697:                ObjectName oname = MBeanUtils.createObjectName(managed
1698:                        .getDomain(), env);
1699:                return (oname.toString());
1700:
1701:            }
1702:
1703:            /**
1704:             * Add a resource reference for this web application.
1705:             *
1706:             * @param resourceName New resource reference name
1707:             */
1708:            public String addResource(String resourceName, String type)
1709:                    throws MalformedObjectNameException {
1710:
1711:                NamingResources nresources = getNamingResources();
1712:                if (nresources == null) {
1713:                    return null;
1714:                }
1715:                ContextResource resource = nresources
1716:                        .findResource(resourceName);
1717:                if (resource != null) {
1718:                    throw new IllegalArgumentException(
1719:                            "Invalid resource name - already exists'"
1720:                                    + resourceName + "'");
1721:                }
1722:                resource = new ContextResource();
1723:                resource.setName(resourceName);
1724:                resource.setType(type);
1725:                nresources.addResource(resource);
1726:
1727:                // Return the corresponding MBean name
1728:                ManagedBean managed = Registry.getRegistry(null, null)
1729:                        .findManagedBean("ContextResource");
1730:                ObjectName oname = MBeanUtils.createObjectName(managed
1731:                        .getDomain(), resource);
1732:
1733:                return (oname.toString());
1734:            }
1735:
1736:            /**
1737:             * Add a resource link for this web application.
1738:             *
1739:             * @param resourceLinkName New resource link name
1740:             */
1741:            public String addResourceLink(String resourceLinkName,
1742:                    String global, String name, String type)
1743:                    throws MalformedObjectNameException {
1744:
1745:                NamingResources nresources = getNamingResources();
1746:                if (nresources == null) {
1747:                    return null;
1748:                }
1749:                ContextResourceLink resourceLink = nresources
1750:                        .findResourceLink(resourceLinkName);
1751:                if (resourceLink != null) {
1752:                    throw new IllegalArgumentException(
1753:                            "Invalid resource link name - already exists'"
1754:                                    + resourceLinkName + "'");
1755:                }
1756:                resourceLink = new ContextResourceLink();
1757:                resourceLink.setGlobal(global);
1758:                resourceLink.setName(resourceLinkName);
1759:                resourceLink.setType(type);
1760:                nresources.addResourceLink(resourceLink);
1761:
1762:                // Return the corresponding MBean name
1763:                ManagedBean managed = Registry.getRegistry(null, null)
1764:                        .findManagedBean("ContextResourceLink");
1765:                ObjectName oname = MBeanUtils.createObjectName(managed
1766:                        .getDomain(), resourceLink);
1767:                return (oname.toString());
1768:            }
1769:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.