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.deciderules;
26
27 import org.archive.crawler.framework.CrawlController;
28 import org.archive.crawler.settings.ModuleType;
29
30
31 /***
32 * Interface for rules which, given an object to evaluate,
33 * respond with a decision: {@link DecideRule#ACCEPT},
34 * {@link DecideRule#REJECT}, or
35 * {@link DecideRule#PASS}.
36 *
37 * Rules return {@link #PASS} by default.
38 *
39 * @author gojomo
40 * @see org.archive.crawler.deciderules.DecideRuleSequence
41 */
42 public class DecideRule extends ModuleType {
43
44 private static final long serialVersionUID = 3437522810581532520L;
45
46 public static final String ACCEPT = "ACCEPT".intern();
47 public static final String REJECT = "REJECT".intern();
48 public static final String PASS = "PASS".intern();
49
50 /***
51 * Constructor.
52 * @param name Name of this rule.
53 */
54 public DecideRule(String name) {
55 super(name);
56 }
57
58 /***
59 * Make decision on passed <code>object</code>.
60 * @param object Object to rule on.
61 * @return {@link #ACCEPT}, {@link #REJECT}, or {@link #PASS}.
62 */
63 public Object decisionFor(Object object) {
64 return PASS;
65 }
66
67 /***
68 * If this rule is "one-way" -- can only return a single
69 * possible decision other than PASS -- return that
70 * decision. Otherwise return null. Most rules will be
71 * one-way.
72 * @param object
73 *
74 * @return the one decision other than PASS this rule might
75 * return, if there is only one
76 */
77 public Object singlePossibleNonPassDecision(Object object) {
78
79 return null;
80 }
81
82 /***
83 * Respond to a settings update, refreshing any internal settings-derived
84 * state.
85 *
86 * This method gives implementors a chance to refresh internal state
87 * after a settings change. Normally new settings are picked up w/o
88 * the need of work on the part of settings' clients but some facilities
89 * -- for example, Surt classes need to sort submissions into
90 * common-prefix-coalesced collection of Surt prefixes, or,
91 * settings changes that alter external file or seeds/directives
92 * references -- need to be flagged so they can take
93 * compensatory action.
94 */
95 public void kickUpdate() {
96
97 }
98
99 /***
100 * Get the controller object.
101 *
102 * @return the controller object.
103 */
104 public CrawlController getController() {
105 return getSettingsHandler().getOrder().getController();
106 }
107 }