    001package 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 1706239 2015-10-01 13:18:35Z tv $
    033 */
    034public 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    @Override
    061    public void setInitableBroker(InitableBroker broker)
    062    {
    063        this.initableBroker = broker;
    064    }
    065
    066    /**
    067     * Returns an InitableBroker reference.
    068     *
    069     * @return The InitableBroker that instantiated this object.
    070     */
    071    public InitableBroker getInitableBroker()
    072    {
    073        return initableBroker;
    074    }
    075
    076    /**
    077     * Performs early initialization.  Used in a manner similar to a ctor.
    078     *
    079     * BaseInitable doesn't need early initialization, therefore it
    080     * ignores all objects passed to it and performs no initialization
    081     * activities.
    082     *
    083     * @param data An Object to use for initialization activities.
    084     * @exception InitializationException Initialization of this
    085     * class was not successful.
    086     */
    087    @Override
    088    public void init(Object data) throws InitializationException
    089    {
    090        // empty
    091    }
    092
    093    /**
    094     * Performs late initialization.  Called when the Service is requested
    095     * for the first time (if not already completely initialized by the
    096     * early initializer).
    097     *
    098     * Late initialization of a BaseInitable is always successful.
    099     *
    100     * @exception InitializationException Initialization of this
    101     * class was not successful.
    102     */
    103    @Override
    104    public void init() throws InitializationException
    105    {
    106        // empty
    107    }
    108
    109    /**
    110     * Returns an Initable to uninitialized state.
    111     *
    112     * Calls setInit(false) to mark that we are no longer in initialized
    113     * state.
    114     */
    115    @Override
    116    public void shutdown()
    117    {
    118        setInit(false);
    119    }
    120
    121    /**
    122     * Returns initialization status.
    123     *
    124     * @return True if the initable is initialized.
    125     */
    126    @Override
    127    public boolean getInit()
    128    {
    129        return isInitialized;
    130    }
    131
    132    /**
    133     * Sets initialization status.
    134     *
    135     * @param value The new initialization status.
    136     */
    137    protected void setInit(boolean value)
    138    {
    139        this.isInitialized = value;
    140    }
    141}