19
19
import org .culturegraph .mf .framework .StreamReceiver ;
20
20
21
21
/**
22
- * A stream receiver that throws an {@link WellformednessException} if
23
- * the stream event methods are called in an invalid order. Additionally,
22
+ * A stream receiver that throws an {@link WellformednessException} if
23
+ * the stream event methods are called in an invalid order. Additionally,
24
24
* the stream receiver checks that entity and literal names are not null.
25
- *
25
+ *
26
26
* @see StreamValidator
27
27
* @see WellformednessException
28
- *
28
+ *
29
29
* @author Christoph Böhme
30
- *
30
+ *
31
31
*/
32
32
public final class WellFormednessChecker implements StreamReceiver {
33
-
33
+
34
+ private static final String ID_MUST_NOT_BE_NULL = "id must not be null" ;
34
35
private static final String NAME_MUST_NOT_BE_NULL = "name must not be null" ;
35
-
36
+
36
37
private static final String NOT_IN_RECORD = "Not in record" ;
37
38
private static final String NOT_IN_ENTITY = "Not in entity" ;
38
39
private static final String IN_ENTITY = "In entity" ;
39
40
private static final String IN_RECORD = "In record" ;
40
-
41
+
41
42
private int nestingLevel ;
42
-
43
+
43
44
@ Override
44
45
public void startRecord (final String identifier ) {
46
+ if (identifier == null ) {
47
+ throw new WellformednessException (ID_MUST_NOT_BE_NULL );
48
+ }
45
49
if (nestingLevel > 0 ) {
46
50
throw new WellformednessException (IN_RECORD );
47
51
}
@@ -50,10 +54,10 @@ public void startRecord(final String identifier) {
50
54
51
55
@ Override
52
56
public void endRecord () {
53
- if (nestingLevel < 1 ) {
57
+ if (nestingLevel < 1 ) {
54
58
throw new WellformednessException (NOT_IN_RECORD );
55
59
} else if (nestingLevel > 1 ) {
56
- throw new WellformednessException (IN_ENTITY );
60
+ throw new WellformednessException (IN_ENTITY );
57
61
}
58
62
nestingLevel -= 1 ;
59
63
}
@@ -86,7 +90,7 @@ public void literal(final String name, final String value) {
86
90
throw new WellformednessException (NOT_IN_RECORD );
87
91
}
88
92
}
89
-
93
+
90
94
@ Override
91
95
public void resetStream () {
92
96
nestingLevel = 0 ;
0 commit comments