1 package com.quantum.wizards;
3 import java.util.ArrayList;
4 import java.util.Arrays;
7 import com.quantum.adapters.AdapterFactory;
8 import com.quantum.model.JDBCDriver;
10 import org.eclipse.swt.widgets.Composite;
16 public class URLSetupControlFactory {
18 public static boolean hasControl(JDBCDriver driver) {
19 return null != getControlClass(driver);
22 public static URLSetupControl create(JDBCDriver driver, Composite composite) {
23 Class controlClass = getControlClass(driver);
25 if (BasicThreePartURLSetupControl.class == controlClass) {
26 URLSetupControl control = new BasicThreePartURLSetupControl(composite, driver);
29 } else if (BasicOnePartURLSetupControl.class == controlClass) {
30 String[] properties = getProperties(driver);
31 URLSetupControl control = new BasicOnePartURLSetupControl(composite, driver, properties[0]);
34 } else if (InformixURLSetupControl.class == controlClass) {
35 URLSetupControl control = new InformixURLSetupControl(composite, driver);
43 private static Class getControlClass(JDBCDriver driver) {
44 String[] parameters = getProperties(driver);
45 List parametersList = new ArrayList();
46 if (parameters != null) {
47 parametersList.addAll(Arrays.asList(parameters));
50 if (parametersList.size() == 3
51 && parametersList.contains("dbname")
52 && parametersList.contains("hostname")
53 && parametersList.contains("port")) {
54 return BasicThreePartURLSetupControl.class;
55 } else if (parametersList.size() == 4
56 && parametersList.contains("dbname")
57 && parametersList.contains("hostname")
58 && parametersList.contains("informixserver")
59 && parametersList.contains("port")) {
60 return InformixURLSetupControl.class;
61 } else if (parametersList.size() == 1
62 && (parametersList.contains("dbname")
63 || parametersList.contains("datasource"))) {
64 return BasicOnePartURLSetupControl.class;
74 private static String[] getProperties(JDBCDriver driver) {
75 String driverClassName = driver.getClassName();
76 String urlPattern = AdapterFactory.getInstance().getURLPattern(driverClassName);
77 String[] parameters = URLBuilder.getVariableNames(urlPattern);