1 package com.sri.emo.wizard.completion;
2
3 import com.jcorporate.expresso.core.controller.Transition;
4 import com.jcorporate.expresso.core.db.DBException;
5 import com.sri.emo.controller.CompletionWizardAction;
6 import com.sri.emo.wizard.WizardException;
7 import com.sri.emo.wizard.completion.persistence.CompletionDefinition;
8 import com.sri.emo.wizard.expressoimpl.WizardController;
9 import com.sri.emo.wizard.wizardgateway.RunWizard;
10 import com.sri.emo.wizard.wizardgateway.WizardGatewayController;
11
12 /***
13 * Allows for locating completion wizards for a given node.
14 *
15 * @author Michael Rimov
16 * @version 1.0
17 */
18 public class CompletionWizardSelector {
19 public CompletionWizardSelector() {
20 super();
21 }
22
23 /***
24 * Resolves a definingNodeId to a CompletionWizard.
25 *
26 * @param definingNodeId String the target node id by which the completion wizard
27 * is found.
28 * @param optionalNodeToModifyId String the node id to operate the wizard on. May be null.
29 * @return Transition to the appropriate wizard gateway with parameters populated
30 * or null if no appropriate completion wizard is found.
31 * @throws WizardException
32 */
33 public Transition locateCompletionWizardForNode(final String definingNodeId,
34 final String optionalNodeToModifyId) throws WizardException {
35 try {
36 CompletionDefinition definition = new CompletionDefinition();
37 definition.setField(CompletionDefinition.FLD_TARGET_NODE, definingNodeId);
38 if (definition.find()) {
39 Transition wizardGateway = new Transition();
40 wizardGateway.setControllerObject(WizardGatewayController.class);
41 wizardGateway.setState(RunWizard.STATE_NAME);
42 wizardGateway.setLabel("Run Wizard");
43 wizardGateway.addParam(WizardController.WIZ_PARAMETER_ID,
44 definition.getField(CompletionDefinition.FLD_ID));
45 if (optionalNodeToModifyId != null) {
46 wizardGateway.addParam(CompletionWizardAction.PARAM_TARGET_ID, optionalNodeToModifyId);
47 }
48
49 return wizardGateway;
50 } else {
51 return null;
52 }
53 } catch (DBException ex) {
54 throw new WizardException("Error searching for matching completion wizard", ex);
55 }
56 }
57
58 }