1 package net.sourceforge.phpdt.sql.adapters;
3 import java.util.ArrayList;
5 public class AdapterFactory {
6 public static final String GENERIC = "GENERIC";
7 public static final String ORACLE = "ORACLE";
8 public static final String POSTGRES = "POSTGRES";
9 public static final String MYSQL = "MYSQL";
10 public static final String DB2 = "DB2";
11 public static final String DB2AS400 = "DB2AS400";
12 public static final String ADABASD = "ADABASD";
14 private static AdapterFactory instance;
16 private ArrayList drivers;
18 private AdapterFactory() {
21 public static synchronized AdapterFactory getInstance() {
22 if (instance == null) {
23 instance = new AdapterFactory();
29 * Master list of supported drivers
31 private void loadDrivers() {
32 drivers = new ArrayList();
34 DriverInfo generic = new DriverInfo(GENERIC, Messages.getString("adapters.generic"), new GenericAdapter());
35 DriverInfo oracle = new DriverInfo(ORACLE, Messages.getString("adapters.oracle"), new OracleAdapter());
36 DriverInfo db2 = new DriverInfo(DB2, Messages.getString("adapters.db2"), new DB2Adapter());
37 DriverInfo db2as400 = new DriverInfo(DB2AS400, Messages.getString("adapters.db2as400"), new DB2AS400Adapter());
38 DriverInfo postgres = new DriverInfo(POSTGRES, Messages.getString("adapters.postgres"), new PostgresAdapter());
39 DriverInfo mysql = new DriverInfo(MYSQL, Messages.getString("adapters.mysql"), new MySQLAdapter());
40 DriverInfo adabasd = new DriverInfo(ADABASD, Messages.getString("adapters.adabasd"), new AdabasDAdapter());
45 drivers.add(db2as400);
46 drivers.add(postgres);
51 public synchronized DatabaseAdapter getAdapter(String type) throws NoSuchAdapterException {
52 if (drivers == null) {
55 for (int i = 0; i < drivers.size(); i++) {
56 DriverInfo info = (DriverInfo) drivers.get(i);
57 if (type.equals(info.getDriverType())) {
58 return info.getAdapter().getInstance();
61 throw new NoSuchAdapterException(type);
64 public synchronized DriverInfo[] getDriverList() {
65 DriverInfo[] driverList = new DriverInfo[drivers.size()];
66 for (int i = 0; i < drivers.size(); i++) {
67 DriverInfo info = (DriverInfo) drivers.get(i);