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;
020    
021    import java.awt.Color;
022    
023    import net.dpml.logging.Logger;
024    
025    /**
026     * Component used to validate the singleton lisfestyle policy.
027     * 
028     * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
029     * @version 1.2.0 
030     */
031    public class SingletonComponent implements ColorManager
032    {
033        //------------------------------------------------------------------
034        // concerns
035        //------------------------------------------------------------------
036    
037       /**
038        * The componet defined construction criteria.
039        */
040        public interface Context
041        {
042           /**
043            * Return the assigned color.
044            * @return the color value
045            */
046            Color getColor();
047        }
048    
049        //------------------------------------------------------------------
050        // state
051        //------------------------------------------------------------------
052    
053       /**
054        * The logging channel.
055        */
056        private final Logger m_logger;
057    
058       /**
059        * The assigned context instance.
060        */
061        private final Context m_context;
062    
063        //------------------------------------------------------------------
064        // constructor
065        //------------------------------------------------------------------
066    
067       /**
068        * Creation of a new singleton component instance.
069        * @param logger the assinged logging channel
070        * @param context a context implementation fullfil,ling the context criteria
071        */
072        public SingletonComponent( final Logger logger, final Context context )
073        {
074            m_context = context;
075            m_logger = logger;
076            
077            getLogger().debug( "example component created" );
078        }
079    
080        //------------------------------------------------------------------
081        // Example
082        //------------------------------------------------------------------
083       
084       /**
085        * Return the color value assigned to the component context.
086        * @return the color value
087        */
088        public Color getColor()
089        {
090            return m_context.getColor();
091        }
092        
093        //------------------------------------------------------------------
094        // internal
095        //------------------------------------------------------------------
096    
097       /**
098        * Return the assigned logging channel.
099        * @return the logging channel
100        */
101        private Logger getLogger()
102        {
103            return m_logger;
104        }
105    }