1 19 20 package org.netbeans.modules.db.runtime; 21 22 import java.util.Collection ; 23 import java.util.Iterator ; 24 import java.util.LinkedList ; 25 import java.util.List ; 26 import javax.swing.SwingUtilities ; 27 import org.netbeans.spi.db.explorer.DatabaseRuntime; 28 import org.openide.ErrorManager; 29 import org.openide.filesystems.FileObject; 30 import org.openide.filesystems.Repository; 31 import org.openide.loaders.DataFolder; 32 import org.openide.loaders.FolderLookup; 33 import org.openide.util.Lookup; 34 35 36 45 public final class DatabaseRuntimeManager { 46 47 private static final ErrorManager LOGGER = ErrorManager.getDefault().getInstance(DatabaseRuntimeManager.class.getName()); 48 private static final boolean LOG = LOGGER.isLoggable(ErrorManager.INFORMATIONAL); 49 50 53 private static final String RUNTIMES_PATH = "Databases/Runtimes"; 55 58 private static DatabaseRuntimeManager DEFAULT = null; 59 60 63 private Lookup.Result result = getLookupResult(); 64 65 68 public static synchronized DatabaseRuntimeManager getDefault() { 69 if (DEFAULT == null) { 70 DEFAULT = new DatabaseRuntimeManager(); 71 } 72 return DEFAULT; 73 } 74 75 public DatabaseRuntime[] getRuntimes() { 76 Collection runtimes = result.allInstances(); 77 return (DatabaseRuntime[])runtimes.toArray(new DatabaseRuntime[runtimes.size()]); 78 } 79 80 90 public DatabaseRuntime[] getRuntimes(String jdbcDriverClassName) { 91 if (jdbcDriverClassName == null) { 92 throw new NullPointerException (); 93 } 94 List runtimeList = new LinkedList (); 95 for (Iterator i = result.allInstances().iterator(); i.hasNext();) { 96 DatabaseRuntime runtime = (DatabaseRuntime)i.next(); 97 if (LOG) { 98 LOGGER.log(ErrorManager.INFORMATIONAL, "Runtime: " + runtime.getClass().getName() + " for driver " + runtime.getJDBCDriverClass()); } 100 if (jdbcDriverClassName.equals(runtime.getJDBCDriverClass())) { 101 runtimeList.add(runtime); 102 } 103 } 104 return (DatabaseRuntime[])runtimeList.toArray(new DatabaseRuntime[runtimeList.size()]); 105 } 106 107 private synchronized Lookup.Result getLookupResult() { 108 if (result == null) { 109 FileObject fo = Repository.getDefault().getDefaultFileSystem().findResource(RUNTIMES_PATH); 110 DataFolder folder = DataFolder.findFolder(fo); 111 result = new FolderLookup(folder).getLookup().lookup(new Lookup.Template(DatabaseRuntime.class)); 112 } 113 return result; 114 } 115 } 116 | Popular Tags |