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.util.logging.Level;
27
28 /***
29 * A constraint that checks that an attribute value matches one of the items in
30 * the list of legal values.
31 *
32 * @author John Erik Halse
33 */
34 public class LegalValueListConstraint extends Constraint {
35
36 private static final long serialVersionUID = -4293290799574408033L;
37
38 /***
39 * Constructs a new LegalValueListConstraint.
40 *
41 * @param level the severity level.
42 * @param msg the default error message.
43 */
44 public LegalValueListConstraint(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 LegalValueListConstraint(String msg) {
55 this(Level.WARNING, msg);
56 }
57
58 /***
59 * Constructs a new LegalValueListConstraint using default error message.
60 *
61 * @param level
62 */
63 public LegalValueListConstraint(Level level) {
64 this(level, "Value not in legal values list");
65 }
66
67 /***
68 * Constructs a new LegalValueListConstraint using default severity level
69 * ({@link Level#WARNING}) and default error message.
70 *
71 */
72 public LegalValueListConstraint() {
73 this(Level.WARNING);
74 }
75
76
77
78
79
80
81
82 public FailedCheck innerCheck(CrawlerSettings settings, ComplexType owner,
83 Type definition,
84 Object value) {
85 FailedCheck res = null;
86
87
88
89 Object legalValues[] = definition.getLegalValues();
90 if (legalValues != null) {
91 boolean found = false;
92 for (int i = 0; i < legalValues.length && !found; i++) {
93 if (legalValues[i].equals(value)) {
94 found = true;
95 }
96 }
97 if (!found) {
98 res = new FailedCheck(settings, owner, definition, value);
99 }
100 }
101 return res;
102 }
103
104 }