View Javadoc
1   /*
2    * 
3    * $Revision: 1.6 $
4    * $Date: 2005/03/15 21:16:21 $
5    *
6    * ====================================================================
7    * struts-it
8    * Copyright (C) 2004-2005 - Manfred Wolff and the strutsit community
9    * 
10   * Licensed under the Apache License, Version 2.0 (the "License");
11   * you may not use this file except in compliance with the License.
12   * You may obtain a copy of the License at
13   * 
14   *      http://www.apache.org/licenses/LICENSE-2.0
15   * 
16   * Unless required by applicable law or agreed to in writing, software
17   * distributed under the License is distributed on an "AS IS" BASIS,
18   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19   * See the License for the specific language governing permissions and
20   * limitations under the License.
21   *
22   * Projekt       : struts-it solutions for webbased projects
23   * Part          : demo application for the struts-it architecture
24   * Created       : 26.02.2005 mwolff
25   */
26  package org.struts.velocity.demo.util;
27  
28  import javax.servlet.ServletException;
29  
30  import org.apache.commons.logging.Log;
31  import org.apache.commons.logging.LogFactory;
32  import org.apache.struts.action.ActionServlet;
33  import org.apache.struts.action.PlugIn;
34  import org.apache.struts.config.ModuleConfig;
35  import org.strutsit.architecture.hivemind.StrutsHive;
36  import org.strutsit.examples.service.PropertyService;
37  
38  /***
39   * Initplugin must be called after the StrutsHivePlugin is called, because
40   * StrutsHivePlugin initializes the database connection.
41   * 
42   * @author <a href="mailto:wolff@struts-it.de">Manfred Wolff </a>
43   * @since JDK 1.4
44   * @version $Revision: 1.6 $
45   */
46  
47  public class InitPlugin implements PlugIn {
48  
49      /// The Logger for this class.
50      private static final Log log = LogFactory.getLog(InitPlugin.class);
51  
52      /***
53       * Inits the plugin
54       */
55      public void init(ActionServlet actionServlet, ModuleConfig moduleConfig)
56              throws ServletException {
57  
58          if (log.isTraceEnabled()) {
59              log.trace("init -> START");
60          }
61  
62          // The Hivemind configuration is stored in the application context.
63          StrutsHive hive = (StrutsHive) actionServlet.getServletContext()
64                  .getAttribute(StrutsHive.STRUTSHIVE_REGISTRY);
65  
66          // Do a lookup
67          Object o = null;
68          try {
69              o = hive.lookup("org.strutsit.examples.service.PropertyService",
70                      org.strutsit.examples.service.PropertyService.class);
71          } catch (Throwable e) {
72              log.error(e);
73          }
74  
75          // cast to the proper type
76          PropertyService pservice = (PropertyService) o;
77          // initialize the property service as well.
78          pservice.init();
79  
80  
81          if (log.isTraceEnabled()) {
82              log.trace("init -> END");
83          }
84      }
85  
86      /***
87       * Will be called, if the servlet cointainer goes down.
88       */
89      public void destroy() {
90          // does nothing
91      }
92  
93  }