1 package com.quantum.adapters;
3 import java.util.ArrayList;
4 import java.util.Collections;
7 import com.quantum.Messages;
11 * Basically this Factory is a Singleton that is used to return the proper adapter
13 public class AdapterFactory {
14 public static final String GENERIC = "GENERIC"; //$NON-NLS-1$
15 public static final String ORACLE = "ORACLE"; //$NON-NLS-1$
16 public static final String POSTGRES = "POSTGRES"; //$NON-NLS-1$
17 public static final String MYSQL = "MYSQL"; //$NON-NLS-1$
18 public static final String DB2 = "DB2"; //$NON-NLS-1$
19 public static final String DB2AS400 = "DB2AS400"; //$NON-NLS-1$
20 public static final String ADABASD = "ADABASD"; //$NON-NLS-1$
21 public static final String INFORMIX = "INFORMIX"; //$NON-NLS-1$
22 public static final String REDBRICK = "REDBRICK"; //$NON-NLS-1$
23 public static final String SYBASE = "SYBASE"; //$NON-NLS-1$
25 private static AdapterFactory instance;
27 private ArrayList drivers;
29 private AdapterFactory() {
32 public static synchronized AdapterFactory getInstance() {
33 if (instance == null) {
34 instance = new AdapterFactory();
40 * Master list of supported drivers
42 private void loadDrivers() {
43 drivers = new ArrayList();
45 DriverInfo generic = new DriverInfo(GENERIC, Messages.getString("adapters.generic"), new GenericAdapter()); //$NON-NLS-1$
46 DriverInfo oracle = new DriverInfo(ORACLE, Messages.getString("adapters.oracle"), new OracleAdapter()); //$NON-NLS-1$
47 DriverInfo db2 = new DriverInfo(DB2, Messages.getString("adapters.db2"), new DB2Adapter()); //$NON-NLS-1$
48 DriverInfo db2as400 = new DriverInfo(DB2AS400, Messages.getString("adapters.db2as400"), new DB2AS400Adapter()); //$NON-NLS-1$
49 DriverInfo postgres = new DriverInfo(POSTGRES, Messages.getString("adapters.postgres"), new PostgresAdapter()); //$NON-NLS-1$
50 DriverInfo mysql = new DriverInfo(MYSQL, Messages.getString("adapters.mysql"), new GenericAdapter()); //$NON-NLS-1$
51 DriverInfo adabasd = new DriverInfo(ADABASD, Messages.getString("adapters.adabasd"), new AdabasDAdapter()); //$NON-NLS-1$
52 DriverInfo informix = new DriverInfo(INFORMIX, Messages.getString("adapters.informix"), new GenericAdapter()); //$NON-NLS-1$
53 DriverInfo redbrick = new DriverInfo(REDBRICK, Messages.getString("adapters.redbrick"), new RedBrickAdapter()); //$NON-NLS-1$
54 DriverInfo sybase = new DriverInfo(SYBASE, Messages.getString("adapters.sybase"), new GenericAdapter()); //$NON-NLS-1$
59 drivers.add(db2as400);
60 drivers.add(postgres);
63 drivers.add(informix);
64 drivers.add(redbrick);
68 public synchronized DatabaseAdapter getAdapter(String type){
69 if (drivers == null) {
72 for (int i = 0; i < drivers.size(); i++) {
73 DriverInfo info = (DriverInfo) drivers.get(i);
74 if (type.equals(info.getDriverType())) {
75 return info.getAdapter();
78 // If its not a recognized driver, we return the generic one
79 for (int i = 0; i < drivers.size(); i++) {
80 DriverInfo info = (DriverInfo) drivers.get(i);
81 if (type.equals(GENERIC)) {
82 return info.getAdapter();
88 public synchronized DriverInfo[] getDriverList() {
89 List list = new ArrayList(this.drivers);
90 Collections.sort(list);
91 return (DriverInfo[]) list.toArray(new DriverInfo[list.size()]);