1 13 package com.tonbeller.wcf.controller; 14 import java.util.ArrayList ; 15 import java.util.Collections ; 16 import java.util.Iterator ; 17 import java.util.LinkedList ; 18 import java.util.List ; 19 20 import javax.servlet.http.HttpSession ; 21 22 import org.apache.log4j.Logger; 23 29 public class WcfController extends Controller { 30 private static Logger logger = Logger.getLogger(WcfController.class); 31 private List requestListeners = new LinkedList (); 32 33 WcfController() { 34 } 35 36 private static final String WEBKEY = WcfController.class.getName() + ".dispatcher"; 37 38 public static Controller instance(HttpSession session) { 39 WcfController ctrl = (WcfController) session.getAttribute(WEBKEY); 40 if (ctrl == null) { 41 ctrl = new WcfController(); 42 session.setAttribute(WEBKEY, ctrl); 43 } 44 return ctrl; 45 } 46 47 public void addRequestListener(RequestListener l) { 48 requestListeners.add(l); 49 } 50 51 public void removeRequestListener(RequestListener l) { 52 requestListeners.remove(l); 53 } 54 55 public void setNextView(String uri) { 56 RequestContext context = RequestContext.instance(); 57 context.getRequest().setAttribute(RequestFilter.NEXTVIEW, uri); 58 } 59 60 public String getNextView() { 61 RequestContext context = RequestContext.instance(); 62 return (String )context.getRequest().getAttribute(RequestFilter.NEXTVIEW); 63 } 64 65 public void request(RequestContext context) throws Exception { 66 ArrayList list = new ArrayList (requestListeners); 69 for (Iterator it = list.iterator(); it.hasNext();) { 70 RequestListener l = (RequestListener) it.next(); 71 l.request(context); 72 } 73 } 74 75 public List getRootListeners() { 76 return Collections.unmodifiableList(requestListeners); 77 } 78 } 79 | Popular Tags |