View Javadoc

1   package org.apache.turbine.services;
2   
3   /*
4    * Copyright 2001-2005 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License")
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  /***
20   * This class provides a generic implementation of
21   * <code>Initable</code>.  This implementation, that other
22   * <code>Initables</code> are welcome to extend, contains facilities
23   * to maintain internal state.
24   *
25   * @author <a href="mailto:burton@apache.org">Kevin Burton</a>
26   * @author <a href="mailto:krzewski@e-point.pl">Rafal Krzewski</a>
27   * @version $Id: BaseInitable.java 264148 2005-08-29 14:21:04Z henning $
28   */
29  public class BaseInitable
30          implements Initable
31  {
32      /*** InitableBroker that instantiatd this class. */
33      protected InitableBroker initableBroker;
34  
35      /*** Initialization status of this class. */
36      protected boolean isInitialized = false;
37  
38      /***
39       * Default constructor of BaseInitable.
40       *
41       * This constructor does nothing.  Your own constructurs should be
42       * modest in allocating memory and other resources, leaving this
43       * to the <code>init()</code> method.
44       */
45      public BaseInitable()
46      {
47      }
48  
49      /***
50       * Saves InitableBroker reference for later use.
51       *
52       * @param broker The InitableBroker that instantiated this object.
53       */
54      public void setInitableBroker(InitableBroker broker)
55      {
56          this.initableBroker = broker;
57      }
58  
59      /***
60       * Returns an InitableBroker reference.
61       *
62       * @return The InitableBroker that instantiated this object.
63       */
64      public InitableBroker getInitableBroker()
65      {
66          return initableBroker;
67      }
68  
69      /***
70       * Performs early initialization.  Used in a manner similar to a ctor.
71       *
72       * BaseInitable doesn't need early initialization, therefore it
73       * ignores all objects passed to it and performs no initialization
74       * activities.
75       *
76       * @param data An Object to use for initialization activities.
77       * @exception InitializationException Initialization of this
78       * class was not successful.
79       */
80      public void init(Object data) throws InitializationException
81      {
82      }
83  
84      /***
85       * Performs late initializtion.  Called when the Service is requested
86       * for the first time (if not already completely initialized by the
87       * early initializer).
88       *
89       * Late intialization of a BaseInitable is alwas successful.
90       *
91       * @exception InitializationException Initialization of this
92       * class was not successful.
93       */
94      public void init() throws InitializationException
95      {
96      }
97  
98      /***
99       * Returns an Initable to uninitialized state.
100      *
101      * Calls setInit(false) to mark that we are no longer in initialized
102      * state.
103      */
104     public void shutdown()
105     {
106         setInit(false);
107     }
108 
109     /***
110      * Returns initialization status.
111      *
112      * @return True if the initable is initialized.
113      */
114     public boolean getInit()
115     {
116         return isInitialized;
117     }
118 
119     /***
120      * Sets initailization status.
121      *
122      * @param value The new initialization status.
123      */
124     protected void setInit(boolean value)
125     {
126         this.isInitialized = value;
127     }
128 }