001    package org.apache.turbine.services;
002    
003    
004    /*
005     * Licensed to the Apache Software Foundation (ASF) under one
006     * or more contributor license agreements.  See the NOTICE file
007     * distributed with this work for additional information
008     * regarding copyright ownership.  The ASF licenses this file
009     * to you under the Apache License, Version 2.0 (the
010     * "License"); you may not use this file except in compliance
011     * with the License.  You may obtain a copy of the License at
012     *
013     *   http://www.apache.org/licenses/LICENSE-2.0
014     *
015     * Unless required by applicable law or agreed to in writing,
016     * software distributed under the License is distributed on an
017     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
018     * KIND, either express or implied.  See the License for the
019     * specific language governing permissions and limitations
020     * under the License.
021     */
022    
023    
024    /**
025     * This class provides a generic implementation of
026     * <code>Initable</code>.  This implementation, that other
027     * <code>Initables</code> are welcome to extend, contains facilities
028     * to maintain internal state.
029     *
030     * @author <a href="mailto:burton@apache.org">Kevin Burton</a>
031     * @author <a href="mailto:krzewski@e-point.pl">Rafal Krzewski</a>
032     * @version $Id: BaseInitable.java 1078552 2011-03-06 19:58:46Z tv $
033     */
034    public class BaseInitable
035            implements Initable
036    {
037        /** InitableBroker that instantiatd this class. */
038        protected InitableBroker initableBroker;
039    
040        /** Initialization status of this class. */
041        protected boolean isInitialized = false;
042    
043        /**
044         * Default constructor of BaseInitable.
045         *
046         * This constructor does nothing.  Your own constructurs should be
047         * modest in allocating memory and other resources, leaving this
048         * to the <code>init()</code> method.
049         */
050        public BaseInitable()
051        {
052            // empty
053        }
054    
055        /**
056         * Saves InitableBroker reference for later use.
057         *
058         * @param broker The InitableBroker that instantiated this object.
059         */
060        public void setInitableBroker(InitableBroker broker)
061        {
062            this.initableBroker = broker;
063        }
064    
065        /**
066         * Returns an InitableBroker reference.
067         *
068         * @return The InitableBroker that instantiated this object.
069         */
070        public InitableBroker getInitableBroker()
071        {
072            return initableBroker;
073        }
074    
075        /**
076         * Performs early initialization.  Used in a manner similar to a ctor.
077         *
078         * BaseInitable doesn't need early initialization, therefore it
079         * ignores all objects passed to it and performs no initialization
080         * activities.
081         *
082         * @param data An Object to use for initialization activities.
083         * @exception InitializationException Initialization of this
084         * class was not successful.
085         */
086        public void init(Object data) throws InitializationException
087        {
088            // empty
089        }
090    
091        /**
092         * Performs late initializtion.  Called when the Service is requested
093         * for the first time (if not already completely initialized by the
094         * early initializer).
095         *
096         * Late intialization of a BaseInitable is alwas successful.
097         *
098         * @exception InitializationException Initialization of this
099         * class was not successful.
100         */
101        public void init() throws InitializationException
102        {
103            // empty
104        }
105    
106        /**
107         * Returns an Initable to uninitialized state.
108         *
109         * Calls setInit(false) to mark that we are no longer in initialized
110         * state.
111         */
112        public void shutdown()
113        {
114            setInit(false);
115        }
116    
117        /**
118         * Returns initialization status.
119         *
120         * @return True if the initable is initialized.
121         */
122        public boolean getInit()
123        {
124            return isInitialized;
125        }
126    
127        /**
128         * Sets initailization status.
129         *
130         * @param value The new initialization status.
131         */
132        protected void setInit(boolean value)
133        {
134            this.isInitialized = value;
135        }
136    }