package com.quantum.adapters; import java.util.ArrayList; import java.util.Collections; import java.util.List; import com.quantum.Messages; /** * @author root * Basically this Factory is a Singleton that is used to return the proper adapter */ public class AdapterFactory { public static final String GENERIC = "GENERIC"; //$NON-NLS-1$ public static final String ORACLE = "ORACLE"; //$NON-NLS-1$ public static final String POSTGRES = "POSTGRES"; //$NON-NLS-1$ public static final String MYSQL = "MYSQL"; //$NON-NLS-1$ public static final String DB2 = "DB2"; //$NON-NLS-1$ public static final String DB2AS400 = "DB2AS400"; //$NON-NLS-1$ public static final String ADABASD = "ADABASD"; //$NON-NLS-1$ public static final String INFORMIX = "INFORMIX"; //$NON-NLS-1$ public static final String REDBRICK = "REDBRICK"; //$NON-NLS-1$ public static final String SYBASE = "SYBASE"; //$NON-NLS-1$ 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()); //$NON-NLS-1$ DriverInfo oracle = new DriverInfo(ORACLE, Messages.getString("adapters.oracle"), new OracleAdapter()); //$NON-NLS-1$ DriverInfo db2 = new DriverInfo(DB2, Messages.getString("adapters.db2"), new DB2Adapter()); //$NON-NLS-1$ DriverInfo db2as400 = new DriverInfo(DB2AS400, Messages.getString("adapters.db2as400"), new DB2AS400Adapter()); //$NON-NLS-1$ DriverInfo postgres = new DriverInfo(POSTGRES, Messages.getString("adapters.postgres"), new PostgresAdapter()); //$NON-NLS-1$ DriverInfo mysql = new DriverInfo(MYSQL, Messages.getString("adapters.mysql"), new GenericAdapter()); //$NON-NLS-1$ DriverInfo adabasd = new DriverInfo(ADABASD, Messages.getString("adapters.adabasd"), new AdabasDAdapter()); //$NON-NLS-1$ DriverInfo informix = new DriverInfo(INFORMIX, Messages.getString("adapters.informix"), new GenericAdapter()); //$NON-NLS-1$ DriverInfo redbrick = new DriverInfo(REDBRICK, Messages.getString("adapters.redbrick"), new RedBrickAdapter()); //$NON-NLS-1$ DriverInfo sybase = new DriverInfo(SYBASE, Messages.getString("adapters.sybase"), new GenericAdapter()); //$NON-NLS-1$ drivers.add(generic); drivers.add(oracle); drivers.add(db2); drivers.add(db2as400); drivers.add(postgres); drivers.add(mysql); drivers.add(adabasd); drivers.add(informix); drivers.add(redbrick); drivers.add(sybase); } public synchronized DatabaseAdapter getAdapter(String type){ 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(); } } // If its not a recognized driver, we return the generic one for (int i = 0; i < drivers.size(); i++) { DriverInfo info = (DriverInfo) drivers.get(i); if (type.equals(GENERIC)) { return info.getAdapter(); } } return null; } public synchronized DriverInfo[] getDriverList() { List list = new ArrayList(this.drivers); Collections.sort(list); return (DriverInfo[]) list.toArray(new DriverInfo[list.size()]); } }