26
26
import com .github .fge .jsonschema .core .report .ListProcessingReport ;
27
27
import com .github .fge .jsonschema .core .report .MessageProvider ;
28
28
import com .github .fge .jsonschema .core .report .ProcessingReport ;
29
- import com .github .fge .jsonschema .core .report .ReportProvider ;
30
- import com .github .fge .jsonschema .core .tree .SchemaTree ;
31
- import com .github .fge .jsonschema .core .tree .SimpleJsonTree ;
32
- import com .github .fge .jsonschema .processors .data .FullData ;
33
- import com .github .fge .jsonschema .processors .validation .ValidationProcessor ;
34
-
35
- import javax .annotation .concurrent .Immutable ;
36
29
37
30
/**
38
31
* Single-schema instance validator
39
32
*
40
- * <p>This is the class you will use the most often. It is, in essence, a {@link
33
+ * <p>This is the interface you will use the most often. It is, in essence, a {@link
41
34
* JsonValidator} initialized with a single JSON Schema. Note however that this
42
35
* class still retains the ability to resolve JSON References.</p>
43
- *
44
- * <p>It has no public constructors: you should use the appropriate methods in
45
- * {@link JsonSchemaFactory} to obtain an instance of this class.</p>
46
36
*/
47
- @ Immutable
48
- public final class JsonSchema
49
- {
50
- private final ValidationProcessor processor ;
51
- private final SchemaTree schema ;
52
- private final ReportProvider reportProvider ;
53
-
54
- /**
55
- * Package private constructor
56
- *
57
- * @param processor the validation processor
58
- * @param schema the schema to bind to this instance
59
- * @param reportProvider the report provider
60
- */
61
- JsonSchema (final ValidationProcessor processor , final SchemaTree schema ,
62
- final ReportProvider reportProvider )
63
- {
64
- this .processor = processor ;
65
- this .schema = schema ;
66
- this .reportProvider = reportProvider ;
67
- }
68
-
69
- private ProcessingReport doValidate (final JsonNode node ,
70
- final boolean deepCheck )
71
- throws ProcessingException
72
- {
73
- final FullData data = new FullData (schema , new SimpleJsonTree (node ),
74
- deepCheck );
75
- final ProcessingReport report = reportProvider .newReport ();
76
- final ProcessingResult <FullData > result
77
- = ProcessingResult .of (processor , report , data );
78
- return result .getReport ();
79
- }
80
-
81
- private ProcessingReport doValidateUnchecked (final JsonNode node ,
82
- final boolean deepCheck )
83
- {
84
- final FullData data = new FullData (schema , new SimpleJsonTree (node ),
85
- deepCheck );
86
- final ProcessingReport report = reportProvider .newReport ();
87
- final ProcessingResult <FullData > result
88
- = ProcessingResult .uncheckedResult (processor , report , data );
89
- return result .getReport ();
90
- }
91
-
37
+ public interface JsonSchema {
92
38
/**
93
39
* Validate an instance and return a processing report
94
40
*
@@ -102,12 +48,8 @@ private ProcessingReport doValidateUnchecked(final JsonNode node,
102
48
*
103
49
* @since 2.1.8
104
50
*/
105
- public ProcessingReport validate (final JsonNode instance ,
106
- final boolean deepCheck )
107
- throws ProcessingException
108
- {
109
- return doValidate (instance , deepCheck );
110
- }
51
+ ProcessingReport validate (JsonNode instance , boolean deepCheck )
52
+ throws ProcessingException ;
111
53
112
54
/**
113
55
* Validate an instance and return a processing report
@@ -119,11 +61,8 @@ public ProcessingReport validate(final JsonNode instance,
119
61
* @return a processing report
120
62
* @throws ProcessingException a processing error occurred during validation
121
63
*/
122
- public ProcessingReport validate (final JsonNode instance )
123
- throws ProcessingException
124
- {
125
- return validate (instance , false );
126
- }
64
+ ProcessingReport validate (JsonNode instance )
65
+ throws ProcessingException ;
127
66
128
67
/**
129
68
* Validate an instance and return a processing report (unchecked version)
@@ -148,12 +87,8 @@ public ProcessingReport validate(final JsonNode instance)
148
87
*
149
88
* @since 2.1.8
150
89
*/
151
- public ProcessingReport validateUnchecked (final JsonNode instance ,
152
- final boolean deepCheck )
153
- {
154
- return doValidateUnchecked (instance , deepCheck );
155
- }
156
-
90
+ ProcessingReport validateUnchecked (JsonNode instance ,
91
+ boolean deepCheck );
157
92
/**
158
93
* Validate an instance and return a processing report (unchecked version)
159
94
*
@@ -164,10 +99,7 @@ public ProcessingReport validateUnchecked(final JsonNode instance,
164
99
* @return a report (a {@link ListProcessingReport} if an exception was
165
100
* thrown during processing)
166
101
*/
167
- public ProcessingReport validateUnchecked (final JsonNode instance )
168
- {
169
- return doValidateUnchecked (instance , false );
170
- }
102
+ ProcessingReport validateUnchecked (JsonNode instance );
171
103
172
104
/**
173
105
* Check whether an instance is valid against this schema
@@ -176,11 +108,8 @@ public ProcessingReport validateUnchecked(final JsonNode instance)
176
108
* @return true if the instance is valid
177
109
* @throws ProcessingException an error occurred during processing
178
110
*/
179
- public boolean validInstance (final JsonNode instance )
180
- throws ProcessingException
181
- {
182
- return doValidate (instance , false ).isSuccess ();
183
- }
111
+ boolean validInstance (JsonNode instance )
112
+ throws ProcessingException ;
184
113
185
114
/**
186
115
* Check whether an instance is valid against this schema (unchecked
@@ -192,8 +121,5 @@ public boolean validInstance(final JsonNode instance)
192
121
* @param instance the instance to validate
193
122
* @return true if the instance is valid
194
123
*/
195
- public boolean validInstanceUnchecked (final JsonNode instance )
196
- {
197
- return doValidateUnchecked (instance , false ).isSuccess ();
198
- }
124
+ boolean validInstanceUnchecked (JsonNode instance );
199
125
}
0 commit comments