6
6
import oracle .sql .STRUCT ;
7
7
import org .utplsql .api .compatibility .CompatibilityProxy ;
8
8
9
- import java .sql .Connection ;
10
9
import java .sql .SQLException ;
11
- import java .util .Arrays ;
12
10
import java .util .HashMap ;
13
11
import java .util .Map ;
14
12
import java .util .function .BiFunction ;
15
13
16
14
/** This class manages the instantiation of reporters.
17
15
* One can register a supplier method for a specific name which will then be callable via createReporter(name)
18
16
*
17
+ * Use the static createEmpty or createDefault methods to get a new instance.
18
+ * We don't allow direct instantiation because we want
19
+ * <ul>
20
+ * <li>Register default ReporterFactoryMethods for Core-Reporters</li>
21
+ * <li>Be able to add more than one ReporterFactory implementation due to backwards-compatibility in future</li>
22
+ * </ul>
23
+ *
19
24
* @author pesse
20
25
*/
21
26
public final class ReporterFactory implements ORADataFactory {
22
27
23
- public static class ReporterInfo {
24
- public ReporterInfo (BiFunction <String , Object [], ? extends Reporter > factoryMethod , String description ) {
28
+ public static class ReporterFactoryMethodInfo {
29
+ public ReporterFactoryMethodInfo (BiFunction <String , Object [], ? extends Reporter > factoryMethod , String description ) {
25
30
this .factoryMethod = factoryMethod ;
26
31
this .description = description ;
27
32
}
28
33
public BiFunction <String , Object [], ? extends Reporter > factoryMethod ;
29
34
public String description ;
30
35
}
31
36
32
- private Map <String , ReporterInfo > reportFactoryMethodMap = new HashMap <>();
33
-
34
- ReporterFactory () {
37
+ private Map <String , ReporterFactoryMethodInfo > reportFactoryMethodMap = new HashMap <>();
35
38
36
- }
39
+ ReporterFactory () { }
37
40
38
41
/** Registers a creation method for a specified reporter name. Overrides eventually existing creation method
39
42
*
@@ -42,19 +45,28 @@ public ReporterInfo(BiFunction<String, Object[], ? extends Reporter> factoryMeth
42
45
* @param description the description of the reporter
43
46
* @return Object with information about the registered reporter
44
47
*/
45
- public synchronized ReporterInfo registerReporterFactoryMethod ( String reporterName , BiFunction <String , Object [], ? extends Reporter > factoryMethod , String description ) {
46
- return reportFactoryMethodMap .put (reporterName .toUpperCase (), new ReporterInfo (factoryMethod , description ));
48
+ public synchronized ReporterFactoryMethodInfo registerReporterFactoryMethod (String reporterName , BiFunction <String , Object [], ? extends Reporter > factoryMethod , String description ) {
49
+ return reportFactoryMethodMap .put (reporterName .toUpperCase (), new ReporterFactoryMethodInfo (factoryMethod , description ));
47
50
}
48
51
49
52
/** Unregisters a specified reporter name.
50
53
*
51
54
* @param reporterName the reporter's name to unregister
52
55
* @return information about the reporter which was previously registered or null
53
56
*/
54
- public synchronized ReporterInfo unregisterReporterFactoryMethod ( String reporterName ) {
57
+ public synchronized ReporterFactoryMethodInfo unregisterReporterFactoryMethod (String reporterName ) {
55
58
return reportFactoryMethodMap .remove (reporterName .toUpperCase ());
56
59
}
57
60
61
+ /** Checks whether a given reporter has a registered FactoryMethod or not
62
+ *
63
+ * @param reporterName the reporter's name
64
+ * @return true or false
65
+ */
66
+ public synchronized boolean hasRegisteredFactoryMethodFor ( String reporterName ) {
67
+ return reportFactoryMethodMap .containsKey (reporterName .toUpperCase ());
68
+ }
69
+
58
70
/** Returns a new reporter of the given name.
59
71
* If no specific ReporterFactoryMethod is registered, returns a default {Reporter}
60
72
*
@@ -69,9 +81,9 @@ public Reporter createReporter(String reporterName, Object[] attributes) {
69
81
70
82
if ( reportFactoryMethodMap .containsKey (reporterName )) {
71
83
72
- ReporterInfo ri = reportFactoryMethodMap .get (reporterName );
84
+ ReporterFactoryMethodInfo ri = reportFactoryMethodMap .get (reporterName );
73
85
if (ri == null )
74
- throw new RuntimeException ("ReporterInfo for " + reporterName + " was null" );
86
+ throw new RuntimeException ("ReporterFactoryMethodInfo for " + reporterName + " was null" );
75
87
76
88
supplier = ri .factoryMethod ;
77
89
}
@@ -89,23 +101,14 @@ public Reporter createReporter( String reporterName ) {
89
101
return createReporter (reporterName , null );
90
102
}
91
103
92
- /** Returns a new reporter of the given DefaultReporter type
93
- *
94
- * @param reporter
95
- * @return
96
- */
97
- public Reporter createReporter ( CoreReporters reporter ) {
98
- return createReporter (reporter .name ());
99
- }
100
-
101
104
/** Returns a set of all registered reporter's names
102
105
*
103
106
* @return Set of reporter names
104
107
*/
105
108
public Map <String , String > getRegisteredReporterInfo () {
106
109
Map <String , String > descMap = new HashMap <>(reportFactoryMethodMap .size ());
107
110
108
- for (Map .Entry <String , ReporterInfo > entry : reportFactoryMethodMap .entrySet ()) {
111
+ for (Map .Entry <String , ReporterFactoryMethodInfo > entry : reportFactoryMethodMap .entrySet ()) {
109
112
descMap .put (entry .getKey (), entry .getValue ().description );
110
113
}
111
114
return descMap ;
@@ -132,7 +135,7 @@ public static ReporterFactory createEmpty() {
132
135
}
133
136
134
137
/** Returns a new instance of a ReporterFactory with the default ReporterFactoryMethods registered.
135
- * This can depend upon the version of utPLSQL, therefore you have to provide a CompatibilityProxy
138
+ * This can depend on the version of utPLSQL, therefore you have to provide a CompatibilityProxy
136
139
*
137
140
* @param proxy Compatibility proxy
138
141
* @return a new ReporterFactory instance with all default ReporterFactoryMethods registered
0 commit comments