1 package org.apache.turbine.modules.actions;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.util.Hashtable;
20 import java.util.Iterator;
21 import java.util.Properties;
22 import javax.naming.InitialContext;
23 import javax.naming.NamingException;
24
25 import org.apache.commons.configuration.Configuration;
26
27 import org.apache.turbine.Turbine;
28 import org.apache.turbine.modules.Action;
29 import org.apache.turbine.util.RunData;
30
31 /***
32 * Used to initialize JNDI contexts.
33 *
34 * @author <a href="mailto:greg@shwoop.com">Greg Ritter</a>
35 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
36 * @version $Id: InitContextsAction.java 264148 2005-08-29 14:21:04Z henning $
37 */
38 public class InitContextsAction
39 extends Action
40 {
41 /***
42 * This action will place the contexts defined in the
43 * TurbineResources instance (if any) into the data.contexts
44 * Hashtable.
45 *
46 * @param data The RunData object for the current request.
47 * @exception NamingException could not create InitialContext
48 */
49 public void doPerform(RunData data)
50 throws NamingException
51 {
52 Configuration conf = Turbine.getConfiguration();
53
54
55
56
57
58
59
60
61 Hashtable contextPropsList = new Hashtable();
62 for (Iterator contextKeys = conf.getKeys("context.");
63 contextKeys.hasNext();)
64 {
65 String key = (String) contextKeys.next();
66 int start = key.indexOf(".") + 1;
67 int end = key.indexOf(".", start);
68 String contextName = key.substring(start, end);
69 Properties contextProps = null;
70 if (contextPropsList.containsKey(contextName))
71 {
72 contextProps = (Properties) contextPropsList.get(contextName);
73 }
74 else
75 {
76 contextProps = new Properties();
77 }
78 contextProps.put(key.substring(end + 1),
79 conf.getString(key));
80 contextPropsList.put(contextName, contextProps);
81 }
82 for (Iterator contextPropsKeys = contextPropsList.keySet().iterator();
83 contextPropsKeys.hasNext();)
84 {
85 String key = (String) contextPropsKeys.next();
86 Properties contextProps = (Properties) contextPropsList.get(key);
87 InitialContext context = new InitialContext(contextProps);
88 data.getJNDIContexts().put(key, context);
89 }
90 }
91 }