Coverage Report - org.jaxen.pattern.Pattern

Classes in this Package Line Coverage Branch Coverage Complexity
Pattern
33% 
N/A 
1

 1  
 /*
 2  
  * $Header: /home/projects/jaxen/scm/jaxen/src/java/main/org/jaxen/pattern/Pattern.java,v 1.8 2005/04/15 20:19:47 elharo Exp $
 3  
  * $Revision: 1.8 $
 4  
  * $Date: 2005/04/15 20:19:47 $
 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.8 2005/04/15 20:19:47 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.8 $
 72  
   */
 73  88
 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 - NOTE this differs from DOM */
 100  
     // XXXX: ????
 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  
     /** @return true if the pattern matches the given node
 117  
       */
 118  
     public abstract boolean matches( Object node, Context context ) throws JaxenException;
 119  
     
 120  
     /** Returns the default resolution policy of the pattern according to the
 121  
       * <a href="http://www.w3.org/TR/xslt11/#conflict">
 122  
       * XSLT conflict resolution rules</a>. 
 123  
       * 
 124  
       */
 125  
     public double getPriority() 
 126  
     {
 127  0
         return 0.5;
 128  
     }
 129  
     
 130  
     /** If this pattern is a union pattern then this
 131  
       * method should return an array of patterns which
 132  
       * describe the union pattern, which should contain more than one pattern.
 133  
       * Otherwise this method should return null.
 134  
       *
 135  
       * @return an array of the patterns which make up this union pattern
 136  
       * or null if this pattern is not a union pattern
 137  
       */
 138  
     public Pattern[] getUnionPatterns() 
 139  
     {
 140  0
         return null;
 141  
     }
 142  
 
 143  
     
 144  
     /** @return the type of node the pattern matches;
 145  
       * ANY_NODE unless overridden
 146  
       */
 147  
     public short getMatchType() 
 148  
     {
 149  0
         return ANY_NODE;
 150  
     }
 151  
 
 152  
 
 153  
     /** For patterns which only match an ATTRIBUTE_NODE or an 
 154  
       * ELEMENT_NODE then this pattern may return the name of the
 155  
       * element or attribute it matches. This allows a more efficient
 156  
       * rule matching algorithm to be performed, rather than a brute 
 157  
       * force approach of evaluating every pattern for a given Node.
 158  
       *
 159  
       * @return the name of the element or attribute this pattern matches
 160  
       * or null if this pattern matches any or more than one name
 161  
       */
 162  
     public String getMatchesNodeName() 
 163  
     {
 164  10
         return null;
 165  
     }
 166  
     
 167  
     
 168  
     public Pattern simplify() 
 169  
     {
 170  0
         return this;
 171  
     }
 172  
     
 173  
     /** Returns a textual representation of this pattern
 174  
      */
 175  
     public abstract String getText();
 176  
 
 177  
 }