Classes in this File | Line Coverage | Branch Coverage | Complexity | |||||||
Pattern |
|
| 1.0;1 |
1 | /* |
|
2 | * $Header: /home/projects/jaxen/scm/jaxen/src/java/main/org/jaxen/pattern/Pattern.java,v 1.11 2005/06/28 13:44:44 elharo Exp $ |
|
3 | * $Revision: 1.11 $ |
|
4 | * $Date: 2005/06/28 13:44:44 $ |
|
5 | * |
|
6 | * ==================================================================== |
|
7 | * |
|
8 | * Copyright (C) 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 |
|
13 | * are met: |
|
14 | * |
|
15 | * 1. Redistributions of source code must retain the above copyright |
|
16 | * notice, this list of conditions, and the following disclaimer. |
|
17 | * |
|
18 | * 2. Redistributions in binary form must reproduce the above copyright |
|
19 | * notice, this list of conditions, and the disclaimer that follows |
|
20 | * these conditions in the documentation and/or other materials |
|
21 | * provided with the distribution. |
|
22 | * |
|
23 | * 3. The name "Jaxen" must not be used to endorse or promote products |
|
24 | * derived from this software without prior written permission. For |
|
25 | * written permission, please contact license@jaxen.org. |
|
26 | * |
|
27 | * 4. Products derived from this software may not be called "Jaxen", nor |
|
28 | * may "Jaxen" appear in their name, without prior written permission |
|
29 | * from the Jaxen Project Management (pm@jaxen.org). |
|
30 | * |
|
31 | * In addition, we request (but do not require) that you include in the |
|
32 | * end-user documentation provided with the redistribution and/or in the |
|
33 | * software itself an acknowledgement equivalent to the following: |
|
34 | * "This product includes software developed by the |
|
35 | * Jaxen Project <http://www.jaxen.org/>." |
|
36 | * Alternatively, the acknowledgment may be graphical using the logos |
|
37 | * available at http://www.jaxen.org/ |
|
38 | * |
|
39 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
|
40 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
|
41 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
42 | * DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT |
|
43 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
45 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
46 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
|
47 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
|
48 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
|
49 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
50 | * SUCH DAMAGE. |
|
51 | * |
|
52 | * ==================================================================== |
|
53 | * This software consists of voluntary contributions made by many |
|
54 | * individuals on behalf of the Jaxen Project and was originally |
|
55 | * created by bob mcwhirter <bob@werken.com> and |
|
56 | * James Strachan <jstrachan@apache.org>. For more information on the |
|
57 | * Jaxen Project, please see <http://www.jaxen.org/>. |
|
58 | * |
|
59 | * $Id: Pattern.java,v 1.11 2005/06/28 13:44:44 elharo Exp $ |
|
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.11 $ |
|
72 | */ |
|
73 | 528 | public abstract class Pattern { |
74 | ||
75 | // These node numbers are compatible with both DOM and dom4j's node types |
|
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 | //public static final short ENTITY_NODE = 6; |
|
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 | //public static final short DOCUMENT_FRAGMENT_NODE = 11; |
|
97 | //public static final short NOTATION_NODE = 12; |
|
98 | ||
99 | /** Matches a Namespace Node */ |
|
100 | // This has the same value as the DOM Level 3 XPathNamespace type |
|
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 | 0 | 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 | 0 | 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 | 0 | 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 | 60 | return null; |
176 | } |
|
177 | ||
178 | ||
179 | public Pattern simplify() |
|
180 | { |
|
181 | 0 | 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 | } |