Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Pattern |
|
| 1.0;1 |
1 | /* | |
2 | * $Header$ | |
3 | * $Revision$ | |
4 | * $Date$ | |
5 | * | |
6 | * ==================================================================== | |
7 | * | |
8 | * Copyright 2000-2002 bob mcwhirter & James Strachan. | |
9 | * All rights reserved. | |
10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions are | |
13 | * met: | |
14 | * | |
15 | * * Redistributions of source code must retain the above copyright | |
16 | * notice, this list of conditions and the following disclaimer. | |
17 | * | |
18 | * * Redistributions in binary form must reproduce the above copyright | |
19 | * notice, this list of conditions and the following disclaimer in the | |
20 | * documentation and/or other materials provided with the distribution. | |
21 | * | |
22 | * * Neither the name of the Jaxen Project nor the names of its | |
23 | * contributors may be used to endorse or promote products derived | |
24 | * from this software without specific prior written permission. | |
25 | * | |
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | |
27 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
28 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | |
29 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER | |
30 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
31 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
32 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
33 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
34 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
35 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
36 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
37 | * | |
38 | * ==================================================================== | |
39 | * This software consists of voluntary contributions made by many | |
40 | * individuals on behalf of the Jaxen Project and was originally | |
41 | * created by bob mcwhirter <bob@werken.com> and | |
42 | * James Strachan <jstrachan@apache.org>. For more information on the | |
43 | * Jaxen Project, please see <http://www.jaxen.org/>. | |
44 | * | |
45 | * $Id$ | |
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$ | |
58 | * @deprecated will be removed in Jaxen 2.0 | |
59 | */ | |
60 | 167 | public abstract class Pattern { |
61 | ||
62 | // These node numbers are compatible with both DOM and dom4j's node types | |
63 | /** Matches Element nodes */ | |
64 | public static final short ELEMENT_NODE = 1; | |
65 | /** Matches attribute nodes */ | |
66 | public static final short ATTRIBUTE_NODE = 2; | |
67 | /** Matches text nodes */ | |
68 | public static final short TEXT_NODE = 3; | |
69 | /** Matches CDATA section nodes */ | |
70 | public static final short CDATA_SECTION_NODE = 4; | |
71 | /** Matches entity reference nodes */ | |
72 | public static final short ENTITY_REFERENCE_NODE = 5; | |
73 | /** Matches entity nodes */ | |
74 | //public static final short ENTITY_NODE = 6; | |
75 | /** Matches ProcessingInstruction */ | |
76 | public static final short PROCESSING_INSTRUCTION_NODE = 7; | |
77 | /** Matches comment nodes */ | |
78 | public static final short COMMENT_NODE = 8; | |
79 | /** Matches document nodes */ | |
80 | public static final short DOCUMENT_NODE = 9; | |
81 | /** Matches DocumentType nodes */ | |
82 | public static final short DOCUMENT_TYPE_NODE = 10; | |
83 | //public static final short DOCUMENT_FRAGMENT_NODE = 11; | |
84 | //public static final short NOTATION_NODE = 12; | |
85 | ||
86 | /** Matches a Namespace Node */ | |
87 | // This has the same value as the DOM Level 3 XPathNamespace type | |
88 | public static final short NAMESPACE_NODE = 13; | |
89 | ||
90 | /** Does not match any valid node */ | |
91 | public static final short UNKNOWN_NODE = 14; | |
92 | ||
93 | /** The maximum number of node types for sizing purposes */ | |
94 | public static final short MAX_NODE_TYPE = 14; | |
95 | ||
96 | /** Matches any node */ | |
97 | public static final short ANY_NODE = 0; | |
98 | ||
99 | /** Matches no nodes */ | |
100 | public static final short NO_NODE = 14; | |
101 | ||
102 | ||
103 | /** | |
104 | * | |
105 | * @param node ???? | |
106 | * @param context ???? | |
107 | * @return true if the pattern matches the given node | |
108 | * @throws JaxenException if ???? | |
109 | */ | |
110 | public abstract boolean matches( Object node, Context context ) throws JaxenException; | |
111 | ||
112 | /** Returns the default resolution policy of the pattern according to the | |
113 | * <a href="https://www.w3.org/TR/xslt#conflict"> | |
114 | * XSLT conflict resolution rules</a>. | |
115 | * | |
116 | * @return 0.5; the default priority defined in XSLT | |
117 | * | |
118 | * @see <a href="https://www.w3.org/TR/xslt#conflict" target="_top">Section 5.5 of the XSLT specification</a> | |
119 | * | |
120 | */ | |
121 | public double getPriority() | |
122 | { | |
123 | 0 | return 0.5; |
124 | } | |
125 | ||
126 | /** If this pattern is a union pattern then this | |
127 | * method should return an array of patterns which | |
128 | * describe the union pattern, which should contain more than one pattern. | |
129 | * Otherwise this method should return null. | |
130 | * | |
131 | * @return an array of the patterns which make up this union pattern | |
132 | * or null if this pattern is not a union pattern | |
133 | */ | |
134 | public Pattern[] getUnionPatterns() | |
135 | { | |
136 | 0 | return null; |
137 | } | |
138 | ||
139 | ||
140 | /** | |
141 | * Returns the type of node the pattern matches. | |
142 | * | |
143 | * @return <code>ANY_NODE</code> unless overridden | |
144 | */ | |
145 | public short getMatchType() | |
146 | { | |
147 | 0 | return ANY_NODE; |
148 | } | |
149 | ||
150 | ||
151 | /** For patterns which only match an ATTRIBUTE_NODE or an | |
152 | * ELEMENT_NODE then this pattern may return the name of the | |
153 | * element or attribute it matches. This allows a more efficient | |
154 | * rule matching algorithm to be performed, rather than a brute | |
155 | * force approach of evaluating every pattern for a given Node. | |
156 | * | |
157 | * @return the name of the element or attribute this pattern matches | |
158 | * or null if this pattern matches any or more than one name | |
159 | */ | |
160 | public String getMatchesNodeName() | |
161 | { | |
162 | 20 | return null; |
163 | } | |
164 | ||
165 | ||
166 | public Pattern simplify() | |
167 | { | |
168 | 0 | return this; |
169 | } | |
170 | ||
171 | /** Returns a textual representation of this pattern | |
172 | * | |
173 | * @return the usual string form of this XSLT pattern | |
174 | */ | |
175 | public abstract String getText(); | |
176 | ||
177 | } |