|
Evaluating Software Design Patterns — the "Gang of Four" patterns implemented in Java 6 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
R
- The type of requests handled by this chain.public interface HandlerChain<R>
A handler chain is an ordered list of handlers
that will be passed a request in turn until the first applicable
handler can handle it. To handle a given request, the
handle(Object)
method is used.
Any handler can register
it self to a proper handler chain, and delegate the chain
handling responsibility to the chain in case the handler cannot
handle the request.
Handler chains can change at runtime.
Implementation notes:
The handler chain is Composite
and allows other handler chains to be registered as handlers.
An alternative to using handler interfaces is to use annotations
to mark handlers in a given class. The
Observer pattern utilises such
an approach to identify the methods
(handlers)
to notify relevant observers in the ObserverManager
class.
HandlerLink
,
ObservableSequence
,
CompositeSequence
Method Summary | |
---|---|
List<Handler<R>> |
getHandlers(Handler<R> handler)
Returns an ordered list of the handlers
currently associated with this chain, starting from
the handler after handler , if supplied. |
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. |
boolean |
isRegistered(Handler<R> handler)
Returns true if handler is registered to this handler
chain, false if not. |
void |
register(Handler<R> handler)
Registers the handler supplied
as handler to this handler chain. |
int |
size()
Return the size of this handler chain. |
void |
unregister(Handler<R> handler)
Removes the handler supplied
as handler from this handler chain. |
Methods inherited from interface dk.rode.thesis.chainofresponsibility.Handler |
---|
handle |
Methods inherited from interface dk.rode.thesis.chainofresponsibility.HandlerLink |
---|
forward |
Method Detail |
---|
List<Handler<R>> getHandlers(Handler<R> handler)
handlers
currently associated with this chain, starting from
the handler after handler
, if supplied.
If handler
is null, the entire list of handlers
is returned. If handler
is not registered to
this chain, the entire list of handlers is returned.
Modifying the returned list will not affect this chain.
handler
- The handler to start from; can be null.
handler
; never null, but can be empty.Handler<R> handle(R request)
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 getHandlers(Handler)
with a null argument.
request
- The request to handle. This chain allows it to
be null, but individual handlers may not.
request
, if any; may be null.boolean isRegistered(Handler<R> handler)
handler
is registered to this handler
chain, false if not.
handler
- The handler to test; cannot be null.
NullPointerException
- If handler
is null.void register(Handler<R> handler)
handler
supplied
as handler
to this handler chain. Registering the same handler twice is an error.
handler
- The handler to add; cannot be null.
NullPointerException
- If handler
is null.
IllegalArgumentException
- If handler
is already
registered to this chain.unregister(Handler)
int size()
void unregister(Handler<R> handler)
handler
supplied
as handler
from this handler chain. Trying to remove a handler that is not associated with this handler chain is an error.
handler
- The handler to remove; cannot be null.
NullPointerException
- If handler
is null.
IllegalArgumentException
- If handler
is not
registered to this chain.register(Handler)
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |