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: DefaultPattern.java,v 1.1 2001/02/07 14:51:18 jstrachan Exp $
008 */
009
010package org.dom4j.rule.pattern;
011
012import org.dom4j.Node;
013import org.dom4j.NodeFilter;
014import org.dom4j.rule.Pattern;
015
016
017/** <p><code>DefaultPattern</code> a default implementation of Pattern
018  * which can take any XPath implementation or NodeFilter for defining the pattern.
019  * <b>WARNING</b> this implementation causes a worst case, brute force XSLT 
020  * rule evaluation to be performed. 
021  * Wherever possible the methods 
022  *  {@link #getPriority}, 
023  *  {@link #getMatchType} and
024  *  {@link #getMatchesNodeName}
025  * should be overloaded to allow more rule filtering to occur.</p>
026  *
027  * @author <a href="mailto:james.strachan@metastuff.com">James Strachan</a>
028  * @version $Revision: 1.1 $
029  */
030public class DefaultPattern implements Pattern {
031    
032    private NodeFilter filter;
033
034    
035    public DefaultPattern(NodeFilter filter) {
036        this.filter = filter;
037    }
038
039    public boolean matches( Node node ) {
040        return filter.matches( node );
041    }
042    
043    public double getPriority()  {
044        return Pattern.DEFAULT_PRIORITY;
045    }
046    
047    public Pattern[] getUnionPatterns() {
048        return null;
049    }
050
051    public short getMatchType() {
052        return ANY_NODE;
053    }
054
055    public String getMatchesNodeName() {
056        return null;
057    }
058
059}
060
061
062
063
064/*
065 * Redistribution and use of this software and associated documentation
066 * ("Software"), with or without modification, are permitted provided
067 * that the following conditions are met:
068 *
069 * 1. Redistributions of source code must retain copyright
070 *    statements and notices.  Redistributions must also contain a
071 *    copy of this document.
072 *
073 * 2. Redistributions in binary form must reproduce the
074 *    above copyright notice, this list of conditions and the
075 *    following disclaimer in the documentation and/or other
076 *    materials provided with the distribution.
077 *
078 * 3. The name "DOM4J" must not be used to endorse or promote
079 *    products derived from this Software without prior written
080 *    permission of MetaStuff, Ltd.  For written permission,
081 *    please contact dom4j-info@metastuff.com.
082 *
083 * 4. Products derived from this Software may not be called "DOM4J"
084 *    nor may "DOM4J" appear in their names without prior written
085 *    permission of MetaStuff, Ltd. DOM4J is a registered
086 *    trademark of MetaStuff, Ltd.
087 *
088 * 5. Due credit should be given to the DOM4J Project
089 *    (http://dom4j.org/).
090 *
091 * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
092 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
093 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
094 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
095 * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
096 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
097 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
098 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
099 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
100 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
101 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
102 * OF THE POSSIBILITY OF SUCH DAMAGE.
103 *
104 * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved.
105 *
106 * $Id: DefaultPattern.java,v 1.1 2001/02/07 14:51:18 jstrachan Exp $
107 */