001    /*
002     * Copyright 2005 Stephen J. McConnell.
003     *
004     * Licensed  under the  Apache License,  Version 2.0  (the "License");
005     * you may not use  this file  except in  compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *   http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed  under the  License is distributed on an "AS IS" BASIS,
012     * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
013     * implied.
014     *
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    
019    package net.dpml.test.lifecycle;
020    
021    import net.dpml.logging.Logger;
022    
023    /**
024     * Test component that provides feedback on the application of lifecycle
025     * stages handled by the container.
026     * 
027     * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
028     * @version 1.2.0 
029     */
030    public class StartableComponent
031    {
032        //------------------------------------------------------------------
033        // state
034        //------------------------------------------------------------------
035    
036       /**
037        * The logging channel.
038        */
039        private final Logger m_logger;
040        
041        private boolean m_started = false;
042        private boolean m_stopped = false;
043    
044        //------------------------------------------------------------------
045        // constructor
046        //------------------------------------------------------------------
047    
048       /**
049        * Creation of a new startable component instance.
050        * @param logger the assingned logging channel
051        */
052        public StartableComponent( final Logger logger )
053        {
054            m_logger = logger;
055        }
056        
057        //------------------------------------------------------------------
058        // lifecycle
059        //------------------------------------------------------------------
060    
061       /**
062        * Start the component.
063        */
064        public void start()
065        {
066            m_started = true;
067        }
068        
069       /**
070        * Stop the component.
071        */
072        public void stop()
073        {
074            m_stopped = true;
075        }
076    
077        //------------------------------------------------------------------
078        // validation operations
079        //------------------------------------------------------------------
080        
081       /**
082        * Utility to test if the component was stated (used in JUnit test).
083        * @return true if the start operation was invoked
084        */
085        public boolean wasStarted()
086        {
087            return m_started;
088        }
089        
090       /**
091        * Utility to test if the component was stopped (used in JUnit test).
092        * @return true if the stop operation was invoked
093        */
094        public boolean wasStopped()
095        {
096            return m_stopped;
097        }
098    }