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