executionCustomizer) {
+ return walk(createExecutionContext(), deserialize(input, inputFormat), validate, executionCustomizer);
+ }
/**
* Walk at the node.
@@ -1529,7 +1569,7 @@ public void walk(ExecutionContext executionContext, JsonNode node, JsonNode root
try {
// Call all the pre-walk listeners. If at least one of the pre walk listeners
// returns SKIP, then skip the walk.
- if (executionContext.getWalkConfig().getKeywordWalkListenerRunner().runPreWalkListeners(executionContext,
+ if (executionContext.getWalkConfig().getKeywordWalkHandler().preWalk(executionContext,
validator.getKeyword(), node, rootNode, instanceLocation,
this, validator)) {
executionContext.evaluationPathAddLast(validator.getKeyword());
@@ -1543,7 +1583,7 @@ public void walk(ExecutionContext executionContext, JsonNode node, JsonNode root
}
} finally {
// Call all the post-walk listeners.
- executionContext.getWalkConfig().getKeywordWalkListenerRunner().runPostWalkListeners(executionContext,
+ executionContext.getWalkConfig().getKeywordWalkHandler().postWalk(executionContext,
validator.getKeyword(), node, rootNode, instanceLocation,
this, validator,
executionContext.getErrors().subList(currentErrors, executionContext.getErrors().size()));
diff --git a/src/main/java/com/networknt/schema/SchemaRegistry.java b/src/main/java/com/networknt/schema/SchemaRegistry.java
index 0b8af9432..8095d4176 100644
--- a/src/main/java/com/networknt/schema/SchemaRegistry.java
+++ b/src/main/java/com/networknt/schema/SchemaRegistry.java
@@ -36,7 +36,6 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-import java.net.URI;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -651,6 +650,69 @@ public Schema getSchema(final SchemaLocation schemaUri) {
return schema;
}
+ /**
+ * Gets the schema.
+ *
+ * @param schemaUri the base absolute IRI
+ * @param jsonNode the node
+ * @return the schema
+ */
+ public Schema getSchema(final SchemaLocation schemaUri, final JsonNode jsonNode) {
+ return newSchema(schemaUri, jsonNode);
+ }
+
+ /**
+ * Gets the schema.
+ *
+ * @param schemaUri the base absolute IRI
+ * @param schema the input schema data
+ * @param inputFormat input format
+ * @return the schema
+ */
+ public Schema getSchema(final SchemaLocation schemaUri, final String schema, InputFormat inputFormat) {
+ try {
+ final JsonNode schemaNode = readTree(schema, inputFormat);
+ return newSchema(schemaUri, schemaNode);
+ } catch (IOException ioe) {
+ logger.error("Failed to load json schema!", ioe);
+ throw new SchemaException(ioe);
+ }
+ }
+
+ /**
+ * Gets the schema.
+ *
+ * @param schemaUri the base absolute IRI
+ * @param schemaStream the input schema data
+ * @param inputFormat input format
+ * @return the schema
+ */
+ public Schema getSchema(final SchemaLocation schemaUri, final InputStream schemaStream, InputFormat inputFormat) {
+ try {
+ final JsonNode schemaNode = readTree(schemaStream, inputFormat);
+ return newSchema(schemaUri, schemaNode);
+ } catch (IOException ioe) {
+ logger.error("Failed to load json schema!", ioe);
+ throw new SchemaException(ioe);
+ }
+ }
+
+ /**
+ * Gets the schema.
+ *
+ * Using this is not recommended as there is potentially no base IRI for
+ * resolving references to the absolute IRI.
+ *
+ * Prefer {@link #getSchema(SchemaLocation, JsonNode)} instead to ensure the
+ * base IRI if no id is present.
+ *
+ * @param jsonNode the node
+ * @return the schema
+ */
+ public Schema getSchema(final JsonNode jsonNode) {
+ return newSchema(null, jsonNode);
+ }
+
/**
* Loads the schema.
*
@@ -720,56 +782,6 @@ protected Schema getMappedSchema(final SchemaLocation schemaUri) {
}
}
- /**
- * Gets the schema.
- *
- * @param schemaUri the absolute IRI of the schema which can map to the
- * retrieval IRI.
- * @return the schema
- */
- public Schema getSchema(final URI schemaUri) {
- return getSchema(SchemaLocation.of(schemaUri.toString()));
- }
-
- /**
- * Gets the schema.
- *
- * @param schemaUri the absolute IRI of the schema which can map to the
- * retrieval IRI.
- * @param jsonNode the node
- * @return the schema
- */
- public Schema getSchema(final URI schemaUri, final JsonNode jsonNode) {
- return newSchema(SchemaLocation.of(schemaUri.toString()), jsonNode);
- }
-
- /**
- * Gets the schema.
- *
- * @param schemaUri the base absolute IRI
- * @param jsonNode the node
- * @return the schema
- */
- public Schema getSchema(final SchemaLocation schemaUri, final JsonNode jsonNode) {
- return newSchema(schemaUri, jsonNode);
- }
-
- /**
- * Gets the schema.
- *
- * Using this is not recommended as there is potentially no base IRI for
- * resolving references to the absolute IRI.
- *
- * Prefer {@link #getSchema(SchemaLocation, JsonNode)} instead to ensure the
- * base IRI if no id is present.
- *
- * @param jsonNode the node
- * @return the schema
- */
- public Schema getSchema(final JsonNode jsonNode) {
- return newSchema(null, jsonNode);
- }
-
/**
* Gets the schema registry config.
*
diff --git a/src/main/java/com/networknt/schema/keyword/DependenciesValidator.java b/src/main/java/com/networknt/schema/keyword/DependenciesValidator.java
index af18b6293..1acad4aba 100644
--- a/src/main/java/com/networknt/schema/keyword/DependenciesValidator.java
+++ b/src/main/java/com/networknt/schema/keyword/DependenciesValidator.java
@@ -24,6 +24,7 @@
import com.networknt.schema.SchemaContext;
import java.util.*;
+import java.util.Map.Entry;
/**
* {@link KeywordValidator} for dependencies.
@@ -44,9 +45,10 @@ public DependenciesValidator(SchemaLocation schemaLocation, JsonNode schemaNode,
super(KeywordType.DEPENDENCIES, schemaNode, schemaLocation, parentSchema, schemaContext);
- for (Iterator it = schemaNode.fieldNames(); it.hasNext(); ) {
- String pname = it.next();
- JsonNode pvalue = schemaNode.get(pname);
+ for (Iterator> it = schemaNode.fields(); it.hasNext(); ) {
+ Entry entry = it.next();
+ String pname = entry.getKey();
+ JsonNode pvalue = entry.getValue();
if (pvalue.isArray()) {
List depsProps = propertyDeps.get(pname);
if (depsProps == null) {
diff --git a/src/main/java/com/networknt/schema/keyword/ItemsLegacyValidator.java b/src/main/java/com/networknt/schema/keyword/ItemsLegacyValidator.java
index 85e5c7d7e..5c83a5658 100644
--- a/src/main/java/com/networknt/schema/keyword/ItemsLegacyValidator.java
+++ b/src/main/java/com/networknt/schema/keyword/ItemsLegacyValidator.java
@@ -367,13 +367,13 @@ private void walkSchema(ExecutionContext executionContext, Schema walkSchema, Js
executionContext.evaluationPathAddLast(keyword);
}
try {
- boolean executeWalk = executionContext.getWalkConfig().getItemWalkListenerRunner()
- .runPreWalkListeners(executionContext, keyword, node, rootNode, instanceLocation, walkSchema, this);
+ boolean executeWalk = executionContext.getWalkConfig().getItemWalkHandler()
+ .preWalk(executionContext, keyword, node, rootNode, instanceLocation, walkSchema, this);
int currentErrors = executionContext.getErrors().size();
if (executeWalk) {
walkSchema.walk(executionContext, node, rootNode, instanceLocation, shouldValidateSchema);
}
- executionContext.getWalkConfig().getItemWalkListenerRunner().runPostWalkListeners(executionContext, keyword,
+ executionContext.getWalkConfig().getItemWalkHandler().postWalk(executionContext, keyword,
node, rootNode, instanceLocation, walkSchema, this,
executionContext.getErrors().subList(currentErrors, executionContext.getErrors().size()));
} finally {
diff --git a/src/main/java/com/networknt/schema/keyword/ItemsValidator.java b/src/main/java/com/networknt/schema/keyword/ItemsValidator.java
index 5877edaf3..5938a247c 100644
--- a/src/main/java/com/networknt/schema/keyword/ItemsValidator.java
+++ b/src/main/java/com/networknt/schema/keyword/ItemsValidator.java
@@ -146,7 +146,7 @@ private static JsonNode getDefaultNode(Schema schema, ExecutionContext execution
private void walkSchema(ExecutionContext executionContext, Schema walkSchema, JsonNode node, JsonNode rootNode,
NodePath instanceLocation, boolean shouldValidateSchema) {
//@formatter:off
- boolean executeWalk = executionContext.getWalkConfig().getItemWalkListenerRunner().runPreWalkListeners(
+ boolean executeWalk = executionContext.getWalkConfig().getItemWalkHandler().preWalk(
executionContext,
KeywordType.ITEMS.getValue(),
node,
@@ -158,7 +158,7 @@ private void walkSchema(ExecutionContext executionContext, Schema walkSchema, Js
if (executeWalk) {
walkSchema.walk(executionContext, node, rootNode, instanceLocation, shouldValidateSchema);
}
- executionContext.getWalkConfig().getItemWalkListenerRunner().runPostWalkListeners(
+ executionContext.getWalkConfig().getItemWalkHandler().postWalk(
executionContext,
KeywordType.ITEMS.getValue(),
node,
diff --git a/src/main/java/com/networknt/schema/keyword/PatternPropertiesValidator.java b/src/main/java/com/networknt/schema/keyword/PatternPropertiesValidator.java
index 6b262ed79..6dc0355bc 100644
--- a/src/main/java/com/networknt/schema/keyword/PatternPropertiesValidator.java
+++ b/src/main/java/com/networknt/schema/keyword/PatternPropertiesValidator.java
@@ -26,6 +26,7 @@
import com.networknt.schema.path.NodePath;
import com.networknt.schema.regex.RegularExpression;
import java.util.*;
+import java.util.Map.Entry;
/**
* {@link KeywordValidator} for patternProperties.
@@ -56,11 +57,12 @@ public void validate(ExecutionContext executionContext, JsonNode node, JsonNode
return;
}
Set matchedInstancePropertyNames = null;
- Iterator names = node.fieldNames();
+ Iterator> fields = node.fields();
boolean collectAnnotations = hasUnevaluatedPropertiesInEvaluationPath(executionContext) || collectAnnotations(executionContext);
- while (names.hasNext()) {
- String name = names.next();
- JsonNode n = node.get(name);
+ while (fields.hasNext()) {
+ Entry field = fields.next();
+ String name = field.getKey();
+ JsonNode n = field.getValue();
for (Map.Entry entry : schemas.entrySet()) {
if (entry.getKey().matches(name)) {
NodePath path = instanceLocation.append(name);
diff --git a/src/main/java/com/networknt/schema/keyword/PrefixItemsValidator.java b/src/main/java/com/networknt/schema/keyword/PrefixItemsValidator.java
index a81f6c60d..0d443b3f4 100644
--- a/src/main/java/com/networknt/schema/keyword/PrefixItemsValidator.java
+++ b/src/main/java/com/networknt/schema/keyword/PrefixItemsValidator.java
@@ -157,7 +157,7 @@ private void doWalk(ExecutionContext executionContext, int i,
private void walkSchema(ExecutionContext executionContext, int schemaIndex, Schema walkSchema, JsonNode node, JsonNode rootNode,
NodePath instanceLocation, boolean shouldValidateSchema) {
//@formatter:off
- boolean executeWalk = executionContext.getWalkConfig().getItemWalkListenerRunner().runPreWalkListeners(
+ boolean executeWalk = executionContext.getWalkConfig().getItemWalkHandler().preWalk(
executionContext,
KeywordType.PREFIX_ITEMS.getValue(),
node,
@@ -174,7 +174,7 @@ private void walkSchema(ExecutionContext executionContext, int schemaIndex, Sche
executionContext.evaluationPathRemoveLast();
}
}
- executionContext.getWalkConfig().getItemWalkListenerRunner().runPostWalkListeners(
+ executionContext.getWalkConfig().getItemWalkHandler().postWalk(
executionContext,
KeywordType.PREFIX_ITEMS.getValue(),
node,
diff --git a/src/main/java/com/networknt/schema/keyword/PropertiesValidator.java b/src/main/java/com/networknt/schema/keyword/PropertiesValidator.java
index 884e0e880..603ce880f 100644
--- a/src/main/java/com/networknt/schema/keyword/PropertiesValidator.java
+++ b/src/main/java/com/networknt/schema/keyword/PropertiesValidator.java
@@ -28,7 +28,7 @@
import com.networknt.schema.annotation.Annotation;
import com.networknt.schema.path.NodePath;
import com.networknt.schema.utils.SchemaRefs;
-import com.networknt.schema.walk.WalkListenerRunner;
+import com.networknt.schema.walk.WalkHandler;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
@@ -81,7 +81,7 @@ protected void validate(ExecutionContext executionContext, JsonNode node, JsonNo
entry.getValue().validate(executionContext, propertyNode, rootNode, path);
} else {
// check if walker is enabled. If it is enabled it is upto the walker implementation to decide about the validation.
- walkSchema(executionContext, entry, node, rootNode, instanceLocation, true, executionContext.getWalkConfig().getPropertyWalkListenerRunner());
+ walkSchema(executionContext, entry, node, rootNode, instanceLocation, true, executionContext.getWalkConfig().getPropertyWalkHandler());
}
} finally {
executionContext.evaluationPathRemoveLast();
@@ -96,7 +96,7 @@ protected void validate(ExecutionContext executionContext, JsonNode node, JsonNo
executionContext.evaluationPathAddLast(entry.getKey());
try {
walkSchema(executionContext, entry, node, rootNode, instanceLocation, true,
- executionContext.getWalkConfig().getPropertyWalkListenerRunner());
+ executionContext.getWalkConfig().getPropertyWalkHandler());
} finally {
executionContext.evaluationPathRemoveLast();
}
@@ -123,11 +123,11 @@ public void walk(ExecutionContext executionContext, JsonNode node, JsonNode root
validate(executionContext, node == null ? MissingNode.getInstance() : node, rootNode,
instanceLocation, true);
} else {
- WalkListenerRunner propertyWalkListenerRunner = executionContext.getWalkConfig().getPropertyWalkListenerRunner();
+ WalkHandler propertyWalkHandler = executionContext.getWalkConfig().getPropertyWalkHandler();
for (Map.Entry entry : this.schemas.entrySet()) {
executionContext.evaluationPathAddLast(entry.getKey());
try {
- walkSchema(executionContext, entry, node, rootNode, instanceLocation, shouldValidateSchema, propertyWalkListenerRunner);
+ walkSchema(executionContext, entry, node, rootNode, instanceLocation, shouldValidateSchema, propertyWalkHandler);
} finally {
executionContext.evaluationPathRemoveLast();
}
@@ -163,11 +163,11 @@ private static JsonNode getDefaultNode(Schema schema, ExecutionContext execution
}
private void walkSchema(ExecutionContext executionContext, Map.Entry entry, JsonNode node,
- JsonNode rootNode, NodePath instanceLocation, boolean shouldValidateSchema, WalkListenerRunner propertyWalkListenerRunner) {
+ JsonNode rootNode, NodePath instanceLocation, boolean shouldValidateSchema, WalkHandler propertyWalkHandler) {
Schema propertySchema = entry.getValue();
JsonNode propertyNode = (node == null ? null : node.get(entry.getKey()));
NodePath path = instanceLocation.append(entry.getKey());
- boolean executeWalk = propertyWalkListenerRunner.runPreWalkListeners(executionContext,
+ boolean executeWalk = propertyWalkHandler.preWalk(executionContext,
KeywordType.PROPERTIES.getValue(), propertyNode, rootNode, path,
propertySchema, this);
if (propertyNode == null && node != null) {
@@ -178,7 +178,7 @@ private void walkSchema(ExecutionContext executionContext, Map.Entry itemWalkListeners;
- public ItemWalkListenerRunner(List itemWalkListeners) {
+ public ItemWalkHandler(List itemWalkListeners) {
this.itemWalkListeners = itemWalkListeners;
}
@Override
- public boolean runPreWalkListeners(ExecutionContext executionContext, String keyword, JsonNode instanceNode,
+ public boolean preWalk(ExecutionContext executionContext, String keyword, JsonNode instanceNode,
JsonNode rootNode, NodePath instanceLocation, Schema schema, KeywordValidator validator) {
WalkEvent walkEvent = constructWalkEvent(executionContext, keyword, instanceNode, rootNode, instanceLocation,
schema, validator);
@@ -47,7 +47,7 @@ public boolean runPreWalkListeners(ExecutionContext executionContext, String key
}
@Override
- public void runPostWalkListeners(ExecutionContext executionContext, String keyword, JsonNode instanceNode,
+ public void postWalk(ExecutionContext executionContext, String keyword, JsonNode instanceNode,
JsonNode rootNode, NodePath instanceLocation, Schema schema, KeywordValidator validator, List errors) {
WalkEvent walkEvent = constructWalkEvent(executionContext, keyword, instanceNode, rootNode, instanceLocation,
schema, validator);
@@ -71,8 +71,8 @@ public Builder itemWalkListeners(Consumer> itemWalkListeners)
return this;
}
- public ItemWalkListenerRunner build() {
- return new ItemWalkListenerRunner(itemWalkListeners);
+ public ItemWalkHandler build() {
+ return new ItemWalkHandler(itemWalkListeners);
}
}
diff --git a/src/main/java/com/networknt/schema/walk/KeywordWalkListenerRunner.java b/src/main/java/com/networknt/schema/walk/KeywordWalkHandler.java
similarity index 87%
rename from src/main/java/com/networknt/schema/walk/KeywordWalkListenerRunner.java
rename to src/main/java/com/networknt/schema/walk/KeywordWalkHandler.java
index 9a22e2340..ac0af1897 100644
--- a/src/main/java/com/networknt/schema/walk/KeywordWalkListenerRunner.java
+++ b/src/main/java/com/networknt/schema/walk/KeywordWalkHandler.java
@@ -31,20 +31,20 @@
import com.networknt.schema.path.NodePath;
/**
- * A {@link WalkListenerRunner} for walking keywords.
+ * A {@link WalkHandler} for walking keywords.
*/
-public class KeywordWalkListenerRunner extends AbstractWalkListenerRunner {
+public class KeywordWalkHandler extends AbstractWalkHandler {
private final List allKeywordWalkListeners;
private final Map> keywordWalkListenersMap;
- public KeywordWalkListenerRunner(List allKeywordWalkListeners,
+ public KeywordWalkHandler(List allKeywordWalkListeners,
Map> keywordWalkListenersMap) {
this.allKeywordWalkListeners = allKeywordWalkListeners;
this.keywordWalkListenersMap = keywordWalkListenersMap;
}
@Override
- public boolean runPreWalkListeners(ExecutionContext executionContext, String keyword, JsonNode instanceNode,
+ public boolean preWalk(ExecutionContext executionContext, String keyword, JsonNode instanceNode,
JsonNode rootNode, NodePath instanceLocation, Schema schema, KeywordValidator validator) {
boolean continueRunningListenersAndWalk = true;
WalkEvent keywordWalkEvent = constructWalkEvent(executionContext, keyword, instanceNode, rootNode,
@@ -60,7 +60,7 @@ public boolean runPreWalkListeners(ExecutionContext executionContext, String key
}
@Override
- public void runPostWalkListeners(ExecutionContext executionContext, String keyword, JsonNode instanceNode,
+ public void postWalk(ExecutionContext executionContext, String keyword, JsonNode instanceNode,
JsonNode rootNode, NodePath instanceLocation, Schema schema, KeywordValidator validator,
List errors) {
WalkEvent keywordWalkEvent = constructWalkEvent(executionContext, keyword, instanceNode, rootNode,
@@ -99,8 +99,8 @@ public Builder keywordWalkListeners(Consumer