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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 package org.jaxen.pattern;
63
64 import org.jaxen.Context;
65 import org.jaxen.JaxenException;
66
67 /*** <p><code>Pattern</code> defines the behaviour for pattern in
68 * the XSLT processing model.</p>
69 *
70 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
71 * @version $Revision: 1.8 $
72 */
73 public abstract class Pattern {
74
75
76 /*** Matches Element nodes */
77 public static final short ELEMENT_NODE = 1;
78 /*** Matches attribute nodes */
79 public static final short ATTRIBUTE_NODE = 2;
80 /*** Matches text nodes */
81 public static final short TEXT_NODE = 3;
82 /*** Matches CDATA section nodes */
83 public static final short CDATA_SECTION_NODE = 4;
84 /*** Matches entity reference nodes */
85 public static final short ENTITY_REFERENCE_NODE = 5;
86 /*** Matches entity nodes */
87
88 /*** Matches ProcessingInstruction */
89 public static final short PROCESSING_INSTRUCTION_NODE = 7;
90 /*** Matches comment nodes */
91 public static final short COMMENT_NODE = 8;
92 /*** Matches document nodes */
93 public static final short DOCUMENT_NODE = 9;
94 /*** Matches DocumentType nodes */
95 public static final short DOCUMENT_TYPE_NODE = 10;
96
97
98
99 /*** Matches a Namespace Node - NOTE this differs from DOM */
100
101 public static final short NAMESPACE_NODE = 13;
102
103 /*** Does not match any valid node */
104 public static final short UNKNOWN_NODE = 14;
105
106 /*** The maximum number of node types for sizing purposes */
107 public static final short MAX_NODE_TYPE = 14;
108
109 /*** Matches any node */
110 public static final short ANY_NODE = 0;
111
112 /*** Matches no nodes */
113 public static final short NO_NODE = 14;
114
115
116 /*** @return true if the pattern matches the given node
117 */
118 public abstract boolean matches( Object node, Context context ) throws JaxenException;
119
120 /*** Returns the default resolution policy of the pattern according to the
121 * <a href="http://www.w3.org/TR/xslt11/#conflict">
122 * XSLT conflict resolution rules</a>.
123 *
124 */
125 public double getPriority()
126 {
127 return 0.5;
128 }
129
130 /*** If this pattern is a union pattern then this
131 * method should return an array of patterns which
132 * describe the union pattern, which should contain more than one pattern.
133 * Otherwise this method should return null.
134 *
135 * @return an array of the patterns which make up this union pattern
136 * or null if this pattern is not a union pattern
137 */
138 public Pattern[] getUnionPatterns()
139 {
140 return null;
141 }
142
143
144 /*** @return the type of node the pattern matches;
145 * ANY_NODE unless overridden
146 */
147 public short getMatchType()
148 {
149 return ANY_NODE;
150 }
151
152
153 /*** For patterns which only match an ATTRIBUTE_NODE or an
154 * ELEMENT_NODE then this pattern may return the name of the
155 * element or attribute it matches. This allows a more efficient
156 * rule matching algorithm to be performed, rather than a brute
157 * force approach of evaluating every pattern for a given Node.
158 *
159 * @return the name of the element or attribute this pattern matches
160 * or null if this pattern matches any or more than one name
161 */
162 public String getMatchesNodeName()
163 {
164 return null;
165 }
166
167
168 public Pattern simplify()
169 {
170 return this;
171 }
172
173 /*** Returns a textual representation of this pattern
174 */
175 public abstract String getText();
176
177 }