66import oracle .sql .STRUCT ;
77import org .utplsql .api .compatibility .CompatibilityProxy ;
88
9- import java .sql .Connection ;
109import java .sql .SQLException ;
11- import java .util .Arrays ;
1210import java .util .HashMap ;
1311import java .util .Map ;
1412import java .util .function .BiFunction ;
1513
1614/** This class manages the instantiation of reporters.
1715 * One can register a supplier method for a specific name which will then be callable via createReporter(name)
1816 *
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+ *
1924 * @author pesse
2025 */
2126public final class ReporterFactory implements ORADataFactory {
2227
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 ) {
2530 this .factoryMethod = factoryMethod ;
2631 this .description = description ;
2732 }
2833 public BiFunction <String , Object [], ? extends Reporter > factoryMethod ;
2934 public String description ;
3035 }
3136
32- private Map <String , ReporterInfo > reportFactoryMethodMap = new HashMap <>();
33-
34- ReporterFactory () {
37+ private Map <String , ReporterFactoryMethodInfo > reportFactoryMethodMap = new HashMap <>();
3538
36- }
39+ ReporterFactory () { }
3740
3841 /** Registers a creation method for a specified reporter name. Overrides eventually existing creation method
3942 *
@@ -42,19 +45,28 @@ public ReporterInfo(BiFunction<String, Object[], ? extends Reporter> factoryMeth
4245 * @param description the description of the reporter
4346 * @return Object with information about the registered reporter
4447 */
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 ));
4750 }
4851
4952 /** Unregisters a specified reporter name.
5053 *
5154 * @param reporterName the reporter's name to unregister
5255 * @return information about the reporter which was previously registered or null
5356 */
54- public synchronized ReporterInfo unregisterReporterFactoryMethod ( String reporterName ) {
57+ public synchronized ReporterFactoryMethodInfo unregisterReporterFactoryMethod (String reporterName ) {
5558 return reportFactoryMethodMap .remove (reporterName .toUpperCase ());
5659 }
5760
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+
5870 /** Returns a new reporter of the given name.
5971 * If no specific ReporterFactoryMethod is registered, returns a default {Reporter}
6072 *
@@ -69,9 +81,9 @@ public Reporter createReporter(String reporterName, Object[] attributes) {
6981
7082 if ( reportFactoryMethodMap .containsKey (reporterName )) {
7183
72- ReporterInfo ri = reportFactoryMethodMap .get (reporterName );
84+ ReporterFactoryMethodInfo ri = reportFactoryMethodMap .get (reporterName );
7385 if (ri == null )
74- throw new RuntimeException ("ReporterInfo for " + reporterName + " was null" );
86+ throw new RuntimeException ("ReporterFactoryMethodInfo for " + reporterName + " was null" );
7587
7688 supplier = ri .factoryMethod ;
7789 }
@@ -89,23 +101,14 @@ public Reporter createReporter( String reporterName ) {
89101 return createReporter (reporterName , null );
90102 }
91103
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-
101104 /** Returns a set of all registered reporter's names
102105 *
103106 * @return Set of reporter names
104107 */
105108 public Map <String , String > getRegisteredReporterInfo () {
106109 Map <String , String > descMap = new HashMap <>(reportFactoryMethodMap .size ());
107110
108- for (Map .Entry <String , ReporterInfo > entry : reportFactoryMethodMap .entrySet ()) {
111+ for (Map .Entry <String , ReporterFactoryMethodInfo > entry : reportFactoryMethodMap .entrySet ()) {
109112 descMap .put (entry .getKey (), entry .getValue ().description );
110113 }
111114 return descMap ;
@@ -132,7 +135,7 @@ public static ReporterFactory createEmpty() {
132135 }
133136
134137 /** 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
136139 *
137140 * @param proxy Compatibility proxy
138141 * @return a new ReporterFactory instance with all default ReporterFactoryMethods registered
0 commit comments