1 package com.explosion.expfmodules.rdbmsconn.connectwizard.actions;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 /***
23 * @author Stephen Cowx
24 * Created on 21-Feb-2005
25 */
26 import java.util.Properties;
27
28 import com.explosion.expf.Application;
29 import com.explosion.expfmodules.rdbmsconn.RdbmsConnModuleManager;
30 import com.explosion.expfmodules.rdbmsconn.connectwizard.ConnectNow;
31 import com.explosion.expfmodules.wizard.StepAction;
32 import com.explosion.expfmodules.wizard.Wizard;
33 import com.explosion.expfmodules.wizard.standard.PreferenceDataItem;
34 import com.explosion.utilities.exception.ExceptionManagerFactory;
35 import com.explosion.utilities.preferences.groups.PreferenceGroup;
36
37 public class SaveConnectionAction implements StepAction {
38
39 /***
40 * Creates a MySQL database connection based on the information
41 * collected in the wizard.
42 */
43 public boolean execute(Wizard wizard) {
44
45 try {
46
47
48 String connectionName = (String) ((PreferenceDataItem) wizard.getWizardDataValues().get("connectionname")).getPreference().getValue();
49 boolean connectNow = ((Boolean) ((PreferenceDataItem) wizard.getWizardDataValues().get("connectnow")).getPreference().getValue()).booleanValue();
50 PreferenceGroup descriptor = (PreferenceGroup) wizard.getWizardDataValues().get("connection_descriptor");
51
52 descriptor.setIdentifier(connectionName);
53 RdbmsConnModuleManager.instance().getConnectionDescriptorManager().addGroup(connectionName, descriptor);
54 descriptor.commit();
55
56 if (connectNow)
57 {
58 Properties properties = Application.getInstance().getPropertiesForModule(RdbmsConnModuleManager.class.getName());
59 properties.list(System.out);
60 String className = properties.getProperty("connectionwizard.connectNowClassName");
61 if (className != null)
62 {
63 ConnectNow connectNowClass = (ConnectNow) Class.forName(className).newInstance();
64 connectNowClass.connect(descriptor);
65 }
66 }
67
68 return true;
69
70 } catch (Exception e) {
71 ExceptionManagerFactory.getExceptionManager().manageException(e, "Error:");
72 }
73
74 return false;
75
76 }
77 }