FileDocCategorySizeDatePackage
ProtocolCommandSupport.javaAPI DocApache Commons NET 1.4.1 API4618Sat Dec 03 10:05:48 GMT 2005org.apache.commons.net

ProtocolCommandSupport

public class ProtocolCommandSupport extends Object implements Serializable
ProtocolCommandSupport is a convenience class for managing a list of ProtocolCommandListeners and firing ProtocolCommandEvents. You can simply delegate ProtocolCommandEvent firing and listener registering/unregistering tasks to this class.

see
ProtocolCommandEvent
see
ProtocolCommandListener
author
Daniel F. Savarese

Fields Summary
private Object
__source
private org.apache.commons.net.util.ListenerList
__listeners
Constructors Summary
public ProtocolCommandSupport(Object source)
Creates a ProtocolCommandSupport instant using the indicated source as the source of fired ProtocolCommandEvents.

param
source The source to use for all generated ProtocolCommandEvents.

        __listeners = new ListenerList();
        __source = source;
    
Methods Summary
public voidaddProtocolCommandListener(ProtocolCommandListener listener)
Adds a ProtocolCommandListener.

param
listener The ProtocolCommandListener to add.

        __listeners.addListener(listener);
    
public voidfireCommandSent(java.lang.String command, java.lang.String message)
Fires a ProtocolCommandEvent signalling the sending of a command to all registered listeners, invoking their {@link org.apache.commons.net.ProtocolCommandListener#protocolCommandSent protocolCommandSent() } methods.

param
command The string representation of the command type sent, not including the arguments (e.g., "STAT" or "GET").
param
message The entire command string verbatim as sent to the server, including all arguments.

        Enumeration en;
        ProtocolCommandEvent event;
        ProtocolCommandListener listener;

        en = __listeners.getListeners();

        event = new ProtocolCommandEvent(__source, command, message);

        while (en.hasMoreElements())
        {
            listener = (ProtocolCommandListener)en.nextElement();
            listener.protocolCommandSent(event);
        }
    
public voidfireReplyReceived(int replyCode, java.lang.String message)
Fires a ProtocolCommandEvent signalling the reception of a command reply to all registered listeners, invoking their {@link org.apache.commons.net.ProtocolCommandListener#protocolReplyReceived protocolReplyReceived() } methods.

param
replyCode The integer code indicating the natureof the reply. This will be the protocol integer value for protocols that use integer reply codes, or the reply class constant corresponding to the reply for protocols like POP3 that use strings like OK rather than integer codes (i.e., POP3Repy.OK).
param
message The entire reply as received from the server.

        Enumeration en;
        ProtocolCommandEvent event;
        ProtocolCommandListener listener;

        en = __listeners.getListeners();

        event = new ProtocolCommandEvent(__source, replyCode, message);

        while (en.hasMoreElements())
        {
            listener = (ProtocolCommandListener)en.nextElement();
            listener.protocolReplyReceived(event);
        }
    
public intgetListenerCount()
Returns the number of ProtocolCommandListeners currently registered.

return
The number of ProtocolCommandListeners currently registered.

        return __listeners.getListenerCount();
    
public voidremoveProtocolCommandListener(ProtocolCommandListener listener)
Removes a ProtocolCommandListener.

param
listener The ProtocolCommandListener to remove.

        __listeners.removeListener(listener);