Evaluating Software Design Patterns
— the "Gang of Four" patterns implemented in Java 6

dk.rode.thesis.chainofresponsibility
Class AbstractHandlerChain<R>

java.lang.Object
  extended by dk.rode.thesis.chainofresponsibility.AbstractHandlerChain<R>
Type Parameters:
R - The type of requests handled by this chain.
All Implemented Interfaces:
Handler<R>, HandlerChain<R>, HandlerLink<R>
Direct Known Subclasses:
StandardHandlerChain, WeakHandlerChain

public abstract class AbstractHandlerChain<R>
extends Object
implements HandlerChain<R>

An abstract handler chain implements the basic traits of the HandlerChain interface.

Author:
Gunni Rode / rode.dk

Constructor Summary
protected AbstractHandlerChain()
          No-arg constructor.
 
Method Summary
 Handler<R> forward(R request, Handler<R> current)
          Forwards the the request supplied as request to the handler represented by this link.
 Handler<R> handle(R request)
          Handles the request supplied as request by forwarding it to each handler in this chain until a handler can handle it, starting from the first registered handler.
 Handler<R> handle(R request, HandlerLink<R> link)
          Handles the request supplied as request or forwards it to the next handler in the chain represented by the handler link supplied as link, if any.
 String toString()
          Returns the string representation of this handler chain.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface dk.rode.thesis.chainofresponsibility.HandlerChain
getHandlers, isRegistered, register, size, unregister
 

Constructor Detail

AbstractHandlerChain

protected AbstractHandlerChain()
No-arg constructor.

Method Detail

forward

public Handler<R> forward(R request,
                          Handler<R> current)
Description copied from interface: HandlerLink
Forwards the the request supplied as request to the handler represented by this link.

The next handler is the handler after current in the chain. current can be located at any place in the chain, and if not found, all handlers in the chain are tried.

Specified by:
forward in interface HandlerLink<R>
Parameters:
request - The request to handle; nullability determined by the actual handler implementation.
current - The handler in the chain that could not handle request; can be null if this link represents the first handler in the chain.
Returns:
The handler that handled request, if any. Can be null.

handle

public Handler<R> handle(R request)
Handles the request supplied as request by forwarding it to each handler in this chain until a handler can handle it, starting from the first registered handler.

The handlers used are those delivered by HandlerChain.getHandlers(Handler) with a null argument.

Specified by:
handle in interface HandlerChain<R>
Parameters:
request - The request to handle. This chain allows it to be null, but individual handlers may not.
Returns:
The handler that handled request, if any; may be null.

handle

public Handler<R> handle(R request,
                         HandlerLink<R> link)
Description copied from interface: Handler
Handles the request supplied as request or forwards it to the next handler in the chain represented by the handler link supplied as link, if any. link can be null, in which case this handler is considered the last handler in the chain.

If this handler handles request, this handler is returned. If this handler cannot handle request, the result from handling the request using link is returned. Finally, if link is null, null is returned.

Specified by:
handle in interface Handler<R>
Parameters:
request - The request to handle; nullability determined by the actual handler implementation.
link - The link to the next handler in the current chain; can be null.
Returns:
The handler that handled request, if any. Can be null.

toString

public String toString()
Returns the string representation of this handler chain.

Overrides:
toString in class Object
Returns:
The string representation; never null.

Gunni Rode / rode.dk

Feel free to use and/or modify the Java 6 source code developed for this thesis AT YOUR OWN RISK, but note that the source code comes WITHOUT ANY — and I do mean WITHOUT ANY — form of warranty WHAT SO EVER!

The original thesis and source code are available at rode.dk/thesis.