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.app;
020    
021    import net.dpml.logging.Logger;
022    
023    /**
024     * A server.
025     * 
026     * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
027     * @version 1.2.0 
028     */
029    public class DefaultListener implements Listener
030    {
031        //------------------------------------------------------------------
032        // concerns
033        //------------------------------------------------------------------
034    
035       /**
036        * The construction criteria.
037        */
038        public interface Context
039        {
040           /**
041            * Return the server.
042            * @return the server.
043            */
044            Server getServer();
045        }
046    
047        //------------------------------------------------------------------
048        // state
049        //------------------------------------------------------------------
050        
051        private final Logger m_logger;
052        private final Server m_server;
053        
054        private int m_count = 0;
055    
056        //------------------------------------------------------------------
057        // constructor
058        //------------------------------------------------------------------
059    
060       /**
061        * Creation of a new singleton component instance.
062        * @param logger an assigned logging channel
063        * @param context a context implementation fullfilling the context criteria
064        */
065        public DefaultListener( final Logger logger, final Context context )
066        {
067            m_logger = logger;
068            m_server = context.getServer();
069            m_server.addListener( this );
070        }
071    
072        //------------------------------------------------------------------
073        // Server
074        //------------------------------------------------------------------
075       
076       /**
077        * Handle notification from the server.
078        * @param message the nofication
079        */
080        public void notify( String message )
081        {
082            m_logger.debug( message );
083            m_count++;
084        }
085        
086        //------------------------------------------------------------------
087        // Test case hook
088        //------------------------------------------------------------------
089        
090       /**
091        * Return the number of time the notify method has been invoked.
092        * @return the notification count
093        */
094        public int getCount()
095        {
096            return m_count;
097        }
098    }