|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| package jtr.config; |
|
8 |
| |
|
9 |
| import jtr.assigner.IFactory; |
|
10 |
| |
|
11 |
| import java.util.*; |
|
12 |
| import org.apache.log4j.Logger; |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| public class RegisteredFactories { |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
12
| public synchronized static void registerFactory(String key, String fqn) throws RegistrationFailedException {
|
|
36 |
12
| try {
|
|
37 |
12
| logger.debug("Trying to register a new IFactory: [" + "key=" + key + ", fqn= " + fqn + "]");
|
|
38 |
12
| Class clazz = Class.forName(fqn, true, Thread.currentThread().getContextClassLoader());
|
|
39 |
12
| logger.debug("Class " + fqn + " loaded");
|
|
40 |
12
| try {
|
|
41 |
12
| registerFactory(key, (IFactory) clazz.newInstance());
|
|
42 |
12
| logger.debug("Class " + fqn + " instantiated & registered!");
|
|
43 |
| } catch (IllegalAccessException e) { |
|
44 |
0
| String msg = "Unable to initialize the specified class: " + fqn + ". Please, check security constraints";
|
|
45 |
0
| RegistrationFailedException rfe = new RegistrationFailedException(msg, e);
|
|
46 |
0
| logger.fatal(msg, rfe);
|
|
47 |
0
| throw rfe;
|
|
48 |
| } catch (InstantiationException e) { |
|
49 |
0
| String msg = "Unable to initialize the specified class: " + fqn + ". Please, check security constraints";
|
|
50 |
0
| RegistrationFailedException rfe = new RegistrationFailedException(msg, e);
|
|
51 |
0
| logger.fatal(msg, rfe);
|
|
52 |
0
| throw rfe;
|
|
53 |
| } |
|
54 |
| } catch (ClassNotFoundException e) { |
|
55 |
0
| String msg = "Unable to find the specified class: " + fqn + ". Please, check classpath settings or the specified fqn";
|
|
56 |
0
| RegistrationFailedException rfe = new RegistrationFailedException(msg, e);
|
|
57 |
0
| logger.fatal(msg, rfe);
|
|
58 |
0
| throw rfe;
|
|
59 |
| } |
|
60 |
| } |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
12
| public synchronized static void registerFactory(String key, IFactory instace) {
|
|
72 |
12
| factories.put(key, instace);
|
|
73 |
| } |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
148
| public synchronized static IFactory getFactory(String key) {
|
|
84 |
148
| if (factories.containsKey(key)) {
|
|
85 |
148
| return (IFactory) factories.get(key);
|
|
86 |
| } else { |
|
87 |
0
| String msg = "Unable to locate concrete factory for service "+key+".\n"+
|
|
88 |
| "Please, check your factories section in your jtr.xml file."; |
|
89 |
0
| throw new MissingFactoryException(msg);
|
|
90 |
| } |
|
91 |
| } |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
| public static final String IASSIGNMENT_POLICY_FACTORY = "IAssignmentPolicyFactory"; |
|
98 |
| |
|
99 |
| |
|
100 |
| |
|
101 |
| |
|
102 |
| |
|
103 |
| public static final String IOUTCOME_FACTORY = "IOutcomeFactory"; |
|
104 |
| |
|
105 |
| |
|
106 |
| |
|
107 |
| |
|
108 |
| |
|
109 |
| public static final String IWSHELPER_FACTORY = "IWsHelperFactory"; |
|
110 |
| |
|
111 |
| |
|
112 |
| |
|
113 |
| |
|
114 |
| |
|
115 |
| public static final String ITEST_RESULT_DISPLAYER = "ITestResultDisplayer"; |
|
116 |
| |
|
117 |
| |
|
118 |
| |
|
119 |
| |
|
120 |
| |
|
121 |
| public static final String ITEST_COMPLETION_LISTENER = "ITestCompletionListener"; |
|
122 |
| |
|
123 |
| |
|
124 |
| |
|
125 |
| |
|
126 |
| |
|
127 |
| public static final String ITEST_SNAPSHOT_FACTORY = "ITestSnapshotFactory"; |
|
128 |
| |
|
129 |
| |
|
130 |
| |
|
131 |
| |
|
132 |
| |
|
133 |
| public static final String ITEST_RESULTS_EXPORTER = "ITestResultsExporter"; |
|
134 |
| |
|
135 |
| private static HashMap<String,IFactory> factories = new HashMap<String,IFactory>(); |
|
136 |
| |
|
137 |
| private static final Logger logger = Logger.getLogger(RegisteredFactories.class); |
|
138 |
| } |