Lines 20-31
Link Here
|
20 |
import java.sql.DriverManager; |
20 |
import java.sql.DriverManager; |
21 |
import java.sql.SQLException; |
21 |
import java.sql.SQLException; |
22 |
import java.text.MessageFormat; |
22 |
import java.text.MessageFormat; |
|
|
23 |
import java.util.Collection; |
23 |
import java.util.Collections; |
24 |
import java.util.Collections; |
24 |
import java.util.HashSet; |
25 |
import java.util.HashSet; |
25 |
import java.util.Iterator; |
26 |
import java.util.Iterator; |
26 |
import java.util.Properties; |
27 |
import java.util.Properties; |
27 |
import java.util.ResourceBundle; |
28 |
import java.util.ResourceBundle; |
28 |
import java.util.Set; |
29 |
import java.util.Set; |
|
|
30 |
import org.openide.ErrorManager; |
31 |
import org.openide.util.Lookup; |
32 |
import org.openide.util.LookupEvent; |
33 |
import org.openide.util.LookupListener; |
29 |
|
34 |
|
30 |
import org.openide.util.NbBundle; |
35 |
import org.openide.util.NbBundle; |
31 |
import org.openide.util.RequestProcessor; |
36 |
import org.openide.util.RequestProcessor; |
Lines 91-116
Link Here
|
91 |
public static final String PROP_DRIVERNAME = "drivername"; //NOI18N |
96 |
public static final String PROP_DRIVERNAME = "drivername"; //NOI18N |
92 |
public static final String PROP_NAME = "name"; //NOI18N |
97 |
public static final String PROP_NAME = "name"; //NOI18N |
93 |
|
98 |
|
94 |
OpenConnectionInterface openConnection; |
99 |
private OpenConnectionInterface openConnection; |
95 |
|
100 |
|
96 |
/** Default constructor */ |
101 |
static private final Lookup.Result openConnectionLookupResult; |
97 |
public DatabaseConnection() { |
102 |
static private Collection openConnectionServices = null; |
98 |
propertySupport = new PropertyChangeSupport(this); |
103 |
static { |
99 |
|
104 |
openConnectionLookupResult = Lookup.getDefault().lookup(new Lookup.Template(OpenConnectionInterface.class)); |
100 |
// For Java Studio Enterprise. Create instanceof OpenConnection |
105 |
openConnectionLookupResult.addLookupListener(new LookupListener() { |
101 |
try { |
106 |
public void resultChanged(LookupEvent ev) { |
102 |
ClassLoader cl = Thread.currentThread().getContextClassLoader(); |
107 |
synchronized (DatabaseConnection.class) { |
103 |
try { |
108 |
openConnectionServices = null; |
104 |
openConnection = (OpenConnectionInterface) Class.forName(bundle.getString("CLASS_open_connection"), true, cl).newInstance(); |
|
|
105 |
} catch(ClassNotFoundException cnfe) { |
106 |
org.openide.ErrorManager.getDefault().log(cnfe.getMessage()); |
107 |
} |
109 |
} |
108 |
if (openConnection == null) { |
|
|
109 |
openConnection = (OpenConnectionInterface) Class.forName(bundle.getString("CLASS_open_connection")).newInstance(); |
110 |
} |
110 |
} |
111 |
} catch(Exception ex) { |
111 |
}); |
112 |
org.openide.ErrorManager.getDefault().notify(ex); |
|
|
113 |
} |
112 |
} |
|
|
113 |
|
114 |
/** Default constructor */ |
115 |
public DatabaseConnection() { |
116 |
propertySupport = new PropertyChangeSupport(this); |
117 |
openConnection = new OpenConnection(); |
114 |
} |
118 |
} |
115 |
|
119 |
|
116 |
/** Advanced constructor |
120 |
/** Advanced constructor |
Lines 128-133
Link Here
|
128 |
pwd = password; |
132 |
pwd = password; |
129 |
name = null; |
133 |
name = null; |
130 |
name = getName(); |
134 |
name = getName(); |
|
|
135 |
|
136 |
// For Java Studio Enterprise. Create instanceof OpenConnection |
137 |
try { |
138 |
Collection c = getOpenConnections(); |
139 |
for (Iterator i=c.iterator(); driver != null && i.hasNext();) { |
140 |
OpenConnectionInterface oci = (OpenConnectionInterface) i.next(); |
141 |
if (oci.isFor(driver)) { |
142 |
openConnection = oci; |
143 |
break; |
144 |
} |
145 |
} |
146 |
} catch(Exception ex) { |
147 |
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); |
148 |
} |
149 |
} |
150 |
|
151 |
private Collection getOpenConnections() { |
152 |
if (openConnectionServices == null) { |
153 |
openConnectionServices = openConnectionLookupResult.allInstances(); |
154 |
} |
155 |
return openConnectionServices; |
131 |
} |
156 |
} |
132 |
|
157 |
|
133 |
/** Returns driver URL */ |
158 |
/** Returns driver URL */ |