1 package com.sri.emo.wizard.branch; 2 3 import com.sri.emo.wizard.AbstractWizard; 4 import com.sri.emo.wizard.WizardMonitor; 5 import com.jcorporate.expresso.core.db.DBException; 6 import com.sri.emo.wizard.WizardPage; 7 import java.util.List; 8 import com.sri.emo.wizard.Wizard; 9 import com.sri.emo.dbobj.WizDefinition; 10 import java.lang.reflect.*; 11 import com.sri.emo.wizard.defaults.Log4jWizMonitor; 12 import java.util.Iterator; 13 import com.sri.emo.wizard.selection.DisplaySummaryPage; 14 import com.sri.emo.wizard.selection.EmoSelectionWizardFactory; 15 import com.sri.emo.controller.CreationWizardAction; 16 import com.sri.emo.wizard.expressoimpl.ExpressoLink; 17 import com.jcorporate.expresso.core.controller.Transition; 18 19 /*** 20 * <p>Title: </p> 21 * 22 * <p>Description: </p> 23 * 24 * <p>Copyright: Copyright (c) 2003</p> 25 * 26 * <p>Company: </p> 27 * 28 * @author not attributable 29 * @version 1.0 30 */ 31 public class EmoBranchingWizardFactory extends EmoSelectionWizardFactory { 32 public EmoBranchingWizardFactory() { 33 } 34 35 /*** 36 * Constructs the wizard itself. 37 * 38 * @param definition the WizDefinition dbobject for this wizard. 39 * @param steps the List of steps that were constructed previously in 40 * the constructSteps function. 41 * @return fully constructed Wizard instance. 42 * @throws DBException upon database exception error. 43 */ 44 protected Wizard constructWizard(final WizDefinition definition, 45 final List branchNodes) throws DBException { 46 String wizardClassString = definition.getWizardClass(); 47 Class wizardClass; 48 try { 49 wizardClass = Thread.currentThread().getContextClassLoader() 50 .loadClass(wizardClassString); 51 if (!BranchingWizard.class.isAssignableFrom(wizardClass)) { 52 throw new IllegalArgumentException("If you do not" 53 + " implement a wizard" 54 + 55 " that derives from SequentialWizard and uses the same " 56 + 57 "constructor then you need to implement your own" 58 + 59 " Wizard Factory implementation"); 60 61 } 62 63 Constructor c = wizardClass.getConstructor(new Class[] { 64 WizardMonitor.class, BranchNode[].class}); 65 AbstractWizard emoWizard = (AbstractWizard) c 66 .newInstance( 67 new Object[] {constructMonitor(), 68 (BranchNode[]) branchNodes. 69 toArray( 70 new BranchNode[branchNodes.size()])}); 71 72 emoWizard.setId(new Integer(definition.getId())); 73 emoWizard.setTitle(definition.getWizName()); 74 emoWizard.setSummary(definition.getSummary()); 75 setWizardForStepsThatNeedIt(emoWizard, branchNodes); 76 return emoWizard; 77 } catch (ClassNotFoundException ex) { 78 throw new IllegalArgumentException("Unknown class: " 79 + wizardClassString 80 + 81 " edit your wizard definition to solve this problem"); 82 } catch (InvocationTargetException ex) { 83 throw new DBException("An Exception was thrown constructing the " + 84 "wizard", ex); 85 } catch (IllegalAccessException ex) { 86 throw new IllegalArgumentException("The wizard specified: " 87 + wizardClassString + 88 " does not have a public constructor" 89 + 90 " like the default. You may need to implement your own " 91 + "wizard factory."); 92 } catch (InstantiationException ex) { 93 throw new DBException("There was an error constructing your " 94 + "wizard.", ex); 95 } catch (NoSuchMethodException ex) { 96 throw new IllegalArgumentException("No appropriate constructor" 97 + " found:" + ex.getMessage()); 98 } 99 100 } 101 102 private void setWizardForStepsThatNeedIt(final Wizard constructedWizard, 103 final List steps) { 104 for (Iterator i = steps.iterator(); i.hasNext(); ) { 105 BranchNode oneStep = (BranchNode) i.next(); 106 107 if (oneStep.getPage() instanceof DisplaySummaryPage) { 108 ((DisplaySummaryPage) oneStep.getPage()).setMyOwner(constructedWizard); 109 } 110 } 111 112 } 113 114 }