org.perfectjpattern.core.behavioral.chainofresponsibility
Class AbstractHandler<R>

java.lang.Object
  extended by org.perfectjpattern.core.behavioral.chainofresponsibility.AbstractHandler<R>
Type Parameters:
R - Request parameter type
All Implemented Interfaces:
IHandler<R>
Direct Known Subclasses:
AbstractParameterlessHandler

public abstract class AbstractHandler<R>
extends Object
implements IHandler<R>

Abstract reusable implementation of IHandler interface.

The Default Strategy is OnlyOneHandleStrategy same as in GoF.

Version:
$Revision: 1.0 $ $Date: Jun 23, 2007 1:31:27 PM $
Author:
Giovanni Azua
See Also:
IHandler, NullHandler
 

Constructor Summary
AbstractHandler()
          Constructs a AbstractHandler from a NullHandler
AbstractHandler(IHandler<R> aSuccessor)
          Constructs a AbstractHandler from a Successor
 
Method Summary
 boolean canHandle(R aRequest)
          Returns true if this IHandler can handle the given request, false otherwise.
 IHandler<R> getSuccessor()
          Returns the Successor handler.
 void handle(R aRequest)
          Handle the given request.
 void setChainStrategy(IChainStrategy aStrategy)
          Set the IChainStrategy to this IHandler.
 void setSuccessor(IHandler<R> aSuccessor)
          Sets the Successor element.
 void start(R aRequest)
          Triggers execution of the Chain if the target Handler is the first reference, otherwise implements the decision-making regarding forwarding the request to its successor IHandler instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractHandler

public AbstractHandler()
Constructs a AbstractHandler from a NullHandler


AbstractHandler

public AbstractHandler(IHandler<R> aSuccessor)
                throws IllegalArgumentException
Constructs a AbstractHandler from a Successor

Parameters:
aSuccessor - Successor handler.
Throws:
IllegalArgumentException - 'aSuccessor' must not be null.
Method Detail

start

public final void start(R aRequest)
                 throws IllegalArgumentException
Triggers execution of the Chain if the target Handler is the first reference, otherwise implements the decision-making regarding forwarding the request to its successor IHandler instance.

Specified by:
start in interface IHandler<R>
Parameters:
aRequest - Context-specific request to handle.
Throws:
IllegalArgumentException - 'aRequest' must not be null.

getSuccessor

public final IHandler<R> getSuccessor()
Returns the Successor handler.

Specified by:
getSuccessor in interface IHandler<R>
Returns:
Successor handler.

canHandle

public boolean canHandle(R aRequest)
                  throws IllegalArgumentException
Returns true if this IHandler can handle the given request, false otherwise.

Specified by:
canHandle in interface IHandler<R>
Parameters:
aRequest - Context-specific request to handle.
Returns:
true if this IHandler can handle the given request, false otherwise.
Throws:
IllegalArgumentException - 'aRequest' must not be null.

handle

public void handle(R aRequest)
            throws IllegalArgumentException
Handle the given request. Implements the actual handling logic and must not contain any decision-making regarding e.g. forwarding the request.

Specified by:
handle in interface IHandler<R>
Parameters:
aRequest - Context-specific request to handle.
Throws:
IllegalArgumentException - 'aRequest' must not be null.

setSuccessor

public final void setSuccessor(IHandler<R> aSuccessor)
                        throws IllegalArgumentException
Sets the Successor element.

Specified by:
setSuccessor in interface IHandler<R>
Parameters:
aSuccessor - Successor handler
Throws:
IllegalArgumentException - 'aSuccessor' must not be null.

setChainStrategy

public final void setChainStrategy(IChainStrategy aStrategy)
                            throws IllegalArgumentException
Set the IChainStrategy to this IHandler. IChainStrategy allows to easily modify how the Chain should behave. Possible implementations are e.g.

Specified by:
setChainStrategy in interface IHandler<R>
Parameters:
aStrategy - Continuation strategy defines how the chain should behave
Throws:
IllegalArgumentException - 'aStrategy' must not be null.


Copyright © 2007-2009. All Rights Reserved.