1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.archive.crawler.settings;
25
26 import java.io.Serializable;
27 import java.util.logging.Level;
28
29 /***
30 * A constraint that checks that an attribute value is of the right type
31 *
32 * @author John Erik Halse
33 */
34 public class LegalValueTypeConstraint
35 extends Constraint implements Serializable {
36 private static final long serialVersionUID = 6106774072922858976L;
37
38 /***
39 * Constructs a new LegalValueListConstraint.
40 *
41 * @param level the severity level.
42 * @param msg the default error message.
43 */
44 public LegalValueTypeConstraint(Level level, String msg) {
45 super(level, msg);
46 }
47
48 /***
49 * Constructs a new LegalValueListConstraint using default severity level
50 * ({@link Level#WARNING}).
51 *
52 * @param msg the default error message.
53 */
54 public LegalValueTypeConstraint(String msg) {
55 this(Level.SEVERE, msg);
56 }
57
58 /***
59 * Constructs a new LegalValueListConstraint using default error message.
60 *
61 * @param level
62 */
63 public LegalValueTypeConstraint(Level level) {
64 this(level, "Value of illegal type: ''{3}'', ''{4}'' was expected.");
65 }
66
67 /***
68 * Constructs a new LegalValueListConstraint using default severity level
69 * ({@link Level#WARNING}) and default error message.
70 *
71 */
72 public LegalValueTypeConstraint() {
73 this(Level.SEVERE);
74 }
75
76 public FailedCheck innerCheck(CrawlerSettings settings, ComplexType owner,
77 Type definition, Object value) {
78 FailedCheck res = null;
79
80
81 if (!definition.getLegalValueType().isInstance(value)) {
82 res = new FailedCheck(settings, owner, definition, value);
83 res.messageArguments.add((value != null)?
84 value.getClass().getName(): "null");
85 res.messageArguments.add(definition.getLegalValueType().getName());
86 }
87 return res;
88 }
89 }