net.sf.urlchecker.commands
Class AbstractCommand

Package class diagram package AbstractCommand
java.lang.Object
  extended by net.sf.urlchecker.commands.AbstractCommand
All Implemented Interfaces:
Command
Direct Known Subclasses:
CheckUrlsGeneric, URLMatchCommand

public abstract class AbstractCommand
extends Object
implements Command

The default implementation of the chain of responsibility for the commands. All implementations of the URLChecker commands should better extend from this class to avoid repeating the tedious methods to maintain the chain. When extending this class the overriding method process must call super.process(Context) to assure the continuation of the chain of responsibility. End events are fired here just as soon as the process method is called. immutable

$Id: AbstractCommand.java 181 2010-12-12 23:39:00Z georgosn $

Version:
$LastChangedRevision: 181 $
Author:
$LastChangedBy: georgosn $

Constructor Summary
AbstractCommand()
          Empty constructor to use when no successor is needed.
AbstractCommand(Command successor)
          Instantiates a new abstract command setting the successor command.
 
Method Summary
protected  void fireEvent(ChainEvent event)
          Fires an event by passing the event object to all registered listeners.
 Command getSuccessor()
          Returns the successor command.CAUTION: this method will return null if no successor is set during instantiation of the class.
 Set<Result> process(Context input)
          This method processes the input Context and forwards the results on to the successor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractCommand

public AbstractCommand()
Empty constructor to use when no successor is needed.


AbstractCommand

public AbstractCommand(Command successor)
Instantiates a new abstract command setting the successor command. If there should be no further command in the chain, this parameter can be set to null

Parameters:
successor - the successor
Method Detail

fireEvent

protected void fireEvent(ChainEvent event)
Fires an event by passing the event object to all registered listeners.

Parameters:
event - the event object to be passed to all listeners.

getSuccessor

public Command getSuccessor()
Returns the successor command.CAUTION: this method will return null if no successor is set during instantiation of the class.

Specified by:
getSuccessor in interface Command
Returns:
the successor command.

process

public Set<Result> process(Context input)
                    throws org.apache.commons.configuration.ConfigurationException
This method processes the input Context and forwards the results on to the successor. This implementation of the method simply checks if there are any successors and passes the context. if no successor is registered for the command then it merely returns the results from the context. The method also fires a BasicChainEvent before sending the control to the successor command with an END Type. This behavior allows the subclasses to concentrate in processing the input while the rest of the package releases all the features of event firing and handling. Events can be fired from within subclasses but it is better not to fire END events as this is handled here. START events though, must be fired in the subclasses if they are needed.

Specified by:
process in interface Command
Parameters:
input - the input
Returns:
the set
Throws:
org.apache.commons.configuration.ConfigurationException - the configuration exception


Copyright © 2010 Nikolaos Georgosopoulos. All Rights Reserved.