1 package org.apache.turbine.modules.actions; 2 3 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 38 public class InitContextsAction 39 extends Action 40 { 41 49 public void doPerform(RunData data) 50 throws NamingException 51 { 52 Configuration conf = Turbine.getConfiguration(); 53 54 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 } 92 | Popular Tags |