1 5 6 package org.infohazard.maverick.flow; 7 8 import java.io.IOException ; 9 import javax.servlet.*; 10 11 import org.apache.commons.logging.Log; 12 import org.apache.commons.logging.LogFactory; 13 14 30 abstract class CommandBase implements Command 31 { 32 37 private static Log log = LogFactory.getLog(CommandBase.class); 38 39 44 protected Controller controller; 45 46 51 public CommandBase(Controller ctl) 52 { 53 this.controller = ctl; 54 } 55 56 59 public void go(MaverickContext mctx) throws IOException , ServletException 60 { 61 Object model = null; 62 63 try 64 { 65 String viewName = this.controller.go(mctx); 67 68 model = mctx.getModel(); 70 71 if (log.isDebugEnabled()) 72 log.debug("Switching to view: " + viewName); 73 74 View target = this.getView(viewName); 75 if (null == target) 76 throw new ServletException("Controller specified view \"" + viewName 77 + "\", but no view with that name is defined."); 78 79 target.go(mctx); 80 } 81 finally 82 { 83 if (model instanceof ModelLifetime) 86 ((ModelLifetime)model).discard(); 87 } 88 } 89 90 92 protected abstract View getView(String name); 93 } | Popular Tags |