1 package com.explosion.expfmodules.rdbmsconn;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.HashMap;
23 import java.util.prefs.Preferences;
24
25 import com.explosion.utilities.preferences.Preference;
26 import com.explosion.utilities.preferences.groups.PreferenceGroup;
27 import com.explosion.utilities.preferences.groups.PreferenceGroupManager;
28
29 /***
30 * @author Stephen Cowx
31 * Date created:@25-Jan-2003
32 */
33 public class ConnectionDescriptorManager extends PreferenceGroupManager
34 {
35
36 private DriverDescriptorManager driverManager;
37
38 /***
39 * Contructor for this.
40 * @param driverManager
41 * @param referenceToStore
42 * @throws Exception
43 */
44 public ConnectionDescriptorManager(DriverDescriptorManager driverManager, Object referenceToStore) throws Exception
45 {
46 super(referenceToStore);
47 this.driverManager = driverManager;
48 loadUsing(referenceToStore);
49 }
50
51 /***
52 *
53 */
54 public void loadUsing(Object referenceToStore) throws Exception
55 {
56
57
58
59 if (getReferenceToStore() instanceof Preferences)
60 {
61 Preferences root = (Preferences) getReferenceToStore();
62
63 String[] names = root.childrenNames();
64
65 for (int i=0;i<names.length;i++)
66 {
67
68 this.addGroup(names[i], createGroup(names[i]));
69 }
70 }
71 }
72
73 /***
74 * Return the correct node for the group with the given identifier
75 * @param identifier
76 * @return
77 */
78 public Object getReferenceForGroup(String identifier)
79 {
80 if (getReferenceToStore() instanceof Preferences)
81 {
82 Preferences pref = (Preferences) getReferenceToStore();
83 return pref.node(identifier);
84 }
85 else
86 {
87 return new HashMap();
88 }
89
90 }
91
92 /***
93 * This method creates a new ConnectionPersistentObject
94 */
95 public PreferenceGroup createGroup(String identifier) throws Exception
96 {
97 Object correctReferenceForThisGroup = getReferenceForGroup(identifier);
98
99
100 Preference url = new Preference(RdbmsConnConstants.CD_URL, Preference.PROPERTY_TYPE_TEXT, "", correctReferenceForThisGroup);
101 ConnectionDescriptorPreference driver = new ConnectionDescriptorPreference(RdbmsConnConstants.CD_DRIVER, Preference.PROPERTY_TYPE_STRING_CHOICE, "", correctReferenceForThisGroup, this.driverManager);
102 Preference user = new Preference(RdbmsConnConstants.CD_USER, Preference.PROPERTY_TYPE_TEXT, "", correctReferenceForThisGroup);
103 Preference pass = new Preference(RdbmsConnConstants.CD_PASS, Preference.PROPERTY_TYPE_ENCRYPTED, "", correctReferenceForThisGroup);
104
105
106 url.setLongName("Connect string");
107 url.setDescription("The connection url may be different for each driver. Essentially it provides information as to the location of the database.");
108 user.setLongName("Username");
109 user.setDescription("The username to be used when connecting to the database.");
110 pass.setLongName("Password");
111 pass.setDescription("The password to be used when connecting to the database.");
112 driver.setLongName("Driver");
113 driver.setDescription("The driver refers to the JDBC driver to be used for this connection.");
114
115
116 driver.setChoiceValues(driverManager.getIdentifiers());
117
118
119 PreferenceGroup persistentDescriptor = new PreferenceGroup( correctReferenceForThisGroup, identifier);
120 persistentDescriptor.addPreference(RdbmsConnConstants.CD_DRIVER, driver);
121 persistentDescriptor.addPreference(RdbmsConnConstants.CD_URL, url);
122 persistentDescriptor.addPreference(RdbmsConnConstants.CD_USER, user);
123 persistentDescriptor.addPreference(RdbmsConnConstants.CD_PASS, pass);
124
125 return persistentDescriptor;
126 }
127 }
128