org.mockftpserver.core.command
Class SimpleCompositeCommandHandler

java.lang.Object
  extended by org.mockftpserver.core.command.SimpleCompositeCommandHandler
All Implemented Interfaces:
CommandHandler, ReplyTextBundleAware

public final class SimpleCompositeCommandHandler
extends Object
implements CommandHandler, ReplyTextBundleAware

Composite CommandHandler that manages an internal list of CommandHandlers to which it delegates. The internal CommandHandlers are maintained in an ordered list. Starting with the first CommandHandler in the list, each invocation of this composite handler will invoke (delegate to) the current internal CommandHander. Then it moves on the next CommandHandler in the internal list.

The following example replaces the CWD CommandHandler with a SimpleCompositeCommandHandler. The first invocation of the CWD command will fail (reply code 500). The seconds will succeed.


 
 StubFtpServer stubFtpServer = new StubFtpServer();
 
 CommandHandler commandHandler1 = new StaticReplyCommandHandler(500);
 CommandHandler commandHandler2 = new CwdCommandHandler();
 
 SimpleCompositeCommandHandler simpleCompositeCommandHandler = new SimpleCompositeCommandHandler();
 simpleCompositeCommandHandler.addCommandHandler(commandHandler1);
 simpleCompositeCommandHandler.addCommandHandler(commandHandler2);
 
 stubFtpServer.setCommandHandler("CWD", simpleCompositeCommandHandler);
 

Version:
$Revision: 184 $ - $Date: 2008-12-03 17:52:39 -0500 (Wed, 03 Dec 2008) $
Author:
Chris Mair

Constructor Summary
SimpleCompositeCommandHandler()
           
 
Method Summary
 void addCommandHandler(CommandHandler commandHandler)
          Add a CommandHandler to the internal list of handlers.
 CommandHandler getCommandHandler(int index)
          Return the CommandHandler corresponding to the specified invocation index.
 ResourceBundle getReplyTextBundle()
          Returns null.
 void handleCommand(Command command, Session session)
          Handle the specified command for the session.
 void setCommandHandlers(List commandHandlers)
          Set the List of CommandHandlers to which to delegate.
 void setReplyTextBundle(ResourceBundle replyTextBundle)
          Call setReplyTextBundle() on each of the command handlers within the internal list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleCompositeCommandHandler

public SimpleCompositeCommandHandler()
Method Detail

addCommandHandler

public void addCommandHandler(CommandHandler commandHandler)
Add a CommandHandler to the internal list of handlers.

Parameters:
commandHandler - - the CommandHandler
Throws:
AssertFailedException - - if the commandHandler is null

setCommandHandlers

public void setCommandHandlers(List commandHandlers)
Set the List of CommandHandlers to which to delegate. This replaces any CommandHandlers that have been defined previously.

Parameters:
commandHandlers - - the complete List of CommandHandlers to which invocations are delegated

getCommandHandler

public CommandHandler getCommandHandler(int index)
Return the CommandHandler corresponding to the specified invocation index. In other words, return the CommandHandler instance to which the Nth handleCommand(Command, Session) has been or will be delegated (where N=index).

Parameters:
index - - the index of the desired invocation (zero-based).
Returns:
the CommandHandler
Throws:
AssertFailedException - - if no CommandHandler is defined for the index or the index is not valid

handleCommand

public void handleCommand(Command command,
                          Session session)
                   throws Exception
Description copied from interface: CommandHandler
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
See Also:
CommandHandler.handleCommand(org.mockftpserver.core.command.Command, org.mockftpserver.core.session.Session)

getReplyTextBundle

public ResourceBundle getReplyTextBundle()
Returns null. This is a composite, and has no reply text bundle.

Specified by:
getReplyTextBundle in interface ReplyTextBundleAware
Returns:
the replyTextBundle
See Also:
ReplyTextBundleAware.getReplyTextBundle()

setReplyTextBundle

public void setReplyTextBundle(ResourceBundle replyTextBundle)
Call setReplyTextBundle() on each of the command handlers within the internal list.

Specified by:
setReplyTextBundle in interface ReplyTextBundleAware
Parameters:
replyTextBundle - - the replyTextBundle to set
See Also:
ReplyTextBundleAware.setReplyTextBundle(java.util.ResourceBundle)


Copyright © 2014. All rights reserved.