1 package org.apache.turbine.services;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import javax.servlet.ServletConfig;
23
24 import org.apache.turbine.util.RunData;
25
26 /***
27 * <p>This class provides a <code>Service</code> implementation that
28 * Services used in Turbine are required to extend. The
29 * functionality provided in addition to <code>BaseService</code>
30 * functionality is recognizing objects used in early initialization
31 * of <code>Services</code> in Turbine, and passing them to
32 * appropriate convenience methods. These methods should be overriden
33 * to provide desired initialization functionality.</p>
34 *
35 * <p><strong>Note!</strong><br>Remember to call
36 * <code>setInit(true)</code> after successful initialization.</p>
37 *
38 * <p><strong>Note!</strong><br>If you need to use another
39 * <code>Service</code> inside your early initialization, remember to
40 * request initialization of that <code>Service</code> before using
41 * it:</p>
42 *
43 * <pre><code>
44 * getServiceBroker().initClass("OtherService",data);
45 * OtherService service =
46 * (OtherService)getServiceBroker().getService("OtherService");
47 * </code></pre>
48 *
49 * @author <a href="mailto:greg@shwoop.com">Greg Ritter</a>
50 * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
51 * @author <a href="mailto:burton@apache.org">Kevin Burton</a>
52 * @author <a href="mailto:krzewski@e-point.pl">Rafal Krzewski</a>
53 * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
54 * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
55 * @version $Id: TurbineBaseService.java 534527 2007-05-02 16:10:59Z tv $
56 */
57 public abstract class TurbineBaseService
58 extends BaseService
59 {
60 /***
61 * Performs early initialization. Overrides init() method in
62 * BaseService to detect objects used in Turbine's Service
63 * initialization and pass them to apropriate init() methods.
64 *
65 * @param data An Object to use for initialization activities.
66 * @exception InitializationException if initialization of this
67 * class was not successful.
68 */
69 public void init(Object data)
70 throws InitializationException
71 {
72 if (data instanceof ServletConfig)
73 {
74 init((ServletConfig) data);
75 }
76 else if (data instanceof RunData)
77 {
78 init((RunData) data);
79 }
80 }
81
82 /***
83 * Performs early initialization.
84 *
85 * @param config A ServletConfing to use for initialization
86 * activities.
87 * @exception InitializationException if initialization of this
88 * class was not successful.
89 * @deprecated Use init() instead
90 */
91 public void init(ServletConfig config) throws InitializationException
92 {
93 }
94
95 /***
96 * Performs early initialization.
97 *
98 * @param data An RunData to use for initialization activities.
99 * @exception InitializationException if initialization of this
100 * class was not successful.
101 */
102 public void init(RunData data) throws InitializationException
103 {
104 }
105
106 /***
107 * Performs late initialization.
108 *
109 * If your class relies on early initialization, and the object it
110 * expects was not received, you can use late initialization to
111 * throw an exception and complain.
112 *
113 * @exception InitializationException, if initialization of this
114 * class was not successful.
115 */
116 public void init() throws InitializationException
117 {
118 setInit(true);
119 }
120
121 /***
122 * Returns to uninitialized state.
123 *
124 * You can use this method to release resources thet your Service
125 * allocated when Turbine shuts down.
126 */
127 public void shutdown()
128 {
129 setInit(false);
130 }
131 }