1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.archive.crawler.settings;
26
27 /***
28 * A type that holds a Java type.
29 *
30 * @author John Erik Halse
31 *
32 */
33 public class SimpleType extends Type {
34
35 private static final long serialVersionUID = -5134952907004648419L;
36
37 private final String description;
38 private Object[] legalValues = null;
39
40 /***
41 * Create a new instance of SimpleType.
42 *
43 * @param name the name of the type.
44 * @param description a description suitable for the UI.
45 * @param defaultValue the default value for this type. This also set what
46 * kind of Java type that this Type can hold.
47 */
48 public SimpleType(String name, String description, Object defaultValue) {
49 super(name, defaultValue);
50 this.description = description;
51 }
52
53 /***
54 * Create a new instance of SimpleType.
55 *
56 * @param name the name of the type.
57 * @param description a description suitable for the UI.
58 * @param defaultValue the default value for this type. This also set what
59 * kind of Java type that this Type can hold.
60 * @param legalValues an array of legal values for this simple type. The
61 * objects in this array must be of the same type as the default
62 * value.
63 */
64 public SimpleType(String name, String description, Object defaultValue,
65 Object[] legalValues) {
66 this(name, description, defaultValue);
67 setLegalValues(legalValues);
68 }
69
70
71
72
73 public String getDescription() {
74 return description;
75 }
76
77
78
79
80 public Object getDefaultValue() {
81 return getValue();
82 }
83
84 /***
85 * Get the array of legal values for this Type.
86 */
87 public Object[] getLegalValues() {
88 return legalValues;
89 }
90
91 /***
92 * Set the array of legal values for this type.
93 * <p>
94 *
95 * The objects in this array must be of the same type as the default value.
96 *
97 * @param legalValues
98 */
99 public void setLegalValues(Object[] legalValues) {
100 this.legalValues = legalValues;
101 if (legalValues != null) {
102 addConstraint(new LegalValueListConstraint());
103 }
104 }
105 }