23
23
import com .github .fge .jsonschema .library .Dictionary ;
24
24
import com .github .fge .jsonschema .processing .Processor ;
25
25
import com .github .fge .jsonschema .processors .data .SchemaHolder ;
26
- import com .github .fge .jsonschema .report .ProcessingMessage ;
27
26
import com .github .fge .jsonschema .report .ProcessingReport ;
28
27
import com .github .fge .jsonschema .tree .SchemaTree ;
29
28
import com .google .common .collect .Lists ;
30
29
import com .google .common .collect .Maps ;
31
- import com .google .common .collect .Ordering ;
32
30
import com .google .common .collect .Sets ;
33
31
34
32
import java .util .List ;
35
33
import java .util .Map ;
36
- import java .util .Set ;
37
-
38
- import static com .github .fge .jsonschema .messages .SyntaxMessages .*;
39
34
40
35
/*
41
36
* NOTE NOTE NOTE: the schema MUST be valid at this point
42
37
*/
43
- public final class SchemaWalker
38
+ public abstract class SchemaWalker
44
39
implements Processor <SchemaHolder , SchemaHolder >
45
40
{
46
- private final Map <String , KeywordWalker > walkers ;
41
+ private final Map <String , PointerCollector > collectors ;
47
42
48
- public SchemaWalker (final Dictionary <KeywordWalker > dict )
43
+ protected SchemaWalker (final Dictionary <PointerCollector > dict )
49
44
{
50
- walkers = dict .entries ();
45
+ collectors = dict .entries ();
51
46
}
52
47
53
48
@ Override
54
- public SchemaHolder process (final ProcessingReport report ,
49
+ public final SchemaHolder process (final ProcessingReport report ,
55
50
final SchemaHolder input )
56
51
throws ProcessingException
57
52
{
58
53
walk (report , input .getValue ());
59
54
return input ;
60
55
}
61
56
57
+ public abstract void processCurrent (final ProcessingReport report ,
58
+ final SchemaTree tree )
59
+ throws ProcessingException ;
60
+
62
61
private void walk (final ProcessingReport report , final SchemaTree tree )
63
62
throws ProcessingException
64
63
{
64
+ processCurrent (report , tree );
65
65
final JsonNode node = tree .getNode ();
66
66
67
- /*
68
- * Grab all walkers and object member names. Retain walkers only for
69
- * registered keywords, and remove from the member names set what is in
70
- * the walkers' key set: if non empty, some walkers are missing (on
71
- * purpose or not), report them.
72
- */
73
- final Map <String , KeywordWalker > map = Maps .newTreeMap ();
74
- map .putAll (walkers );
75
-
76
- final Set <String > fieldNames = Sets .newHashSet (node .fieldNames ());
77
- map .keySet ().retainAll (fieldNames );
78
- fieldNames .removeAll (map .keySet ());
67
+ final Map <String , PointerCollector > map = Maps .newTreeMap ();
68
+ map .putAll (collectors );
79
69
80
- if (!fieldNames .isEmpty ())
81
- report .warn (newMsg (tree ).message (UNKNOWN_KEYWORDS )
82
- .put ("ignored" , Ordering .natural ().sortedCopy (fieldNames )));
70
+ map .keySet ().retainAll (Sets .newHashSet (node .fieldNames ()));
83
71
84
72
/*
85
- * Now, walk each keyword, and collect pointers for further processing.
73
+ * Collect pointers for further processing.
86
74
*/
87
75
final List <JsonPointer > pointers = Lists .newArrayList ();
88
- for (final KeywordWalker walker : map .values ())
89
- walker . walk (pointers , report , tree );
76
+ for (final PointerCollector collector : map .values ())
77
+ collector . collect (pointers , tree );
90
78
91
79
/*
92
80
* Operate on these pointers.
@@ -95,11 +83,6 @@ private void walk(final ProcessingReport report, final SchemaTree tree)
95
83
walk (report , tree .append (pointer ));
96
84
}
97
85
98
- private static ProcessingMessage newMsg (final SchemaTree tree )
99
- {
100
- return new ProcessingMessage ().put ("schema" , tree );
101
- }
102
-
103
86
@ Override
104
87
public String toString ()
105
88
{
0 commit comments