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

dk.rode.thesis.chainofresponsibility
Class CharacterHandler

java.lang.Object
  extended by dk.rode.thesis.chainofresponsibility.CharacterHandler
All Implemented Interfaces:
Handler<Character>
Direct Known Subclasses:
LetterCaseHandler, LetterHandler, SymbolHandler, WhitespaceHandler

@Participant(value="Handler")
public abstract class CharacterHandler
extends Object
implements Handler<Character>

An abstract character handler implements the basic traits of handlers handling Character objects.

Character handlers ignore null requests.

Author:
Gunni Rode / rode.dk

Constructor Summary
protected CharacterHandler()
          No-arg constructor.
protected CharacterHandler(HandlerChain<Character> chain)
          Constructor, which registers this character handler to the end of the handler chain supplied as chain.
 
Method Summary
protected abstract  boolean handle(Character character)
          Returns true if this handler can and have handled character, false if not.
 Handler<Character> handle(Character character, HandlerLink<Character> link)
          Implements the semantics required for chaining character handlers so sub-classes do not have to.
 void register(HandlerChain<Character> chain)
          Registers this character handler to the handler chain supplied as chain.
 String toString()
          Returns the string representation of this handler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CharacterHandler

protected CharacterHandler()
No-arg constructor.

This handler is not registered to any handler chain until specifically registered using the register(HandlerChain) method.


CharacterHandler

protected CharacterHandler(HandlerChain<Character> chain)
Constructor, which registers this character handler to the end of the handler chain supplied as chain.

Parameters:
chain - The handler chain; cannot be null.
Throws:
NullPointerException - If chain is null.
Method Detail

handle

protected abstract boolean handle(Character character)
Returns true if this handler can and have handled character, false if not.

Parameters:
character - The character; can be null.
Returns:
True if character was handled, false if not.

handle

public Handler<Character> handle(Character character,
                                 HandlerLink<Character> link)
Implements the semantics required for chaining character handlers so sub-classes do not have to. The actual handling is performed by the handle(Character) method, which sub-classes must implement.

If this handler can handle character, this handler is returned. If not, link is used to forward character to the next handler in the current chain. If link is null, null is returned.

Specified by:
handle in interface Handler<Character>
Parameters:
character - 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.

register

public void register(HandlerChain<Character> chain)
Registers this character handler to the handler chain supplied as chain.

Parameters:
chain - The handler chain; cannot be null.
Throws:
NullPointerException - If chain is null.
IllegalArgumentException - If this handler has already been registered to chain.

toString

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

Overrides:
toString in class Object
Returns:
The string representation; never null.
See Also:
ObjectPolicy.ID

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.