2
* $Header: /cvsroot/xena/xena/src/org/jaxen/pattern/Pattern.java,v 1.2 2009/12/10 03:18:44 matthewoliver Exp $
4
* $Date: 2009/12/10 03:18:44 $
6
* ====================================================================
8
* Copyright 2000-2002 bob mcwhirter & James Strachan.
11
* Redistribution and use in source and binary forms, with or without
12
* modification, are permitted provided that the following conditions are
15
* * Redistributions of source code must retain the above copyright
16
* notice, this list of conditions and the following disclaimer.
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.
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.
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.
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/>.
45
* $Id: Pattern.java,v 1.2 2009/12/10 03:18:44 matthewoliver Exp $
48
package org.jaxen.pattern;
50
import org.jaxen.Context;
51
import org.jaxen.JaxenException;
53
/** <p><code>Pattern</code> defines the behaviour for pattern in
54
* the XSLT processing model.</p>
56
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
57
* @version $Revision: 1.2 $
59
public abstract class Pattern {
61
// These node numbers are compatible with both DOM and dom4j's node types
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
//public static final short ENTITY_NODE = 6;
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
//public static final short DOCUMENT_FRAGMENT_NODE = 11;
83
//public static final short NOTATION_NODE = 12;
85
/** Matches a Namespace Node */
86
// This has the same value as the DOM Level 3 XPathNamespace type
87
public static final short NAMESPACE_NODE = 13;
89
/** Does not match any valid node */
90
public static final short UNKNOWN_NODE = 14;
92
/** The maximum number of node types for sizing purposes */
93
public static final short MAX_NODE_TYPE = 14;
95
/** Matches any node */
96
public static final short ANY_NODE = 0;
98
/** Matches no nodes */
99
public static final short NO_NODE = 14;
105
* @param context ????
106
* @return true if the pattern matches the given node
107
* @throws JaxenException if ????
109
public abstract boolean matches( Object node, Context context ) throws JaxenException;
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>.
115
* @return 0.5; the default priority defined in XSLT
117
* @see <a href="http://www.w3.org/TR/xslt#conflict" target="_top">Section 5.5 of the XSLT specification</a>
120
public double getPriority()
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.
130
* @return an array of the patterns which make up this union pattern
131
* or null if this pattern is not a union pattern
133
public Pattern[] getUnionPatterns()
140
* Returns the type of node the pattern matches.
142
* @return <code>ANY_NODE</code> unless overridden
144
public short getMatchType()
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.
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
159
public String getMatchesNodeName()
165
public Pattern simplify()
170
/** Returns a textual representation of this pattern
172
* @return the usual string form of this XSLT pattern
174
public abstract String getText();