1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sourceforge.jwebunit.util;
20
21 import java.util.Hashtable;
22
23 import net.sourceforge.jwebunit.api.ITestingEngine;
24 import net.sourceforge.jwebunit.exception.TestingEngineRegistryException;
25
26
27
28
29
30
31 public class TestingEngineRegistry {
32
33
34
35
36 public final static String TESTING_ENGINE_HTMLUNIT = "TestingEngineHtmlUnit";
37
38
39
40
41 public final static String TESTING_ENGINE_WEBDRIVER = "TestingEngineWebdriver";
42
43 private static Hashtable<String,Class<?>> testingEngineMap = new Hashtable<String,Class<?>>();
44
45 static {
46 String cp = "net.sourceforge.jwebunit.htmlunit.HtmlUnitTestingEngineImpl";
47
48 try {
49 addTestingEngine(TESTING_ENGINE_HTMLUNIT, cp);
50 } catch (ClassNotFoundException e) {
51
52 }
53 cp = "net.sourceforge.jwebunit.webdriver.WebDriverTestingEngineImpl";
54
55 try {
56 addTestingEngine(TESTING_ENGINE_WEBDRIVER, cp);
57 } catch (ClassNotFoundException e) {
58
59 }
60 }
61
62
63
64
65
66
67
68 public static Class<?> getTestingEngineClass(String aKey)
69 throws ClassNotFoundException {
70 Class<?> theClass = (Class<?>) testingEngineMap.get(aKey);
71 return theClass;
72 }
73
74
75
76
77
78
79
80
81 public static void addTestingEngine(String key, String classpath)
82 throws ClassNotFoundException {
83 Class<?> c = Class.forName(classpath);
84 if (ITestingEngine.class.isAssignableFrom(c)) {
85 testingEngineMap.put(key, c);
86 } else {
87 throw new TestingEngineRegistryException(classpath
88 + " is not an instance of ITestingEngine");
89 }
90 }
91
92
93
94
95
96
97 public static String getFirstAvailable() {
98 if (testingEngineMap.isEmpty()) {
99 return null;
100 } else {
101 return (String) testingEngineMap.keys().nextElement();
102 }
103 }
104
105 }