1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.pluto.portalImpl.services;
21
22 import javax.servlet.ServletConfig;
23 import javax.servlet.ServletContext;
24
25 import org.apache.pluto.portalImpl.util.Properties;
26
27 /***
28 ** This is the base class for all services of the system. It prototypes
29 ** only two methods: <CODE>init()</CODE> and <CODE>destroy()</CODE>, both
30 ** of which are optional to override by a service. However, it is
31 ** recommended to implement at least <CODE>init()</CODE>. The
32 ** <CODE>destroy()</CODE> method only serves as a hook to release any
33 ** resources that the service may have cached or opened for its life-time.
34 **
35 ** <P>
36 ** To be more precise, this class prototypes three different
37 ** <CODE>init()</CODE> methods. Only one of them should be overriden.
38 ** The are different with respect to the arguments they take, but
39 ** are otherwise identical.
40 **
41 ** @see ServiceManager
42 **/
43
44 public abstract class Service
45 {
46
47 /***
48 ** Constructs the service.
49 **/
50 protected Service () {
51
52 }
53
54 /***
55 ** Initializes the service using the servlet configuration
56 ** and the service properties.
57 **
58 ** @param aConfig
59 ** the servlet configuration
60 ** @param aProperties
61 ** the service properties
62 **
63 ** @throws Exception
64 ** if the initialization fails
65 **/
66
67 protected void init (ServletConfig aConfig,
68 Properties aProperties) throws Exception
69 {
70 if(aConfig != null)
71 {
72 init (aConfig.getServletContext (), aProperties);
73 }
74 else
75 {
76 init (aProperties);
77 }
78
79 }
80
81 /***
82 ** Initializes the service using the servlet context
83 ** and the service properties.
84 **
85 ** @param aContext
86 ** the servlet context
87 ** @param aProperties
88 ** the service properties
89 **
90 ** @throws Exception
91 ** if the initialization fails
92 **/
93
94 protected void init (ServletContext aContext,
95 Properties aProperties) throws Exception
96 {
97 init (aProperties);
98 }
99
100 /***
101 ** Initializes the service using the service properties.
102 **
103 ** @param aProperties
104 ** the service properties
105 **
106 ** @throws Exception
107 ** if the initialization fails
108 **/
109
110 protected void init (Properties aProperties) throws Exception
111 {
112 }
113
114 /***
115 * This methods can be used to setup things after the services has
116 * been initialized via init.
117 *
118 * @throws Exception
119 * if the postInit fails for any reason
120 **/
121 protected void postInit(ServletConfig aConfig) throws Exception
122 {
123 postInit();
124 }
125
126 /***
127 * This methods can be used to setup things after the services has
128 * been initialized via init.
129 *
130 * @throws Exception
131 * if the postInit fails for any reason
132 **/
133 protected void postInit() throws Exception
134 {
135 }
136
137 /***
138 ** Destroys the services. This method allows the service
139 ** to cleanup any resources.
140 **
141 ** @param aConfig
142 ** the servlet configuration
143 **
144 ** @throws Exception
145 ** if the destruction fails
146 **/
147 protected void destroy (ServletConfig aConfig) throws Exception
148 {
149 destroy();
150 }
151
152 /***
153 ** Destroys the services. This method allows the service
154 ** to cleanup any resources.
155 **
156 ** @throws Exception
157 ** if the destruction fails
158 **/
159 protected void destroy () throws Exception
160 {
161 }
162
163 }