View Javadoc

1   package com.sri.emo.wizard.completion;
2   
3   import com.sri.common.dbobj.ObjectNotFoundException;
4   import com.sri.common.dbobj.RepositoryConversionException;
5   import com.sri.common.dbobj.RepositoryException;
6   import com.sri.emo.wizard.completion.model.CompletionBean;
7   import com.sri.emo.wizard.expressoimpl.ExpressoLink;
8   import com.sri.emo.wizard.selection.EmoSelectionWizardFactory;
9   
10  
11  /***
12   * Base class for things that build Completion Wizards.  This can either be
13   * Factories or <tt>Memento</tt> converters.
14   *
15   * @author Michael Rimov
16   * @version 1.0
17   */
18  class CompletionBuilder extends EmoSelectionWizardFactory {
19  
20      /***
21       * Constructs a completion builder.
22       *
23       * @param completionRepository CompletionRepository
24       */
25      public CompletionBuilder(final CompletionRepository completionRepository) {
26          super();
27          repository = completionRepository;
28      }
29  
30      /***
31       * The completion repository to use for querying the wizard.
32       */
33      final protected CompletionRepository repository;
34  
35      /***
36       * The completion definition.
37       */
38      private CompletionBean myDefinition;
39  
40      /***
41       * Finish link.
42       */
43      protected ExpressoLink finish;
44  
45      /***
46       * Next page link
47       */
48      protected ExpressoLink next;
49  
50      /***
51       * Back Link.
52       */
53      protected ExpressoLink back;
54  
55      /***
56       * Cancel link.
57       */
58      protected ExpressoLink cancel;
59  
60      /***
61       * To be set by the factory.
62       *
63       * @param newId int
64       */
65      public void setWizardId(int newId) {
66          super.setWizardId(newId);
67          extractDefinition(newId);
68          next = buildNextLink(newId);
69          finish = buildFinishLink(newId);
70          cancel = buildCancelLink(newId);
71          back = buildBackLink(newId);
72      }
73  
74      /***
75       * Queries the repository to grab the wizard id.
76       *
77       * @param wizardId int the id of the wizard to extract.
78       * @throws RepositoryConversionException
79       * @throws RepositoryException
80       * @throws IllegalArgumentException      if the wizard id doesn't exist.
81       */
82      private void extractDefinition(int wizardId) throws RepositoryConversionException, RepositoryException,
83              IllegalArgumentException {
84          try {
85              myDefinition = repository.findById(wizardId);
86          } catch (ObjectNotFoundException ex) {
87              throw new IllegalArgumentException("Unable to locate the wizard definition by id of : " + wizardId);
88          }
89      }
90  
91      protected CompletionBean getDefinition() {
92          return myDefinition;
93      }
94  
95  
96  }