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
20
21
22 import java.util.Hashtable;
23 import java.util.Iterator;
24 import java.util.Map.Entry;
25 import java.util.Properties;
26
27 import javax.naming.InitialContext;
28 import javax.naming.NamingException;
29
30 import org.apache.commons.configuration.Configuration;
31 import org.apache.turbine.annotation.TurbineConfiguration;
32 import org.apache.turbine.modules.Action;
33 import org.apache.turbine.pipeline.PipelineData;
34 import org.apache.turbine.util.RunData;
35
36
37
38
39
40
41
42
43
44 public class InitContextsAction
45 extends Action
46 {
47
48 @TurbineConfiguration
49 private Configuration conf;
50
51
52
53
54
55
56
57
58
59 @Override
60 public void doPerform(PipelineData pipelineData)
61 throws NamingException
62 {
63 RunData data = getRunData(pipelineData);
64
65
66
67
68
69
70
71 Hashtable<String, Properties> contextPropsList = new Hashtable<String, Properties>();
72 for (Iterator<String> contextKeys = conf.getKeys("context.");
73 contextKeys.hasNext();)
74 {
75 String key = contextKeys.next();
76 int start = key.indexOf(".") + 1;
77 int end = key.indexOf(".", start);
78 String contextName = key.substring(start, end);
79 Properties contextProps = null;
80 if (contextPropsList.containsKey(contextName))
81 {
82 contextProps = contextPropsList.get(contextName);
83 }
84 else
85 {
86 contextProps = new Properties();
87 }
88 contextProps.put(key.substring(end + 1),
89 conf.getString(key));
90 contextPropsList.put(contextName, contextProps);
91 }
92
93 for (Entry<String, Properties> contextProps : contextPropsList.entrySet())
94 {
95 InitialContext context = new InitialContext(contextProps.getValue());
96 data.getJNDIContexts().put(contextProps.getKey(), context);
97 }
98 }
99 }