20
20
import java .io .InputStream ;
21
21
import java .net .URI ;
22
22
import java .net .URISyntaxException ;
23
- import java .util .ArrayList ;
24
23
import java .util .Collection ;
25
24
import java .util .HashMap ;
26
- import java .util .List ;
27
25
import java .util .Map ;
28
26
import java .util .concurrent .ConcurrentHashMap ;
29
27
import java .util .concurrent .ConcurrentMap ;
42
40
import com .networknt .schema .uri .URLFactory ;
43
41
import com .networknt .schema .uri .URLFetcher ;
44
42
import com .networknt .schema .urn .URNFactory ;
45
- import com .networknt .schema .walk .WalkListener ;
46
43
47
44
public class JsonSchemaFactory {
48
45
private static final Logger logger = LoggerFactory
49
46
.getLogger (JsonSchemaFactory .class );
50
- // This is just a constant for listening to all Keywords.
51
- public static final String ALL_KEYWORD_WALK_LISTENER_KEY = "com.networknt.AllKeywordWalkListener" ;
52
47
53
48
54
49
public static class Builder {
@@ -59,8 +54,7 @@ public static class Builder {
59
54
private URNFactory urnFactory ;
60
55
private final Map <String , JsonMetaSchema > jsonMetaSchemas = new HashMap <String , JsonMetaSchema >();
61
56
private final Map <String , String > uriMap = new HashMap <String , String >();
62
- private final Map <String , List <WalkListener >> keywordWalkListenersMap = new HashMap <String , List <WalkListener >>();
63
- private final List <WalkListener > propertyWalkListeners = new ArrayList <WalkListener >();
57
+
64
58
65
59
public Builder () {
66
60
// Adds support for creating {@link URL}s.
@@ -144,52 +138,7 @@ public Builder addUrnFactory(URNFactory urnFactory) {
144
138
return this ;
145
139
}
146
140
147
- public Builder addKeywordWalkListener (WalkListener keywordWalkListener ) {
148
- if (keywordWalkListenersMap .get (ALL_KEYWORD_WALK_LISTENER_KEY ) == null ) {
149
- List <WalkListener > keywordWalkListeners = new ArrayList <WalkListener >();
150
- keywordWalkListenersMap .put (ALL_KEYWORD_WALK_LISTENER_KEY , keywordWalkListeners );
151
- }
152
- keywordWalkListenersMap .get (ALL_KEYWORD_WALK_LISTENER_KEY ).add (keywordWalkListener );
153
- return this ;
154
- }
155
-
156
- public Builder addKeywordWalkListener (String keyword , WalkListener keywordWalkListener ) {
157
- if (keywordWalkListenersMap .get (keyword ) == null ) {
158
- List <WalkListener > keywordWalkListeners = new ArrayList <WalkListener >();
159
- keywordWalkListenersMap .put (keyword , keywordWalkListeners );
160
- }
161
- keywordWalkListenersMap .get (keyword ).add (keywordWalkListener );
162
- return this ;
163
- }
164
-
165
-
166
- public Builder addKeywordWalkListeners (List <WalkListener > keywordWalkListeners ) {
167
- if (keywordWalkListenersMap .get (ALL_KEYWORD_WALK_LISTENER_KEY ) == null ) {
168
- List <WalkListener > ikeywordWalkListeners = new ArrayList <WalkListener >();
169
- keywordWalkListenersMap .put (ALL_KEYWORD_WALK_LISTENER_KEY , ikeywordWalkListeners );
170
- }
171
- keywordWalkListenersMap .get (ALL_KEYWORD_WALK_LISTENER_KEY ).addAll (keywordWalkListeners );
172
- return this ;
173
- }
174
141
175
- public Builder addKeywordWalkListeners (String keyword , List <WalkListener > keywordWalkListeners ) {
176
- if (keywordWalkListenersMap .get (keyword ) == null ) {
177
- List <WalkListener > ikeywordWalkListeners = new ArrayList <WalkListener >();
178
- keywordWalkListenersMap .put (keyword , ikeywordWalkListeners );
179
- }
180
- keywordWalkListenersMap .get (keyword ).addAll (keywordWalkListeners );
181
- return this ;
182
- }
183
-
184
- public Builder addPropertyWalkListeners (List <WalkListener > propertyWalkListeners ) {
185
- this .propertyWalkListeners .addAll (propertyWalkListeners );
186
- return this ;
187
- }
188
-
189
- public Builder addPropertyWalkListener (WalkListener propertyWalkListener ) {
190
- this .propertyWalkListeners .add (propertyWalkListener );
191
- return this ;
192
- }
193
142
194
143
public JsonSchemaFactory build () {
195
144
// create builtin keywords with (custom) formats.
@@ -200,9 +149,7 @@ public JsonSchemaFactory build() {
200
149
new URISchemeFetcher (uriFetcherMap ),
201
150
urnFactory ,
202
151
jsonMetaSchemas ,
203
- uriMap ,
204
- keywordWalkListenersMap ,
205
- propertyWalkListeners
152
+ uriMap
206
153
);
207
154
}
208
155
}
@@ -215,8 +162,6 @@ public JsonSchemaFactory build() {
215
162
private final Map <String , JsonMetaSchema > jsonMetaSchemas ;
216
163
private final Map <String , String > uriMap ;
217
164
private final ConcurrentMap <URI , JsonSchema > uriSchemaCache = new ConcurrentHashMap <URI , JsonSchema >();
218
- private final Map <String , List <WalkListener >> keywordWalkListenersMap ;
219
- private final List <WalkListener > propertyWalkListeners ;
220
165
221
166
222
167
private JsonSchemaFactory (
@@ -226,9 +171,7 @@ private JsonSchemaFactory(
226
171
final URISchemeFetcher uriFetcher ,
227
172
final URNFactory urnFactory ,
228
173
final Map <String , JsonMetaSchema > jsonMetaSchemas ,
229
- final Map <String , String > uriMap ,
230
- final Map <String , List <WalkListener >> keywordWalkListenersMap ,
231
- final List <WalkListener > propertyWalkListeners ) {
174
+ final Map <String , String > uriMap ) {
232
175
if (mapper == null ) {
233
176
throw new IllegalArgumentException ("ObjectMapper must not be null" );
234
177
} else if (defaultMetaSchemaURI == null || defaultMetaSchemaURI .trim ().isEmpty ()) {
@@ -251,8 +194,6 @@ private JsonSchemaFactory(
251
194
this .urnFactory = urnFactory ;
252
195
this .jsonMetaSchemas = jsonMetaSchemas ;
253
196
this .uriMap = uriMap ;
254
- this .keywordWalkListenersMap = keywordWalkListenersMap ;
255
- this .propertyWalkListeners = propertyWalkListeners ;
256
197
}
257
198
258
199
/**
@@ -326,8 +267,7 @@ protected JsonSchema newJsonSchema(final URI schemaUri, final JsonNode schemaNod
326
267
327
268
protected ValidationContext createValidationContext (final JsonNode schemaNode ) {
328
269
final JsonMetaSchema jsonMetaSchema = findMetaSchemaForSchema (schemaNode );
329
- return new ValidationContext (this .uriFactory , this .urnFactory , jsonMetaSchema , this , null ,
330
- this .keywordWalkListenersMap , this .propertyWalkListeners );
270
+ return new ValidationContext (this .uriFactory , this .urnFactory , jsonMetaSchema , this , null );
331
271
}
332
272
333
273
private JsonMetaSchema findMetaSchemaForSchema (final JsonNode schemaNode ) {
@@ -400,8 +340,7 @@ public JsonSchema getSchema(final URI schemaUri, final SchemaValidatorsConfig co
400
340
JsonSchema jsonSchema ;
401
341
if (idMatchesSourceUri (jsonMetaSchema , schemaNode , schemaUri )) {
402
342
jsonSchema = new JsonSchema (
403
- new ValidationContext (this .uriFactory , this .urnFactory , jsonMetaSchema , this , config ,
404
- this .keywordWalkListenersMap , this .propertyWalkListeners ),
343
+ new ValidationContext (this .uriFactory , this .urnFactory , jsonMetaSchema , this , config ),
405
344
mappedUri , schemaNode , true /* retrieved via id, resolving will not change anything */ );
406
345
} else {
407
346
final ValidationContext validationContext = createValidationContext (schemaNode );
0 commit comments