From 5ce00f4d31f83f02b3dbee57f34d8828d6fc528b Mon Sep 17 00:00:00 2001
From: Francis Galiegue
Date: Sat, 18 Oct 2014 15:05:48 +0200
Subject: [PATCH 1/3] FullData: remove immutability
We need this class to be modifiable in order to store schema pointer paths.
Signed-off-by: Francis Galiegue
---
.../jsonschema/processors/data/FullData.java | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/src/main/java/com/github/fge/jsonschema/processors/data/FullData.java b/src/main/java/com/github/fge/jsonschema/processors/data/FullData.java
index 09ecd12c0..38dae4bb6 100644
--- a/src/main/java/com/github/fge/jsonschema/processors/data/FullData.java
+++ b/src/main/java/com/github/fge/jsonschema/processors/data/FullData.java
@@ -25,8 +25,6 @@
import com.github.fge.jsonschema.core.tree.JsonTree;
import com.github.fge.jsonschema.core.tree.SchemaTree;
-import javax.annotation.concurrent.Immutable;
-
/**
* Validation data for a validation processor
*
@@ -41,12 +39,11 @@
* The {@link ProcessingMessage} template generated contains information
* about both the schema and instance.
*/
-@Immutable
public final class FullData
implements MessageProvider
{
- private final SchemaTree schema;
- private final JsonTree instance;
+ private SchemaTree schema;
+ private JsonTree instance;
private final boolean deepCheck;
public FullData(final SchemaTree schema, final JsonTree instance,
@@ -83,6 +80,16 @@ public boolean isDeepCheck()
return deepCheck;
}
+ public void setSchema(final SchemaTree schema)
+ {
+ this.schema = schema;
+ }
+
+ public void setInstance(final JsonTree instance)
+ {
+ this.instance = instance;
+ }
+
/**
* Return a new full data with another schema
*
From c5b700038422870a73cef8e2dcdcd2dd6679bb93 Mon Sep 17 00:00:00 2001
From: Francis Galiegue
Date: Sat, 18 Oct 2014 21:20:19 +0200
Subject: [PATCH 2/3] FullData: add a Deque and a utility method to
gather URIs
As the comment in the code mentions, this Deque will be emptied whenever the
instance changes (recall: an instance in a validation context is the JSON
instance itself plus the pointer into the instance).
Signed-off-by: Francis Galiegue
---
.../jsonschema/processors/data/FullData.java | 28 +++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/src/main/java/com/github/fge/jsonschema/processors/data/FullData.java b/src/main/java/com/github/fge/jsonschema/processors/data/FullData.java
index 38dae4bb6..df5b81ad3 100644
--- a/src/main/java/com/github/fge/jsonschema/processors/data/FullData.java
+++ b/src/main/java/com/github/fge/jsonschema/processors/data/FullData.java
@@ -20,10 +20,16 @@
package com.github.fge.jsonschema.processors.data;
+import com.github.fge.jsonschema.core.ref.JsonRef;
import com.github.fge.jsonschema.core.report.MessageProvider;
import com.github.fge.jsonschema.core.report.ProcessingMessage;
import com.github.fge.jsonschema.core.tree.JsonTree;
import com.github.fge.jsonschema.core.tree.SchemaTree;
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Queues;
+
+import java.util.Deque;
/**
* Validation data for a validation processor
@@ -39,6 +45,7 @@
* The {@link ProcessingMessage} template generated contains information
* about both the schema and instance.
*/
+// TODO: rework, rename; nulls are badly handled, etc
public final class FullData
implements MessageProvider
{
@@ -46,6 +53,13 @@ public final class FullData
private JsonTree instance;
private final boolean deepCheck;
+ /*
+ * Deque of SchemaTrees we had to go through during validation of a
+ * particular instance/pointer pair; when the latter changes,the deque is
+ * emptied.
+ */
+ private final Deque schemaPath = Queues.newArrayDeque();
+
public FullData(final SchemaTree schema, final JsonTree instance,
final boolean deepCheck)
{
@@ -122,4 +136,18 @@ public ProcessingMessage newMessage()
ret.put("instance", instance);
return ret;
}
+
+ public Iterable getSchemaPath()
+ {
+ final Iterable iterable = Iterables.transform(schemaPath,
+ new Function()
+ {
+ @Override
+ public JsonRef apply(final SchemaTree input)
+ {
+ return input.getContext();
+ }
+ });
+ return Iterables.unmodifiableIterable(iterable);
+ }
}
From e338cd685ccbb59ce4b12a4c48a12829ef41ccd7 Mon Sep 17 00:00:00 2001
From: Francis Galiegue
Date: Sat, 18 Oct 2014 21:24:39 +0200
Subject: [PATCH 3/3] FullData: @ParametersAreNonNullByDefault
The only constructor possibly yielding a null instance is deprecated.
Signed-off-by: Francis Galiegue
---
.../fge/jsonschema/processors/data/FullData.java | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/src/main/java/com/github/fge/jsonschema/processors/data/FullData.java b/src/main/java/com/github/fge/jsonschema/processors/data/FullData.java
index df5b81ad3..6018b1874 100644
--- a/src/main/java/com/github/fge/jsonschema/processors/data/FullData.java
+++ b/src/main/java/com/github/fge/jsonschema/processors/data/FullData.java
@@ -26,9 +26,11 @@
import com.github.fge.jsonschema.core.tree.JsonTree;
import com.github.fge.jsonschema.core.tree.SchemaTree;
import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
import com.google.common.collect.Queues;
+import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Deque;
/**
@@ -46,6 +48,7 @@
* about both the schema and instance.
*/
// TODO: rework, rename; nulls are badly handled, etc
+@ParametersAreNonnullByDefault
public final class FullData
implements MessageProvider
{
@@ -63,8 +66,8 @@ public final class FullData
public FullData(final SchemaTree schema, final JsonTree instance,
final boolean deepCheck)
{
- this.schema = schema;
- this.instance = instance;
+ this.schema = Preconditions.checkNotNull(schema);
+ this.instance = Preconditions.checkNotNull(instance);
this.deepCheck = deepCheck;
}
@@ -73,6 +76,11 @@ public FullData(final SchemaTree schema, final JsonTree instance)
this(schema, instance, false);
}
+ /**
+ * UNUSED
+ *
+ * @param schema the schema
+ */
@Deprecated
public FullData(final SchemaTree schema)
{
@@ -96,12 +104,12 @@ public boolean isDeepCheck()
public void setSchema(final SchemaTree schema)
{
- this.schema = schema;
+ this.schema = Preconditions.checkNotNull(schema);
}
public void setInstance(final JsonTree instance)
{
- this.instance = instance;
+ this.instance = Preconditions.checkNotNull(instance);
}
/**