Author: sebb
Date: Mon Mar 28 23:41:33 2011
New Revision: 1086445
URL: http://svn.apache.org/viewvc?rev=1086445&view=rev
Log:
NET-395 Move ProtocolCommandSupport to SocketClient
Modified:
commons/proper/net/trunk/src/changes/changes.xml
commons/proper/net/trunk/src/main/java/org/apache/commons/net/SocketClient.java
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTP.java
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java
commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAP.java
commons/proper/net/trunk/src/main/java/org/apache/commons/net/nntp/NNTP.java
commons/proper/net/trunk/src/main/java/org/apache/commons/net/pop3/POP3.java
commons/proper/net/trunk/src/main/java/org/apache/commons/net/smtp/SMTP.java
Modified: commons/proper/net/trunk/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/changes/changes.xml?rev=1086445&r1=1086444&r2=1086445&view=diff
==============================================================================
--- commons/proper/net/trunk/src/changes/changes.xml (original)
+++ commons/proper/net/trunk/src/changes/changes.xml Mon Mar 28 23:41:33 2011
@@ -57,6 +57,9 @@ The <action> type attribute can be add,u
<body>
<release version="3.0" date="TBA" description="TBA">
+ <action issue="NET-395" dev="sebb" type="update">
+ Move ProtocolCommandSupport to SocketClient.
+ </action>
<action issue="NET-393" dev="sebb" type="update">
Should the sendCommandWithID() methods be public?
Made methods private, and deleted currently unused ones.
Modified:
commons/proper/net/trunk/src/main/java/org/apache/commons/net/SocketClient.java
URL:
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/SocketClient.java?rev=1086445&r1=1086444&r2=1086445&view=diff
==============================================================================
---
commons/proper/net/trunk/src/main/java/org/apache/commons/net/SocketClient.java
(original)
+++
commons/proper/net/trunk/src/main/java/org/apache/commons/net/SocketClient.java
Mon Mar 28 23:41:33 2011
@@ -100,6 +100,12 @@ public abstract class SocketClient
int sendBufferSize = -1;
/**
+ * A ProtocolCommandSupport object used to manage the registering of
+ * ProtocolCommandListeners and te firing of ProtocolCommandEvents.
+ */
+ private ProtocolCommandSupport _commandSupport_;
+
+ /**
* Default constructor for SocketClient. Initializes
* _socket_ to null, _timeout_ to 0, _defaultPort to 0,
* _isConnected_ to false, and _socketFactory_ to a shared instance of
@@ -114,6 +120,7 @@ public abstract class SocketClient
_defaultPort_ = 0;
_socketFactory_ = __DEFAULT_SOCKET_FACTORY;
_serverSocketFactory_ = __DEFAULT_SERVER_SOCKET_FACTORY;
+ _commandSupport_ = new ProtocolCommandSupport(this);
}
@@ -673,6 +680,39 @@ public abstract class SocketClient
return _serverSocketFactory_;
}
+
+ /**
+ * Adds a ProtocolCommandListener. Delegates this task to
+ * {@link #_commandSupport_ _commandSupport_ }.
+ * <p>
+ * @param listener The ProtocolCommandListener to add.
+ */
+ public void addProtocolCommandListener(ProtocolCommandListener listener) {
+ _commandSupport_.addProtocolCommandListener(listener);
+ }
+
+ /***
+ * Removes a ProtocolCommandListener. Delegates this task to
+ * {@link #_commandSupport_ _commandSupport_ }.
+ * <p>
+ * @param listener The ProtocolCommandListener to remove.
+ ***/
+ public void removeProtocolCommandListener(ProtocolCommandListener
listener) {
+ _commandSupport_.removeProtocolCommandListener(listener);
+ }
+
+ protected void fireReplyReceived(int replyCode, String reply) {
+ if (_commandSupport_.getListenerCount() > 0) {
+ _commandSupport_.fireReplyReceived(replyCode, reply);
+ }
+ }
+
+ protected void fireCommandSent(String command, String message) {
+ if (_commandSupport_.getListenerCount() > 0) {
+ _commandSupport_.fireCommandSent(command, message);
+ }
+ }
+
}
Modified:
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTP.java
URL:
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTP.java?rev=1086445&r1=1086444&r2=1086445&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTP.java
(original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTP.java
Mon Mar 28 23:41:33 2011
@@ -29,8 +29,6 @@ import java.net.SocketTimeoutException;
import java.util.ArrayList;
import org.apache.commons.net.MalformedServerReplyException;
-import org.apache.commons.net.ProtocolCommandListener;
-import org.apache.commons.net.ProtocolCommandSupport;
import org.apache.commons.net.SocketClient;
/***
@@ -247,12 +245,6 @@ public class FTP extends SocketClient
protected BufferedWriter _controlOutput_;
/***
- * A ProtocolCommandSupport object used to manage the registering of
- * ProtocolCommandListeners and te firing of ProtocolCommandEvents.
- ***/
- protected ProtocolCommandSupport _commandSupport_;
-
- /***
* The default FTP constructor. Sets the default port to
* <code>DEFAULT_PORT</code> and initializes internal data structures
* for saving FTP reply information.
@@ -264,7 +256,6 @@ public class FTP extends SocketClient
_replyLines = new ArrayList<String>();
_newReplyString = false;
_replyString = null;
- _commandSupport_ = new ProtocolCommandSupport(this);
_controlEncoding = DEFAULT_CONTROL_ENCODING;
}
@@ -355,9 +346,7 @@ public class FTP extends SocketClient
while ( isStrictMultilineParsing() ? __strictCheck(line, code) :
__lenientCheck(line));
}
- if (reportReply && _commandSupport_.getListenerCount() > 0) {
- _commandSupport_.fireReplyReceived(_replyCode, getReplyString());
- }
+ fireReplyReceived(_replyCode, getReplyString());
if (_replyCode == FTPReply.SERVICE_NOT_AVAILABLE) {
throw new FTPConnectionClosedException("FTP response 421 received.
Server closed connection.");
@@ -423,29 +412,6 @@ public class FTP extends SocketClient
/***
- * Adds a ProtocolCommandListener. Delegates this task to
- * {@link #_commandSupport_ _commandSupport_ }.
- * <p>
- * @param listener The ProtocolCommandListener to add.
- ***/
- public void addProtocolCommandListener(ProtocolCommandListener listener)
- {
- _commandSupport_.addProtocolCommandListener(listener);
- }
-
- /***
- * Removes a ProtocolCommandListener. Delegates this task to
- * {@link #_commandSupport_ _commandSupport_ }.
- * <p>
- * @param listener The ProtocolCommandListener to remove.
- ***/
- public void removeProtocolCommandListener(ProtocolCommandListener listener)
- {
- _commandSupport_.removeProtocolCommandListener(listener);
- }
-
-
- /***
* Closes the control connection to the FTP server and sets to null
* some internal data so that the memory may be reclaimed by the
* garbage collector. The reply text and code information from the
@@ -495,8 +461,7 @@ public class FTP extends SocketClient
__send(message);
- if (_commandSupport_.getListenerCount() > 0)
- _commandSupport_.fireCommandSent(command, message);
+ fireCommandSent(command, message);
__getReply();
return _replyCode;
Modified:
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java
URL:
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java?rev=1086445&r1=1086444&r2=1086445&view=diff
==============================================================================
---
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java
(original)
+++
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java
Mon Mar 28 23:41:33 2011
@@ -482,10 +482,8 @@ implements Configurable
// reply is a local address, but target is not - assume NAT box
changed the PASV reply
if (host.isSiteLocalAddress() &&
!getRemoteAddress().isSiteLocalAddress()){
String hostAddress = getRemoteAddress().getHostAddress();
- if (_commandSupport_.getListenerCount() > 0) {
- _commandSupport_.fireReplyReceived(0,
+ fireReplyReceived(0,
"[Replacing site local address "+__passiveHost+"
with "+hostAddress+"]\n");
- }
__passiveHost = hostAddress;
}
} catch (UnknownHostException e) { // Should not happen as we are
passing in an IP address
Modified:
commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAP.java
URL:
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAP.java?rev=1086445&r1=1086444&r2=1086445&view=diff
==============================================================================
---
commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAP.java
(original)
+++
commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAP.java
Mon Mar 28 23:41:33 2011
@@ -26,8 +26,6 @@ import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;
-import org.apache.commons.net.ProtocolCommandListener;
-import org.apache.commons.net.ProtocolCommandSupport;
import org.apache.commons.net.SocketClient;
import org.apache.commons.net.io.CRLFLineReader;
@@ -69,12 +67,6 @@ public class IMAP extends SocketClient
private char[] _initialID = { 'A', 'A', 'A', 'A' };
/**
- * A ProtocolCommandSupport object used to manage the registering of
- * ProtocolCommandListeners and te firing of ProtocolCommandEvents.
- */
- protected ProtocolCommandSupport _commandSupport_;
-
- /**
* The default IMAPClient constructor. Initializes the state
* to <code>DISCONNECTED_STATE</code>.
*/
@@ -85,7 +77,6 @@ public class IMAP extends SocketClient
_reader = null;
__writer = null;
_replyLines = new ArrayList<String>();
- _commandSupport_ = new ProtocolCommandSupport(this);
}
/**
@@ -129,8 +120,7 @@ public class IMAP extends SocketClient
_replyCode = IMAPReply.getUntaggedReplyCode(line);
}
- if (_commandSupport_.getListenerCount() > 0)
- _commandSupport_.fireReplyReceived(_replyCode, getReplyString());
+ fireReplyReceived(_replyCode, getReplyString());
}
/**
@@ -159,29 +149,6 @@ public class IMAP extends SocketClient
}
/**
- * Adds a ProtocolCommandListener. Delegates this task to
- * {@link #_commandSupport_ _commandSupport_ }.
- * <p>
- * @param listener The ProtocolCommandListener to add.
- */
- public void addProtocolCommandListener(ProtocolCommandListener listener)
- {
- _commandSupport_.addProtocolCommandListener(listener);
- }
-
- /**
- * Removes a ProtocolCommandListener. Delegates this task to
- * {@link #_commandSupport_ _commandSupport_ }.
- * <p>
- * @param listener The ProtocolCommandListener to remove.
- */
- public void removeProtocolCommandistener(ProtocolCommandListener listener)
- {
- _commandSupport_.removeProtocolCommandListener(listener);
- }
-
-
- /**
* Sets IMAP client state. This must be one of the
* <code>_STATE</code> constants.
* <p>
@@ -251,8 +218,7 @@ public class IMAP extends SocketClient
__writer.write(message);
__writer.flush();
- if (_commandSupport_.getListenerCount() > 0)
- _commandSupport_.fireCommandSent(command, message);
+ fireCommandSent(command, message);
__getReply();
return _replyCode;
Modified:
commons/proper/net/trunk/src/main/java/org/apache/commons/net/nntp/NNTP.java
URL:
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/nntp/NNTP.java?rev=1086445&r1=1086444&r2=1086445&view=diff
==============================================================================
---
commons/proper/net/trunk/src/main/java/org/apache/commons/net/nntp/NNTP.java
(original)
+++
commons/proper/net/trunk/src/main/java/org/apache/commons/net/nntp/NNTP.java
Mon Mar 28 23:41:33 2011
@@ -24,8 +24,6 @@ import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import org.apache.commons.net.MalformedServerReplyException;
-import org.apache.commons.net.ProtocolCommandListener;
-import org.apache.commons.net.ProtocolCommandSupport;
import org.apache.commons.net.SocketClient;
/***
@@ -110,12 +108,6 @@ public class NNTP extends SocketClient
protected BufferedWriter _writer_;
/***
- * A ProtocolCommandSupport object used to manage the registering of
- * ProtocolCommandListeners and te firing of ProtocolCommandEvents.
- ***/
- protected ProtocolCommandSupport _commandSupport_;
-
- /***
* The default NNTP constructor. Sets the default port to
* <code>DEFAULT_PORT</code> and initializes internal data structures
* for saving NNTP reply information.
@@ -127,7 +119,6 @@ public class NNTP extends SocketClient
_reader_ = null;
_writer_ = null;
_isAllowedToPost = false;
- _commandSupport_ = new ProtocolCommandSupport(this);
}
private void __getReply() throws IOException
@@ -153,9 +144,7 @@ public class NNTP extends SocketClient
"Could not parse response code.\nServer Reply: " +
_replyString);
}
- if (_commandSupport_.getListenerCount() > 0)
- _commandSupport_.fireReplyReceived(_replyCode, _replyString +
- SocketClient.NETASCII_EOL);
+ fireReplyReceived(_replyCode, _replyString +
SocketClient.NETASCII_EOL);
if (_replyCode == NNTPReply.SERVICE_DISCONTINUED)
throw new NNTPConnectionClosedException(
@@ -184,28 +173,6 @@ public class NNTP extends SocketClient
}
/***
- * Adds a ProtocolCommandListener. Delegates this task to
- * {@link #_commandSupport_ _commandSupport_ }.
- * <p>
- * @param listener The ProtocolCommandListener to add.
- ***/
- public void addProtocolCommandListener(ProtocolCommandListener listener)
- {
- _commandSupport_.addProtocolCommandListener(listener);
- }
-
- /***
- * Removes a ProtocolCommandListener. Delegates this task to
- * {@link #_commandSupport_ _commandSupport_ }.
- * <p>
- * @param listener The ProtocolCommandListener to remove.
- ***/
- public void removeProtocolCommandListener(ProtocolCommandListener listener)
- {
- _commandSupport_.removeProtocolCommandListener(listener);
- }
-
- /***
* Closes the connection to the NNTP server and sets to null
* some internal data so that the memory may be reclaimed by the
* garbage collector. The reply text and code information from the
@@ -272,8 +239,7 @@ public class NNTP extends SocketClient
_writer_.write(message = __commandBuffer.toString());
_writer_.flush();
- if (_commandSupport_.getListenerCount() > 0)
- _commandSupport_.fireCommandSent(command, message);
+ fireCommandSent(command, message);
__getReply();
return _replyCode;
Modified:
commons/proper/net/trunk/src/main/java/org/apache/commons/net/pop3/POP3.java
URL:
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/pop3/POP3.java?rev=1086445&r1=1086444&r2=1086445&view=diff
==============================================================================
---
commons/proper/net/trunk/src/main/java/org/apache/commons/net/pop3/POP3.java
(original)
+++
commons/proper/net/trunk/src/main/java/org/apache/commons/net/pop3/POP3.java
Mon Mar 28 23:41:33 2011
@@ -27,8 +27,6 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.commons.net.MalformedServerReplyException;
-import org.apache.commons.net.ProtocolCommandListener;
-import org.apache.commons.net.ProtocolCommandSupport;
import org.apache.commons.net.SocketClient;
/***
@@ -88,12 +86,6 @@ public class POP3 extends SocketClient
List<String> _replyLines;
/***
- * A ProtocolCommandSupport object used to manage the registering of
- * ProtocolCommandListeners and te firing of ProtocolCommandEvents.
- ***/
- protected ProtocolCommandSupport _commandSupport_;
-
- /***
* The default POP3Client constructor. Initializes the state
* to <code>DISCONNECTED_STATE</code>.
***/
@@ -104,7 +96,6 @@ public class POP3 extends SocketClient
_reader = null;
__writer = null;
_replyLines = new ArrayList<String>();
- _commandSupport_ = new ProtocolCommandSupport(this);
}
private void __getReply() throws IOException
@@ -131,8 +122,7 @@ public class POP3 extends SocketClient
_replyLines.add(line);
_lastReplyLine = line;
- if (_commandSupport_.getListenerCount() > 0)
- _commandSupport_.fireReplyReceived(_replyCode, getReplyString());
+ fireReplyReceived(_replyCode, getReplyString());
}
@@ -156,29 +146,6 @@ public class POP3 extends SocketClient
/***
- * Adds a ProtocolCommandListener. Delegates this task to
- * {@link #_commandSupport_ _commandSupport_ }.
- * <p>
- * @param listener The ProtocolCommandListener to add.
- ***/
- public void addProtocolCommandListener(ProtocolCommandListener listener)
- {
- _commandSupport_.addProtocolCommandListener(listener);
- }
-
- /***
- * Removes a ProtocolCommandListener. Delegates this task to
- * {@link #_commandSupport_ _commandSupport_ }.
- * <p>
- * @param listener The ProtocolCommandListener to remove.
- ***/
- public void removeProtocolCommandistener(ProtocolCommandListener listener)
- {
- _commandSupport_.removeProtocolCommandListener(listener);
- }
-
-
- /***
* Sets POP3 client state. This must be one of the
* <code>_STATE</code> constants.
* <p>
@@ -262,8 +229,7 @@ public class POP3 extends SocketClient
__writer.write(message = __commandBuffer.toString());
__writer.flush();
- if (_commandSupport_.getListenerCount() > 0)
- _commandSupport_.fireCommandSent(command, message);
+ fireCommandSent(command, message);
__getReply();
return _replyCode;
Modified:
commons/proper/net/trunk/src/main/java/org/apache/commons/net/smtp/SMTP.java
URL:
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/smtp/SMTP.java?rev=1086445&r1=1086444&r2=1086445&view=diff
==============================================================================
---
commons/proper/net/trunk/src/main/java/org/apache/commons/net/smtp/SMTP.java
(original)
+++
commons/proper/net/trunk/src/main/java/org/apache/commons/net/smtp/SMTP.java
Mon Mar 28 23:41:33 2011
@@ -25,8 +25,6 @@ import java.io.OutputStreamWriter;
import java.util.ArrayList;
import org.apache.commons.net.MalformedServerReplyException;
-import org.apache.commons.net.ProtocolCommandListener;
-import org.apache.commons.net.ProtocolCommandSupport;
import org.apache.commons.net.SocketClient;
/***
@@ -104,12 +102,6 @@ public class SMTP extends SocketClient
String _replyString;
/***
- * A ProtocolCommandSupport object used to manage the registering of
- * ProtocolCommandListeners and te firing of ProtocolCommandEvents.
- ***/
- protected ProtocolCommandSupport _commandSupport_;
-
- /***
* The default SMTP constructor. Sets the default port to
* <code>DEFAULT_PORT</code> and initializes internal data structures
* for saving SMTP reply information.
@@ -120,7 +112,6 @@ public class SMTP extends SocketClient
_replyLines = new ArrayList<String>();
_newReplyString = false;
_replyString = null;
- _commandSupport_ = new ProtocolCommandSupport(this);
}
/**
@@ -152,8 +143,7 @@ public class SMTP extends SocketClient
_writer.write(message = __commandBuffer.toString());
_writer.flush();
- if (_commandSupport_.getListenerCount() > 0)
- _commandSupport_.fireCommandSent(command, message);
+ fireCommandSent(command, message);
__getReply();
return _replyCode;
@@ -222,8 +212,7 @@ public class SMTP extends SocketClient
// line.startsWith(code)));
}
- if (_commandSupport_.getListenerCount() > 0)
- _commandSupport_.fireReplyReceived(_replyCode, getReplyString());
+ fireReplyReceived(_replyCode, getReplyString());
if (_replyCode == SMTPReply.SERVICE_NOT_AVAILABLE)
throw new SMTPConnectionClosedException(
@@ -247,29 +236,6 @@ public class SMTP extends SocketClient
/***
- * Adds a ProtocolCommandListener. Delegates this task to
- * {@link #_commandSupport_ _commandSupport_ }.
- * <p>
- * @param listener The ProtocolCommandListener to add.
- ***/
- public void addProtocolCommandListener(ProtocolCommandListener listener)
- {
- _commandSupport_.addProtocolCommandListener(listener);
- }
-
- /***
- * Removes a ProtocolCommandListener. Delegates this task to
- * {@link #_commandSupport_ _commandSupport_ }.
- * <p>
- * @param listener The ProtocolCommandListener to remove.
- ***/
- public void removeProtocolCommandistener(ProtocolCommandListener listener)
- {
- _commandSupport_.removeProtocolCommandListener(listener);
- }
-
-
- /***
* Closes the connection to the SMTP server and sets to null
* some internal data so that the memory may be reclaimed by the
* garbage collector. The reply text and code information from the