1 16 package org.apache.commons.net; 17 18 import java.io.Serializable ; 19 import java.util.Enumeration ; 20 import org.apache.commons.net.util.ListenerList; 21 22 33 34 public class ProtocolCommandSupport implements Serializable 35 { 36 private Object __source; 37 private ListenerList __listeners; 38 39 45 public ProtocolCommandSupport(Object source) 46 { 47 __listeners = new ListenerList(); 48 __source = source; 49 } 50 51 52 63 public void fireCommandSent(String command, String message) 64 { 65 Enumeration en; 66 ProtocolCommandEvent event; 67 ProtocolCommandListener listener; 68 69 en = __listeners.getListeners(); 70 71 event = new ProtocolCommandEvent(__source, command, message); 72 73 while (en.hasMoreElements()) 74 { 75 listener = (ProtocolCommandListener)en.nextElement(); 76 listener.protocolCommandSent(event); 77 } 78 } 79 80 93 public void fireReplyReceived(int replyCode, String message) 94 { 95 Enumeration en; 96 ProtocolCommandEvent event; 97 ProtocolCommandListener listener; 98 99 en = __listeners.getListeners(); 100 101 event = new ProtocolCommandEvent(__source, replyCode, message); 102 103 while (en.hasMoreElements()) 104 { 105 listener = (ProtocolCommandListener)en.nextElement(); 106 listener.protocolReplyReceived(event); 107 } 108 } 109 110 115 public void addProtocolCommandListener(ProtocolCommandListener listener) 116 { 117 __listeners.addListener(listener); 118 } 119 120 125 public void removeProtocolCommandListener(ProtocolCommandListener listener) 126 { 127 __listeners.removeListener(listener); 128 } 129 130 131 136 public int getListenerCount() 137 { 138 return __listeners.getListenerCount(); 139 } 140 141 } 142 143 | Popular Tags |