001/* 002 * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved. 003 * 004 * This software is open source. 005 * See the bottom of this file for the licence. 006 * 007 * $Id: NodeTypePattern.java,v 1.2 2001/02/07 16:44:54 jstrachan Exp $ 008 */ 009 010package org.dom4j.rule.pattern; 011 012import org.dom4j.Node; 013import org.dom4j.rule.Pattern; 014 015 016/** <p><code>NodeTypePattern</code> implements a Pattern which matches 017 * any node of the given node type. 018 * 019 * @author <a href="mailto:james.strachan@metastuff.com">James Strachan</a> 020 * @version $Revision: 1.2 $ 021 */ 022public class NodeTypePattern implements Pattern { 023 024 /** A pattern which matches any Attribute node */ 025 public static final NodeTypePattern ANY_ATTRIBUTE 026 = new NodeTypePattern( Node.ATTRIBUTE_NODE ); 027 028 /** A pattern which matches any Comment node */ 029 public static final NodeTypePattern ANY_COMMENT 030 = new NodeTypePattern( Node.COMMENT_NODE ); 031 032 /** A pattern which matches any Document node */ 033 public static final NodeTypePattern ANY_DOCUMENT 034 = new NodeTypePattern( Node.DOCUMENT_NODE ); 035 036 /** A pattern which matches any Element node */ 037 public static final NodeTypePattern ANY_ELEMENT 038 = new NodeTypePattern( Node.ELEMENT_NODE ); 039 040 /** A pattern which matches any ProcessingInstruction node */ 041 public static final NodeTypePattern ANY_PROCESSING_INSTRUCTION 042 = new NodeTypePattern( Node.PROCESSING_INSTRUCTION_NODE ); 043 044 /** A pattern which matches any Text node */ 045 public static final NodeTypePattern ANY_TEXT 046 = new NodeTypePattern( Node.TEXT_NODE ); 047 048 private short nodeType; 049 050 051 public NodeTypePattern(short nodeType) { 052 this.nodeType = nodeType; 053 } 054 055 public boolean matches( Node node ) { 056 return node.getNodeType() == nodeType; 057 } 058 059 public double getPriority() { 060 return Pattern.DEFAULT_PRIORITY; 061 } 062 063 public Pattern[] getUnionPatterns() { 064 return null; 065 } 066 067 public short getMatchType() { 068 return nodeType; 069 } 070 071 public String getMatchesNodeName() { 072 return null; 073 } 074 075} 076 077 078 079 080/* 081 * Redistribution and use of this software and associated documentation 082 * ("Software"), with or without modification, are permitted provided 083 * that the following conditions are met: 084 * 085 * 1. Redistributions of source code must retain copyright 086 * statements and notices. Redistributions must also contain a 087 * copy of this document. 088 * 089 * 2. Redistributions in binary form must reproduce the 090 * above copyright notice, this list of conditions and the 091 * following disclaimer in the documentation and/or other 092 * materials provided with the distribution. 093 * 094 * 3. The name "DOM4J" must not be used to endorse or promote 095 * products derived from this Software without prior written 096 * permission of MetaStuff, Ltd. For written permission, 097 * please contact dom4j-info@metastuff.com. 098 * 099 * 4. Products derived from this Software may not be called "DOM4J" 100 * nor may "DOM4J" appear in their names without prior written 101 * permission of MetaStuff, Ltd. DOM4J is a registered 102 * trademark of MetaStuff, Ltd. 103 * 104 * 5. Due credit should be given to the DOM4J Project 105 * (http://dom4j.org/). 106 * 107 * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS 108 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 109 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 110 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 111 * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 112 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 113 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 114 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 115 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 116 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 117 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 118 * OF THE POSSIBILITY OF SUCH DAMAGE. 119 * 120 * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved. 121 * 122 * $Id: NodeTypePattern.java,v 1.2 2001/02/07 16:44:54 jstrachan Exp $ 123 */