View Javadoc

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