You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by cr...@locus.apache.org on 2000/09/24 04:53:02 UTC
cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/xml XmlMapper.java
craigmcc 00/09/23 19:53:01
Modified: catalina/src/conf server.xml
catalina/src/share/org/apache/catalina Context.java
catalina/src/share/org/apache/catalina/core
ApplicationContext.java StandardContext.java
catalina/src/share/org/apache/catalina/startup Catalina.java
catalina/src/share/org/apache/catalina/util/xml
XmlMapper.java
Added: catalina/src/share/org/apache/catalina/deploy
ApplicationParameter.java
Log:
Allow default environmental paramters for a particular web application to
be configured in the $CATALINA_HOME/conf/server.xml file as a convenience
to application deployers, who will no longer need to modify web.xml files
to customize these values. The configuration is done with new nested
elements inside a <Context> element in the server.xml file, as follows:
* The new <Ejb> element corresponds to an <ejb-ref> element in web.xml.
* The new <Environment> element corresponds to an <env-entry> element
in web.xml.
* The new <Parameter> element corresponds to a <context-param> element
in web.xml.
* The new <Resource> element corresponds to a <resource-ref> element
in web.xml.
In all cases except <Parameter>, entries from the deployment descriptor
will override a default entry with the same name. For <Parameter>
entries, you can specify (via the "override" attribute) whether or not the
default context initialization parameter can be overridden from web.xml.
By default, default context initialization paramaters *can* be overridden.
Thanks to Nic Ferrier <nf...@tapsellferrier.co.uk> for the suggestion
to allow some level of application configuration in the server.xml file.
Revision Changes Path
1.7 +9 -0 jakarta-tomcat-4.0/catalina/src/conf/server.xml
Index: server.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/conf/server.xml,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- server.xml 2000/09/12 00:10:06 1.6
+++ server.xml 2000/09/24 02:52:57 1.7
@@ -107,6 +107,15 @@
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_examples_log." suffix=".txt"
timestamp="true"/>
+ <Ejb name="ejb/EmplRecord" type="Entity"
+ home="com.wombat.empl.EmployeeRecordHome"
+ remote="com.wombat.empl.EmployeeRecord"/>
+ <Environment name="maxExemptions" type="java.lang.Integer"
+ value="15"/>
+ <Parameter name="context.param.name" value="context.param.value"
+ override="false"/>
+ <Resource name="jdbc/EmployeeAppDb" auth="SERVLET"
+ type="javax.sql.DataSource"/>
</Context>
-->
1.6 +28 -4 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Context.java
Index: Context.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Context.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Context.java 2000/09/14 00:14:55 1.5
+++ Context.java 2000/09/24 02:52:58 1.6
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Context.java,v 1.5 2000/09/14 00:14:55 craigmcc Exp $
- * $Revision: 1.5 $
- * $Date: 2000/09/14 00:14:55 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Context.java,v 1.6 2000/09/24 02:52:58 craigmcc Exp $
+ * $Revision: 1.6 $
+ * $Date: 2000/09/24 02:52:58 $
*
* ====================================================================
*
@@ -66,6 +66,7 @@
import javax.servlet.ServletContext;
+import org.apache.catalina.deploy.ApplicationParameter;
import org.apache.catalina.deploy.ContextEjb;
import org.apache.catalina.deploy.ContextEnvironment;
import org.apache.catalina.deploy.ContextResource;
@@ -93,7 +94,7 @@
* <p>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.5 $ $Date: 2000/09/14 00:14:55 $
+ * @version $Revision: 1.6 $ $Date: 2000/09/24 02:52:58 $
*/
public interface Context extends Container {
@@ -294,6 +295,14 @@
/**
+ * Add a new application parameter for this application.
+ *
+ * @param parameter The new application parameter
+ */
+ public void addApplicationParameter(ApplicationParameter parameter);
+
+
+ /**
* Add a security constraint to the set for this web application.
*/
public void addConstraint(SecurityConstraint constraint);
@@ -455,6 +464,12 @@
/**
+ * Return the set of application parameters for this application.
+ */
+ public ApplicationParameter[] findApplicationParameters();
+
+
+ /**
* Return the set of security constraints for this web application.
* If there are none, a zero-length array is returned.
*/
@@ -702,6 +717,15 @@
* @param listener Java class name of the listener to be removed
*/
public void removeApplicationListener(String listener);
+
+
+ /**
+ * Remove the application parameter with the specified name from
+ * the set for this application.
+ *
+ * @param name Name of the application parameter to remove
+ */
+ public void removeApplicationParameter(String name);
/**
1.5 +51 -7 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationContext.java
Index: ApplicationContext.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationContext.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ApplicationContext.java 2000/08/24 23:56:59 1.4
+++ ApplicationContext.java 2000/09/24 02:52:59 1.5
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationContext.java,v 1.4 2000/08/24 23:56:59 craigmcc Exp $
- * $Revision: 1.4 $
- * $Date: 2000/08/24 23:56:59 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationContext.java,v 1.5 2000/09/24 02:52:59 craigmcc Exp $
+ * $Revision: 1.5 $
+ * $Date: 2000/09/24 02:52:59 $
*
* ====================================================================
*
@@ -86,6 +86,7 @@
import org.apache.catalina.Resources;
import org.apache.catalina.Wrapper;
import org.apache.catalina.connector.HttpRequestBase;
+import org.apache.catalina.deploy.ApplicationParameter;
import org.apache.catalina.util.Enumerator;
import org.apache.catalina.util.StringManager;
@@ -96,7 +97,7 @@
* associated with each instance of <code>StandardContext</code>.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.4 $ $Date: 2000/08/24 23:56:59 $
+ * @version $Revision: 1.5 $ $Date: 2000/09/24 02:52:59 $
*/
public final class ApplicationContext
@@ -143,6 +144,12 @@
/**
+ * The merged context initialization parameters for this Context.
+ */
+ private HashMap parameters = null;
+
+
+ /**
* The string manager for this package.
*/
private static final StringManager sm =
@@ -243,7 +250,10 @@
*/
public String getInitParameter(String name) {
- return (context.findParameter(name));
+ mergeParameters();
+ synchronized (parameters) {
+ return ((String) parameters.get(name));
+ }
}
@@ -254,8 +264,10 @@
*/
public Enumeration getInitParameterNames() {
- String parameters[] = context.findParameters();
- return (new Enumerator(Arrays.asList(parameters)));
+ mergeParameters();
+ synchronized (parameters) {
+ return (new Enumerator(parameters.keySet()));
+ }
}
@@ -593,6 +605,38 @@
log(sm.getString("applicationContext.attributeEvent"), t);
}
}
+
+ }
+
+
+ // -------------------------------------------------------- Private Methods
+
+
+ /**
+ * Merge the context initialization parameters specified in the application
+ * deployment descriptor with the application parameters described in the
+ * server configuration, respecting the <code>override</code> property of
+ * the application parameters appropriately.
+ */
+ private void mergeParameters() {
+
+ if (parameters != null)
+ return;
+ HashMap results = new HashMap();
+ String names[] = context.findParameters();
+ for (int i = 0; i < names.length; i++)
+ results.put(names[i], context.findParameter(names[i]));
+ ApplicationParameter params[] =
+ context.findApplicationParameters();
+ for (int i = 0; i < params.length; i++) {
+ if (params[i].getOverride()) {
+ if (results.get(params[i].getName()) == null)
+ results.put(params[i].getName(), params[i].getValue());
+ } else {
+ results.put(params[i].getName(), params[i].getValue());
+ }
+ }
+ parameters = results;
}
1.14 +81 -4 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java
Index: StandardContext.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- StandardContext.java 2000/09/14 00:14:56 1.13
+++ StandardContext.java 2000/09/24 02:52:59 1.14
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java,v 1.13 2000/09/14 00:14:56 craigmcc Exp $
- * $Revision: 1.13 $
- * $Date: 2000/09/14 00:14:56 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java,v 1.14 2000/09/24 02:52:59 craigmcc Exp $
+ * $Revision: 1.14 $
+ * $Date: 2000/09/24 02:52:59 $
*
* ====================================================================
*
@@ -88,6 +88,7 @@
import org.apache.catalina.Request;
import org.apache.catalina.Response;
import org.apache.catalina.Wrapper;
+import org.apache.catalina.deploy.ApplicationParameter;
import org.apache.catalina.deploy.ContextEjb;
import org.apache.catalina.deploy.ContextEnvironment;
import org.apache.catalina.deploy.ContextResource;
@@ -104,7 +105,7 @@
* requests directed to a particular servlet.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.13 $ $Date: 2000/09/14 00:14:56 $
+ * @version $Revision: 1.14 $ $Date: 2000/09/24 02:52:59 $
*/
public final class StandardContext
@@ -144,6 +145,13 @@
/**
+ * The set of application parameters defined for this application.
+ */
+ private ApplicationParameter applicationParameters[] =
+ new ApplicationParameter[0];
+
+
+ /**
* The security constraints for this web application.
*/
private SecurityConstraint constraints[] = new SecurityConstraint[0];
@@ -702,6 +710,26 @@
/**
+ * Add a new application parameter for this application.
+ *
+ * @param parameter The new application parameter
+ */
+ public void addApplicationParameter(ApplicationParameter parameter) {
+
+ synchronized (applicationParameters) {
+ ApplicationParameter results[] =
+ new ApplicationParameter[applicationParameters.length + 1];
+ System.arraycopy(applicationParameters, 0, results, 0,
+ applicationParameters.length);
+ results[applicationParameters.length] = parameter;
+ applicationParameters = results;
+ }
+ fireContainerEvent("addApplicationParameter", parameter);
+
+ }
+
+
+ /**
* Add a child Container, only if the proposed child is an implementation
* of Wrapper.
*
@@ -1139,6 +1167,16 @@
/**
+ * Return the set of application parameters for this application.
+ */
+ public ApplicationParameter[] findApplicationParameters() {
+
+ return (applicationParameters);
+
+ }
+
+
+ /**
* Return the security constraints for this web application.
* If there are none, a zero-length array is returned.
*/
@@ -1808,6 +1846,45 @@
fireContainerEvent("removeApplicationListener", listener);
// FIXME - behavior if already started?
+
+ }
+
+
+ /**
+ * Remove the application parameter with the specified name from
+ * the set for this application.
+ *
+ * @param name Name of the application parameter to remove
+ */
+ public void removeApplicationParameter(String name) {
+
+ synchronized (applicationParameters) {
+
+ // Make sure this parameter is currently present
+ int n = -1;
+ for (int i = 0; i < applicationParameters.length; i++) {
+ if (name.equals(applicationParameters[i].getName())) {
+ n = i;
+ break;
+ }
+ }
+ if (n < 0)
+ return;
+
+ // Remove the specified parameter
+ int j = 0;
+ ApplicationParameter results[] =
+ new ApplicationParameter[applicationParameters.length - 1];
+ for (int i = 0; i < applicationParameters.length; i++) {
+ if (i != n)
+ results[j++] = applicationParameters[i];
+ }
+ applicationParameters = results;
+
+ }
+
+ // Inform interested listeners
+ fireContainerEvent("removeApplicationParameter", name);
}
1.1 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/deploy/ApplicationParameter.java
Index: ApplicationParameter.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/deploy/ApplicationParameter.java,v 1.1 2000/09/24 02:53:00 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2000/09/24 02:53:00 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.catalina.deploy;
/**
* Representation of a context initialization parameter that is configured
* in the server configuration file, rather than the application deployment
* descriptor. This is convenient for establishing default values (which
* may be configured to allow application overrides or not) without having
* to modify the application deployment descriptor itself.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/09/24 02:53:00 $
*/
public final class ApplicationParameter {
// ------------------------------------------------------------- Properties
/**
* The name of this application parameter.
*/
private String name = null;
public String getName() {
return (this.name);
}
public void setName(String name) {
this.name = name;
}
/**
* Does this application parameter allow overrides by the application
* deployment descriptor?
*/
private boolean override = true;
public boolean getOverride() {
return (this.override);
}
public void setOverride(boolean override) {
this.override = override;
}
/**
* The value of this application parameter.
*/
private String value = null;
public String getValue() {
return (this.value);
}
public void setValue(String value) {
this.value = value;
}
// --------------------------------------------------------- Public Methods
/**
* Return a String representation of this object.
*/
public String toString() {
StringBuffer sb = new StringBuffer("ApplicationParameter[");
sb.append("name=");
sb.append(name);
sb.append(", value=");
sb.append(value);
sb.append(", override=");
sb.append(override);
sb.append("]");
return (sb.toString());
}
}
1.4 +39 -4 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Catalina.java
Index: Catalina.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Catalina.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Catalina.java 2000/09/11 18:46:19 1.3
+++ Catalina.java 2000/09/24 02:53:00 1.4
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Catalina.java,v 1.3 2000/09/11 18:46:19 craigmcc Exp $
- * $Revision: 1.3 $
- * $Date: 2000/09/11 18:46:19 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Catalina.java,v 1.4 2000/09/24 02:53:00 craigmcc Exp $
+ * $Revision: 1.4 $
+ * $Date: 2000/09/24 02:53:00 $
*
* ====================================================================
*
@@ -94,7 +94,7 @@
* </u>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.3 $ $Date: 2000/09/11 18:46:19 $
+ * @version $Revision: 1.4 $ $Date: 2000/09/24 02:53:00 $
*/
public class Catalina {
@@ -307,6 +307,23 @@
mapper.addRule("Server/Engine/Host/Context", mapper.addChild
("addChild", "org.apache.catalina.Container"));
+ mapper.addRule("Server/Engine/Host/Context/Ejb", mapper.objectCreate
+ ("org.apache.catalina.deploy.ContextEjb"));
+ mapper.addRule("Server/Engine/Host/Context/Ejb",
+ mapper.setProperties());
+ mapper.addRule("Server/Engine/Host/Context/Ejb", mapper.addChild
+ ("addEjb", "org.apache.catalina.deploy.ContextEjb"));
+
+ mapper.addRule("Server/Engine/Host/Context/Environment",
+ mapper.objectCreate
+ ("org.apache.catalina.deploy.ContextEnvironment"));
+ mapper.addRule("Server/Engine/Host/Context/Environment",
+ mapper.setProperties());
+ mapper.addRule("Server/Engine/Host/Context/Environment",
+ mapper.addChild
+ ("addEnvironment",
+ "org.apache.catalina.deploy.ContextEnvironment"));
+
mapper.addRule("Server/Engine/Host/Context/InstanceListener",
mapper.methodSetter("addInstanceListener", 0));
@@ -344,12 +361,30 @@
mapper.addRule("Server/Engine/Host/Context/Manager", mapper.addChild
("setManager", "org.apache.catalina.Manager"));
+ mapper.addRule("Server/Engine/Host/Context/Parameter", mapper.objectCreate
+ ("org.apache.catalina.deploy.ApplicationParameter"));
+ mapper.addRule("Server/Engine/Host/Context/Parameter",
+ mapper.setProperties());
+ mapper.addRule("Server/Engine/Host/Context/Parameter", mapper.addChild
+ ("addApplicationParameter",
+ "org.apache.catalina.deploy.ApplicationParameter"));
+
mapper.addRule("Server/Engine/Host/Context/Realm", mapper.objectCreate
(null, "className"));
mapper.addRule("Server/Engine/Host/Context/Realm",
mapper.setProperties());
mapper.addRule("Server/Engine/Host/Context/Realm", mapper.addChild
("setRealm", "org.apache.catalina.Realm"));
+
+ mapper.addRule("Server/Engine/Host/Context/Resource",
+ mapper.objectCreate
+ ("org.apache.catalina.deploy.ContextResource"));
+ mapper.addRule("Server/Engine/Host/Context/Resource",
+ mapper.setProperties());
+ mapper.addRule("Server/Engine/Host/Context/Resource",
+ mapper.addChild
+ ("addResource",
+ "org.apache.catalina.deploy.ContextResource"));
mapper.addRule("Server/Engine/Host/Context/Resources",
mapper.objectCreate
1.2 +4 -4 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/xml/XmlMapper.java
Index: XmlMapper.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/xml/XmlMapper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XmlMapper.java 2000/08/11 22:46:26 1.1
+++ XmlMapper.java 2000/09/24 02:53:01 1.2
@@ -47,8 +47,8 @@
boolean validating=false;
public XmlMapper() {
- attributeStack = new Object[100]; // depth of the xml doc
- tagStack = new String[100];
+ attributeStack = new Object[256]; // depth of the xml doc
+ tagStack = new String[256];
initDefaultRules();
}
@@ -300,8 +300,8 @@
this.action=action;
}
}
- Rule rules[]=new Rule[100];
- Rule matching[]=new Rule[100];
+ Rule rules[]=new Rule[256];
+ Rule matching[]=new Rule[256];
int ruleCount=0;
/**