Index: DatabaseConnection.java =================================================================== RCS file: /cvs/db/src/org/netbeans/modules/db/explorer/DatabaseConnection.java,v retrieving revision 1.33 diff -u -b -r1.33 DatabaseConnection.java --- DatabaseConnection.java 25 Mar 2005 07:40:17 -0000 1.33 +++ DatabaseConnection.java 25 Mar 2005 09:12:29 -0000 @@ -20,12 +20,17 @@ import java.sql.DriverManager; import java.sql.SQLException; import java.text.MessageFormat; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.Properties; import java.util.ResourceBundle; import java.util.Set; +import org.openide.ErrorManager; +import org.openide.util.Lookup; +import org.openide.util.LookupEvent; +import org.openide.util.LookupListener; import org.openide.util.NbBundle; import org.openide.util.RequestProcessor; @@ -91,26 +96,25 @@ public static final String PROP_DRIVERNAME = "drivername"; //NOI18N public static final String PROP_NAME = "name"; //NOI18N - OpenConnectionInterface openConnection; + private OpenConnectionInterface openConnection; - /** Default constructor */ - public DatabaseConnection() { - propertySupport = new PropertyChangeSupport(this); - - // For Java Studio Enterprise. Create instanceof OpenConnection - try { - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - try { - openConnection = (OpenConnectionInterface) Class.forName(bundle.getString("CLASS_open_connection"), true, cl).newInstance(); - } catch(ClassNotFoundException cnfe) { - org.openide.ErrorManager.getDefault().log(cnfe.getMessage()); + static private final Lookup.Result openConnectionLookupResult; + static private Collection openConnectionServices = null; + static { + openConnectionLookupResult = Lookup.getDefault().lookup(new Lookup.Template(OpenConnectionInterface.class)); + openConnectionLookupResult.addLookupListener(new LookupListener() { + public void resultChanged(LookupEvent ev) { + synchronized (DatabaseConnection.class) { + openConnectionServices = null; } - if (openConnection == null) { - openConnection = (OpenConnectionInterface) Class.forName(bundle.getString("CLASS_open_connection")).newInstance(); } - } catch(Exception ex) { - org.openide.ErrorManager.getDefault().notify(ex); + }); } + + /** Default constructor */ + public DatabaseConnection() { + propertySupport = new PropertyChangeSupport(this); + openConnection = new OpenConnection(); } /** Advanced constructor @@ -128,6 +132,27 @@ pwd = password; name = null; name = getName(); + + // For Java Studio Enterprise. Create instanceof OpenConnection + try { + Collection c = getOpenConnections(); + for (Iterator i=c.iterator(); driver != null && i.hasNext();) { + OpenConnectionInterface oci = (OpenConnectionInterface) i.next(); + if (oci.isFor(driver)) { + openConnection = oci; + break; + } + } + } catch(Exception ex) { + ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); + } + } + + private Collection getOpenConnections() { + if (openConnectionServices == null) { + openConnectionServices = openConnectionLookupResult.allInstances(); + } + return openConnectionServices; } /** Returns driver URL */ Index: OpenConnection.java =================================================================== RCS file: /cvs/db/src/org/netbeans/modules/db/explorer/OpenConnection.java,v retrieving revision 1.2 diff -u -b -r1.2 OpenConnection.java --- OpenConnection.java 8 Feb 2005 07:36:57 -0000 1.2 +++ OpenConnection.java 25 Mar 2005 09:12:29 -0000 @@ -22,6 +22,10 @@ /** Creates a new instance of OpenConnection */ public OpenConnection() { } + + public boolean isFor(String driverName) { + return true; + } public void enable() { // No implementation in open source. Index: OpenConnectionInterface.java =================================================================== RCS file: /cvs/db/src/org/netbeans/modules/db/explorer/OpenConnectionInterface.java,v retrieving revision 1.2 diff -u -b -r1.2 OpenConnectionInterface.java --- OpenConnectionInterface.java 8 Feb 2005 07:36:57 -0000 1.2 +++ OpenConnectionInterface.java 25 Mar 2005 09:12:29 -0000 @@ -18,6 +18,7 @@ * @author Administrator */ public interface OpenConnectionInterface { + public boolean isFor(String driverName); public void enable(); public void disable(); }