1
2
3
4 package net.sourceforge.pmd.lang.rule.xpath;
5
6 import java.util.ArrayList;
7 import java.util.List;
8 import java.util.Map;
9
10 import net.sourceforge.pmd.PropertyDescriptor;
11 import net.sourceforge.pmd.RuleContext;
12 import net.sourceforge.pmd.lang.ast.Node;
13
14
15
16
17 public abstract class AbstractXPathRuleQuery implements XPathRuleQuery {
18
19
20
21
22 protected String xpath;
23
24
25
26
27 protected String version;
28
29
30
31
32 protected Map<PropertyDescriptor<?>, Object> properties;
33
34
35
36
37 protected final List<String> ruleChainVisits = new ArrayList<String>();
38
39
40
41
42 public void setXPath(String xpath) {
43 this.xpath = xpath;
44 }
45
46
47
48
49 public void setVersion(String version) throws UnsupportedOperationException {
50 if (!isSupportedVersion(version)) {
51 throw new UnsupportedOperationException(this.getClass().getSimpleName()
52 + " does not support XPath version: " + version);
53 }
54 this.version = version;
55 }
56
57
58
59
60
61
62
63
64
65 protected abstract boolean isSupportedVersion(String version);
66
67
68
69
70 public void setProperties(Map<PropertyDescriptor<?>, Object> properties) {
71 this.properties = properties;
72 }
73
74
75
76
77 public List<String> getRuleChainVisits() {
78 return ruleChainVisits;
79 }
80
81
82
83
84 public abstract List<Node> evaluate(Node node, RuleContext data);
85 }