1 package com.sri.emo.wizard.wizardgateway; 2 3 import com.jcorporate.expresso.core.controller.Controller; 4 import com.jcorporate.expresso.core.controller.ControllerException; 5 import com.jcorporate.expresso.core.controller.ExpressoRequest; 6 import com.jcorporate.expresso.core.controller.ExpressoResponse; 7 import com.jcorporate.expresso.core.db.DBException; 8 import com.sri.common.controller.StateHandler; 9 import com.sri.emo.dbobj.WizDefinition; 10 import com.sri.emo.wizard.IWizardManager; 11 import com.sri.emo.wizard.WizDefinitionRepository; 12 13 /*** 14 * Runs the wizard. 15 * 16 * @author Michael Rimov 17 * @version 1.0 18 */ 19 public class RunWizard extends WizardGatewayHandler implements StateHandler { 20 21 /*** 22 * Name of the State for which this handler deals with. 23 */ 24 public static final String STATE_NAME = "RunWizard"; 25 26 27 /*** 28 * Friendly description of this handler. 29 */ 30 public static final String STATE_DESCRIPTION = "Run a Wizard"; 31 32 33 /*** 34 * Constructs this particular state handler. 35 * 36 * @param handlerOwner Controller the controller that is the parent of this 37 * state handler. 38 * @param myRepository WizDefinitionRepository the repository to use 39 * for data access methods. 40 */ 41 public RunWizard(final Controller handlerOwner, final WizDefinitionRepository myRepository) { 42 super(handlerOwner, myRepository); 43 44 45 } 46 47 /*** 48 * Called to handle the request. 49 * 50 * @param request ControllerRequest The Function's ControllerRequest 51 * object. 52 * @param response ControllerResponse The Function's ControllerResponse 53 * object. 54 * @throws DBException upon underlying database exception error. 55 * @throws ControllerException upon underlying ControllerException error. 56 */ 57 public void handleRequest(final ExpressoRequest request, final ExpressoResponse response) throws DBException, 58 ControllerException { 59 60 WizDefinition definition = this.getWizDef(request); 61 Controller targetController = definition.getManagingController(); 62 if (!(targetController instanceof IWizardManager)) { 63 throw new ControllerException("Class: " + targetController.getClass().getName() 64 + " must implement interface: IWizardManager"); 65 } 66 67 ((IWizardManager) targetController).run(definition, request, response); 68 69 } 70 71 72 }