/*
* $Id: QuoteServer.html,v 1.4 2003/08/26 17:04:38 suhrin Exp $
*
* Copyright (c) 1999-2003 Gnome Ltd. All Rights Reserved.
*
* This software is the confidential and proprietary information of
* Gnome Ltd. You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms
* of the license agreement you entered into with Gnome Ltd.
*/
package SK.gnome.dwarf.sample;
import java.util.Properties;
import SK.gnome.dwarf.tcpip.TCPIPServer;
/**
* Container for the Quote of the Day Service (RFC 865) handlers.
*
* <p>It extends the generic {@link TCPIPServer} class. The {@link #getQuote()} method
* must be implemented because it is required by the {@link QuoteHandler} class.
*/
public class QuoteServer extends TCPIPServer
{
/**
* Array of string quotes.
*/
protected String[] quotes;
/**
* Creates a new <tt>QuoteServer</tt>.
*/
public QuoteServer(String name)
{ super(name);
}
/**
* Sets the quote strings.
*
* @param quotes the quote strings
*/
public void setQuotes(Properties quotes)
{ this.quotes = (String[])quotes.values().toArray(new String[0]);
}
private int index = 0;
/**
* Returns a single quote string.
*
* <p>It cycles through the quote string array and returns a single quote string each
* time the method is invoked. The method must be synchronized to ensure the proper
* cycling of the quotes.
*
* @return a single string quote
*/
public synchronized String getQuote()
{ if (index == quotes.length)
index = 0;
return quotes[index++];
}
}
|