KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > web > catalina55 > JCatalinaRuleSet


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2005 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: JCatalinaRuleSet.java,v 1.2 2005/05/05 16:09:14 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.web.catalina55;
27
28 import org.apache.tomcat.util.digester.Digester;
29 import org.apache.tomcat.util.digester.Rule;
30 import org.apache.tomcat.util.digester.RuleSetBase;
31
32 import org.apache.catalina.Container;
33 import org.apache.catalina.startup.ClusterRuleSet;
34 import org.apache.catalina.startup.ConnectorCreateRule;
35 import org.apache.catalina.startup.ContextRuleSet;
36 import org.apache.catalina.startup.EngineRuleSet;
37 import org.apache.catalina.startup.HostRuleSet;
38 import org.apache.catalina.startup.NamingRuleSet;
39 import org.apache.catalina.startup.SetAllPropertiesRule;
40
41 import org.xml.sax.Attributes JavaDoc;
42
43 /**
44  * Defines the rules to parse the Tomcat server.xml file
45  * Some rules are customized for JOnAS
46  * @author Tomcat team
47  * @author Florent Benoit
48  */

49 public class JCatalinaRuleSet extends RuleSetBase {
50
51     /**
52      * Parent class loader use for Tomcat
53      */

54     private ClassLoader JavaDoc parentClassLoader = null;
55
56     /**
57      * Constructor of the rules of parsing for server.xml
58      * @param parentClassLoader the parent class loader to use
59      */

60     public JCatalinaRuleSet(final ClassLoader JavaDoc parentClassLoader) {
61         super();
62         this.parentClassLoader = parentClassLoader;
63     }
64
65
66
67     /**
68      * Add the rules to the digester object
69      * @param digester object on whcih to define rules
70      */

71     public void addRuleInstances(Digester digester) {
72
73         // Configure the actions we will be using
74
digester.addObjectCreate("Server",
75                                  "org.apache.catalina.core.StandardServer",
76                                  "className");
77         digester.addSetProperties("Server");
78         digester.addSetNext("Server",
79                             "setServer",
80                             "org.apache.catalina.Server");
81
82         digester.addObjectCreate("Server/GlobalNamingResources",
83                                  "org.apache.catalina.deploy.NamingResources");
84         digester.addSetProperties("Server/GlobalNamingResources");
85         digester.addSetNext("Server/GlobalNamingResources",
86                             "setGlobalNamingResources",
87                             "org.apache.catalina.deploy.NamingResources");
88
89
90         digester.addObjectCreate("Server/Listener",
91                                  null, // MUST be specified in the element
92
"className");
93         digester.addSetProperties("Server/Listener");
94         digester.addSetNext("Server/Listener",
95                             "addLifecycleListener",
96                             "org.apache.catalina.LifecycleListener");
97
98         digester.addObjectCreate("Server/Service",
99                                  "org.apache.catalina.core.StandardService",
100                                  "className");
101         digester.addSetProperties("Server/Service");
102         digester.addSetNext("Server/Service",
103                             "addService",
104                             "org.apache.catalina.Service");
105
106         digester.addObjectCreate("Server/Service/Listener",
107                                  null, // MUST be specified in the element
108
"className");
109         digester.addSetProperties("Server/Service/Listener");
110         digester.addSetNext("Server/Service/Listener",
111                             "addLifecycleListener",
112                             "org.apache.catalina.LifecycleListener");
113
114         digester.addRule("Server/Service/Connector",
115                 new ConnectorCreateRule());
116         digester.addRule("Server/Service/Connector",
117                 new SetAllPropertiesRule());
118         digester.addSetNext("Server/Service/Connector",
119                 "addConnector",
120         "org.apache.catalina.connector.Connector");
121
122
123         digester.addObjectCreate("Server/Service/Connector/Listener",
124                 null, // MUST be specified in the element
125
"className");
126         digester.addSetProperties("Server/Service/Connector/Listener");
127         digester.addSetNext("Server/Service/Connector/Listener",
128                 "addLifecycleListener",
129         "org.apache.catalina.LifecycleListener");
130
131
132         // Add RuleSets for nested elements
133
digester.addRuleSet(new NamingRuleSet("Server/GlobalNamingResources/"));
134         digester.addRuleSet(new EngineRuleSet("Server/Service/"));
135         digester.addRuleSet(new HostRuleSet("Server/Service/Engine/"));
136         digester.addRuleSet(new ContextRuleSet("Server/Service/Engine/Host/"));
137         digester.addRuleSet(new ClusterRuleSet("Server/Service/Engine/Host/Cluster/"));
138         digester.addRuleSet(new NamingRuleSet("Server/Service/Engine/Host/Context/"));
139
140         // When the 'engine' is found, set the parentClassLoader.
141
digester.addRule("Server/Service/Engine",
142                          new SetParentClassLoaderRule(parentClassLoader));
143     }
144 }
145
146 /**
147  * Class that sets the parent class loader for the top class on the stack.
148  * @author take from Catalina.
149  */

150 final class SetParentClassLoaderRule extends Rule {
151
152     /**
153      * The parent class loader to be set.
154      */

155     private ClassLoader JavaDoc parentClassLoader = null;
156
157
158     /**
159      * Construct a new action.
160      * @param parentClassLoader The new parent class loader
161      */

162     public SetParentClassLoaderRule(final ClassLoader JavaDoc parentClassLoader) {
163         super();
164         this.parentClassLoader = parentClassLoader;
165     }
166
167     /**
168      * Add the requested parent class loader.
169      * @param namespace the namespace URI of the matching element, or an
170      * empty string if the parser is not namespace aware
171      * or the element has no namespace
172      * @param name the local name if the parser is namespace aware,
173      * or just the element name otherwise
174      * @param attributes the attributes.
175      * @throws Exception if an error occurs.
176      */

177     public void begin(String JavaDoc namespace, String JavaDoc name, Attributes JavaDoc attributes) throws Exception JavaDoc {
178         Container top = (Container) digester.peek();
179         top.setParentClassLoader(parentClassLoader);
180     }
181 }
182
183
Popular Tags