FileDocCategorySizeDatePackage
ReqHandlerRegistry.javaAPI DocExample1495Sun Sep 02 14:59:06 BST 2001com.oreilly.forum.servlet

ReqHandlerRegistry

public class ReqHandlerRegistry extends Object
A utility class that locates request handler instances based on extra path information.

Fields Summary
private ReqHandler
defaultHandler
private Map
handlerMap
Constructors Summary
public ReqHandlerRegistry(ReqHandler defaultHandler)


       
        this.defaultHandler = defaultHandler;
    
Methods Summary
public ReqHandlergetHandler(javax.servlet.http.HttpServletRequest request)

        ReqHandler rh = null;
        String pathInfo = request.getPathInfo();
        if (pathInfo != null) {
            int firstSlashPos = pathInfo.indexOf('/");
            int secondSlashPos = (firstSlashPos > -1) ?
                    pathInfo.indexOf('/", firstSlashPos+1) : -1;


            String key = null;
            if (firstSlashPos > -1) {
                if (secondSlashPos > -1) {
                    key = pathInfo.substring(firstSlashPos+1, secondSlashPos);
                } else {
                    key = pathInfo.substring(firstSlashPos+1);
                }
            } else {
                key = pathInfo;
            }
            if (key != null && key.length() > 0) {
                rh = (ReqHandler) this.handlerMap.get(key);
            }
        }
        return (rh != null) ? rh : this.defaultHandler;
    
public voidregister(ReqHandler handler)

        this.handlerMap.put(handler.getPathInfo(), handler);