com.arsdigita.dispatcher
Class DispatcherChain

java.lang.Object
  extended bycom.arsdigita.dispatcher.DispatcherChain
All Implemented Interfaces:
Dispatcher

public class DispatcherChain
extends Object
implements Dispatcher

Generic implementation of "try this URL-resource mapping; if nothing found try ..." pattern. This is useful for packages whose URL-to-resource mapping is a composition of many separate, reusable mappings. The goal is to reduce multi-branched, hard-coded if-else blocks.

This class makes it easier to break up dispatchers into a series of smaller, re-usable, but not totally self-contained classes whose dispatch method tries to find a resource according to its mapping, and serves it if it finds one. If it can't find a resource, it returns a failure status code (DISPATCHER_CONTINUE) and the DispatcherChain tries the next dispatcher in the sequence.

The dispatcher chain tries each dispatcher in the dispatcher chain successively in the order in which they were added to the chain.


Field Summary
static String versionId
           
 
Constructor Summary
DispatcherChain()
           
 
Method Summary
 void addChainedDispatcher(ChainedDispatcher cd)
          Adds a dispatcher to the dispatcher chain.
 void dispatch(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, RequestContext ctx)
          Dispatches to the dispatcher chain.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

versionId

public static final String versionId
See Also:
Constant Field Values
Constructor Detail

DispatcherChain

public DispatcherChain()
Method Detail

dispatch

public void dispatch(javax.servlet.http.HttpServletRequest req,
                     javax.servlet.http.HttpServletResponse resp,
                     RequestContext ctx)
              throws javax.servlet.ServletException,
                     IOException
Dispatches to the dispatcher chain. Tries each dispatcher in the sequence, in which they were added, and breaks out of the loop when either one dispatcher returns DISPATCH_BREAK or a dispatcher throws an exception.

Specified by:
dispatch in interface Dispatcher
Parameters:
req - the current servlet request
resp - the current servlet response object
ctx - the current RequestContext object
Throws:
IOException - re-thrown when a dispatcher in the chain throws an IOException.
javax.servlet.ServletException - re-thrown when a dispatcher in the chain throws a ServletException.

addChainedDispatcher

public void addChainedDispatcher(ChainedDispatcher cd)
Adds a dispatcher to the dispatcher chain. Dispatchers are executed in the order they are added to the chain, so this dispatcher will be executed after all the dispatchers that were previously added to the chain and before all the dispatchers that haven't yet been added to the chain.

Parameters:
cd - the dispatcher to add


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 21 2004:2337 UTC