package net.sourceforge.phpdt.sql.adapters; import java.util.ArrayList; public class AdapterFactory { public static final String GENERIC = "GENERIC"; public static final String ORACLE = "ORACLE"; public static final String POSTGRES = "POSTGRES"; public static final String MYSQL = "MYSQL"; public static final String DB2 = "DB2"; public static final String DB2AS400 = "DB2AS400"; public static final String ADABASD = "ADABASD"; private static AdapterFactory instance; private ArrayList drivers; private AdapterFactory() { loadDrivers(); } public static synchronized AdapterFactory getInstance() { if (instance == null) { instance = new AdapterFactory(); } return instance; } /** * Master list of supported drivers */ private void loadDrivers() { drivers = new ArrayList(); DriverInfo generic = new DriverInfo(GENERIC, Messages.getString("adapters.generic"), new GenericAdapter()); DriverInfo oracle = new DriverInfo(ORACLE, Messages.getString("adapters.oracle"), new OracleAdapter()); DriverInfo db2 = new DriverInfo(DB2, Messages.getString("adapters.db2"), new DB2Adapter()); DriverInfo db2as400 = new DriverInfo(DB2AS400, Messages.getString("adapters.db2as400"), new DB2AS400Adapter()); DriverInfo postgres = new DriverInfo(POSTGRES, Messages.getString("adapters.postgres"), new PostgresAdapter()); DriverInfo mysql = new DriverInfo(MYSQL, Messages.getString("adapters.mysql"), new MySQLAdapter()); DriverInfo adabasd = new DriverInfo(ADABASD, Messages.getString("adapters.adabasd"), new AdabasDAdapter()); drivers.add(generic); drivers.add(oracle); drivers.add(db2); drivers.add(db2as400); drivers.add(postgres); drivers.add(mysql); drivers.add(adabasd); } public synchronized DatabaseAdapter getAdapter(String type) throws NoSuchAdapterException { if (drivers == null) { loadDrivers(); } for (int i = 0; i < drivers.size(); i++) { DriverInfo info = (DriverInfo) drivers.get(i); if (type.equals(info.getDriverType())) { return info.getAdapter().getInstance(); } } throw new NoSuchAdapterException(type); } public synchronized DriverInfo[] getDriverList() { DriverInfo[] driverList = new DriverInfo[drivers.size()]; for (int i = 0; i < drivers.size(); i++) { DriverInfo info = (DriverInfo) drivers.get(i); driverList[i] = info; } return driverList; } }