001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.catalina.startup;
019:
020: import org.apache.tomcat.util.digester.Digester;
021: import org.apache.tomcat.util.digester.RuleSetBase;
022:
023: /**
024: * <p><strong>RuleSet</strong> for processing the contents of a
025: * Context or DefaultContext definition element. To enable parsing of a
026: * DefaultContext, be sure to specify a prefix that ends with "/Default".</p>
027: *
028: * @author Craig R. McClanahan
029: * @version $Revision: 500684 $ $Date: 2007-01-28 00:27:18 +0100 (dim., 28 janv. 2007) $
030: */
031:
032: public class ContextRuleSet extends RuleSetBase {
033:
034: // ----------------------------------------------------- Instance Variables
035:
036: /**
037: * The matching pattern prefix to use for recognizing our elements.
038: */
039: protected String prefix = null;
040:
041: /**
042: * Should the context be created.
043: */
044: protected boolean create = true;
045:
046: // ------------------------------------------------------------ Constructor
047:
048: /**
049: * Construct an instance of this <code>RuleSet</code> with the default
050: * matching pattern prefix.
051: */
052: public ContextRuleSet() {
053:
054: this ("");
055:
056: }
057:
058: /**
059: * Construct an instance of this <code>RuleSet</code> with the specified
060: * matching pattern prefix.
061: *
062: * @param prefix Prefix for matching pattern rules (including the
063: * trailing slash character)
064: */
065: public ContextRuleSet(String prefix) {
066:
067: super ();
068: this .namespaceURI = null;
069: this .prefix = prefix;
070:
071: }
072:
073: /**
074: * Construct an instance of this <code>RuleSet</code> with the specified
075: * matching pattern prefix.
076: *
077: * @param prefix Prefix for matching pattern rules (including the
078: * trailing slash character)
079: */
080: public ContextRuleSet(String prefix, boolean create) {
081:
082: super ();
083: this .namespaceURI = null;
084: this .prefix = prefix;
085: this .create = create;
086:
087: }
088:
089: // --------------------------------------------------------- Public Methods
090:
091: /**
092: * <p>Add the set of Rule instances defined in this RuleSet to the
093: * specified <code>Digester</code> instance, associating them with
094: * our namespace URI (if any). This method should only be called
095: * by a Digester instance.</p>
096: *
097: * @param digester Digester instance to which the new Rule instances
098: * should be added.
099: */
100: public void addRuleInstances(Digester digester) {
101:
102: if (create) {
103: digester.addObjectCreate(prefix + "Context",
104: "org.apache.catalina.core.StandardContext",
105: "className");
106: digester.addSetProperties(prefix + "Context");
107: } else {
108: digester.addRule(prefix + "Context",
109: new SetContextPropertiesRule());
110: }
111:
112: if (create) {
113: digester
114: .addRule(
115: prefix + "Context",
116: new LifecycleListenerRule(
117: "org.apache.catalina.startup.ContextConfig",
118: "configClass"));
119: digester.addSetNext(prefix + "Context", "addChild",
120: "org.apache.catalina.Container");
121: }
122: digester.addCallMethod(prefix + "Context/InstanceListener",
123: "addInstanceListener", 0);
124:
125: digester.addObjectCreate(prefix + "Context/Listener", null, // MUST be specified in the element
126: "className");
127: digester.addSetProperties(prefix + "Context/Listener");
128: digester.addSetNext(prefix + "Context/Listener",
129: "addLifecycleListener",
130: "org.apache.catalina.LifecycleListener");
131:
132: digester.addObjectCreate(prefix + "Context/Loader",
133: "org.apache.catalina.loader.WebappLoader", "className");
134: digester.addSetProperties(prefix + "Context/Loader");
135: digester.addSetNext(prefix + "Context/Loader", "setLoader",
136: "org.apache.catalina.Loader");
137:
138: digester.addObjectCreate(prefix + "Context/Manager",
139: "org.apache.catalina.session.StandardManager",
140: "className");
141: digester.addSetProperties(prefix + "Context/Manager");
142: digester.addSetNext(prefix + "Context/Manager", "setManager",
143: "org.apache.catalina.Manager");
144:
145: digester.addObjectCreate(prefix + "Context/Manager/Store",
146: null, // MUST be specified in the element
147: "className");
148: digester.addSetProperties(prefix + "Context/Manager/Store");
149: digester.addSetNext(prefix + "Context/Manager/Store",
150: "setStore", "org.apache.catalina.Store");
151:
152: digester.addObjectCreate(prefix + "Context/Parameter",
153: "org.apache.catalina.deploy.ApplicationParameter");
154: digester.addSetProperties(prefix + "Context/Parameter");
155: digester.addSetNext(prefix + "Context/Parameter",
156: "addApplicationParameter",
157: "org.apache.catalina.deploy.ApplicationParameter");
158:
159: digester.addObjectCreate(prefix + "Context/Realm", null, // MUST be specified in the element
160: "className");
161: digester.addSetProperties(prefix + "Context/Realm");
162: digester.addSetNext(prefix + "Context/Realm", "setRealm",
163: "org.apache.catalina.Realm");
164:
165: digester.addObjectCreate(prefix + "Context/Resources",
166: "org.apache.naming.resources.FileDirContext",
167: "className");
168: digester.addSetProperties(prefix + "Context/Resources");
169: digester.addSetNext(prefix + "Context/Resources",
170: "setResources", "javax.naming.directory.DirContext");
171:
172: digester.addObjectCreate(prefix + "Context/ResourceLink",
173: "org.apache.catalina.deploy.ContextResourceLink");
174: digester.addSetProperties(prefix + "Context/ResourceLink");
175: digester
176: .addRule(
177: prefix + "Context/ResourceLink",
178: new SetNextNamingRule("addResourceLink",
179: "org.apache.catalina.deploy.ContextResourceLink"));
180:
181: digester.addObjectCreate(prefix + "Context/Valve", null, // MUST be specified in the element
182: "className");
183: digester.addSetProperties(prefix + "Context/Valve");
184: digester.addSetNext(prefix + "Context/Valve", "addValve",
185: "org.apache.catalina.Valve");
186:
187: digester.addCallMethod(prefix + "Context/WatchedResource",
188: "addWatchedResource", 0);
189:
190: digester.addCallMethod(prefix + "Context/WrapperLifecycle",
191: "addWrapperLifecycle", 0);
192:
193: digester.addCallMethod(prefix + "Context/WrapperListener",
194: "addWrapperListener", 0);
195:
196: }
197:
198: }
|