##### Coverage Report - org.apache.turbine.modules.actions.InitContextsAction

Classes in this File | Line Coverage | Branch Coverage | Complexity
InitContextsAction |
0% | 0/27
0% | 0/6
| 2.5;2,5

1 |  |
     package org.apache.turbine.modules.actions;
2 |  |
3 |  |
     /*
4 |  |
      * Licensed to the Apache Software Foundation (ASF) under one
5 |  |
      * or more contributor license agreements.  See the NOTICE file
6 |  |
      * distributed with this work for additional information
7 |  |
      * regarding copyright ownership.  The ASF licenses this file
8 |  |
      * to you under the Apache License, Version 2.0 (the
9 |  |
      * "License"); you may not use this file except in compliance
10 |  |
      * with the License.  You may obtain a copy of the License at
11 |  |
      *
12 |  |
      *   http://www.apache.org/licenses/LICENSE-2.0
13 |  |
      *
14 |  |
      * Unless required by applicable law or agreed to in writing,
15 |  |
      * software distributed under the License is distributed on an
16 |  |
      * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 |  |
      * KIND, either express or implied.  See the License for the
18 |  |
      * specific language governing permissions and limitations
19 |  |
      * under the License.
20 |  |
      */
21 |  |
22 |  |
     import java.util.Hashtable;
23 |  |
     import java.util.Iterator;
24 |  |
     import java.util.Properties;
25 |  |
     import javax.naming.InitialContext;
26 |  |
     import javax.naming.NamingException;
27 |  |
28 |  |
     import org.apache.commons.configuration.Configuration;
29 |  |
30 |  |
     import org.apache.turbine.Turbine;
31 |  |
     import org.apache.turbine.modules.Action;
32 |  |
     import org.apache.turbine.pipeline.PipelineData;
33 |  |
     import org.apache.turbine.util.RunData;
34 |  |
35 |  |
     /**
36 |  |
      * Used to initialize JNDI contexts.
37 |  |
      *
38 |  |
      * @author <a href="mailto:greg@shwoop.com">Greg Ritter</a>
39 |  |
      * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
40 |  |
      * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
41 |  |
      * @version $Id: InitContextsAction.java 1066529 2011-02-02 17:01:46Z ludwig $
42 |  |
      */
43 | 0 |
     public class InitContextsAction
44 |  |
             extends Action
45 |  |
     {
46 |  |
         /**
47 |  |
          * This action will place the contexts defined in the
48 |  |
          * TurbineResources instance (if any) into the data.contexts
49 |  |
          * Hashtable.
50 |  |
          *
51 |  |
          * @deprecated Use PipelineData version instead.
52 |  |
          * @param data The RunData object for the current request.
53 |  |
          * @exception NamingException could not create InitialContext
54 |  |
          */
55 |  |
         @SuppressWarnings("unchecked")
56 |  |
         @Deprecated
57 |  |
         @Override
58 |  |
         public void doPerform(RunData data)
59 |  |
                 throws NamingException
60 |  |
         {
61 | 0 |
             Configuration conf = Turbine.getConfiguration();
62 |  |
63 |  |
             // Context properties are specified in lines in the properties
64 |  |
             // file that begin with "context.contextname.", allowing
65 |  |
             // multiple named contexts to be used.  Everything after the
66 |  |
             // "contextname." is the name of the property that will be
67 |  |
             // used by the InitialContext class to create a new context
68 |  |
             // instance.
69 |  |
70 | 0 |
             Hashtable<String, Properties> contextPropsList = new Hashtable<String, Properties>();
71 | 0 |
             for (Iterator<String> contextKeys = conf.getKeys("context.");
72 | 0 |
                     contextKeys.hasNext();)
73 |  |
             {
74 | 0 |
                 String key = contextKeys.next();
75 | 0 |
                 int start = key.indexOf(".") + 1;
76 | 0 |
                 int end = key.indexOf(".", start);
77 | 0 |
                 String contextName = key.substring(start, end);
78 | 0 |
                 Properties contextProps = null;
79 | 0 |
                 if (contextPropsList.containsKey(contextName))
80 |  |
                 {
81 | 0 |
                     contextProps = contextPropsList.get(contextName);
82 |  |
                 }
83 |  |
                 else
84 |  |
                 {
85 | 0 |
                     contextProps = new Properties();
86 |  |
                 }
87 | 0 |
                 contextProps.put(key.substring(end + 1),
88 |  |
                                  conf.getString(key));
89 | 0 |
                 contextPropsList.put(contextName, contextProps);
90 | 0 |
             }
91 | 0 |
             for (Iterator<String> contextPropsKeys = contextPropsList.keySet().iterator();
92 | 0 |
                     contextPropsKeys.hasNext();)
93 |  |
             {
94 | 0 |
                 String key = contextPropsKeys.next();
95 | 0 |
                 Properties contextProps = contextPropsList.get(key);
96 | 0 |
                 InitialContext context = new InitialContext(contextProps);
97 | 0 |
                 data.getJNDIContexts().put(key, context);
98 | 0 |
             }
99 | 0 |
         }
100 |  |
101 |  |
         /**
102 |  |
          * This action will place the contexts defined in the
103 |  |
          * TurbineResources instance (if any) into the data.contexts
104 |  |
          * Hashtable.
105 |  |
          *
106 |  |
          * @param pipelineData The PipelineRunData object for the current request.
107 |  |
          * @exception NamingException could not create InitialContext
108 |  |
          */
109 |  |
         @Override
110 |  |
         public void doPerform(PipelineData pipelineData)
111 |  |
         throws NamingException
112 |  |
         {
113 | 0 |
             RunData data = getRunData(pipelineData);
114 | 0 |
             doPerform(data);
115 | 0 |
         }
116 |  |
117 |  |
118 |  |
     }