org.mockftpserver.core.command
Class AbstractTrackingCommandHandler

java.lang.Object
  extended by org.mockftpserver.core.command.AbstractCommandHandler
      extended by org.mockftpserver.core.command.AbstractTrackingCommandHandler
All Implemented Interfaces:
CommandHandler, InvocationHistory, ReplyTextBundleAware
Direct Known Subclasses:
AbstractStaticReplyCommandHandler, AbstractStubDataCommandHandler

public abstract class AbstractTrackingCommandHandler
extends AbstractCommandHandler
implements InvocationHistory

The abstract superclass for CommandHandler classes that manage the List of InvocationRecord objects corresponding to each invocation of the command handler, and provide helper methods for subclasses.

Version:
$Revision: 192 $ - $Date: 2008-12-06 21:52:07 -0500 (Sat, 06 Dec 2008) $
Author:
Chris Mair

Field Summary
 
Fields inherited from class org.mockftpserver.core.command.AbstractCommandHandler
LOG
 
Constructor Summary
AbstractTrackingCommandHandler()
           
 
Method Summary
 void clearInvocations()
          Clear out the invocation history for this CommandHandler.
 InvocationRecord getInvocation(int index)
          Return the InvocationRecord representing the command invoction data for the nth invocation for this command handler instance.
 void handleCommand(Command command, Session session)
          Handle the specified command for the session.
protected abstract  void handleCommand(Command command, Session session, InvocationRecord invocationRecord)
          Handle the specified command for the session.
 int numberOfInvocations()
           
protected  void sendReply(Session session, int replyCode, String replyMessageKey, String replyText, Object[] arguments)
          Send a reply for this command on the control connection.
 
Methods inherited from class org.mockftpserver.core.command.AbstractCommandHandler
assertValidReplyCode, getReplyTextBundle, quotes, setReplyTextBundle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractTrackingCommandHandler

public AbstractTrackingCommandHandler()
Method Detail

handleCommand

public final void handleCommand(Command command,
                                Session session)
                         throws Exception
Handle the specified command for the session. This method is declared to throw Exception, allowing CommandHandler implementations to avoid unnecessary exception-handling. All checked exceptions are expected to be wrapped and handled by the caller.

Specified by:
handleCommand in interface CommandHandler
Parameters:
command - - the Command to be handled
session - - the session on which the Command was submitted
Throws:
Exception
AssertFailedException - - if the command or session is null
See Also:
CommandHandler.handleCommand(org.mockftpserver.core.command.Command, org.mockftpserver.core.session.Session)

handleCommand

protected abstract void handleCommand(Command command,
                                      Session session,
                                      InvocationRecord invocationRecord)
                               throws Exception
Handle the specified command for the session. This method is declared to throw Exception, allowing CommandHandler implementations to avoid unnecessary exception-handling. All checked exceptions are expected to be wrapped and handled by the caller.

Parameters:
command - - the Command to be handled
session - - the session on which the Command was submitted
invocationRecord - - the InvocationRecord; CommandHandlers are expected to add handler-specific data to the InvocationRecord, as appropriate
Throws:
Exception

sendReply

protected void sendReply(Session session,
                         int replyCode,
                         String replyMessageKey,
                         String replyText,
                         Object[] arguments)
Send a reply for this command on the control connection.

The reply code is designated by the replyCode property, and the reply text is determined by the following rules:

  1. If the replyText property is non-null, then use that.
  2. Otherwise, if replyMessageKey is non-null, the use that to retrieve a localized message from the replyText ResourceBundle.
  3. Otherwise, retrieve the reply text from the replyText ResourceBundle, using the reply code as the key.
If the arguments Object[] is not null, then these arguments are substituted within the reply text using the MessageFormat class.

Parameters:
session - - the Session
replyCode - - the reply code
replyMessageKey - - if not null (and replyText is null), this is used as the ResourceBundle message key instead of the reply code.
replyText - - if non-null, this is used as the reply text
arguments - - the array of arguments to be formatted and substituted within the reply text; may be null
Throws:
AssertFailedException - - if session is null
See Also:
MessageFormat

numberOfInvocations

public int numberOfInvocations()
Specified by:
numberOfInvocations in interface InvocationHistory
Returns:
the number of invocation records stored for this command handler instance
See Also:
InvocationHistory.numberOfInvocations()

getInvocation

public InvocationRecord getInvocation(int index)
Return the InvocationRecord representing the command invoction data for the nth invocation for this command handler instance. One InvocationRecord should be stored for each invocation of the CommandHandler.

Specified by:
getInvocation in interface InvocationHistory
Parameters:
index - - the index of the invocation record to return. The first record is at index zero.
Returns:
the InvocationRecord for the specified index
Throws:
AssertFailedException - - if there is no invocation record corresponding to the specified index
See Also:
InvocationHistory.getInvocation(int)

clearInvocations

public void clearInvocations()
Clear out the invocation history for this CommandHandler. After invoking this method, the numberOfInvocations() method will return zero.

Specified by:
clearInvocations in interface InvocationHistory
See Also:
InvocationHistory.clearInvocations()


Copyright © 2014. All rights reserved.