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