jvanzyl 01/05/23 06:51:34
Modified: src/java/org/apache/turbine/services/naming
TurbineNamingService.java
Log:
- applying a patch sent to me by colin chalmers.
From colin:
I think the biggest change was the init() method which means we can
initialise easier instead of having to wait for the first ServletRequest.
Further the contextPropsList (which is a Hashtable of property objects) has
been made global so that when we try to get a context from the the method it
looks into this Hashtable for the context matching a specific name.
I've tested this with two different context variations; one for local disk
called disk and the second using iiop called iiop, together with WebSphere.
comments:
we don't need the init(RunData) either do we? we should probably
get rid of that.
and could the JNDI stuff in RunData be removed? do we really need
JNDI info in RunData?
Revision Changes Path
1.9 +82 -52
jakarta-turbine/src/java/org/apache/turbine/services/naming/TurbineNamingService.java
Index: TurbineNamingService.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/naming/TurbineNamingService.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- TurbineNamingService.java 2001/05/20 00:49:08 1.8
+++ TurbineNamingService.java 2001/05/23 13:51:32 1.9
@@ -25,13 +25,13 @@
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
- * 4. The names "Apache" and "Apache Software Foundation" and
- * "Apache Turbine" must not be used to endorse or promote products
- * derived from this software without prior written permission. For
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache Turbine" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
- * "Apache Turbine", nor may "Apache" appear in their name, without
+ * "Apache Turbine", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
@@ -72,22 +72,22 @@
* provides JNDI naming contexts.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Greg Ritter</a>
- * @version $Id: TurbineNamingService.java,v 1.8 2001/05/20 00:49:08 jon Exp $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Colin Chalmers</a>
+ * @version $Id: TurbineNamingService.java,v 1.9 2001/05/23 13:51:32 jvanzyl Exp $
*/
-public class TurbineNamingService
- extends TurbineBaseService
- implements NamingService
+public class TurbineNamingService extends TurbineBaseService implements
NamingService
{
/**
- * Places the contexts defined in the TurbineResources instance
- * (if any) into the data.contexts Hashtable.
+ * A global HashTable of Property objects which are initialised using
+ * parameters from the ResourcesFile
+ */
+ private static Hashtable contextPropsList = null;
+
+ /**
+ * Called the first time the Service is used.<br>
*
- * @param data The RunData object for the current request.
- * @exception InitializationException, if there was a problem
- * during initialization.
*/
- public void init( RunData data )
- throws InitializationException
+ public void init() throws InitializationException
{
// Context properties are specified in lines in the properties
// file that begin with "context.contextname.", allowing
@@ -95,75 +95,105 @@
// "contextname." is the name of the property that will be
// used by the InitialContext class to create a new context
// instance.
-
try
{
Iterator contextKeys = TurbineResources.getKeys("context.");
- Hashtable contextPropsList = new Hashtable();
- while( contextKeys.hasNext() )
+ contextPropsList = new Hashtable();
+
+ while (contextKeys.hasNext())
{
String key = (String) contextKeys.next();
int start = key.indexOf(".") + 1;
int end = key.indexOf(".", start);
String contextName = key.substring(start, end);
Properties contextProps = null;
- if( contextPropsList.containsKey(contextName) )
+
+ if (contextPropsList.containsKey(contextName))
{
- contextProps =
- (Properties) contextPropsList.get(contextName);
+ contextProps = (Properties)
+ contextPropsList.get(contextName);
}
else
{
contextProps = new Properties();
}
- contextProps.put(key.substring(end + 1),
- TurbineResources.getString(key));
+
+ contextProps.put(
+ key.substring(end + 1),TurbineResources.getString(key));
+
contextPropsList.put(contextName, contextProps);
}
+
+ setInit(true);
+ }
+ catch (Exception e)
+ {
+ Log.error("Failed to initialize JDNI contexts!", e);
+
+ throw new InitializationException(
+ "Failed to initialize JDNI contexts!");
+ }
+ }
+
+ /**
+ * Places the contexts defined in the TurbineResources instance
+ * (if any) into the data.contexts Hashtable.
+ *
+ * @param data The RunData object for the current request.
+ * @exception InitializationException, if there was a problem
+ * during initialization.
+ */
+ public void init(RunData data) throws InitializationException
+ {
+ try
+ {
+ if (contextPropsList == null)
+ {
+ init();
+ }
+
Enumeration contextPropsKeys = contextPropsList.keys();
- while( contextPropsKeys.hasMoreElements() )
+ while (contextPropsKeys.hasMoreElements())
{
String key = (String) contextPropsKeys.nextElement();
Properties contextProps =
- (Properties) contextPropsList.get(key);
+ (Properties) contextPropsList.get(key);
InitialContext context = new InitialContext(contextProps);
data.getJNDIContexts().put(key, context);
}
}
- catch(Exception e)
+ catch (Exception e)
{
- Log.error("Failed to initialize JDNI contexts!");
- Log.error(e);
- throw new InitializationException("Failed to initialize JDNI
contexts!");
+ Log.error("Failed to initialize JDNI contexts!",e);
+
+ throw new InitializationException(
+ "Failed to initialize JDNI contexts!");
}
}
/**
- * Return the Context with the specified name. The Context is
- * constructed using the properties for the context with the
- * specified name; ie. those properties that start with
- * "services.servicename.properties.name.".
- *
- * @param name The name of the context.
- * @return The context with the specified name, or null if no
- * context exists with that name.
- */
- public Context getContext(String name)
+ * Return the Context with the specified name. The Context is
+ * constructed using the properties for the context with the
+ * specified name; ie. those properties that start with
+ * "services.servicename.properties.name.".
+ *
+ * @param name The name of the context.
+ * @return The context with the specified name, or null if no
+ * context exists with that name.
+ */
+ public Context getContext(String contextName)
{
// Get just the properties for the context with the specified
// name.
- Properties allProps = getProperties();
- Properties contextProps = new Properties();
- Enumeration allKeys = allProps.keys();
- while( allKeys.hasMoreElements() )
- {
- String key = (String) allKeys.nextElement();
- String prefix = name + ".";
- if( key.startsWith(prefix) )
- {
- contextProps.put(key.substring(prefix.length()),
- allProps.get(key));
- }
+ Properties contextProps = null;
+
+ if (contextPropsList.containsKey(contextName))
+ {
+ contextProps = (Properties) contextPropsList.get(contextName);
+ }
+ else
+ {
+ contextProps = new Properties();
}
// Construct a new context with the properties.
@@ -171,7 +201,7 @@
{
return new InitialContext(contextProps);
}
- catch( Exception e )
+ catch (Exception e)
{
return null;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]