Skip to content

Commit ccebd93

Browse files
committed
Rename VocabularyFactory to VocabularyRegistry
1 parent 0641aa9 commit ccebd93

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

src/main/java/com/networknt/schema/dialect/Dialect.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import com.networknt.schema.utils.Strings;
3636
import com.networknt.schema.vocabulary.Vocabularies;
3737
import com.networknt.schema.vocabulary.Vocabulary;
38-
import com.networknt.schema.vocabulary.VocabularyFactory;
38+
import com.networknt.schema.vocabulary.VocabularyRegistry;
3939

4040
import org.slf4j.Logger;
4141
import org.slf4j.LoggerFactory;
@@ -81,7 +81,7 @@ public static class Builder {
8181
private final Map<String, Format> formats = new HashMap<>();
8282
private final Map<String, Boolean> vocabularies = new HashMap<>();
8383
private FormatKeywordFactory formatKeywordFactory = null;
84-
private VocabularyFactory vocabularyFactory = null;
84+
private VocabularyRegistry vocabularyRegistry = null;
8585
private KeywordFactory unknownKeywordFactory = null;
8686

8787
public Builder(String id) {
@@ -124,13 +124,13 @@ public Builder formatKeywordFactory(FormatKeywordFactory formatKeywordFactory) {
124124
}
125125

126126
/**
127-
* Sets the vocabulary factory for handling custom vocabularies.
127+
* Sets the vocabulary registry for handling custom vocabularies.
128128
*
129-
* @param vocabularyFactory the factory
129+
* @param vocabularyRegistry the registry
130130
* @return the builder
131131
*/
132-
public Builder vocabularyFactory(VocabularyFactory vocabularyFactory) {
133-
this.vocabularyFactory = vocabularyFactory;
132+
public Builder vocabularyRegistry(VocabularyRegistry vocabularyRegistry) {
133+
this.vocabularyRegistry = vocabularyRegistry;
134134
return this;
135135
}
136136

@@ -293,8 +293,8 @@ public Dialect build() {
293293
for(Entry<String, Boolean> entry : this.vocabularies.entrySet()) {
294294
Vocabulary vocabulary = null;
295295
String id = entry.getKey();
296-
if (this.vocabularyFactory != null) {
297-
vocabulary = this.vocabularyFactory.getVocabulary(id);
296+
if (this.vocabularyRegistry != null) {
297+
vocabulary = this.vocabularyRegistry.getVocabulary(id);
298298
}
299299
if (vocabulary == null) {
300300
vocabulary = Vocabularies.getVocabulary(id);
@@ -385,7 +385,7 @@ public static Builder builder(Dialect blueprint) {
385385
.formats(blueprint.builder.formats.values())
386386
.specificationVersion(blueprint.getSpecificationVersion())
387387
.vocabularies(vocabularies)
388-
.vocabularyFactory(blueprint.builder.vocabularyFactory)
388+
.vocabularyRegistry(blueprint.builder.vocabularyRegistry)
389389
.formatKeywordFactory(blueprint.builder.formatKeywordFactory)
390390
.unknownKeywordFactory(blueprint.builder.unknownKeywordFactory)
391391
;

src/main/java/com/networknt/schema/vocabulary/VocabularyFactory.java renamed to src/main/java/com/networknt/schema/vocabulary/VocabularyRegistry.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
package com.networknt.schema.vocabulary;
1717

1818
/**
19-
* Factory for {@link Vocabulary}.
19+
* Registry for {@link Vocabulary}.
2020
*/
2121
@FunctionalInterface
22-
public interface VocabularyFactory {
22+
public interface VocabularyRegistry {
2323
/**
24-
* Gets the vocabulary given the vocabulary iri.
24+
* Gets the vocabulary given the vocabulary id.
2525
*
26-
* @param iri the vocabulary iri
26+
* @param id the vocabulary id which is an iri
2727
* @return the vocabulary
2828
*/
29-
Vocabulary getVocabulary(String iri);
29+
Vocabulary getVocabulary(String id);
3030
}

src/test/java/com/networknt/schema/vocabulary/VocabularyTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,23 +203,23 @@ void customVocabulary() {
203203
+ " }\r\n"
204204
+ " }\r\n"
205205
+ "}";
206-
VocabularyFactory vocabularyFactory = uri -> {
207-
if ("https://www.example.com/vocab/format".equals(uri)) {
206+
VocabularyRegistry vocabularyRegistry = id -> {
207+
if ("https://www.example.com/vocab/format".equals(id)) {
208208
return new Vocabulary("https://www.example.com/vocab/format", new AnnotationKeyword("hello"));
209209
}
210210
return null;
211211
};
212212

213213
Dialect dialect = Dialect
214214
.builder("https://www.example.com/no-validation-no-format/schema", Dialects.getDraft202012())
215-
.vocabularyFactory(vocabularyFactory)
215+
.vocabularyRegistry(vocabularyRegistry)
216216
.build();
217-
SchemaRegistry factory = SchemaRegistry
217+
SchemaRegistry schemaRegistry = SchemaRegistry
218218
.withDefaultDialect(SpecificationVersion.DRAFT_2020_12,
219219
builder -> builder.dialectRegistry(new BasicDialectRegistry(dialect)).resourceLoaders(resourceLoaders -> resourceLoaders.resources(Collections
220220
.singletonMap("https://www.example.com/no-validation-no-format/schema",
221221
metaSchemaData))));
222-
Schema schema = factory.getSchema(schemaData);
222+
Schema schema = schemaRegistry.getSchema(schemaData);
223223
OutputUnit outputUnit = schema.validate("{}", InputFormat.JSON, OutputFormat.HIERARCHICAL, executionContext -> {
224224
executionContext.executionConfig(executionConfig -> executionConfig
225225
.annotationCollectionEnabled(true).annotationCollectionFilter(keyword -> true));

0 commit comments

Comments
 (0)