01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: RifeLifecycle.java 3643 2007-01-12 15:29:45Z gbevin $
07: */
08: package com.uwyn.rife.servlet;
09:
10: import com.uwyn.rife.engine.Gate;
11: import com.uwyn.rife.engine.InitConfig;
12: import com.uwyn.rife.ioc.HierarchicalProperties;
13: import com.uwyn.rife.rep.BlockingRepository;
14: import com.uwyn.rife.rep.Rep;
15: import com.uwyn.rife.rep.Repository;
16: import java.util.Enumeration;
17: import javax.servlet.ServletContext;
18:
19: public class RifeLifecycle {
20: public Gate init(InitConfig config) {
21: // instantiate the repository
22: Repository rep = Rep.getDefaultRepository();
23: boolean initialize_repository = false;
24: if (null == rep) {
25: initialize_repository = true;
26: rep = new BlockingRepository(config.getServletContext());
27: Rep.setDefaultRepository(rep);
28: }
29:
30: // setup the properties
31: HierarchicalProperties properties = rep.getProperties();
32:
33: Enumeration names = null;
34: String name = null;
35:
36: ServletContext context = config.getServletContext();
37: names = context.getInitParameterNames();
38: name = null;
39: while (names.hasMoreElements()) {
40: name = (String) names.nextElement();
41: properties.put(name, context.getInitParameter(name));
42: }
43:
44: names = config.getInitParameterNames();
45: name = null;
46: while (names.hasMoreElements()) {
47: name = (String) names.nextElement();
48: properties.put(name, config.getInitParameter(name));
49: }
50:
51: // initialize the repository
52: if (initialize_repository) {
53: ((BlockingRepository) rep).initialize(config
54: .getInitParameter("rep.path"), null);
55: }
56:
57: // initialize the gate
58: Gate gate = new Gate();
59: gate.init(config);
60:
61: return gate;
62: }
63:
64: public void destroy() {
65: Rep.cleanup();
66: }
67: }
|