You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@locus.apache.org on 2000/11/02 07:14:18 UTC
cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/java javaURLContextFactory.java
remm 00/11/01 22:14:18
Modified: catalina STATUS.html build.xml
catalina/src/bin catalina.bat catalina.sh
catalina/src/share/org/apache/catalina/core
LocalStrings.properties StandardContext.java
StandardContextValve.java
catalina/src/share/org/apache/catalina/startup Catalina.java
Embedded.java EmbeddedManager.java
EmbeddedManagerMBean.java
Added: catalina/src/share/org/apache/naming Constants.java
ContextAccessController.java ContextBindings.java
EjbRefAddr.java LocalStrings.properties
NameParserImpl.java NamingContext.java
NamingContextBindingsEnumeration.java
NamingContextEnumeration.java NamingEntry.java
NamingService.java NamingServiceMBean.java
ResourceEnvRefAddr.java ResourceRefAddr.java
SelectorContext.java StringManager.java
catalina/src/share/org/apache/naming/factory
LocalStrings.properties
catalina/src/share/org/apache/naming/java
javaURLContextFactory.java
Log:
- JNDI implementation which provides a per web application naming environment.
- 100% independent from Catalina (root package name : org.apache.naming).
- The Context implementation supports federation, links and references.
- Web application environment support ("java" URL scheme), which is a special
read-only JNDI context populated using the web app deployment descriptor.
- Updated STATUS.html to reflect that addition.
- Generic references are used for EJB and Resources. A set of factories
(org.apache.naming.factory) will be provided to interface various popular
J2EE providers, whenever possible.
- Each web application can also get a writable initial context, which is NOT
accessible to other web applications.
- Adds various switches in Catalina to enable / disable the naming support :
* "-nonaming" command line option completely disables naming
* Embedded.setUseNaming(false) also completely disables naming (useful is the
embedding application provides its own naming environment)
* In server.xml, a new attribute of Context element, "useNaming" can be used
to disable the naming support for a specific web application.
* By default, internal naming is enabled for each of the web applications.
- Updates to the JMX wrapper to Embedded to reflect this.
- JMX wrapper to the naming service (named NamingService). It has simple start
and stop commands which initialize / restore to previous values when you stop
the required environment variables.
Revision Changes Path
1.3 +1 -9 jakarta-tomcat-4.0/catalina/STATUS.html
Index: STATUS.html
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/STATUS.html,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- STATUS.html 2000/10/10 01:25:22 1.2
+++ STATUS.html 2000/11/02 06:14:07 1.3
@@ -115,14 +115,6 @@
<th width="60%">Action Item</th>
<th width="30%">Volunteers</th>
</tr>
- <tr>
- <td>Low</td>
- <td>Implement the optional <i>web application environment</i> support
- described in Section 9.9 of the Servlet API Specification Version 2.2,
- and Chapter 5 of the Java2 Platform Enterprise Edition Version 1.2
- Specification.</td>
- <td>---</td>
- </tr>
</table>
@@ -313,7 +305,7 @@
<br>
<div align="center"><hr width="75%"><font size="2">
-$Id: STATUS.html,v 1.2 2000/10/10 01:25:22 craigmcc Exp $
+$Id: STATUS.html,v 1.3 2000/11/02 06:14:07 remm Exp $
</font></div>
</body>
1.19 +10 -3 jakarta-tomcat-4.0/catalina/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/build.xml,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- build.xml 2000/10/12 23:34:09 1.18
+++ build.xml 2000/11/02 06:14:07 1.19
@@ -82,7 +82,12 @@
<!-- Construct bootstrap JAR file -->
<jar jarfile="${catalina.build}/bin/bootstrap.jar"
basedir="${catalina.build}/classes"
- includes="org/apache/catalina/startup/Bootstrap.class,org/apache/catalina/loader/*"/>
+ includes="org/apache/catalina/startup/Bootstrap.class,org/apache/catalina/loader/**"
+ />
+ <jar jarfile="${catalina.build}/bin/naming.jar"
+ basedir="${catalina.build}/classes"
+ includes="**/org/apache/naming/**"
+ />
</target>
@@ -151,7 +156,8 @@
<!-- ====================== DEPLOY: Create Catalina JAR ================= -->
<target name="deploy-main" depends="deploy-static">
<jar jarfile="${catalina.deploy}/server/catalina.jar"
- basedir="${catalina.build}/classes"/>
+ basedir="${catalina.build}/classes"
+ excludes="**/org/apache/naming/**" />
</target>
@@ -184,7 +190,8 @@
<mkdir dir="${catalina.dist}/server"/>
<copydir src="${catalina.build}/server" dest="${catalina.dist}/server"/>
<jar jarfile="${catalina.dist}/server/catalina.jar"
- basedir="${catalina.build}/classes"/>
+ basedir="${catalina.build}/classes"
+ excludes="**/org/apache/naming/**" />
</target>
1.12 +2 -2 jakarta-tomcat-4.0/catalina/src/bin/catalina.bat
Index: catalina.bat
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/bin/catalina.bat,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- catalina.bat 2000/10/16 18:50:56 1.11
+++ catalina.bat 2000/11/02 06:14:08 1.12
@@ -12,7 +12,7 @@
rem
rem JAVA_HOME Must point at your Java Development Kit installation.
rem
-rem $Id: catalina.bat,v 1.11 2000/10/16 18:50:56 craigmcc Exp $
+rem $Id: catalina.bat,v 1.12 2000/11/02 06:14:08 remm Exp $
rem ---------------------------------------------------------------------------
@@ -55,7 +55,7 @@
rem ----- Set Up The Runtime Classpath ----------------------------------------
set CP=%CATALINA_HOME%\bin\bootstrap.jar;%CATALINA_HOME%\bin\servlet.jar
-set CP=%CP%;%JAVA_HOME%\lib\tools.jar
+set CP=%CP%;%CATALINA_HOME%\bin\naming.jar;%JAVA_HOME%\lib\tools.jar
set CLASSPATH=%CP%
echo Using CLASSPATH: %CLASSPATH%
1.8 +2 -2 jakarta-tomcat-4.0/catalina/src/bin/catalina.sh
Index: catalina.sh
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/bin/catalina.sh,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- catalina.sh 2000/10/16 18:27:45 1.7
+++ catalina.sh 2000/11/02 06:14:08 1.8
@@ -12,7 +12,7 @@
#
# JAVA_HOME Must point at your Java Development Kit installation.
#
-# $Id: catalina.sh,v 1.7 2000/10/16 18:27:45 craigmcc Exp $
+# $Id: catalina.sh,v 1.8 2000/11/02 06:14:08 remm Exp $
# -----------------------------------------------------------------------------
@@ -33,7 +33,7 @@
# ----- Set Up The System Classpath -------------------------------------------
-CP=$CATALINA_HOME/bin/bootstrap.jar:$CATALINA_HOME/bin/servlet.jar
+CP=$CATALINA_HOME/bin/bootstrap.jar:$CATALINA_HOME/bin/servlet.jar:$CATALINA_HOME/bin/naming.jar
if [ -f $JAVA_HOME/lib/tools.jar ] ; then
CP=$CP:$JAVA_HOME/lib/tools.jar
1.18 +4 -0 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/LocalStrings.properties
Index: LocalStrings.properties
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/LocalStrings.properties,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- LocalStrings.properties 2000/10/22 09:55:52 1.17
+++ LocalStrings.properties 2000/11/02 06:14:09 1.18
@@ -51,6 +51,10 @@
standardContext.stoppingLoader=Exception stopping Loader
standardContext.stoppingManager=Exception stopping Manager
standardContext.stoppingWrapper=Exception stopping Wrapper for servlet {0}
+standardContext.invalidEnvEntryValue={0} environment entry has an invalid value for specified type
+standardContext.invalidEnvEntryType={0} environment entry has an invalid type
+standardContext.bindFailed=Bind naming operation failed : {0}
+standardContext.namingInitFailed=Error initializing naming context for context {0}
standardEngine.alreadyStarted=Engine has already been started
standardEngine.mappingError=MAPPING configuration error for server name {0}
standardEngine.notHost=Child of an Engine must be a Host
1.25 +225 -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.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- StandardContext.java 2000/10/29 00:35:04 1.24
+++ StandardContext.java 2000/11/02 06:14:09 1.25
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java,v 1.24 2000/10/29 00:35:04 craigmcc Exp $
- * $Revision: 1.24 $
- * $Date: 2000/10/29 00:35:04 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java,v 1.25 2000/11/02 06:14:09 remm Exp $
+ * $Revision: 1.25 $
+ * $Date: 2000/11/02 06:14:09 $
*
* ====================================================================
*
@@ -71,6 +71,8 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.TreeMap;
+import java.util.Hashtable;
+import java.util.StringTokenizer;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
@@ -78,6 +80,16 @@
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.naming.NamingException;
+import javax.naming.InitialContext;
+import javax.naming.Reference;
+import javax.naming.StringRefAddr;
+import org.apache.naming.NamingContext;
+import org.apache.naming.ContextBindings;
+import org.apache.naming.ContextAccessController;
+import org.apache.naming.EjbRefAddr;
+import org.apache.naming.ResourceRefAddr;
+import org.apache.naming.ResourceEnvRefAddr;
import org.apache.catalina.Container;
import org.apache.catalina.ContainerListener;
import org.apache.catalina.Context;
@@ -114,7 +126,8 @@
* requests directed to a particular servlet.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.24 $ $Date: 2000/10/29 00:35:04 $
+ * @author Remy Maucherat
+ * @version $Revision: 1.25 $ $Date: 2000/11/02 06:14:09 $
*/
public final class StandardContext
@@ -399,10 +412,34 @@
private String wrapperClass = "org.apache.catalina.core.StandardWrapper";
- // -----------------------------------------------------Context Properties
+ /**
+ * JNDI use flag.
+ */
+ private boolean useNaming = true;
+
+ // ----------------------------------------------------- Context Properties
+
/**
+ * Returns true if the internal naming support is used.
+ */
+ public boolean isUseNaming() {
+
+ return (useNaming);
+
+ }
+
+
+ /**
+ * Enables or disables naming.
+ */
+ public void setUseNaming(boolean useNaming) {
+ this.useNaming = useNaming;
+ }
+
+
+ /**
* Return the set of initialized application listener objects,
* in the order they were specified in the web application deployment
* descriptor, for this application.
@@ -2736,6 +2773,24 @@
if (!available)
return;
+ // Reading the "catalina.useNaming" environment variable
+ String useNamingProperty = System.getProperty("catalina.useNaming");
+ if ((useNamingProperty != null)
+ && (useNamingProperty.equals("false"))) {
+ useNaming = false;
+ }
+
+ // Create and register the associated naming context, if internal
+ // naming is used
+ if (isUseNaming()) {
+ try {
+ createNamingContext();
+ } catch (NamingException e) {
+ log(sm.getString("standardContext.namingInitFailed",
+ getName()));
+ }
+ }
+
// Configure and call application event listeners and filters
listenerStart();
filterStart();
@@ -2870,6 +2925,172 @@
super.addDefaultMapper(this.mapperClass);
}
+
+
+ // -------------------------------------------------------- Private Methods
+
+
+ /**
+ * Create and initialize the JNDI naming context.
+ */
+ private void createNamingContext()
+ throws NamingException {
+
+ Hashtable contextEnv = new Hashtable();
+ javax.naming.Context namingContext =
+ new NamingContext(contextEnv, getName());
+ ContextAccessController.setSecurityToken(getName(), this);
+ ContextBindings.bindContext(getName(), namingContext, this);
+ ContextBindings.bindThread(getName(), this);
+
+ // Setting the context in read/write mode
+ ContextAccessController.setWritable(getName(), this);
+
+ // Creating the comp subcontext
+ javax.naming.Context compCtx = namingContext.createSubcontext("comp");
+ javax.naming.Context envCtx = compCtx.createSubcontext("env");
+
+ // Now parsing the entries defined in the env, and adding them to the
+ // naming context
+
+ // Environment entries
+ Iterator envsList = envs.values().iterator();
+
+ while (envsList.hasNext()) {
+ ContextEnvironment env = (ContextEnvironment) envsList.next();
+ Object value = null;
+ // Instantiating a new instance of the correct object type, and
+ // initializing it.
+ String type = env.getType();
+ try {
+ if (type.equals("java.lang.String")) {
+ value = env.getValue();
+ } else if (type.equals("java.lang.Byte")) {
+ value = Byte.decode(env.getValue());
+ } else if (type.equals("java.lang.Short")) {
+ value = Short.decode(env.getValue());
+ } else if (type.equals("java.lang.Integer")) {
+ value = Integer.decode(env.getValue());
+ } else if (type.equals("java.lang.Long")) {
+ value = Long.decode(env.getValue());
+ } else if (type.equals("java.lang.Boolean")) {
+ value = Boolean.valueOf(env.getValue());
+ } else if (type.equals("java.lang.Double")) {
+ value = Double.valueOf(env.getValue());
+ } else if (type.equals("java.lang.Float")) {
+ value = Float.valueOf(env.getValue());
+ } else {
+ log(sm.getString("standardContext.invalidEnvEntryType",
+ env.getName()));
+ }
+ } catch (NumberFormatException e) {
+ log(sm.getString("standardContext.invalidEnvEntryValue",
+ env.getName()));
+ }
+ // Binding the object to the appropriate name
+ if (value != null) {
+ try {
+ createSubcontexts(envCtx, env.getName());
+ envCtx.bind(env.getName(), value);
+ } catch (NamingException e) {
+ log(sm.getString("standardContext.invalidEnvEntryValue",
+ e));
+ }
+ }
+
+ }
+
+ // EJB references
+ Iterator ejbsList = ejbs.values().iterator();
+
+ while (ejbsList.hasNext()) {
+ ContextEjb ejb = (ContextEjb) ejbsList.next();
+ // Create a reference to the EJB.
+ EjbRefAddr ejbRefAddr = new EjbRefAddr
+ (ejb.getType(), ejb.getHome(), ejb.getRemote(), ejb.getLink(),
+ ejb.getRunAs());
+ Reference ref = new Reference(ejb.getType(), ejbRefAddr);
+ // Adding the additional parameters, if any
+
+ try {
+ createSubcontexts(compCtx, ejb.getName());
+ compCtx.bind(ejb.getName(), ref);
+ } catch (NamingException e) {
+ log(sm.getString("standardContext.bindFailed", e));
+ }
+
+ }
+
+ // Resources
+ Iterator resourcesList = resources.values().iterator();
+
+ while (resourcesList.hasNext()) {
+ ContextResource resource = (ContextResource) resourcesList.next();
+ // Create a reference to the resource.
+ ResourceRefAddr resourceRefAddr = new ResourceRefAddr
+ (resource.getType(), resource.getDescription(),
+ resource.getScope(), resource.getAuth());
+ Reference ref = new Reference(resource.getType(), resourceRefAddr);
+ // Adding the additional parameters, if any
+
+ try {
+ createSubcontexts(compCtx, resource.getName());
+ compCtx.bind(resource.getName(), ref);
+ } catch (NamingException e) {
+ log(sm.getString("standardContext.bindFailed", e));
+ }
+
+ }
+
+ // Resources Env
+ Iterator resourceEnvsKeyList = resourceEnvRefs.keySet().iterator();
+
+ while (resourceEnvsKeyList.hasNext()) {
+ String key = (String) resourceEnvsKeyList.next();
+ String type = (String) resourceEnvRefs.get(key);
+ // Create a reference to the resource env.
+ Reference ref = new Reference(type);
+ ref.add(new StringRefAddr("name", key));
+ ref.add(new StringRefAddr("type", type));
+ // Adding the additional parameters, if any
+
+ try {
+ createSubcontexts(compCtx, key);
+ compCtx.bind(key, ref);
+ } catch (NamingException e) {
+ log(sm.getString("standardContext.bindFailed", e));
+ }
+
+ }
+
+ // Setting the context in read only mode
+ ContextAccessController.setReadOnly(getName());
+
+ ContextBindings.unbindThread(getName(), this);
+
+ }
+
+
+ /**
+ * Create all intermediate subcontexts.
+ */
+ private void createSubcontexts(javax.naming.Context ctx, String name)
+ throws NamingException {
+ javax.naming.Context currentContext = ctx;
+ StringTokenizer tokenizer = new StringTokenizer(name, "/");
+ while (tokenizer.hasMoreTokens()) {
+ String token = tokenizer.nextToken();
+ if ((!token.equals("")) && (tokenizer.hasMoreTokens())) {
+ try {
+ currentContext = currentContext.createSubcontext(token);
+ } catch (NamingException e) {
+ // Silent catch. Probably an object is already bound in
+ // the context.
+ }
+ }
+ }
+ }
+
/**
1.4 +21 -4 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContextValve.java
Index: StandardContextValve.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContextValve.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- StandardContextValve.java 2000/10/03 21:30:36 1.3
+++ StandardContextValve.java 2000/11/02 06:14:09 1.4
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContextValve.java,v 1.3 2000/10/03 21:30:36 craigmcc Exp $
- * $Revision: 1.3 $
- * $Date: 2000/10/03 21:30:36 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContextValve.java,v 1.4 2000/11/02 06:14:09 remm Exp $
+ * $Revision: 1.4 $
+ * $Date: 2000/11/02 06:14:09 $
*
* ====================================================================
*
@@ -69,6 +69,8 @@
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.naming.NamingException;
+import org.apache.naming.ContextBindings;
import org.apache.catalina.Container;
import org.apache.catalina.Request;
import org.apache.catalina.Response;
@@ -85,7 +87,7 @@
* when processing HTTP requests.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.3 $ $Date: 2000/10/03 21:30:36 $
+ * @version $Revision: 1.4 $ $Date: 2000/11/02 06:14:09 $
*/
final class StandardContextValve
@@ -162,7 +164,22 @@
// Ask this Wrapper to process this Request
response.setContext(context);
+
+ if (context.isUseNaming()) {
+ try {
+ // Bind the thread to the context
+ ContextBindings.bindThread(context.getName(), context);
+ } catch (NamingException e) {
+ e.printStackTrace();
+ }
+ }
+
wrapper.invoke(request, response);
+
+ if (context.isUseNaming()) {
+ // Unbind the thread to the context
+ ContextBindings.unbindThread(context.getName(), context);
+ }
}
1.8 +32 -6 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.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Catalina.java 2000/10/01 00:22:52 1.7
+++ Catalina.java 2000/11/02 06:14:10 1.8
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Catalina.java,v 1.7 2000/10/01 00:22:52 craigmcc Exp $
- * $Revision: 1.7 $
- * $Date: 2000/10/01 00:22:52 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Catalina.java,v 1.8 2000/11/02 06:14:10 remm Exp $
+ * $Revision: 1.8 $
+ * $Date: 2000/11/02 06:14:10 $
*
* ====================================================================
*
@@ -95,7 +95,7 @@
* </u>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.7 $ $Date: 2000/10/01 00:22:52 $
+ * @version $Revision: 1.8 $ $Date: 2000/11/02 06:14:10 $
*/
public class Catalina {
@@ -141,6 +141,12 @@
protected boolean stopping = false;
+ /**
+ * Are we using naming ?
+ */
+ protected boolean useNaming = true;
+
+
// ----------------------------------------------------------- Main Program
@@ -223,6 +229,8 @@
isConfig = true;
} else if (args[i].equals("-debug")) {
debug = true;
+ } else if (args[i].equals("-nonaming")) {
+ useNaming = false;
} else if (args[i].equals("-help")) {
usage();
return (false);
@@ -633,6 +641,22 @@
System.exit(1);
}
+ // Setting additional variables
+ if (!useNaming) {
+ System.setProperty("catalina.useNaming", "false");
+ } else {
+ System.setProperty("catalina.useNaming", "true");
+ String value = "org.apache.naming";
+ String oldValue =
+ System.getProperty(javax.naming.Context.URL_PKG_PREFIXES);
+ if (oldValue != null) {
+ value = oldValue + ":" + value;
+ }
+ System.setProperty(javax.naming.Context.URL_PKG_PREFIXES, value);
+ System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
+ "org.apache.naming.java.javaURLContextFactory");
+ }
+
// Start the new server
if (server instanceof Lifecycle) {
try {
@@ -709,8 +733,10 @@
*/
protected void usage() {
- System.out.println("usage: java org.apache.catalina.startup.Catalina" +
- " [ -config {pathname} ] [ -debug ] { start | stop }");
+ System.out.println
+ ("usage: java org.apache.catalina.startup.Catalina"
+ + " [ -config {pathname} ] [ -debug ]"
+ + " [ -nonaming ] { start | stop }");
}
1.4 +51 -4 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Embedded.java
Index: Embedded.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Embedded.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Embedded.java 2000/10/16 18:27:51 1.3
+++ Embedded.java 2000/11/02 06:14:11 1.4
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Embedded.java,v 1.3 2000/10/16 18:27:51 craigmcc Exp $
- * $Revision: 1.3 $
- * $Date: 2000/10/16 18:27:51 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Embedded.java,v 1.4 2000/11/02 06:14:11 remm Exp $
+ * $Revision: 1.4 $
+ * $Date: 2000/11/02 06:14:11 $
*
* ====================================================================
*
@@ -145,7 +145,7 @@
* </pre>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.3 $ $Date: 2000/10/16 18:27:51 $
+ * @version $Revision: 1.4 $ $Date: 2000/11/02 06:14:11 $
*/
public class Embedded implements Lifecycle {
@@ -197,6 +197,12 @@
/**
+ * Is naming enabled ?
+ */
+ protected boolean useNaming = true;
+
+
+ /**
* The set of Engines that have been deployed in this server. Normally
* there will only be one.
*/
@@ -288,6 +294,31 @@
/**
+ * Return true if naming is enabled.
+ */
+ public boolean isUseNaming() {
+
+ return (this.useNaming);
+
+ }
+
+
+ /**
+ * Enables or disables naming support.
+ *
+ * @param useNaming The new use naming value
+ */
+ public void setUseNaming(boolean useNaming) {
+
+ boolean oldUseNaming = this.useNaming;
+ this.useNaming = useNaming;
+ support.firePropertyChange("useNaming", new Boolean(oldUseNaming),
+ new Boolean(this.useNaming));
+
+ }
+
+
+ /**
* Return the Logger for this component.
*/
public Logger getLogger() {
@@ -861,6 +892,22 @@
(sm.getString("embedded.alreadyStarted"));
lifecycle.fireLifecycleEvent(START_EVENT, null);
started = true;
+
+ // Initialize some naming specific properties
+ if (!useNaming) {
+ System.setProperty("catalina.useNaming", "false");
+ } else {
+ System.setProperty("catalina.useNaming", "true");
+ String value = "org.apache.naming";
+ String oldValue =
+ System.getProperty(javax.naming.Context.URL_PKG_PREFIXES);
+ if (oldValue != null) {
+ value = oldValue + ":" + value;
+ }
+ System.setProperty(javax.naming.Context.URL_PKG_PREFIXES, value);
+ System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
+ "org.apache.naming.java.javaURLContextFactory");
+ }
// Start our defined Engines first
for (int i = 0; i < engines.length; i++) {
1.2 +20 -2 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/EmbeddedManager.java
Index: EmbeddedManager.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/EmbeddedManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- EmbeddedManager.java 2000/10/07 18:35:11 1.1
+++ EmbeddedManager.java 2000/11/02 06:14:11 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/EmbeddedManager.java,v 1.1 2000/10/07 18:35:11 remm Exp $
- * $Revision: 1.1 $
- * $Date: 2000/10/07 18:35:11 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/EmbeddedManager.java,v 1.2 2000/11/02 06:14:11 remm Exp $
+ * $Revision: 1.2 $
+ * $Date: 2000/11/02 06:14:11 $
*
* ====================================================================
*
@@ -87,7 +87,7 @@
* Implementation of the Catalina JMX MBean as a wrapper of the Catalina class.
*
* @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public final class EmbeddedManager
@@ -277,6 +277,24 @@
*/
public void setDebug(int debug) {
embedded.setDebug(debug);
+ }
+
+
+ /**
+ * Return true if naming is enabled.
+ */
+ public boolean isUseNaming() {
+ return embedded.isUseNaming();
+ }
+
+
+ /**
+ * Enables or disables naming support.
+ *
+ * @param useNaming The new use naming value
+ */
+ public void setUseNaming(boolean useNaming) {
+ embedded.setUseNaming(useNaming);
}
1.2 +16 -2 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/EmbeddedManagerMBean.java
Index: EmbeddedManagerMBean.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/EmbeddedManagerMBean.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- EmbeddedManagerMBean.java 2000/10/07 18:35:11 1.1
+++ EmbeddedManagerMBean.java 2000/11/02 06:14:11 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/EmbeddedManagerMBean.java,v 1.1 2000/10/07 18:35:11 remm Exp $
- * $Revision: 1.1 $
- * $Date: 2000/10/07 18:35:11 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/EmbeddedManagerMBean.java,v 1.2 2000/11/02 06:14:11 remm Exp $
+ * $Revision: 1.2 $
+ * $Date: 2000/11/02 06:14:11 $
*
* ====================================================================
*
@@ -82,7 +82,7 @@
* Embedded MBean interface.
*
* @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public interface EmbeddedManagerMBean {
@@ -149,6 +149,20 @@
* @param debug The new debugging detail level
*/
public void setDebug(int debug);
+
+
+ /**
+ * Return true if naming is enabled.
+ */
+ public boolean isUseNaming();
+
+
+ /**
+ * Enables or disables naming support.
+ *
+ * @param useNaming The new use naming value
+ */
+ public void setUseNaming(boolean useNaming);
/**
1.1 jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/Constants.java
Index: Constants.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/Constants.java,v 1.1 2000/11/02 06:14:15 remm Exp $
* $Revision: 1.1 $
* $Date: 2000/11/02 06:14:15 $
*
* ====================================================================
*
* 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.naming;
/**
* Static constants for this package.
*/
public final class Constants {
public static final String Package = "org.apache.naming";
}
1.1 jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/ContextAccessController.java
Index: ContextAccessController.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/ContextAccessController.java,v 1.1 2000/11/02 06:14:16 remm Exp $
* $Revision: 1.1 $
* $Date: 2000/11/02 06:14:16 $
*
* ====================================================================
*
* 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.naming;
import java.util.Hashtable;
import javax.naming.NamingException;
/**
* Handles the access control on the JNDI contexts.
*
* @author Remy Maucherat
* @version $Revision: 1.1 $ $Date: 2000/11/02 06:14:16 $
*/
public class ContextAccessController {
// -------------------------------------------------------------- Variables
/**
* Catalina context names on which writing is not allowed.
*/
private static Hashtable readOnlyContexts = new Hashtable();
/**
* Security tokens repository.
*/
private static Hashtable securityTokens = new Hashtable();
// --------------------------------------------------------- Public Methods
/**
* Set a security token for a context. Can be set only once.
*
* @param name Name of the context
* @param context Security token
*/
public static void setSecurityToken(String name, Object token) {
if ((!securityTokens.containsKey(name)) && (token != null)) {
securityTokens.put(name, token);
}
}
/**
* Check a submitted security token. The submitted token must be equal to
* the token present in the repository. If no token is present for the
* context, then returns true.
*
* @param name Name of the context
* @param context Submitted security token
*/
public static boolean checkSecurityToken
(String name, Object token) {
Object refToken = securityTokens.get(name);
if (refToken == null)
return (true);
if ((refToken != null) && (refToken.equals(token)))
return (true);
return (false);
}
/**
* Allow writing to a context.
*
* @param name Name of the context
* @param token Security token
*/
public static void setWritable(String name, Object token) {
if (checkSecurityToken(name, token))
readOnlyContexts.remove(name);
}
/**
* Set whether or not a context is writable.
*
* @param name Name of the context
*/
public static void setReadOnly(String name) {
readOnlyContexts.put(name, name);
}
/**
* Returns if a context is writable.
*
* @param name Name of the context
*/
public static boolean isWritable(String name) {
return !(readOnlyContexts.containsKey(name));
}
}
1.1 jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/ContextBindings.java
Index: ContextBindings.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/ContextBindings.java,v 1.1 2000/11/02 06:14:16 remm Exp $
* $Revision: 1.1 $
* $Date: 2000/11/02 06:14:16 $
*
* ====================================================================
*
* 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.naming;
import java.util.Hashtable;
import javax.naming.NamingException;
import javax.naming.Context;
/**
* Handles the associations :
* <ul>
* <li>Catalina context name with the NamingContext</li>
* <li>Calling thread with the NamingContext</li>
* </ul>
*
* @author Remy Maucherat
* @version $Revision: 1.1 $ $Date: 2000/11/02 06:14:16 $
*/
public class ContextBindings {
// -------------------------------------------------------------- Variables
/**
* Bindings Catalina context name - naming context. Keyed by context name.
*/
private static Hashtable contextNameBindings = new Hashtable();
/**
* Bindings thread - naming context. Keyed by thread id.
*/
private static Hashtable threadBindings = new Hashtable();
/**
* Bindings thread - name. Keyed by thread id.
*/
private static Hashtable threadNameBindings = new Hashtable();
/**
* The string manager for this package.
*/
protected static StringManager sm =
StringManager.getManager(Constants.Package);
// --------------------------------------------------------- Public Methods
/**
* Binds a context name.
*
* @param name Name of the context
* @param context Associated naming context instance
*/
public static void bindContext(String name, Context context) {
bindContext(name, context, null);
}
/**
* Binds a context name.
*
* @param name Name of the context
* @param context Associated naming context instance
* @param token Security token
*/
public static void bindContext(String name, Context context,
Object token) {
if (ContextAccessController.checkSecurityToken(name, token))
contextNameBindings.put(name, context);
}
/**
* Unbind context name.
*
* @param name Name of the context
*/
public static void unbindContext(String name) {
unbindContext(name, null);
}
/**
* Unbind context name.
*
* @param name Name of the context
* @param token Security token
*/
public static void unbindContext(String name, Object token) {
if (ContextAccessController.checkSecurityToken(name, token))
contextNameBindings.remove(name);
}
/**
* Retrieve a naming context.
*
* @param name Name of the context
*/
public static Context getContext(String name) {
return (Context) contextNameBindings.get(name);
}
/**
* Binds a naming context to a thread.
*
* @param name Name of the context
* @param token Security token
*/
public static void bindThread(String name)
throws NamingException {
bindThread(name, null);
}
/**
* Binds a naming context to a thread.
*
* @param name Name of the context
*/
public static void bindThread(String name, Object token)
throws NamingException {
if (ContextAccessController.checkSecurityToken(name, token)) {
Context context = (Context) contextNameBindings.get(name);
if (context == null)
throw new NamingException
(sm.getString("contextBindings.unknownContext",
name));
threadBindings.put(Thread.currentThread(), context);
threadNameBindings.put(Thread.currentThread(), name);
}
}
/**
* Unbinds a naming context to a thread.
*
* @param name Name of the context
*/
public static void unbindThread(String name) {
unbindThread(null);
}
/**
* Unbinds a naming context to a thread.
*
* @param name Name of the context
* @param token Security token
*/
public static void unbindThread(String name, Object token) {
if (ContextAccessController.checkSecurityToken(name, token)) {
threadBindings.remove(Thread.currentThread());
threadNameBindings.remove(Thread.currentThread());
}
}
/**
* Retrieves the naming context bound to a thread.
*/
public static Context getThread()
throws NamingException {
Context context =
(Context) threadBindings.get(Thread.currentThread());
if (context == null)
throw new NamingException
(sm.getString("contextBindings.noContextBoundToThread"));
return context;
}
/**
* Retrieves the naming context name bound to a thread.
*/
public static String getThreadName()
throws NamingException {
String name =
(String) threadNameBindings.get(Thread.currentThread());
if (name == null)
throw new NamingException
(sm.getString("contextBindings.noContextBoundToThread"));
return name;
}
/**
* Tests if current thread is bound to a context.
*/
public static boolean isThreadBound() {
return (threadBindings.containsKey(Thread.currentThread()));
}
}
1.1 jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/EjbRefAddr.java
Index: EjbRefAddr.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/EjbRefAddr.java,v 1.1 2000/11/02 06:14:16 remm Exp $
* $Revision: 1.1 $
* $Date: 2000/11/02 06:14:16 $
*
* ====================================================================
*
* 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.naming;
import javax.naming.RefAddr;
/**
* Represents a reference address to an EJB.
*
* @author Remy Maucherat
* @version $Revision: 1.1 $ $Date: 2000/11/02 06:14:16 $
*/
public class EjbRefAddr
extends RefAddr {
// -------------------------------------------------------------- Constants
/**
* Ref address type.
*/
public static final String TYPE = "ejb-ref";
// ----------------------------------------------------------- Constructors
/**
* EJB Reference.
*
* @param ejbType EJB type
* @param home Home interface classname
* @param remote Remote interface classname
* @param link EJB link
* @param runAs Run As
*/
public EjbRefAddr(String ejbType, String home, String remote, String link,
String runAs) {
super(TYPE);
this.ejbType = ejbType;
this.home = home;
this.remote = remote;
this.link = link;
this.runAs = runAs;
}
// ----------------------------------------------------- Instance Variables
/**
* EJB type.
*/
protected String ejbType;
/**
* Home interface.
*/
protected String home;
/**
* Remote interface.
*/
protected String remote;
/**
* Link.
*/
protected String link;
/**
* Run as.
*/
protected String runAs;
// -------------------------------------------------------- RefAddr Methods
/**
* Returns the contents of the address.
*/
public Object getContent() {
return this;
}
// ------------------------------------------------------------- Properties
/**
* EJB type accessor.
*/
public String getEjbType() {
return (this.ejbType);
}
/**
* Home accessor.
*/
public String getHome() {
return (this.home);
}
/**
* Remote accessor.
*/
public String getRemote() {
return (this.remote);
}
/**
* Link accessor.
*/
public String getLink() {
return (this.link);
}
/**
* RunAs accessor.
*/
public String getRunAs() {
return (this.runAs);
}
}
1.1 jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/LocalStrings.properties
Index: LocalStrings.properties
===================================================================
contextBindings.unknownContext=Unknown context name : {0}
contextBindings.noContextBoundToThread=No naming context bound to this thread
selectorContext.noJavaUrl=This context must be accessed throught a java: URL
namingContext.contextExpected=Name is not bound to a Context
namingContext.nameNotBound=Name {0} is not bound in this Context
namingContext.readOnly=Context is read only
namingContext.invalidName=Name is not valid
namingContext.alreadyBound=Name {0} is already bound in this Context
namingContext.noAbsoluteName=Can't generate an absolute name for this namespace
1.1 jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/NameParserImpl.java
Index: NameParserImpl.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/NameParserImpl.java,v 1.1 2000/11/02 06:14:16 remm Exp $
* $Revision: 1.1 $
* $Date: 2000/11/02 06:14:16 $
*
* ====================================================================
*
* 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.naming;
import javax.naming.NameParser;
import javax.naming.Name;
import javax.naming.NamingException;
import javax.naming.CompositeName;
/**
* Parses names.
*
* @author Remy Maucherat
* @version $Revision: 1.1 $ $Date: 2000/11/02 06:14:16 $
*/
public class NameParserImpl
implements NameParser {
// ----------------------------------------------------- Instance Variables
// ----------------------------------------------------- NameParser Methods
/**
* Parses a name into its components.
*
* @param name The non-null string name to parse
* @return A non-null parsed form of the name using the naming convention
* of this parser.
*/
public Name parse(String name)
throws NamingException {
return new CompositeName(name);
}
}
1.1 jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/NamingContext.java
Index: NamingContext.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/NamingContext.java,v 1.1 2000/11/02 06:14:16 remm Exp $
* $Revision: 1.1 $
* $Date: 2000/11/02 06:14:16 $
*
* ====================================================================
*
* 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.naming;
import java.util.Hashtable;
import java.util.Enumeration;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.LinkRef;
import javax.naming.CompositeName;
import javax.naming.NameParser;
import javax.naming.Referenceable;
import javax.naming.Reference;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.NameNotFoundException;
import javax.naming.NotContextException;
import javax.naming.InitialContext;
import javax.naming.OperationNotSupportedException;
import javax.naming.spi.NamingManager;
/**
* Catalina JNDI Context implementation.
*
* @author Remy Maucherat
* @version $Revision: 1.1 $ $Date: 2000/11/02 06:14:16 $
*/
public class NamingContext implements Context {
// -------------------------------------------------------------- Constants
/**
* Name parser for this context.
*/
protected static final NameParser nameParser = new NameParserImpl();
// ----------------------------------------------------------- Constructors
/**
* Builds a naming context using the given environment.
*/
public NamingContext(Hashtable env, String name)
throws NamingException {
this.bindings = new Hashtable();
// FIXME ? Could be put in the environment ?
this.name = name;
// Populating the environment hashtable
if (env != null ) {
Enumeration envEntries = env.keys();
while (envEntries.hasMoreElements()) {
String entryName = (String) envEntries.nextElement();
addToEnvironment(entryName, env.get(entryName));
}
}
}
/**
* Builds a naming context using the given environment.
*/
public NamingContext(Hashtable env, String name, Hashtable bindings)
throws NamingException {
this(env, name);
this.bindings = bindings;
}
// ----------------------------------------------------- Instance Variables
/**
* Environment.
*/
protected Hashtable env;
/**
* The string manager for this package.
*/
protected StringManager sm = StringManager.getManager(Constants.Package);
/**
* Bindings in this Context.
*/
protected Hashtable bindings;
/**
* Name of the associated Catalina Context.
*/
protected String name;
// --------------------------------------------------------- Public Methods
// -------------------------------------------------------- Context Methods
/**
* Retrieves the named object. If name is empty, returns a new instance
* of this context (which represents the same naming context as this
* context, but its environment may be modified independently and it may
* be accessed concurrently).
*
* @param name the name of the object to look up
* @return the object bound to name
* @exception NamingException if a naming exception is encountered
*/
public Object lookup(Name name)
throws NamingException {
return lookup(name, true);
}
/**
* Retrieves the named object.
*
* @param name the name of the object to look up
* @return the object bound to name
* @exception NamingException if a naming exception is encountered
*/
public Object lookup(String name)
throws NamingException {
return lookup(new CompositeName(name), true);
}
/**
* Binds a name to an object. All intermediate contexts and the target
* context (that named by all but terminal atomic component of the name)
* must already exist.
*
* @param name the name to bind; may not be empty
* @param obj the object to bind; possibly null
* @exception NameAlreadyBoundException if name is already bound
* @exception InvalidAttributesException if object did not supply all
* mandatory attributes
* @exception NamingException if a naming exception is encountered
*/
public void bind(Name name, Object obj)
throws NamingException {
bind(name, obj, false);
}
/**
* Binds a name to an object.
*
* @param name the name to bind; may not be empty
* @param obj the object to bind; possibly null
* @exception NameAlreadyBoundException if name is already bound
* @exception InvalidAttributesException if object did not supply all
* mandatory attributes
* @exception NamingException if a naming exception is encountered
*/
public void bind(String name, Object obj)
throws NamingException {
bind(new CompositeName(name), obj);
}
/**
* Binds a name to an object, overwriting any existing binding. All
* intermediate contexts and the target context (that named by all but
* terminal atomic component of the name) must already exist.
* <p>
* If the object is a DirContext, any existing attributes associated with
* the name are replaced with those of the object. Otherwise, any
* existing attributes associated with the name remain unchanged.
*
* @param name the name to bind; may not be empty
* @param obj the object to bind; possibly null
* @exception InvalidAttributesException if object did not supply all
* mandatory attributes
* @exception NamingException if a naming exception is encountered
*/
public void rebind(Name name, Object obj)
throws NamingException {
bind(name, obj, true);
}
/**
* Binds a name to an object, overwriting any existing binding.
*
* @param name the name to bind; may not be empty
* @param obj the object to bind; possibly null
* @exception InvalidAttributesException if object did not supply all
* mandatory attributes
* @exception NamingException if a naming exception is encountered
*/
public void rebind(String name, Object obj)
throws NamingException {
rebind(new CompositeName(name), obj);
}
/**
* Unbinds the named object. Removes the terminal atomic name in name
* from the target context--that named by all but the terminal atomic
* part of name.
* <p>
* This method is idempotent. It succeeds even if the terminal atomic
* name is not bound in the target context, but throws
* NameNotFoundException if any of the intermediate contexts do not exist.
*
* @param name the name to bind; may not be empty
* @exception NameNotFoundException if an intermediate context does not
* exist
* @exception NamingException if a naming exception is encountered
*/
public void unbind(Name name)
throws NamingException {
checkWritable();
while ((!name.isEmpty()) && (name.get(0).length() == 0))
name = name.getSuffix(1);
if (name.isEmpty())
throw new NamingException
(sm.getString("namingContext.invalidName"));
NamingEntry entry = (NamingEntry) bindings.get(name.get(0));
if (entry == null) {
throw new NameNotFoundException
(sm.getString("namingContext.nameNotBound", name.get(0)));
}
if (name.size() > 1) {
if (entry.type == NamingEntry.CONTEXT) {
((Context) entry.value).unbind(name.getSuffix(1));
} else {
throw new NamingException
(sm.getString("namingContext.contextExpected"));
}
} else {
bindings.remove(name.get(0));
}
}
/**
* Unbinds the named object.
*
* @param name the name to bind; may not be empty
* @exception NameNotFoundException if an intermediate context does not
* exist
* @exception NamingException if a naming exception is encountered
*/
public void unbind(String name)
throws NamingException {
unbind(new CompositeName(name));
}
/**
* Binds a new name to the object bound to an old name, and unbinds the
* old name. Both names are relative to this context. Any attributes
* associated with the old name become associated with the new name.
* Intermediate contexts of the old name are not changed.
*
* @param oldName the name of the existing binding; may not be empty
* @param newName the name of the new binding; may not be empty
* @exception NameAlreadyBoundException if newName is already bound
* @exception NamingException if a naming exception is encountered
*/
public void rename(Name oldName, Name newName)
throws NamingException {
Object value = lookup(oldName);
bind(newName, value);
unbind(oldName);
}
/**
* Binds a new name to the object bound to an old name, and unbinds the
* old name.
*
* @param oldName the name of the existing binding; may not be empty
* @param newName the name of the new binding; may not be empty
* @exception NameAlreadyBoundException if newName is already bound
* @exception NamingException if a naming exception is encountered
*/
public void rename(String oldName, String newName)
throws NamingException {
rename(new CompositeName(oldName), new CompositeName(newName));
}
/**
* Enumerates the names bound in the named context, along with the class
* names of objects bound to them. The contents of any subcontexts are
* not included.
* <p>
* If a binding is added to or removed from this context, its effect on
* an enumeration previously returned is undefined.
*
* @param name the name of the context to list
* @return an enumeration of the names and class names of the bindings in
* this context. Each element of the enumeration is of type NameClassPair.
* @exception NamingException if a naming exception is encountered
*/
public NamingEnumeration list(Name name)
throws NamingException {
// Removing empty parts
while ((!name.isEmpty()) && (name.get(0).length() == 0))
name = name.getSuffix(1);
if (name.isEmpty()) {
return new NamingContextEnumeration(bindings.elements());
}
NamingEntry entry = (NamingEntry) bindings.get(name.get(0));
if (entry == null) {
throw new NameNotFoundException
(sm.getString("namingContext.nameNotBound", name.get(0)));
}
if (entry.type != NamingEntry.CONTEXT) {
throw new NamingException
(sm.getString("namingContext.contextExpected"));
}
return ((Context) entry.value).list(name.getSuffix(1));
}
/**
* Enumerates the names bound in the named context, along with the class
* names of objects bound to them.
*
* @param name the name of the context to list
* @return an enumeration of the names and class names of the bindings in
* this context. Each element of the enumeration is of type NameClassPair.
* @exception NamingException if a naming exception is encountered
*/
public NamingEnumeration list(String name)
throws NamingException {
return list(new CompositeName(name));
}
/**
* Enumerates the names bound in the named context, along with the
* objects bound to them. The contents of any subcontexts are not
* included.
* <p>
* If a binding is added to or removed from this context, its effect on
* an enumeration previously returned is undefined.
*
* @param name the name of the context to list
* @return an enumeration of the bindings in this context.
* Each element of the enumeration is of type Binding.
* @exception NamingException if a naming exception is encountered
*/
public NamingEnumeration listBindings(Name name)
throws NamingException {
// Removing empty parts
while ((!name.isEmpty()) && (name.get(0).length() == 0))
name = name.getSuffix(1);
if (name.isEmpty()) {
return new NamingContextBindingsEnumeration(bindings.elements());
}
NamingEntry entry = (NamingEntry) bindings.get(name.get(0));
if (entry == null) {
throw new NameNotFoundException
(sm.getString("namingContext.nameNotBound", name.get(0)));
}
if (entry.type != NamingEntry.CONTEXT) {
throw new NamingException
(sm.getString("namingContext.contextExpected"));
}
return ((Context) entry.value).listBindings(name.getSuffix(1));
}
/**
* Enumerates the names bound in the named context, along with the
* objects bound to them.
*
* @param name the name of the context to list
* @return an enumeration of the bindings in this context.
* Each element of the enumeration is of type Binding.
* @exception NamingException if a naming exception is encountered
*/
public NamingEnumeration listBindings(String name)
throws NamingException {
return listBindings(new CompositeName(name));
}
/**
* Destroys the named context and removes it from the namespace. Any
* attributes associated with the name are also removed. Intermediate
* contexts are not destroyed.
* <p>
* This method is idempotent. It succeeds even if the terminal atomic
* name is not bound in the target context, but throws
* NameNotFoundException if any of the intermediate contexts do not exist.
*
* In a federated naming system, a context from one naming system may be
* bound to a name in another. One can subsequently look up and perform
* operations on the foreign context using a composite name. However, an
* attempt destroy the context using this composite name will fail with
* NotContextException, because the foreign context is not a "subcontext"
* of the context in which it is bound. Instead, use unbind() to remove
* the binding of the foreign context. Destroying the foreign context
* requires that the destroySubcontext() be performed on a context from
* the foreign context's "native" naming system.
*
* @param name the name of the context to be destroyed; may not be empty
* @exception NameNotFoundException if an intermediate context does not
* exist
* @exception NotContextException if the name is bound but does not name
* a context, or does not name a context of the appropriate type
*/
public void destroySubcontext(Name name)
throws NamingException {
checkWritable();
while ((!name.isEmpty()) && (name.get(0).length() == 0))
name = name.getSuffix(1);
if (name.isEmpty())
throw new NamingException
(sm.getString("namingContext.invalidName"));
NamingEntry entry = (NamingEntry) bindings.get(name.get(0));
if (entry == null) {
throw new NameNotFoundException
(sm.getString("namingContext.nameNotBound", name.get(0)));
}
if (name.size() > 1) {
if (entry.type == NamingEntry.CONTEXT) {
((Context) entry.value).unbind(name.getSuffix(1));
} else {
throw new NamingException
(sm.getString("namingContext.contextExpected"));
}
} else {
if (entry.type == NamingEntry.CONTEXT) {
((Context) entry.value).close();
bindings.remove(name.get(0));
} else {
throw new NotContextException
(sm.getString("namingContext.contextExpected"));
}
}
}
/**
* Destroys the named context and removes it from the namespace.
*
* @param name the name of the context to be destroyed; may not be empty
* @exception NameNotFoundException if an intermediate context does not
* exist
* @exception NotContextException if the name is bound but does not name
* a context, or does not name a context of the appropriate type
*/
public void destroySubcontext(String name)
throws NamingException {
destroySubcontext(name);
}
/**
* Creates and binds a new context. Creates a new context with the given
* name and binds it in the target context (that named by all but
* terminal atomic component of the name). All intermediate contexts and
* the target context must already exist.
*
* @param name the name of the context to create; may not be empty
* @return the newly created context
* @exception NameAlreadyBoundException if name is already bound
* @exception InvalidAttributesException if creation of the subcontext
* requires specification of mandatory attributes
* @exception NamingException if a naming exception is encountered
*/
public Context createSubcontext(Name name)
throws NamingException {
checkWritable();
Context newContext = new NamingContext(env, this.name);
bind(name, newContext);
return newContext;
}
/**
* Creates and binds a new context.
*
* @param name the name of the context to create; may not be empty
* @return the newly created context
* @exception NameAlreadyBoundException if name is already bound
* @exception InvalidAttributesException if creation of the subcontext
* requires specification of mandatory attributes
* @exception NamingException if a naming exception is encountered
*/
public Context createSubcontext(String name)
throws NamingException {
return createSubcontext(new CompositeName(name));
}
/**
* Retrieves the named object, following links except for the terminal
* atomic component of the name. If the object bound to name is not a
* link, returns the object itself.
*
* @param name the name of the object to look up
* @return the object bound to name, not following the terminal link
* (if any).
* @exception NamingException if a naming exception is encountered
*/
public Object lookupLink(Name name)
throws NamingException {
return lookup(name, false);
}
/**
* Retrieves the named object, following links except for the terminal
* atomic component of the name.
*
* @param name the name of the object to look up
* @return the object bound to name, not following the terminal link
* (if any).
* @exception NamingException if a naming exception is encountered
*/
public Object lookupLink(String name)
throws NamingException {
return lookup(new CompositeName(name), false);
}
/**
* Retrieves the parser associated with the named context. In a
* federation of namespaces, different naming systems will parse names
* differently. This method allows an application to get a parser for
* parsing names into their atomic components using the naming convention
* of a particular naming system. Within any single naming system,
* NameParser objects returned by this method must be equal (using the
* equals() test).
*
* @param name the name of the context from which to get the parser
* @return a name parser that can parse compound names into their atomic
* components
* @exception NamingException if a naming exception is encountered
*/
public NameParser getNameParser(Name name)
throws NamingException {
while ((!name.isEmpty()) && (name.get(0).length() == 0))
name = name.getSuffix(1);
if (name.isEmpty())
return nameParser;
if (name.size() > 1) {
Object obj = bindings.get(name.get(0));
if (obj instanceof Context) {
return ((Context) obj).getNameParser(name.getSuffix(1));
} else {
throw new NotContextException
(sm.getString("namingContext.contextExpected"));
}
}
return nameParser;
}
/**
* Retrieves the parser associated with the named context.
*
* @param name the name of the context from which to get the parser
* @return a name parser that can parse compound names into their atomic
* components
* @exception NamingException if a naming exception is encountered
*/
public NameParser getNameParser(String name)
throws NamingException {
return getNameParser(new CompositeName(name));
}
/**
* Composes the name of this context with a name relative to this context.
* <p>
* Given a name (name) relative to this context, and the name (prefix)
* of this context relative to one of its ancestors, this method returns
* the composition of the two names using the syntax appropriate for the
* naming system(s) involved. That is, if name names an object relative
* to this context, the result is the name of the same object, but
* relative to the ancestor context. None of the names may be null.
*
* @param name a name relative to this context
* @param prefix the name of this context relative to one of its ancestors
* @return the composition of prefix and name
* @exception NamingException if a naming exception is encountered
*/
public Name composeName(Name name, Name prefix)
throws NamingException {
prefix = (Name) name.clone();
return prefix.addAll(name);
}
/**
* Composes the name of this context with a name relative to this context.
*
* @param name a name relative to this context
* @param prefix the name of this context relative to one of its ancestors
* @return the composition of prefix and name
* @exception NamingException if a naming exception is encountered
*/
public String composeName(String name, String prefix)
throws NamingException {
return prefix + "/" + name;
}
/**
* Adds a new environment property to the environment of this context. If
* the property already exists, its value is overwritten.
*
* @param propName the name of the environment property to add; may not
* be null
* @param propVal the value of the property to add; may not be null
* @exception NamingException if a naming exception is encountered
*/
public Object addToEnvironment(String propName, Object propVal)
throws NamingException {
return env.put(propName, propVal);
}
/**
* Removes an environment property from the environment of this context.
*
* @param propName the name of the environment property to remove;
* may not be null
* @exception NamingException if a naming exception is encountered
*/
public Object removeFromEnvironment(String propName)
throws NamingException {
return env.remove(propName);
}
/**
* Retrieves the environment in effect for this context. See class
* description for more details on environment properties.
* The caller should not make any changes to the object returned: their
* effect on the context is undefined. The environment of this context
* may be changed using addToEnvironment() and removeFromEnvironment().
*
* @return the environment of this context; never null
* @exception NamingException if a naming exception is encountered
*/
public Hashtable getEnvironment()
throws NamingException {
return env;
}
/**
* Closes this context. This method releases this context's resources
* immediately, instead of waiting for them to be released automatically
* by the garbage collector.
* This method is idempotent: invoking it on a context that has already
* been closed has no effect. Invoking any other method on a closed
* context is not allowed, and results in undefined behaviour.
*
* @exception NamingException if a naming exception is encountered
*/
public void close()
throws NamingException {
env.clear();
}
/**
* Retrieves the full name of this context within its own namespace.
* <p>
* Many naming services have a notion of a "full name" for objects in
* their respective namespaces. For example, an LDAP entry has a
* distinguished name, and a DNS record has a fully qualified name. This
* method allows the client application to retrieve this name. The string
* returned by this method is not a JNDI composite name and should not be
* passed directly to context methods. In naming systems for which the
* notion of full name does not make sense,
* OperationNotSupportedException is thrown.
*
* @return this context's name in its own namespace; never null
* @exception OperationNotSupportedException if the naming system does
* not have the notion of a full name
* @exception NamingException if a naming exception is encountered
*/
public String getNameInNamespace()
throws NamingException {
throw new OperationNotSupportedException
(sm.getString("namingContext.noAbsoluteName"));
//FIXME ?
}
// ------------------------------------------------------ Protected Methods
/**
* Retrieves the named object.
*
* @param name the name of the object to look up
* @param resolveLinks If true, the links will be resolved
* @return the object bound to name
* @exception NamingException if a naming exception is encountered
*/
protected Object lookup(Name name, boolean resolveLinks)
throws NamingException {
// Removing empty parts
while ((!name.isEmpty()) && (name.get(0).length() == 0))
name = name.getSuffix(1);
if (name.isEmpty()) {
// If name is empty, a newly allocated naming context is returned
return new NamingContext(env, this.name, bindings);
}
NamingEntry entry = (NamingEntry) bindings.get(name.get(0));
if (entry == null) {
throw new NameNotFoundException
(sm.getString("namingContext.nameNotBound", name.get(0)));
}
if (name.size() > 1) {
// If the size of the name is greater that 1, then we go through a
// number of subcontexts.
if (entry.type != NamingEntry.CONTEXT) {
throw new NamingException
(sm.getString("namingContext.contextExpected"));
}
return ((Context) entry.value).lookup(name.getSuffix(1));
} else {
if ((resolveLinks) && (entry.type == NamingEntry.LINK_REF)) {
String link = ((LinkRef) entry.value).getLinkName();
if (link.startsWith(".")) {
// Link relative to this context
return lookup(link.substring(1));
} else {
return (new InitialContext(env)).lookup(link);
}
} else if (entry.type == NamingEntry.REFERENCE) {
try {
return NamingManager.getObjectInstance
(entry.value, name, this, env);
} catch (Exception e) {
throw new NamingException(e.getMessage());
}
} else {
return entry.value;
}
}
}
/**
* Binds a name to an object. All intermediate contexts and the target
* context (that named by all but terminal atomic component of the name)
* must already exist.
*
* @param name the name to bind; may not be empty
* @param obj the object to bind; possibly null
* @param rebind if true, then perform a rebind (ie, overwrite)
* @exception NameAlreadyBoundException if name is already bound
* @exception InvalidAttributesException if object did not supply all
* mandatory attributes
* @exception NamingException if a naming exception is encountered
*/
protected void bind(Name name, Object obj, boolean rebind)
throws NamingException {
checkWritable();
while ((!name.isEmpty()) && (name.get(0).length() == 0))
name = name.getSuffix(1);
if (name.isEmpty())
throw new NamingException
(sm.getString("namingContext.invalidName"));
NamingEntry entry = (NamingEntry) bindings.get(name.get(0));
if (name.size() > 1) {
if (entry == null) {
throw new NameNotFoundException
(sm.getString("namingContext.nameNotBound", name.get(0)));
}
if (entry.type == NamingEntry.CONTEXT) {
if (rebind) {
((Context) entry.value).rebind(name.getSuffix(1), obj);
} else {
((Context) entry.value).bind(name.getSuffix(1), obj);
}
} else {
throw new NamingException
(sm.getString("namingContext.contextExpected"));
}
} else {
if ((!rebind) && (entry != null)) {
throw new NamingException
(sm.getString("namingContext.alreadyBound"));
} else {
// Getting the type of the object and wrapping it within a new
// NamingEntry
if (obj instanceof Context) {
entry = new NamingEntry(name.get(0), obj,
NamingEntry.CONTEXT);
} else if (obj instanceof LinkRef) {
entry = new NamingEntry(name.get(0), obj,
NamingEntry.LINK_REF);
} else if (obj instanceof Reference) {
entry = new NamingEntry(name.get(0), obj,
NamingEntry.REFERENCE);
} else if (obj instanceof Referenceable) {
obj = ((Referenceable) obj).getReference();
entry = new NamingEntry(name.get(0), obj,
NamingEntry.REFERENCE);
} else {
entry = new NamingEntry(name.get(0), obj,
NamingEntry.ENTRY);
}
bindings.put(name.get(0), entry);
}
}
}
/**
* Returns true if writing is allowed on this context.
*/
protected boolean isWritable() {
return ContextAccessController.isWritable(name);
}
/**
* Throws a naming exception is Context is not writable.
*/
protected void checkWritable()
throws NamingException {
if (!isWritable())
throw new NamingException(sm.getString("namingContext.readOnly"));
}
}
1.1 jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/NamingContextBindingsEnumeration.java
Index: NamingContextBindingsEnumeration.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/NamingContextBindingsEnumeration.java,v 1.1 2000/11/02 06:14:16 remm Exp $
* $Revision: 1.1 $
* $Date: 2000/11/02 06:14:16 $
*
* ====================================================================
*
* 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.naming;
import java.util.Hashtable;
import java.util.Vector;
import java.util.Enumeration;
import javax.naming.NamingException;
import javax.naming.NamingEnumeration;
import javax.naming.Binding;
/**
* Naming enumeration implementation.
*
* @author Remy Maucherat
* @version $Revision: 1.1 $ $Date: 2000/11/02 06:14:16 $
*/
public class NamingContextBindingsEnumeration
implements NamingEnumeration {
// ----------------------------------------------------------- Constructors
public NamingContextBindingsEnumeration(Vector entries) {
enum = entries.elements();
}
public NamingContextBindingsEnumeration(Enumeration enum) {
this.enum = enum;
}
// -------------------------------------------------------------- Variables
/**
* Underlying enumeration.
*/
protected Enumeration enum;
// --------------------------------------------------------- Public Methods
/**
* Retrieves the next element in the enumeration.
*/
public Object next()
throws NamingException {
return nextElement();
}
/**
* Determines whether there are any more elements in the enumeration.
*/
public boolean hasMore()
throws NamingException {
return enum.hasMoreElements();
}
/**
* Closes this enumeration.
*/
public void close()
throws NamingException {
}
public boolean hasMoreElements() {
return enum.hasMoreElements();
}
public Object nextElement() {
NamingEntry entry = (NamingEntry) enum.nextElement();
return new Binding(entry.name, entry.value.getClass().getName(),
entry.value, true);
}
}
1.1 jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/NamingContextEnumeration.java
Index: NamingContextEnumeration.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/NamingContextEnumeration.java,v 1.1 2000/11/02 06:14:16 remm Exp $
* $Revision: 1.1 $
* $Date: 2000/11/02 06:14:16 $
*
* ====================================================================
*
* 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.naming;
import java.util.Hashtable;
import java.util.Vector;
import java.util.Enumeration;
import javax.naming.NamingException;
import javax.naming.NamingEnumeration;
import javax.naming.NameClassPair;
/**
* Naming enumeration implementation.
*
* @author Remy Maucherat
* @version $Revision: 1.1 $ $Date: 2000/11/02 06:14:16 $
*/
public class NamingContextEnumeration
implements NamingEnumeration {
// ----------------------------------------------------------- Constructors
public NamingContextEnumeration(Vector entries) {
enum = entries.elements();
}
public NamingContextEnumeration(Enumeration enum) {
this.enum = enum;
}
// -------------------------------------------------------------- Variables
/**
* Underlying enumeration.
*/
protected Enumeration enum;
// --------------------------------------------------------- Public Methods
/**
* Retrieves the next element in the enumeration.
*/
public Object next()
throws NamingException {
return nextElement();
}
/**
* Determines whether there are any more elements in the enumeration.
*/
public boolean hasMore()
throws NamingException {
return enum.hasMoreElements();
}
/**
* Closes this enumeration.
*/
public void close()
throws NamingException {
}
public boolean hasMoreElements() {
return enum.hasMoreElements();
}
public Object nextElement() {
NamingEntry entry = (NamingEntry) enum.nextElement();
return new NameClassPair(entry.name, entry.value.getClass().getName());
}
}
1.1 jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/NamingEntry.java
Index: NamingEntry.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/NamingEntry.java,v 1.1 2000/11/02 06:14:16 remm Exp $
* $Revision: 1.1 $
* $Date: 2000/11/02 06:14:16 $
*
* ====================================================================
*
* 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.naming;
/**
* Represents a binding in a NamingContext.
*
* @author Remy Maucherat
* @version $Revision: 1.1 $ $Date: 2000/11/02 06:14:16 $
*/
public class NamingEntry {
// -------------------------------------------------------------- Constants
public static final int ENTRY = 0;
public static final int LINK_REF = 1;
public static final int REFERENCE = 2;
public static final int CONTEXT = 10;
// ----------------------------------------------------------- Constructors
public NamingEntry(String name, Object value, int type) {
this.name = name;
this.value = value;
this.type = type;
}
// ----------------------------------------------------- Instance Variables
/**
* The type instance variable is used to avoid unsing RTTI when doing
* lookups.
*/
public int type;
public String name;
public Object value;
// --------------------------------------------------------- Object Methods
public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof NamingEntry)) {
return name.equals(((NamingEntry) obj).name);
} else {
return false;
}
}
public int hashCode() {
return name.hashCode();
}
}
1.1 jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/NamingService.java
Index: NamingService.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/NamingService.java,v 1.1 2000/11/02 06:14:16 remm Exp $
* $Revision: 1.1 $
* $Date: 2000/11/02 06:14:16 $
*
* ====================================================================
*
* 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.naming;
import javax.naming.Context;
import javax.management.NotificationBroadcasterSupport;
import javax.management.ObjectName;
import javax.management.MBeanServer;
import javax.management.MBeanRegistration;
import javax.management.AttributeChangeNotification;
import javax.management.Notification;
/**
* Implementation of the NamingService JMX MBean.
*
* @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
* @version $Revision: 1.1 $
*/
public final class NamingService
extends NotificationBroadcasterSupport
implements NamingServiceMBean, MBeanRegistration {
// ----------------------------------------------------- Instance Variables
/**
* Status of the Slide domain.
*/
private int state = STOPPED;
/**
* Notification sequence number.
*/
private long sequenceNumber = 0;
/**
* Old URL packages value.
*/
private String oldUrlValue = "";
/**
* Old initial context value.
*/
private String oldIcValue = "";
// ---------------------------------------------- MBeanRegistration Methods
public ObjectName preRegister(MBeanServer server, ObjectName name)
throws Exception {
return new ObjectName(OBJECT_NAME);
}
public void postRegister(Boolean registrationDone) {
if (!registrationDone.booleanValue())
destroy();
}
public void preDeregister()
throws Exception {
}
public void postDeregister() {
destroy();
}
// ----------------------------------------------------- SlideMBean Methods
/**
* Retruns the Catalina component name.
*/
public String getName() {
return NAME;
}
/**
* Returns the state.
*/
public int getState() {
return state;
}
/**
* Returns a String representation of the state.
*/
public String getStateString() {
return states[state];
}
/**
* Start the servlet container.
*/
public void start()
throws Exception {
Notification notification = null;
if (state != STOPPED)
return;
state = STARTING;
// Notifying the MBEan server that we're starting
notification = new AttributeChangeNotification
(this, sequenceNumber++, System.currentTimeMillis(),
"Starting " + NAME, "State", "java.lang.Integer",
new Integer(STOPPED), new Integer(STARTING));
sendNotification(notification);
try {
String value = "org.apache.naming";
String oldValue = System.getProperty(Context.URL_PKG_PREFIXES);
if (oldValue != null) {
oldUrlValue = oldValue;
value = oldValue + ":" + value;
}
System.setProperty(Context.URL_PKG_PREFIXES, value);
oldValue = System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
if (oldValue != null) {
oldIcValue = oldValue;
}
System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
Constants.Package
+ ".java.javaURLContextFactory");
} catch (Throwable t) {
state = STOPPED;
notification = new AttributeChangeNotification
(this, sequenceNumber++, System.currentTimeMillis(),
"Stopped " + NAME, "State", "java.lang.Integer",
new Integer(STARTING), new Integer(STOPPED));
sendNotification(notification);
}
state = STARTED;
notification = new AttributeChangeNotification
(this, sequenceNumber++, System.currentTimeMillis(),
"Started " + NAME, "State", "java.lang.Integer",
new Integer(STARTING), new Integer(STARTED));
sendNotification(notification);
}
/**
* Stop the servlet container.
*/
public void stop() {
Notification notification = null;
if (state != STARTED)
return;
state = STOPPING;
notification = new AttributeChangeNotification
(this, sequenceNumber++, System.currentTimeMillis(),
"Stopping " + NAME, "State", "java.lang.Integer",
new Integer(STARTED), new Integer(STOPPING));
sendNotification(notification);
try {
System.setProperty(Context.URL_PKG_PREFIXES, oldUrlValue);
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, oldIcValue);
} catch (Throwable t) {
// FIXME
t.printStackTrace();
}
state = STOPPED;
notification = new AttributeChangeNotification
(this, sequenceNumber++, System.currentTimeMillis(),
"Stopped " + NAME, "State", "java.lang.Integer",
new Integer(STOPPING), new Integer(STOPPED));
sendNotification(notification);
}
/**
* Destroy servlet container (if any is running).
*/
public void destroy() {
if (getState() != STOPPED)
stop();
}
}
1.1 jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/NamingServiceMBean.java
Index: NamingServiceMBean.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/NamingServiceMBean.java,v 1.1 2000/11/02 06:14:16 remm Exp $
* $Revision: 1.1 $
* $Date: 2000/11/02 06:14:16 $
*
* ====================================================================
*
* 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.naming;
/**
* Naming MBean interface.
*
* @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
* @version $Revision: 1.1 $
*/
public interface NamingServiceMBean {
// -------------------------------------------------------------- Constants
/**
* Status constants.
*/
public static final String[] states =
{"Stopped", "Stopping", "Starting", "Started"};
public static final int STOPPED = 0;
public static final int STOPPING = 1;
public static final int STARTING = 2;
public static final int STARTED = 3;
/**
* Component name.
*/
public static final String NAME = "Apache JNDI Naming Service";
/**
* Object name.
*/
public static final String OBJECT_NAME = ":service=Naming";
// ------------------------------------------------------ Interface Methods
/**
* Retruns the JNDI component name.
*/
public String getName();
/**
* Returns the state.
*/
public int getState();
/**
* Returns a String representation of the state.
*/
public String getStateString();
/**
* Start the servlet container.
*/
public void start()
throws Exception;
/**
* Stop the servlet container.
*/
public void stop();
/**
* Destroy servlet container (if any is running).
*/
public void destroy();
}
1.1 jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/ResourceEnvRefAddr.java
Index: ResourceEnvRefAddr.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/ResourceEnvRefAddr.java,v 1.1 2000/11/02 06:14:16 remm Exp $
* $Revision: 1.1 $
* $Date: 2000/11/02 06:14:16 $
*
* ====================================================================
*
* 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.naming;
import javax.naming.RefAddr;
/**
* Represents a reference address to a resource environment.
*
* @author Remy Maucherat
* @version $Revision: 1.1 $ $Date: 2000/11/02 06:14:16 $
*/
public class ResourceEnvRefAddr
extends RefAddr {
// -------------------------------------------------------------- Constants
/**
* Ref address type.
*/
public static final String TYPE = "resource-env-ref";
// ----------------------------------------------------------- Constructors
/**
* Resource env reference.
*
* @param type Type
*/
public ResourceEnvRefAddr(String resourceType) {
super(TYPE);
this.resourceType = resourceType;
}
// ----------------------------------------------------- Instance Variables
/**
* Resource environment reference type.
*/
protected String resourceType;
// -------------------------------------------------------- RefAddr Methods
/**
* Returns the contents of the address.
*/
public Object getContent() {
return this;
}
// ------------------------------------------------------------- Properties
/**
* Resource type accessor.
*/
public String getResourceType() {
return resourceType;
}
}
1.1 jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/ResourceRefAddr.java
Index: ResourceRefAddr.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/ResourceRefAddr.java,v 1.1 2000/11/02 06:14:16 remm Exp $
* $Revision: 1.1 $
* $Date: 2000/11/02 06:14:16 $
*
* ====================================================================
*
* 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.naming;
import java.util.Hashtable;
import javax.naming.RefAddr;
/**
* Represents a reference address to a resource.
*
* @author Remy Maucherat
* @version $Revision: 1.1 $ $Date: 2000/11/02 06:14:16 $
*/
public class ResourceRefAddr
extends RefAddr {
// -------------------------------------------------------------- Constants
/**
* Ref address type.
*/
public static final String TYPE = "resource-ref";
// ----------------------------------------------------------- Constructors
/**
* Resource Reference.
*
* @param resourceClass Resource class
* @param scope Resource scope
* @param auth Resource authetication
*/
public ResourceRefAddr(String resourceClass, String description,
String scope, String auth) {
super(TYPE);
this.resourceClass = resourceClass;
this.description = description;
this.scope = scope;
this.auth = auth;
}
// ----------------------------------------------------- Instance Variables
/**
* Resource class.
*/
protected String resourceClass;
/**
* Description.
*/
protected String description;
/**
* Scope.
*/
protected String scope;
/**
* Authentication type.
*/
protected String auth;
// -------------------------------------------------------- RefAddr Methods
/**
* Returns the contents of the address.
*/
public Object getContent() {
return this;
}
// ------------------------------------------------------------- Properties
/**
* Resource class accessor.
*/
public String getResourceClass() {
return (this.resourceClass);
}
/**
* Description accessor.
*/
public String getDescription() {
return (this.description);
}
/**
* Scope accessor.
*/
public String getScope() {
return (this.scope);
}
/**
* Auth accessor.
*/
public String getAuth() {
return (this.auth);
}
}
1.1 jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/SelectorContext.java
Index: SelectorContext.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/SelectorContext.java,v 1.1 2000/11/02 06:14:16 remm Exp $
* $Revision: 1.1 $
* $Date: 2000/11/02 06:14:16 $
*
* ====================================================================
*
* 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.naming;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NameParser;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
/**
* Catalina JNDI Context implementation.
*
* @author Remy Maucherat
* @version $Revision: 1.1 $ $Date: 2000/11/02 06:14:16 $
*/
public class SelectorContext implements Context {
// -------------------------------------------------------------- Constants
/**
* Namespace URL.
*/
public static final String prefix = "java:";
/**
* Namespace URL length.
*/
public static final int prefixLength = prefix.length();
// ----------------------------------------------------------- Constructors
/**
* Builds a Catalina selector context using the given environment.
*/
public SelectorContext(Hashtable env) {
this.env = env;
}
/**
* Builds a Catalina selector context using the given environment.
*/
public SelectorContext(Hashtable env, boolean initialContext) {
this(env);
this.initialContext = initialContext;
}
// ----------------------------------------------------- Instance Variables
/**
* Environment.
*/
protected Hashtable env;
/**
* The string manager for this package.
*/
protected StringManager sm = StringManager.getManager(Constants.Package);
/**
* Request for an initial context.
*/
protected boolean initialContext = false;
// --------------------------------------------------------- Public Methods
// -------------------------------------------------------- Context Methods
/**
* Retrieves the named object. If name is empty, returns a new instance
* of this context (which represents the same naming context as this
* context, but its environment may be modified independently and it may
* be accessed concurrently).
*
* @param name the name of the object to look up
* @return the object bound to name
* @exception NamingException if a naming exception is encountered
*/
public Object lookup(Name name)
throws NamingException {
// Strip the URL header
// Find the appropriate NamingContext according to the current bindings
// Execute the lookup on that context
return getBoundContext().lookup(parseName(name));
}
/**
* Retrieves the named object.
*
* @param name the name of the object to look up
* @return the object bound to name
* @exception NamingException if a naming exception is encountered
*/
public Object lookup(String name)
throws NamingException {
// Strip the URL header
// Find the appropriate NamingContext according to the current bindings
// Execute the lookup on that context
return getBoundContext().lookup(parseName(name));
}
/**
* Binds a name to an object. All intermediate contexts and the target
* context (that named by all but terminal atomic component of the name)
* must already exist.
*
* @param name the name to bind; may not be empty
* @param obj the object to bind; possibly null
* @exception NameAlreadyBoundException if name is already bound
* @exception InvalidAttributesException if object did not supply all
* mandatory attributes
* @exception NamingException if a naming exception is encountered
*/
public void bind(Name name, Object obj)
throws NamingException {
getBoundContext().bind(parseName(name), obj);
}
/**
* Binds a name to an object.
*
* @param name the name to bind; may not be empty
* @param obj the object to bind; possibly null
* @exception NameAlreadyBoundException if name is already bound
* @exception InvalidAttributesException if object did not supply all
* mandatory attributes
* @exception NamingException if a naming exception is encountered
*/
public void bind(String name, Object obj)
throws NamingException {
getBoundContext().bind(parseName(name), obj);
}
/**
* Binds a name to an object, overwriting any existing binding. All
* intermediate contexts and the target context (that named by all but
* terminal atomic component of the name) must already exist.
* <p>
* If the object is a DirContext, any existing attributes associated with
* the name are replaced with those of the object. Otherwise, any
* existing attributes associated with the name remain unchanged.
*
* @param name the name to bind; may not be empty
* @param obj the object to bind; possibly null
* @exception InvalidAttributesException if object did not supply all
* mandatory attributes
* @exception NamingException if a naming exception is encountered
*/
public void rebind(Name name, Object obj)
throws NamingException {
getBoundContext().rebind(parseName(name), obj);
}
/**
* Binds a name to an object, overwriting any existing binding.
*
* @param name the name to bind; may not be empty
* @param obj the object to bind; possibly null
* @exception InvalidAttributesException if object did not supply all
* mandatory attributes
* @exception NamingException if a naming exception is encountered
*/
public void rebind(String name, Object obj)
throws NamingException {
getBoundContext().rebind(parseName(name), obj);
}
/**
* Unbinds the named object. Removes the terminal atomic name in name
* from the target context--that named by all but the terminal atomic
* part of name.
* <p>
* This method is idempotent. It succeeds even if the terminal atomic
* name is not bound in the target context, but throws
* NameNotFoundException if any of the intermediate contexts do not exist.
*
* @param name the name to bind; may not be empty
* @exception NameNotFoundException if an intermediate context does not
* exist
* @exception NamingException if a naming exception is encountered
*/
public void unbind(Name name)
throws NamingException {
getBoundContext().unbind(parseName(name));
}
/**
* Unbinds the named object.
*
* @param name the name to bind; may not be empty
* @exception NameNotFoundException if an intermediate context does not
* exist
* @exception NamingException if a naming exception is encountered
*/
public void unbind(String name)
throws NamingException {
getBoundContext().unbind(parseName(name));
}
/**
* Binds a new name to the object bound to an old name, and unbinds the
* old name. Both names are relative to this context. Any attributes
* associated with the old name become associated with the new name.
* Intermediate contexts of the old name are not changed.
*
* @param oldName the name of the existing binding; may not be empty
* @param newName the name of the new binding; may not be empty
* @exception NameAlreadyBoundException if newName is already bound
* @exception NamingException if a naming exception is encountered
*/
public void rename(Name oldName, Name newName)
throws NamingException {
getBoundContext().rename(parseName(oldName), parseName(newName));
}
/**
* Binds a new name to the object bound to an old name, and unbinds the
* old name.
*
* @param oldName the name of the existing binding; may not be empty
* @param newName the name of the new binding; may not be empty
* @exception NameAlreadyBoundException if newName is already bound
* @exception NamingException if a naming exception is encountered
*/
public void rename(String oldName, String newName)
throws NamingException {
getBoundContext().rename(parseName(oldName), parseName(newName));
}
/**
* Enumerates the names bound in the named context, along with the class
* names of objects bound to them. The contents of any subcontexts are
* not included.
* <p>
* If a binding is added to or removed from this context, its effect on
* an enumeration previously returned is undefined.
*
* @param name the name of the context to list
* @return an enumeration of the names and class names of the bindings in
* this context. Each element of the enumeration is of type NameClassPair.
* @exception NamingException if a naming exception is encountered
*/
public NamingEnumeration list(Name name)
throws NamingException {
return getBoundContext().list(parseName(name));
}
/**
* Enumerates the names bound in the named context, along with the class
* names of objects bound to them.
*
* @param name the name of the context to list
* @return an enumeration of the names and class names of the bindings in
* this context. Each element of the enumeration is of type NameClassPair.
* @exception NamingException if a naming exception is encountered
*/
public NamingEnumeration list(String name)
throws NamingException {
return getBoundContext().list(parseName(name));
}
/**
* Enumerates the names bound in the named context, along with the
* objects bound to them. The contents of any subcontexts are not
* included.
* <p>
* If a binding is added to or removed from this context, its effect on
* an enumeration previously returned is undefined.
*
* @param name the name of the context to list
* @return an enumeration of the bindings in this context.
* Each element of the enumeration is of type Binding.
* @exception NamingException if a naming exception is encountered
*/
public NamingEnumeration listBindings(Name name)
throws NamingException {
return getBoundContext().listBindings(parseName(name));
}
/**
* Enumerates the names bound in the named context, along with the
* objects bound to them.
*
* @param name the name of the context to list
* @return an enumeration of the bindings in this context.
* Each element of the enumeration is of type Binding.
* @exception NamingException if a naming exception is encountered
*/
public NamingEnumeration listBindings(String name)
throws NamingException {
return getBoundContext().listBindings(parseName(name));
}
/**
* Destroys the named context and removes it from the namespace. Any
* attributes associated with the name are also removed. Intermediate
* contexts are not destroyed.
* <p>
* This method is idempotent. It succeeds even if the terminal atomic
* name is not bound in the target context, but throws
* NameNotFoundException if any of the intermediate contexts do not exist.
*
* In a federated naming system, a context from one naming system may be
* bound to a name in another. One can subsequently look up and perform
* operations on the foreign context using a composite name. However, an
* attempt destroy the context using this composite name will fail with
* NotContextException, because the foreign context is not a "subcontext"
* of the context in which it is bound. Instead, use unbind() to remove
* the binding of the foreign context. Destroying the foreign context
* requires that the destroySubcontext() be performed on a context from
* the foreign context's "native" naming system.
*
* @param name the name of the context to be destroyed; may not be empty
* @exception NameNotFoundException if an intermediate context does not
* exist
* @exception NotContextException if the name is bound but does not name
* a context, or does not name a context of the appropriate type
*/
public void destroySubcontext(Name name)
throws NamingException {
getBoundContext().destroySubcontext(parseName(name));
}
/**
* Destroys the named context and removes it from the namespace.
*
* @param name the name of the context to be destroyed; may not be empty
* @exception NameNotFoundException if an intermediate context does not
* exist
* @exception NotContextException if the name is bound but does not name
* a context, or does not name a context of the appropriate type
*/
public void destroySubcontext(String name)
throws NamingException {
getBoundContext().destroySubcontext(parseName(name));
}
/**
* Creates and binds a new context. Creates a new context with the given
* name and binds it in the target context (that named by all but
* terminal atomic component of the name). All intermediate contexts and
* the target context must already exist.
*
* @param name the name of the context to create; may not be empty
* @return the newly created context
* @exception NameAlreadyBoundException if name is already bound
* @exception InvalidAttributesException if creation of the subcontext
* requires specification of mandatory attributes
* @exception NamingException if a naming exception is encountered
*/
public Context createSubcontext(Name name)
throws NamingException {
return getBoundContext().createSubcontext(parseName(name));
}
/**
* Creates and binds a new context.
*
* @param name the name of the context to create; may not be empty
* @return the newly created context
* @exception NameAlreadyBoundException if name is already bound
* @exception InvalidAttributesException if creation of the subcontext
* requires specification of mandatory attributes
* @exception NamingException if a naming exception is encountered
*/
public Context createSubcontext(String name)
throws NamingException {
return getBoundContext().createSubcontext(parseName(name));
}
/**
* Retrieves the named object, following links except for the terminal
* atomic component of the name. If the object bound to name is not a
* link, returns the object itself.
*
* @param name the name of the object to look up
* @return the object bound to name, not following the terminal link
* (if any).
* @exception NamingException if a naming exception is encountered
*/
public Object lookupLink(Name name)
throws NamingException {
return getBoundContext().lookupLink(parseName(name));
}
/**
* Retrieves the named object, following links except for the terminal
* atomic component of the name.
*
* @param name the name of the object to look up
* @return the object bound to name, not following the terminal link
* (if any).
* @exception NamingException if a naming exception is encountered
*/
public Object lookupLink(String name)
throws NamingException {
return getBoundContext().lookupLink(parseName(name));
}
/**
* Retrieves the parser associated with the named context. In a
* federation of namespaces, different naming systems will parse names
* differently. This method allows an application to get a parser for
* parsing names into their atomic components using the naming convention
* of a particular naming system. Within any single naming system,
* NameParser objects returned by this method must be equal (using the
* equals() test).
*
* @param name the name of the context from which to get the parser
* @return a name parser that can parse compound names into their atomic
* components
* @exception NamingException if a naming exception is encountered
*/
public NameParser getNameParser(Name name)
throws NamingException {
return getBoundContext().getNameParser(parseName(name));
}
/**
* Retrieves the parser associated with the named context.
*
* @param name the name of the context from which to get the parser
* @return a name parser that can parse compound names into their atomic
* components
* @exception NamingException if a naming exception is encountered
*/
public NameParser getNameParser(String name)
throws NamingException {
return getBoundContext().getNameParser(parseName(name));
}
/**
* Composes the name of this context with a name relative to this context.
* <p>
* Given a name (name) relative to this context, and the name (prefix)
* of this context relative to one of its ancestors, this method returns
* the composition of the two names using the syntax appropriate for the
* naming system(s) involved. That is, if name names an object relative
* to this context, the result is the name of the same object, but
* relative to the ancestor context. None of the names may be null.
*
* @param name a name relative to this context
* @param prefix the name of this context relative to one of its ancestors
* @return the composition of prefix and name
* @exception NamingException if a naming exception is encountered
*/
public Name composeName(Name name, Name prefix)
throws NamingException {
prefix = (Name) name.clone();
return prefix.addAll(name);
}
/**
* Composes the name of this context with a name relative to this context.
*
* @param name a name relative to this context
* @param prefix the name of this context relative to one of its ancestors
* @return the composition of prefix and name
* @exception NamingException if a naming exception is encountered
*/
public String composeName(String name, String prefix)
throws NamingException {
return prefix + "/" + name;
}
/**
* Adds a new environment property to the environment of this context. If
* the property already exists, its value is overwritten.
*
* @param propName the name of the environment property to add; may not
* be null
* @param propVal the value of the property to add; may not be null
* @exception NamingException if a naming exception is encountered
*/
public Object addToEnvironment(String propName, Object propVal)
throws NamingException {
return getBoundContext().addToEnvironment(propName, propVal);
}
/**
* Removes an environment property from the environment of this context.
*
* @param propName the name of the environment property to remove;
* may not be null
* @exception NamingException if a naming exception is encountered
*/
public Object removeFromEnvironment(String propName)
throws NamingException {
return getBoundContext().removeFromEnvironment(propName);
}
/**
* Retrieves the environment in effect for this context. See class
* description for more details on environment properties.
* The caller should not make any changes to the object returned: their
* effect on the context is undefined. The environment of this context
* may be changed using addToEnvironment() and removeFromEnvironment().
*
* @return the environment of this context; never null
* @exception NamingException if a naming exception is encountered
*/
public Hashtable getEnvironment()
throws NamingException {
return getBoundContext().getEnvironment();
}
/**
* Closes this context. This method releases this context's resources
* immediately, instead of waiting for them to be released automatically
* by the garbage collector.
* This method is idempotent: invoking it on a context that has already
* been closed has no effect. Invoking any other method on a closed
* context is not allowed, and results in undefined behaviour.
*
* @exception NamingException if a naming exception is encountered
*/
public void close()
throws NamingException {
getBoundContext().close();
}
/**
* Retrieves the full name of this context within its own namespace.
* <p>
* Many naming services have a notion of a "full name" for objects in
* their respective namespaces. For example, an LDAP entry has a
* distinguished name, and a DNS record has a fully qualified name. This
* method allows the client application to retrieve this name. The string
* returned by this method is not a JNDI composite name and should not be
* passed directly to context methods. In naming systems for which the
* notion of full name does not make sense,
* OperationNotSupportedException is thrown.
*
* @return this context's name in its own namespace; never null
* @exception OperationNotSupportedException if the naming system does
* not have the notion of a full name
* @exception NamingException if a naming exception is encountered
*/
public String getNameInNamespace()
throws NamingException {
return prefix;
}
// ------------------------------------------------------ Protected Methods
/**
* Get the bound context.
*/
protected Context getBoundContext()
throws NamingException {
if (initialContext) {
String ICName =
"IC_" + ContextBindings.getThreadName();
Context initialContext = ContextBindings.getContext(ICName);
if (initialContext == null) {
// Allocating a new context and binding it to the appropriate
// name
initialContext = new NamingContext(env, ICName);
ContextBindings.bindContext(ICName, initialContext);
}
return initialContext;
} else {
return ContextBindings.getThread();
}
}
/**
* Strips the URL header.
*
* @return the parsed name
* @exception NamingException if there is no "java:" header or if no
* naming context has been bound to this thread
*/
protected String parseName(String name)
throws NamingException {
if ((!initialContext) && (name.startsWith(prefix))) {
return (name.substring(prefixLength));
} else {
if (initialContext) {
return (name);
} else {
throw new NamingException
(sm.getString("selectorContext.noJavaUrl"));
}
}
}
/**
* Strips the URL header.
*
* @return the parsed name
* @exception NamingException if there is no "java:" header or if no
* naming context has been bound to this thread
*/
protected Name parseName(Name name)
throws NamingException {
if ((!initialContext) && (!name.isEmpty())
&& (name.get(0).equals(prefix))) {
return (name.getSuffix(1));
} else {
if (initialContext) {
return (name);
} else {
throw new NamingException
(sm.getString("selectorContext.noJavaUrl"));
}
}
}
}
1.1 jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/StringManager.java
Index: StringManager.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/StringManager.java,v 1.1 2000/11/02 06:14:16 remm Exp $
* $Revision: 1.1 $
* $Date: 2000/11/02 06:14:16 $
*
* ====================================================================
*
* 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.naming;
import java.text.MessageFormat;
import java.util.Hashtable;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
/**
* An internationalization / localization helper class which reduces
* the bother of handling ResourceBundles and takes care of the
* common cases of message formating which otherwise require the
* creation of Object arrays and such.
*
* <p>The StringManager operates on a package basis. One StringManager
* per package can be created and accessed via the getManager method
* call.
*
* <p>The StringManager will look for a ResourceBundle named by
* the package name given plus the suffix of "LocalStrings". In
* practice, this means that the localized information will be contained
* in a LocalStrings.properties file located in the package
* directory of the classpath.
*
* <p>Please see the documentation for java.util.ResourceBundle for
* more information.
*
* @author James Duncan Davidson [duncan@eng.sun.com]
* @author James Todd [gonzo@eng.sun.com]
*/
public class StringManager {
/**
* The ResourceBundle for this StringManager.
*/
private ResourceBundle bundle;
/**
* Creates a new StringManager for a given package. This is a
* private method and all access to it is arbitrated by the
* static getManager method call so that only one StringManager
* per package will be created.
*
* @param packageName Name of package to create StringManager for.
*/
private StringManager(String packageName) {
String bundleName = packageName + ".LocalStrings";
bundle = ResourceBundle.getBundle(bundleName);
}
/**
* Get a string from the underlying resource bundle.
*
* @param key
*/
public String getString(String key) {
if (key == null) {
String msg = "key is null";
throw new NullPointerException(msg);
}
String str = null;
try {
str = bundle.getString(key);
} catch (MissingResourceException mre) {
str = "Cannot find message associated with key '" + key + "'";
}
return str;
}
/**
* Get a string from the underlying resource bundle and format
* it with the given set of arguments.
*
* @param key
* @param args
*/
public String getString(String key, Object[] args) {
String iString = null;
String value = getString(key);
// this check for the runtime exception is some pre 1.1.6
// VM's don't do an automatic toString() on the passed in
// objects and barf out
try {
// ensure the arguments are not null so pre 1.2 VM's don't barf
Object nonNullArgs[] = args;
for (int i=0; i<args.length; i++) {
if (args[i] == null) {
if (nonNullArgs==args) nonNullArgs=(Object[])args.clone();
nonNullArgs[i] = "null";
}
}
iString = MessageFormat.format(value, nonNullArgs);
} catch (IllegalArgumentException iae) {
StringBuffer buf = new StringBuffer();
buf.append(value);
for (int i = 0; i < args.length; i++) {
buf.append(" arg[" + i + "]=" + args[i]);
}
iString = buf.toString();
}
return iString;
}
/**
* Get a string from the underlying resource bundle and format it
* with the given object argument. This argument can of course be
* a String object.
*
* @param key
* @param arg
*/
public String getString(String key, Object arg) {
Object[] args = new Object[] {arg};
return getString(key, args);
}
/**
* Get a string from the underlying resource bundle and format it
* with the given object arguments. These arguments can of course
* be String objects.
*
* @param key
* @param arg1
* @param arg2
*/
public String getString(String key, Object arg1, Object arg2) {
Object[] args = new Object[] {arg1, arg2};
return getString(key, args);
}
/**
* Get a string from the underlying resource bundle and format it
* with the given object arguments. These arguments can of course
* be String objects.
*
* @param key
* @param arg1
* @param arg2
* @param arg3
*/
public String getString(String key, Object arg1, Object arg2,
Object arg3) {
Object[] args = new Object[] {arg1, arg2, arg3};
return getString(key, args);
}
/**
* Get a string from the underlying resource bundle and format it
* with the given object arguments. These arguments can of course
* be String objects.
*
* @param key
* @param arg1
* @param arg2
* @param arg3
* @param arg4
*/
public String getString(String key, Object arg1, Object arg2,
Object arg3, Object arg4) {
Object[] args = new Object[] {arg1, arg2, arg3, arg4};
return getString(key, args);
}
// --------------------------------------------------------------
// STATIC SUPPORT METHODS
// --------------------------------------------------------------
private static Hashtable managers = new Hashtable();
/**
* Get the StringManager for a particular package. If a manager for
* a package already exists, it will be reused, else a new
* StringManager will be created and returned.
*
* @param packageName
*/
public synchronized static StringManager getManager(String packageName) {
StringManager mgr = (StringManager)managers.get(packageName);
if (mgr == null) {
mgr = new StringManager(packageName);
managers.put(packageName, mgr);
}
return mgr;
}
}
1.1 jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/factory/LocalStrings.properties
<<Binary file>>
1.1 jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/java/javaURLContextFactory.java
Index: javaURLContextFactory.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/java/javaURLContextFactory.java,v 1.1 2000/11/02 06:14:18 remm Exp $
* $Revision: 1.1 $
* $Date: 2000/11/02 06:14:18 $
*
* ====================================================================
*
* 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.naming.java;
import java.util.Hashtable;
import javax.naming.Name;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.spi.ObjectFactory;
import javax.naming.spi.InitialContextFactory;
import org.apache.naming.SelectorContext;
import org.apache.naming.NamingContext;
import org.apache.naming.ContextBindings;
/**
* Context factory for the "java:" namespace.
* <p>
* <b>Important note</b> : This factory MUST be associated with the "java" URL
* prefix, which can be done by either :
* <ul>
* <li>Adding a
* java.naming.factory.url.pkgs=org.apache.catalina.util.naming property
* to the JNDI properties file</li>
* <li>Setting an environment variable named Context.URL_PKG_PREFIXES with
* its value including the org.apache.catalina.util.naming package name.
* More detail about this can be found in the JNDI documentation :
* {@link javax.naming.spi.NamingManager#getURLContext(java.lang.String, java.util.Hashtable)}.</li>
* </ul>
*
* @author Remy Maucherat
* @version $Revision: 1.1 $ $Date: 2000/11/02 06:14:18 $
*/
public class javaURLContextFactory
implements ObjectFactory, InitialContextFactory {
// ----------------------------------------------------------- Constructors
// -------------------------------------------------------------- Constants
public static final String MAIN = "initialContext";
// ----------------------------------------------------- Instance Variables
/**
* Initial context.
*/
protected static Context initialContext = null;
// --------------------------------------------------------- Public Methods
// -------------------------------------------------- ObjectFactory Methods
/**
* Crete a new Context's instance.
*/
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
Hashtable environment)
throws NamingException {
if (ContextBindings.isThreadBound()) {
return new SelectorContext(environment);
} else {
return null;
}
}
/**
* Get a new (writable) initial context.
*/
public Context getInitialContext(Hashtable environment)
throws NamingException {
if (ContextBindings.isThreadBound()) {
// Redirect the request to the bound initial context
return new SelectorContext(environment, true);
} else {
// If the thread is not bound, return a shared writable context
if (initialContext == null)
initialContext = new NamingContext(environment, MAIN);
return initialContext;
}
}
}