1 /*
2 * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
3 *
4 * This software is open source.
5 * See the bottom of this file for the licence.
6 */
7
8 package org.dom4j.rule.pattern;
9
10 import org.dom4j.Node;
11 import org.dom4j.rule.Pattern;
12
13 /***
14 * <p>
15 * <code>NodeTypePattern</code> implements a Pattern which matches any node of
16 * the given node type.
17 * </p>
18 *
19 * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
20 * @version $Revision: 1.7 $
21 */
22 public class NodeTypePattern implements Pattern {
23 /*** A pattern which matches any Attribute node */
24 public static final NodeTypePattern ANY_ATTRIBUTE = new NodeTypePattern(
25 Node.ATTRIBUTE_NODE);
26
27 /*** A pattern which matches any Comment node */
28 public static final NodeTypePattern ANY_COMMENT = new NodeTypePattern(
29 Node.COMMENT_NODE);
30
31 /*** A pattern which matches any Document node */
32 public static final NodeTypePattern ANY_DOCUMENT = new NodeTypePattern(
33 Node.DOCUMENT_NODE);
34
35 /*** A pattern which matches any Element node */
36 public static final NodeTypePattern ANY_ELEMENT = new NodeTypePattern(
37 Node.ELEMENT_NODE);
38
39 /*** A pattern which matches any ProcessingInstruction node */
40 public static final NodeTypePattern ANY_PROCESSING_INSTRUCTION =
41 new NodeTypePattern(Node.PROCESSING_INSTRUCTION_NODE);
42
43 /*** A pattern which matches any Text node */
44 public static final NodeTypePattern ANY_TEXT = new NodeTypePattern(
45 Node.TEXT_NODE);
46
47 private short nodeType;
48
49 public NodeTypePattern(short nodeType) {
50 this.nodeType = nodeType;
51 }
52
53 public boolean matches(Node node) {
54 return node.getNodeType() == nodeType;
55 }
56
57 public double getPriority() {
58 return Pattern.DEFAULT_PRIORITY;
59 }
60
61 public Pattern[] getUnionPatterns() {
62 return null;
63 }
64
65 public short getMatchType() {
66 return nodeType;
67 }
68
69 public String getMatchesNodeName() {
70 return null;
71 }
72 }
73
74 /*
75 * Redistribution and use of this software and associated documentation
76 * ("Software"), with or without modification, are permitted provided that the
77 * following conditions are met:
78 *
79 * 1. Redistributions of source code must retain copyright statements and
80 * notices. Redistributions must also contain a copy of this document.
81 *
82 * 2. Redistributions in binary form must reproduce the above copyright notice,
83 * this list of conditions and the following disclaimer in the documentation
84 * and/or other materials provided with the distribution.
85 *
86 * 3. The name "DOM4J" must not be used to endorse or promote products derived
87 * from this Software without prior written permission of MetaStuff, Ltd. For
88 * written permission, please contact dom4j-info@metastuff.com.
89 *
90 * 4. Products derived from this Software may not be called "DOM4J" nor may
91 * "DOM4J" appear in their names without prior written permission of MetaStuff,
92 * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
93 *
94 * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
95 *
96 * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
97 * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
98 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
99 * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
100 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
101 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
102 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
103 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
104 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
105 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
106 * POSSIBILITY OF SUCH DAMAGE.
107 *
108 * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
109 */