KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > go > teaservlet > InternalApplicationConfig


1 /* ====================================================================
2  * TeaServlet - Copyright (c) 1999-2000 Walt Disney Internet Group
3  * ====================================================================
4  * The Tea Software License, Version 1.1
5  *
6  * Copyright (c) 2000 Walt Disney Internet Group. All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Walt Disney Internet Group (http://opensource.go.com/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Tea", "TeaServlet", "Kettle", "Trove" and "BeanDoc" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact opensource@dig.com.
31  *
32  * 5. Products derived from this software may not be called "Tea",
33  * "TeaServlet", "Kettle" or "Trove", nor may "Tea", "TeaServlet",
34  * "Kettle", "Trove" or "BeanDoc" appear in their name, without prior
35  * written permission of the Walt Disney Internet Group.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40  * DISCLAIMED. IN NO EVENT SHALL THE WALT DISNEY INTERNET GROUP OR ITS
41  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
42  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
43  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
44  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
45  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48  * ====================================================================
49  *
50  * For more information about Tea, please see http://opensource.go.com/.
51  */

52
53 package com.go.teaservlet;
54
55 import java.util.*;
56 import javax.servlet.*;
57 import com.go.trove.log.Log;
58 import com.go.trove.util.PropertyMap;
59 import com.go.trove.util.plugin.Plugin;
60
61 /******************************************************************************
62  * An ApplicationConfig implementation that is used for deriving configuration
63  * for internal Applications.
64  *
65  * @author Brian S O'Neill
66  * @version
67  * <!--$$Revision:--> 16 <!-- $-->, <!--$$JustDate:--> 01/03/23 <!-- $-->
68  */

69 class InternalApplicationConfig implements ApplicationConfig {
70     private ApplicationConfig mBaseConfig;
71     private PropertyMap mProperties;
72     private Log mLog;
73     private Map mPluginMap;
74
75     /**
76      * Derive a new ApplicationConfig using the configuration passed in. Any
77      * properties in the "log" sub-map are applied to the new Log, and the
78      * "init" sub-map defines the new properties. Properties not contained
79      * in "applications" from the base configuration are added as defaults to
80      * to the new properties.
81      *
82      * @param config base configuration to derive from
83      * @param properties properties to use
84      * @param name name of internal application; is applied to Log name and
85      * is used to extract the correct properties.
86      */

87     public InternalApplicationConfig(ApplicationConfig config,
88                                      PropertyMap properties,
89                                      Map plugins,
90                                      String JavaDoc name) {
91         mBaseConfig = config;
92         mLog = new Log(name, config.getLog());
93         mLog.applyProperties(properties.subMap("log"));
94         mProperties = new PropertyMap(properties.subMap("init"));
95
96         PropertyMap baseProps = config.getProperties();
97         String JavaDoc filtered = "applications" + baseProps.getSeparator();
98         Iterator it = baseProps.keySet().iterator();
99         while (it.hasNext()) {
100             String JavaDoc key = (String JavaDoc)it.next();
101             if (!key.startsWith(filtered) && !mProperties.containsKey(key)) {
102                 mProperties.put(key, baseProps.get(key));
103             }
104         }
105
106         mPluginMap = plugins;
107     }
108
109     /**
110      * Returns initialization parameters in an easier to use map format.
111      */

112     public PropertyMap getProperties() {
113         return mProperties;
114     }
115
116     /**
117      * Returns the name of this application, which is the same as the log's
118      * name.
119      */

120     public String JavaDoc getName() {
121         return mLog.getName();
122     }
123
124     /**
125      * Returns a log object that this application should use for reporting
126      * information pertaining to the operation of the application.
127      */

128     public Log getLog() {
129         return mLog;
130     }
131     
132     public Plugin getPlugin(String JavaDoc name) {
133         return (Plugin)mPluginMap.get(name);
134     }
135     
136     public Map getPlugins() {
137         return mPluginMap;
138     }
139
140     public ServletContext getServletContext() {
141         return mBaseConfig.getServletContext();
142     }
143     
144     public String JavaDoc getInitParameter(String JavaDoc name) {
145         return mProperties.getString(name);
146     }
147     
148     public Enumeration getInitParameterNames() {
149         return Collections.enumeration(mProperties.keySet());
150     }
151
152     public String JavaDoc getServletName() {
153         return mBaseConfig.getServletName();
154     }
155 }
156
Popular Tags