KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > catalina > startup > ContextRuleSet


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18
19 package org.apache.catalina.startup;
20
21
22 import java.lang.reflect.Constructor JavaDoc;
23
24 import org.apache.catalina.Container;
25 import org.apache.catalina.Loader;
26 import org.apache.tomcat.util.digester.Digester;
27 import org.apache.tomcat.util.digester.Rule;
28 import org.apache.tomcat.util.digester.RuleSetBase;
29 import org.xml.sax.Attributes JavaDoc;
30
31
32 /**
33  * <p><strong>RuleSet</strong> for processing the contents of a
34  * Context or DefaultContext definition element. To enable parsing of a
35  * DefaultContext, be sure to specify a prefix that ends with "/Default".</p>
36  *
37  * @author Craig R. McClanahan
38  * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
39  */

40
41 public class ContextRuleSet extends RuleSetBase {
42
43
44     // ----------------------------------------------------- Instance Variables
45

46
47     /**
48      * The matching pattern prefix to use for recognizing our elements.
49      */

50     protected String JavaDoc prefix = null;
51
52
53     /**
54      * Should the context be created.
55      */

56     protected boolean create = true;
57
58
59     // ------------------------------------------------------------ Constructor
60

61
62     /**
63      * Construct an instance of this <code>RuleSet</code> with the default
64      * matching pattern prefix.
65      */

66     public ContextRuleSet() {
67
68         this("");
69
70     }
71
72
73     /**
74      * Construct an instance of this <code>RuleSet</code> with the specified
75      * matching pattern prefix.
76      *
77      * @param prefix Prefix for matching pattern rules (including the
78      * trailing slash character)
79      */

80     public ContextRuleSet(String JavaDoc prefix) {
81
82         super();
83         this.namespaceURI = null;
84         this.prefix = prefix;
85
86     }
87
88
89     /**
90      * Construct an instance of this <code>RuleSet</code> with the specified
91      * matching pattern prefix.
92      *
93      * @param prefix Prefix for matching pattern rules (including the
94      * trailing slash character)
95      */

96     public ContextRuleSet(String JavaDoc prefix, boolean create) {
97
98         super();
99         this.namespaceURI = null;
100         this.prefix = prefix;
101         this.create = create;
102
103     }
104
105
106     // --------------------------------------------------------- Public Methods
107

108
109     /**
110      * <p>Add the set of Rule instances defined in this RuleSet to the
111      * specified <code>Digester</code> instance, associating them with
112      * our namespace URI (if any). This method should only be called
113      * by a Digester instance.</p>
114      *
115      * @param digester Digester instance to which the new Rule instances
116      * should be added.
117      */

118     public void addRuleInstances(Digester digester) {
119
120         if (create) {
121             digester.addObjectCreate(prefix + "Context",
122                     "org.apache.catalina.core.StandardContext", "className");
123             digester.addSetProperties(prefix + "Context");
124         } else {
125             digester.addRule(prefix + "Context", new SetContextPropertiesRule());
126         }
127
128         if (create) {
129             digester.addRule(prefix + "Context",
130                              new LifecycleListenerRule
131                                  ("org.apache.catalina.startup.ContextConfig",
132                                   "configClass"));
133             digester.addSetNext(prefix + "Context",
134                                 "addChild",
135                                 "org.apache.catalina.Container");
136         }
137         digester.addCallMethod(prefix + "Context/InstanceListener",
138                                "addInstanceListener", 0);
139
140         digester.addObjectCreate(prefix + "Context/Listener",
141                                  null, // MUST be specified in the element
142
"className");
143         digester.addSetProperties(prefix + "Context/Listener");
144         digester.addSetNext(prefix + "Context/Listener",
145                             "addLifecycleListener",
146                             "org.apache.catalina.LifecycleListener");
147
148         digester.addObjectCreate(prefix + "Context/Loader",
149                             "org.apache.catalina.loader.WebappLoader",
150                             "className");
151         digester.addSetProperties(prefix + "Context/Loader");
152         digester.addSetNext(prefix + "Context/Loader",
153                             "setLoader",
154                             "org.apache.catalina.Loader");
155
156         digester.addObjectCreate(prefix + "Context/Manager",
157                                  "org.apache.catalina.session.StandardManager",
158                                  "className");
159         digester.addSetProperties(prefix + "Context/Manager");
160         digester.addSetNext(prefix + "Context/Manager",
161                             "setManager",
162                             "org.apache.catalina.Manager");
163
164         digester.addObjectCreate(prefix + "Context/Manager/Store",
165                                  null, // MUST be specified in the element
166
"className");
167         digester.addSetProperties(prefix + "Context/Manager/Store");
168         digester.addSetNext(prefix + "Context/Manager/Store",
169                             "setStore",
170                             "org.apache.catalina.Store");
171
172         digester.addObjectCreate(prefix + "Context/Parameter",
173                                  "org.apache.catalina.deploy.ApplicationParameter");
174         digester.addSetProperties(prefix + "Context/Parameter");
175         digester.addSetNext(prefix + "Context/Parameter",
176                             "addApplicationParameter",
177                             "org.apache.catalina.deploy.ApplicationParameter");
178
179         digester.addObjectCreate(prefix + "Context/Realm",
180                                  null, // MUST be specified in the element
181
"className");
182         digester.addSetProperties(prefix + "Context/Realm");
183         digester.addSetNext(prefix + "Context/Realm",
184                             "setRealm",
185                             "org.apache.catalina.Realm");
186
187         digester.addObjectCreate(prefix + "Context/Resources",
188                                  "org.apache.naming.resources.FileDirContext",
189                                  "className");
190         digester.addSetProperties(prefix + "Context/Resources");
191         digester.addSetNext(prefix + "Context/Resources",
192                             "setResources",
193                             "javax.naming.directory.DirContext");
194
195         digester.addObjectCreate(prefix + "Context/ResourceLink",
196                 "org.apache.catalina.deploy.ContextResourceLink");
197         digester.addSetProperties(prefix + "Context/ResourceLink");
198         digester.addRule(prefix + "Context/ResourceLink",
199                 new SetNextNamingRule("addResourceLink",
200                         "org.apache.catalina.deploy.ContextResourceLink"));
201
202         digester.addObjectCreate(prefix + "Context/Valve",
203                                  null, // MUST be specified in the element
204
"className");
205         digester.addSetProperties(prefix + "Context/Valve");
206         digester.addSetNext(prefix + "Context/Valve",
207                             "addValve",
208                             "org.apache.catalina.Valve");
209
210         digester.addCallMethod(prefix + "Context/WatchedResource",
211                                "addWatchedResource", 0);
212
213         digester.addCallMethod(prefix + "Context/WrapperLifecycle",
214                                "addWrapperLifecycle", 0);
215
216         digester.addCallMethod(prefix + "Context/WrapperListener",
217                                "addWrapperListener", 0);
218
219     }
220
221 }
222
Popular Tags