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.10 $
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 */
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 /***
117 *
118 * @param node ????
119 * @param context ????
120 * @return true if the pattern matches the given node
121 * @throws JaxenException if ????
122 */
123 public abstract boolean matches( Object node, Context context ) throws JaxenException;
124
125 /*** Returns the default resolution policy of the pattern according to the
126 * <a href="http://www.w3.org/TR/xslt11/#conflict">
127 * XSLT conflict resolution rules</a>.
128 *
129 * @return 0.5; the default priority defined in XSLT
130 *
131 * @see <a href="http://www.w3.org/TR/xslt#conflict" target="_top">Section 5.5 of the XSLT specification</a>
132 *
133 */
134 public double getPriority()
135 {
136 return 0.5;
137 }
138
139 /*** If this pattern is a union pattern then this
140 * method should return an array of patterns which
141 * describe the union pattern, which should contain more than one pattern.
142 * Otherwise this method should return null.
143 *
144 * @return an array of the patterns which make up this union pattern
145 * or null if this pattern is not a union pattern
146 */
147 public Pattern[] getUnionPatterns()
148 {
149 return null;
150 }
151
152
153 /***
154 * Returns the type of node the pattern matches.
155 *
156 * @return <code>ANY_NODE</code> unless overridden
157 */
158 public short getMatchType()
159 {
160 return ANY_NODE;
161 }
162
163
164 /*** For patterns which only match an ATTRIBUTE_NODE or an
165 * ELEMENT_NODE then this pattern may return the name of the
166 * element or attribute it matches. This allows a more efficient
167 * rule matching algorithm to be performed, rather than a brute
168 * force approach of evaluating every pattern for a given Node.
169 *
170 * @return the name of the element or attribute this pattern matches
171 * or null if this pattern matches any or more than one name
172 */
173 public String getMatchesNodeName()
174 {
175 return null;
176 }
177
178
179 public Pattern simplify()
180 {
181 return this;
182 }
183
184 /*** Returns a textual representation of this pattern
185 *
186 * @return the usual string form of this XSLT pattern
187 */
188 public abstract String getText();
189
190 }