001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2005 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: JCatalinaRuleSet.java 9370 2006-08-07 08:29:26Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.web.catalina55;
025:
026: import org.apache.catalina.Container;
027: import org.apache.catalina.startup.ClusterRuleSetFactory;
028: import org.apache.catalina.startup.ConnectorCreateRule;
029: import org.apache.catalina.startup.ContextRuleSet;
030: import org.apache.catalina.startup.EngineRuleSet;
031: import org.apache.catalina.startup.HostRuleSet;
032: import org.apache.catalina.startup.NamingRuleSet;
033: import org.apache.catalina.startup.SetAllPropertiesRule;
034: import org.apache.tomcat.util.digester.Digester;
035: import org.apache.tomcat.util.digester.Rule;
036: import org.apache.tomcat.util.digester.RuleSetBase;
037: import org.xml.sax.Attributes;
038:
039: /**
040: * Defines the rules to parse the Tomcat server.xml file
041: * Some rules are customized for JOnAS
042: * @author Tomcat team
043: * @author Florent Benoit
044: */
045: public class JCatalinaRuleSet extends RuleSetBase {
046:
047: /**
048: * Parent class loader use for Tomcat
049: */
050: private ClassLoader parentClassLoader = null;
051:
052: /**
053: * Constructor of the rules of parsing for server.xml
054: * @param parentClassLoader the parent class loader to use
055: */
056: public JCatalinaRuleSet(final ClassLoader parentClassLoader) {
057: super ();
058: this .parentClassLoader = parentClassLoader;
059: }
060:
061: /**
062: * Add the rules to the digester object
063: * @param digester object on whcih to define rules
064: */
065: public void addRuleInstances(Digester digester) {
066:
067: // Configure the actions we will be using
068: digester.addObjectCreate("Server",
069: "org.apache.catalina.core.StandardServer", "className");
070: digester.addSetProperties("Server");
071: digester.addSetNext("Server", "setServer",
072: "org.apache.catalina.Server");
073:
074: digester.addObjectCreate("Server/GlobalNamingResources",
075: "org.apache.catalina.deploy.NamingResources");
076: digester.addSetProperties("Server/GlobalNamingResources");
077: digester.addSetNext("Server/GlobalNamingResources",
078: "setGlobalNamingResources",
079: "org.apache.catalina.deploy.NamingResources");
080:
081: digester.addObjectCreate("Server/Listener", null, // MUST be specified in the element
082: "className");
083: digester.addSetProperties("Server/Listener");
084: digester.addSetNext("Server/Listener", "addLifecycleListener",
085: "org.apache.catalina.LifecycleListener");
086:
087: digester
088: .addObjectCreate("Server/Service",
089: "org.apache.catalina.core.StandardService",
090: "className");
091: digester.addSetProperties("Server/Service");
092: digester.addSetNext("Server/Service", "addService",
093: "org.apache.catalina.Service");
094:
095: digester.addObjectCreate("Server/Service/Listener", null, // MUST be specified in the element
096: "className");
097: digester.addSetProperties("Server/Service/Listener");
098: digester.addSetNext("Server/Service/Listener",
099: "addLifecycleListener",
100: "org.apache.catalina.LifecycleListener");
101:
102: digester.addRule("Server/Service/Connector",
103: new ConnectorCreateRule());
104: digester.addRule("Server/Service/Connector",
105: new SetAllPropertiesRule());
106: digester.addSetNext("Server/Service/Connector", "addConnector",
107: "org.apache.catalina.connector.Connector");
108:
109: digester.addObjectCreate("Server/Service/Connector/Listener",
110: null, // MUST be specified in the element
111: "className");
112: digester.addSetProperties("Server/Service/Connector/Listener");
113: digester.addSetNext("Server/Service/Connector/Listener",
114: "addLifecycleListener",
115: "org.apache.catalina.LifecycleListener");
116:
117: // Add RuleSets for nested elements
118: digester.addRuleSet(new NamingRuleSet(
119: "Server/GlobalNamingResources/"));
120: digester.addRuleSet(new EngineRuleSet("Server/Service/"));
121: digester.addRuleSet(new HostRuleSet("Server/Service/Engine/"));
122: digester.addRuleSet(new ContextRuleSet(
123: "Server/Service/Engine/Host/"));
124: digester
125: .addRuleSet(ClusterRuleSetFactory
126: .getClusterRuleSet("Server/Service/Engine/Host/Cluster/"));
127: digester.addRuleSet(new NamingRuleSet(
128: "Server/Service/Engine/Host/Context/"));
129:
130: // When the 'engine' is found, set the parentClassLoader.
131: digester.addRule("Server/Service/Engine",
132: new SetParentClassLoaderRule(parentClassLoader));
133: }
134: }
135:
136: /**
137: * Class that sets the parent class loader for the top class on the stack.
138: * @author take from Catalina.
139: */
140: final class SetParentClassLoaderRule extends Rule {
141:
142: /**
143: * The parent class loader to be set.
144: */
145: private ClassLoader parentClassLoader = null;
146:
147: /**
148: * Construct a new action.
149: * @param parentClassLoader The new parent class loader
150: */
151: public SetParentClassLoaderRule(final ClassLoader parentClassLoader) {
152: super ();
153: this .parentClassLoader = parentClassLoader;
154: }
155:
156: /**
157: * Add the requested parent class loader.
158: * @param namespace the namespace URI of the matching element, or an
159: * empty string if the parser is not namespace aware
160: * or the element has no namespace
161: * @param name the local name if the parser is namespace aware,
162: * or just the element name otherwise
163: * @param attributes the attributes.
164: * @throws Exception if an error occurs.
165: */
166: public void begin(String namespace, String name,
167: Attributes attributes) throws Exception {
168: Container top = (Container) digester.peek();
169: top.setParentClassLoader(parentClassLoader);
170: }
171: }
|