View Javadoc

1   package com.sri.emo.wizard.wizardgateway;
2   
3   import com.jcorporate.expresso.core.controller.Controller;
4   import com.jcorporate.expresso.core.controller.ExpressoRequest;
5   import com.jcorporate.expresso.core.db.DBException;
6   import com.sri.common.dbobj.ObjectNotFoundException;
7   import com.sri.emo.dbobj.WizDefinition;
8   import com.sri.emo.wizard.WizDefinitionRepository;
9   import com.sri.emo.wizard.expressoimpl.WizardController;
10  
11  
12  abstract public class WizardGatewayHandler {
13  
14  
15      /***
16       * The parent controller.  If we need to redirect to another state inside
17       * this particular controller, we use this field.
18       */
19      protected final Controller owner;
20  
21  
22      /***
23       * The repository to use for data access methods.
24       */
25      private final WizDefinitionRepository repository;
26  
27      /***
28       * Constructor for a wizard gateway handler that takes a reference to the
29       * controller and the Repository interface
30       *
31       * @param myOwner      Controller
32       * @param myRepository The repository to use for data access methods.
33       */
34      public WizardGatewayHandler(final Controller myOwner, final WizDefinitionRepository myRepository) {
35          assert myOwner != null;
36          assert myRepository != null;
37  
38          owner = myOwner;
39          repository = myRepository;
40      }
41  
42      /***
43       * Retrieve the wizard definition based upon the parameters in the controller request.
44       *
45       * @param request ControllerRequest the ControllerRequest object.
46       * @return WizDefinition the defined wizard definition.
47       * @throws DBException if we are unable to locate it in the database.
48       */
49      protected WizDefinition getWizDef(final ExpressoRequest request) throws DBException {
50          WizDefinition wizdef = null;
51          try {
52              wizdef = getRepository().findById(Integer.parseInt(request.getParameter(WizardController.
53                      WIZ_PARAMETER_ID)));
54          } catch (ObjectNotFoundException ex) {
55              throw new DBException(ex);
56          }
57          return wizdef;
58      }
59  
60  
61      /***
62       * Method that grabs the owning controller.
63       *
64       * @return Controller instance. (never null)
65       */
66      protected Controller getOwner() {
67          return owner;
68      }
69  
70      /***
71       * Method that grabs the repository we are to use for accessing wizard
72       * definition objects.
73       *
74       * @return WizDefinitionRepository
75       */
76      protected WizDefinitionRepository getRepository() {
77          return repository;
78      }
79  }