KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > lifecycle > DefaultLifecycleManager


1 /*****************************************************************************
2  * Copyright (C) Zephyr Business Solution. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  *****************************************************************************/

8
9 /*
10  * Created on Oct 13, 2005
11  *
12  * Author Michelle Lei
13  * ZBS
14  */

15 package jfun.yan.lifecycle;
16
17 import jfun.yan.Component;
18
19 /**
20  * A LifecycleManager that directly supports the default
21  * "init-verify-open-start-stop-close-dispose" scheme.
22  * <p>
23  *
24  * Zephyr Business Solution
25  *
26  * @author Michelle Lei
27  *
28  */

29 public class DefaultLifecycleManager extends LifecycleManager {
30   private final DefaultLifecycleDescriptor desc;
31   
32   /**
33    * To create a DefaultLifecycleManager object.
34    * @param desc the descriptor of the phases.
35    */

36   public DefaultLifecycleManager(DefaultLifecycleDescriptor desc) {
37     this.desc = desc;
38   }
39   /**
40    * To create a DefaultLifecycleManager object.<br>
41    * Equivalent to <code>this(new DefaultLifecycleDescriptor())</code>.
42    */

43   public DefaultLifecycleManager(){
44     this(new DefaultLifecycleDescriptor());
45   }
46   /**
47    * To call the "close" phase for all managed instances.
48    * @throws Throwable when any exception happens.
49    */

50   public void close()
51   throws Throwable JavaDoc{
52     desc.close(this);
53   }
54   /**
55    * To call the "dispose" phase for all managed instances.
56    * @throws Throwable when any exception happens.
57    */

58   public void dispose()
59   throws Throwable JavaDoc{
60     desc.dispose(this);
61   }
62   /**
63    * To call the "init" phase for all managed instances.
64    * @throws Throwable when any exception happens.
65    */

66   public void init()
67   throws Throwable JavaDoc{
68     desc.init(this);
69   }
70   /**
71    * To call the "verify" phase for all managed instances.
72    * @throws Throwable when any exception happens.
73    */

74   public void verify()
75   throws Throwable JavaDoc{
76     desc.verify(this);
77   }
78   /**
79    * To call the "open" phase for all managed instances.
80    * @throws Throwable when any exception happens.
81    */

82   public void open()
83   throws Throwable JavaDoc{
84     desc.open(this);
85   }
86   /**
87    * To call the "start" phase for all managed instances.
88    * @throws Throwable when any exception happens.
89    */

90   public void start()
91   throws Throwable JavaDoc{
92     desc.start(this);
93   }
94   /**
95    * To call the "stop" phase for all managed instances.
96    * @throws Throwable when any exception happens.
97    */

98   public void stop()
99   throws Throwable JavaDoc{
100     desc.stop(this);
101   }
102   /**
103    * To create a DefaultLifecycle object.
104    */

105   public DefaultLifecycle newLifecycle(){
106     return new DefaultLifecycle();
107   }
108   /**
109    * This class is a Lifecycle that directly supports
110    * the default "init-verify-open-start-stop-close-dispose" life-cycle scheme.
111    */

112   public class DefaultLifecycle extends Lifecycle{
113     /**
114      * To register the "open" phase.
115      * @param proc the phase procedure.
116      * @param reentrant whether the procedure is re-entrant.
117      * @return this DefaultLifecycle object itself.
118      */

119     public DefaultLifecycle opener(Procedure proc, boolean reentrant){
120       desc.opener(this, proc, reentrant);
121       return this;
122     }
123     /**
124      * To register the "close" phase.
125      * @param proc the phase procedure.
126      * @param reentrant whether the procedure is re-entrant.
127      * @return this DefaultLifecycle object itself.
128      */

129     public DefaultLifecycle closer(Procedure proc, boolean reentrant){
130       desc.closer(this, proc, reentrant);
131       return this;
132     }
133     /**
134      * To register the "init" phase.
135      * @param proc the phase procedure.
136      * @param reentrant whether the procedure is re-entrant.
137      * @return this DefaultLifecycle object itself.
138      */

139     public DefaultLifecycle initializer(Procedure proc, boolean reentrant){
140       desc.initializer(this, proc, reentrant);
141       return this;
142     }
143     /**
144      * To register the "dispose" phase.
145      * @param proc the phase procedure.
146      * @param reentrant whether the procedure is re-entrant.
147      * @return this DefaultLifecycle object itself.
148      */

149     public DefaultLifecycle disposer(Procedure proc, boolean reentrant){
150       desc.disposer(this, proc, reentrant);
151       return this;
152     }
153     /**
154      * To register the "verify" phase.
155      * @param proc the phase procedure.
156      * @param reentrant whether the procedure is re-entrant.
157      * @return this DefaultLifecycle object itself.
158      */

159     public DefaultLifecycle verifier(Procedure proc, boolean reentrant){
160       desc.verifier(this, proc, reentrant);
161       return this;
162     }
163     /**
164      * To register the "start" phase.
165      * @param proc the phase procedure.
166      * @param reentrant whether the procedure is re-entrant.
167      * @return this DefaultLifecycle object itself.
168      */

169     public DefaultLifecycle starter(Procedure proc, boolean reentrant){
170       desc.starter(this, proc, reentrant);
171       return this;
172     }
173     /**
174      * To register the "stop" phase.
175      * @param proc the phase procedure.
176      * @param reentrant whether the procedure is re-entrant.
177      * @return this DefaultLifecycle object itself.
178      */

179     public DefaultLifecycle stopper(Procedure proc, boolean reentrant){
180       desc.stopper(this, proc, reentrant);
181       return this;
182     }
183     /**
184      * To register the "open" phase as re-entrant.
185      * @param proc the phase procedure.
186      * @return this DefaultLifecycle object itself.
187      */

188     public DefaultLifecycle opener(Procedure proc){
189       desc.opener(this, proc);
190       return this;
191     }
192     /**
193      * To register the "close" phase as re-entrant.
194      * @param proc the phase procedure.
195      * @return this DefaultLifecycle object itself.
196      */

197     public DefaultLifecycle closer(Procedure proc){
198       desc.closer(this, proc);
199       return this;
200     }
201     /**
202      * To register the "init" phase as non-reentrant.
203      * @param proc the phase procedure.
204      * @return this DefaultLifecycle object itself.
205      */

206     public DefaultLifecycle initializer(Procedure proc){
207       desc.initializer(this, proc);
208       return this;
209     }
210     /**
211      * To register the "dispose" phase as non-reentrant.
212      * @param proc the phase procedure.
213      * @return this DefaultLifecycle object itself.
214      */

215     public DefaultLifecycle disposer(Procedure proc){
216       desc.disposer(this, proc);
217       return this;
218     }
219     /**
220      * To register the "verify" phase as reentrant.
221      * @param proc the phase procedure.
222      * @return this DefaultLifecycle object itself.
223      */

224     public DefaultLifecycle verifier(Procedure proc){
225       desc.verifier(this, proc);
226       return this;
227     }
228     /**
229      * To register the "start" phase as re-entrant.
230      * @param proc the phase procedure.
231      * @return this DefaultLifecycle object itself.
232      */

233     public DefaultLifecycle starter(Procedure proc){
234       desc.starter(this, proc);
235       return this;
236     }
237     /**
238      * To register the "stop" phase as re-entrant.
239      * @param proc the phase procedure.
240      * @return this DefaultLifecycle object itself.
241      */

242     public DefaultLifecycle stopper(Procedure proc){
243       desc.stopper(this, proc);
244       return this;
245     }
246     /**
247      * To register the "open" phase as re-entrant.
248      * @param method_name the name of the parameter-less method.
249      * @return this DefaultLifecycle object itself.
250      */

251     public DefaultLifecycle opener(String JavaDoc method_name){
252       opener(Procedures.method(method_name));
253       return this;
254     }
255     /**
256      * To register the "close" phase as re-entrant.
257      * @param method_name the name of the parameter-less method.
258      * @return this DefaultLifecycle object itself.
259      */

260     public DefaultLifecycle closer(String JavaDoc method_name){
261       closer(Procedures.method(method_name));
262       return this;
263     }
264     /**
265      * To register the "init" phase as non-reentrant.
266      * @param method_name the name of the parameter-less method.
267      * @return this DefaultLifecycle object itself.
268      */

269     public DefaultLifecycle initializer(String JavaDoc method_name){
270       initializer(Procedures.method(method_name));
271       return this;
272     }
273     /**
274      * To register the "dispose" phase as non-reentrant.
275      * @param method_name the name of the parameter-less method.
276      * @return this DefaultLifecycle object itself.
277      */

278     public DefaultLifecycle disposer(String JavaDoc method_name){
279       disposer(Procedures.method(method_name));
280       return this;
281     }
282     /**
283      * To register the "verify" phase as reentrant.
284      * @param method_name the name of the parameter-less method.
285      * @return this DefaultLifecycle object itself.
286      */

287     public DefaultLifecycle verifier(String JavaDoc method_name){
288       verifier(Procedures.method(method_name));
289       return this;
290     }
291     /**
292      * To register the "start" phase as re-entrant.
293      * @param method_name the name of the parameter-less method.
294      * @return this DefaultLifecycle object itself.
295      */

296     public DefaultLifecycle starter(String JavaDoc method_name){
297       starter(Procedures.method(method_name));
298       return this;
299     }
300     /**
301      * To register the "stop" phase as re-entrant.
302      * @param method_name the name of the parameter-less method.
303      * @return this DefaultLifecycle object itself.
304      */

305     public DefaultLifecycle stopper(String JavaDoc method_name){
306       stopper(Procedures.method(method_name));
307       return this;
308     }
309     /**
310      * To create a Component with the current lifecycle.
311      * @param c the Component to be managed by the lifecycle.
312      * @return the new Component object with lifecycle management.
313      */

314     public Component manage(Component c){
315       if(this.isEmpty()) return c;
316       return withLifecycle(c, this);
317     }
318     
319     /**
320      * Manage an instance's life.
321      * @param obj the instance.
322      */

323     public void manageInstance(Object JavaDoc obj){
324       if(this.isEmpty()) return;
325       addLiveObject(bear(obj));
326     }
327   }
328 }
329
Popular Tags