Skip to content

Commit af2def0

Browse files
committed
code cleanup in child loader initialization
* adding `LoaderConfig#initLoader()` which creates a new SchemaLoaderBuilder, partially initialized wit the config * renaming `LoadingState#initChildLoader()` to `#initNewDocumentLoader()` which is just a copy of config plus pointers currently under resolution * removing duplicate value copies in ReferenceLookup and LoadingState
1 parent 2f6c2e9 commit af2def0

File tree

3 files changed

+26
-23
lines changed

3 files changed

+26
-23
lines changed

core/src/main/java/org/everit/json/schema/loader/LoaderConfig.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import static java.util.Collections.emptyMap;
44
import static java.util.Objects.requireNonNull;
55
import static org.everit.json.schema.loader.SpecificationVersion.DRAFT_4;
6+
import static org.everit.json.schema.loader.SpecificationVersion.DRAFT_6;
7+
import static org.everit.json.schema.loader.SpecificationVersion.DRAFT_7;
68

79
import java.net.URI;
810
import java.util.HashMap;
@@ -58,4 +60,25 @@ static LoaderConfig defaultV4Config() {
5860
this.regexpFactory = requireNonNull(regexpFactory, "regexpFactory cannot be null");
5961
}
6062

63+
/**
64+
* Creates a new loader builder with {@code this} configuration
65+
*
66+
* @return
67+
*/
68+
SchemaLoader.SchemaLoaderBuilder initLoader() {
69+
SchemaLoader.SchemaLoaderBuilder loaderBuilder = SchemaLoader.builder()
70+
.schemaClient(this.schemaClient)
71+
.useDefaults(this.useDefaults)
72+
.regexpFactory(this.regexpFactory)
73+
.nullableSupport(this.nullableSupport)
74+
.formatValidators(new HashMap<>(this.formatValidators));
75+
loaderBuilder.schemasByURI = schemasByURI;
76+
if (DRAFT_6.equals(specVersion)) {
77+
loaderBuilder.draftV6Support();
78+
} else if (DRAFT_7.equals(specVersion)) {
79+
loaderBuilder.draftV7Support();
80+
}
81+
return loaderBuilder;
82+
}
83+
6184
}

core/src/main/java/org/everit/json/schema/loader/LoadingState.java

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22

33
import static java.lang.String.format;
44
import static java.util.Objects.requireNonNull;
5-
import static org.everit.json.schema.loader.SpecificationVersion.DRAFT_6;
6-
import static org.everit.json.schema.loader.SpecificationVersion.DRAFT_7;
75

86
import java.net.URI;
97
import java.util.ArrayList;
108
import java.util.Collection;
119
import java.util.Collections;
1210
import java.util.Comparator;
13-
import java.util.HashMap;
1411
import java.util.List;
1512
import java.util.Map;
1613

@@ -70,25 +67,8 @@ static URI extractChildId(URI parentScopeId, Object childJson, String idKeyword)
7067
this.schemaJson.ls = this;
7168
}
7269

73-
SchemaLoader.SchemaLoaderBuilder initChildLoader() {
74-
SchemaLoader.SchemaLoaderBuilder rval = SchemaLoader.builder()
75-
.schemaClient(this.config.schemaClient)
76-
.useDefaults(this.config.useDefaults)
77-
.regexpFactory(this.config.regexpFactory)
78-
.nullableSupport(this.config.nullableSupport)
79-
.formatValidators(new HashMap<>(this.config.formatValidators))
80-
.resolutionScope(id)
81-
.schemaJson(schemaJson)
82-
.rootSchemaJson(rootSchemaJson)
83-
.pointerSchemas(pointerSchemas)
84-
.pointerToCurrentObj(pointerToCurrentObj);
85-
rval.schemasByURI = this.config.schemasByURI;
86-
if (DRAFT_6.equals(specVersion())) {
87-
rval.draftV6Support();
88-
} else if (DRAFT_7.equals(specVersion())) {
89-
rval.draftV7Support();
90-
}
91-
return rval;
70+
SchemaLoader.SchemaLoaderBuilder initNewDocumentLoader() {
71+
return config.initLoader().pointerSchemas(pointerSchemas);
9272
}
9373

9474
private Object getRawChildOfObject(JsonObject obj, String key) {

core/src/main/java/org/everit/json/schema/loader/ReferenceLookup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ Schema.Builder<?> lookup(String relPointerString, JsonObject ctx) {
159159

160160
URI resolutionScope = !isSameDocumentRef(absPointerString) ? withoutFragment(absPointerString) : ls.id;
161161
JsonObject containingDocument = result.getContainingDocument();
162-
SchemaLoader childLoader = ls.initChildLoader()
162+
SchemaLoader childLoader = ls.initNewDocumentLoader()
163163
.pointerToCurrentObj(SchemaLocation.parseURI(absPointerString))
164164
.resolutionScope(resolutionScope)
165165
.schemaJson(result.getQueryResult())

0 commit comments

Comments
 (0)