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.wizard.IWizardManager; 10 import org.apache.log4j.Logger; 11 12 /*** 13 * Handles the redirection of the Add wizard user to the appropriate wizard 14 * manager. 15 * 16 * @author Michael Rimov 17 * @version 1.0 18 */ 19 public class DoAddWizard extends AddWizardHandler implements StateHandler { 20 /*** 21 * Name of the State for which this handler deals with. 22 */ 23 public static final String STATE_NAME = "doAddWizard"; 24 25 26 /*** 27 * Friendly description of this handler. 28 */ 29 public static final String STATE_DESCRIPTION = "Add a wizard."; 30 31 /*** 32 * The log4j Logger 33 */ 34 private static final Logger log = Logger.getLogger(DoAddWizard.class); 35 36 /*** 37 * Constructs this particular state handler. 38 */ 39 public DoAddWizard(final Controller owner) { 40 super(owner); 41 42 } 43 44 /*** 45 * Called to handle the request. 46 * 47 * @param request ControllerRequest The Function's ControllerRequest 48 * object. 49 * @param response ControllerResponse The Function's ControllerResponse 50 * object. 51 * @throws DBException upon underlying database exception error. 52 * @throws ControllerException upon underlying ControllerException error. 53 */ 54 public void handleRequest(final ExpressoRequest request, final ExpressoResponse response) throws DBException, 55 ControllerException { 56 57 final String key = request.getParameter(AddWizardHandler.PARAM_WIZARD_TYPE); 58 if (key == null || key.length() == 0) { 59 response.addError("You need to specify a wizard to select"); 60 } 61 62 63 IWizardManager toTransitionTo = null; 64 try { 65 toTransitionTo = (IWizardManager) this.getControllerForKey(key); 66 } catch (ControllerException ex) { 67 log.error("Error resolving input to controller", ex); 68 response.addError("There was an error resolving your input. Error: " + ex.getMessage()); 69 } catch (IllegalArgumentException ex) { 70 log.error("Error resolving input to controller", ex); 71 response.addError("There was an error resolving your input. Error: " + ex.getMessage()); 72 } catch (ClassCastException ex) { 73 throw new ControllerException( 74 this.getControllerForKey(key).getClass().getName() + " must implement class IWizardManager", ex); 75 } 76 77 toTransitionTo.add(request, response); 78 } 79 }