Coverage Report - org.jaxen.expr.DefaultXPathFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultXPathFactory
90%
57/63
100%
3/3
3.115
 
 1  
 /*
 2  
  * $Header: /home/projects/jaxen/scm/jaxen/src/java/main/org/jaxen/expr/DefaultXPathFactory.java,v 1.17 2006/11/09 16:07:36 elharo Exp $
 3  
  * $Revision: 1.17 $
 4  
  * $Date: 2006/11/09 16:07:36 $
 5  
  *
 6  
  * ====================================================================
 7  
  *
 8  
  * Copyright 2000-2002 bob mcwhirter & James Strachan.
 9  
  * All rights reserved.
 10  
  *
 11  
  *
 12  
  * Redistribution and use in source and binary forms, with or without
 13  
  * modification, are permitted provided that the following conditions are
 14  
  * met:
 15  
  * 
 16  
  *   * Redistributions of source code must retain the above copyright
 17  
  *     notice, this list of conditions and the following disclaimer.
 18  
  * 
 19  
  *   * Redistributions in binary form must reproduce the above copyright
 20  
  *     notice, this list of conditions and the following disclaimer in the
 21  
  *     documentation and/or other materials provided with the distribution.
 22  
  * 
 23  
  *   * Neither the name of the Jaxen Project nor the names of its
 24  
  *     contributors may be used to endorse or promote products derived 
 25  
  *     from this software without specific prior written permission.
 26  
  * 
 27  
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 28  
  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 29  
  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 30  
  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
 31  
  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 32  
  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 33  
  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 34  
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 35  
  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 36  
  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 37  
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 38  
  *
 39  
  * ====================================================================
 40  
  * This software consists of voluntary contributions made by many
 41  
  * individuals on behalf of the Jaxen Project and was originally
 42  
  * created by bob mcwhirter <bob@werken.com> and
 43  
  * James Strachan <jstrachan@apache.org>.  For more information on the
 44  
  * Jaxen Project, please see <http://www.jaxen.org/>.
 45  
  *
 46  
  * $Id: DefaultXPathFactory.java,v 1.17 2006/11/09 16:07:36 elharo Exp $
 47  
  */
 48  
 package org.jaxen.expr;
 49  
 
 50  
 import org.jaxen.JaxenException;
 51  
 import org.jaxen.expr.iter.IterableAncestorAxis;
 52  
 import org.jaxen.expr.iter.IterableAncestorOrSelfAxis;
 53  
 import org.jaxen.expr.iter.IterableAttributeAxis;
 54  
 import org.jaxen.expr.iter.IterableAxis;
 55  
 import org.jaxen.expr.iter.IterableChildAxis;
 56  
 import org.jaxen.expr.iter.IterableDescendantAxis;
 57  
 import org.jaxen.expr.iter.IterableDescendantOrSelfAxis;
 58  
 import org.jaxen.expr.iter.IterableFollowingAxis;
 59  
 import org.jaxen.expr.iter.IterableFollowingSiblingAxis;
 60  
 import org.jaxen.expr.iter.IterableNamespaceAxis;
 61  
 import org.jaxen.expr.iter.IterableParentAxis;
 62  
 import org.jaxen.expr.iter.IterablePrecedingAxis;
 63  
 import org.jaxen.expr.iter.IterablePrecedingSiblingAxis;
 64  
 import org.jaxen.expr.iter.IterableSelfAxis;
 65  
 import org.jaxen.saxpath.Axis;
 66  
 import org.jaxen.saxpath.Operator;
 67  
 
 68  
 /**
 69  
  * The concrete implementation of the XPathFactory anstract factory.
 70  
  *
 71  
  *
 72  
  * @see XPathFactory
 73  
  */
 74  6170
 public class DefaultXPathFactory implements XPathFactory
 75  
 {
 76  
     public XPathExpr createXPath( Expr rootExpr ) throws JaxenException
 77  
     {
 78  6124
         return new DefaultXPathExpr( rootExpr );
 79  
     }
 80  
 
 81  
     public PathExpr createPathExpr( FilterExpr filterExpr,
 82  
                                     LocationPath locationPath ) throws JaxenException
 83  
     {
 84  14816
         return new DefaultPathExpr( filterExpr,
 85  
                                     locationPath );
 86  
     }
 87  
 
 88  
     public LocationPath createRelativeLocationPath() throws JaxenException
 89  
     {
 90  2362
         return new DefaultRelativeLocationPath();
 91  
     }
 92  
 
 93  
     public LocationPath createAbsoluteLocationPath() throws JaxenException
 94  
     {
 95  3152
         return new DefaultAbsoluteLocationPath();
 96  
     }
 97  
 
 98  
     public BinaryExpr createOrExpr( Expr lhs,
 99  
                                     Expr rhs ) throws JaxenException
 100  
     {
 101  16
         return new DefaultOrExpr( lhs,
 102  
                                   rhs );
 103  
     }
 104  
 
 105  
     public BinaryExpr createAndExpr( Expr lhs,
 106  
                                      Expr rhs ) throws JaxenException
 107  
     {
 108  248
         return new DefaultAndExpr( lhs,
 109  
                                    rhs );
 110  
     }
 111  
 
 112  
     public BinaryExpr createEqualityExpr( Expr lhs,
 113  
                                           Expr rhs,
 114  
                                           int equalityOperator ) throws JaxenException
 115  
     {
 116  1254
         switch( equalityOperator )
 117  
         {
 118  
             case Operator.EQUALS:
 119  
                 {
 120  1122
                     return new DefaultEqualsExpr( lhs,
 121  
                                                   rhs );
 122  
                 }
 123  
             case Operator.NOT_EQUALS:
 124  
                 {
 125  132
                     return new DefaultNotEqualsExpr( lhs,
 126  
                                                      rhs );
 127  
                 }
 128  
         }
 129  0
         throw new JaxenException( "Unhandled operator in createEqualityExpr(): " + equalityOperator );
 130  
     }
 131  
 
 132  
     public BinaryExpr createRelationalExpr( Expr lhs,
 133  
                                             Expr rhs,
 134  
                                             int relationalOperator ) throws JaxenException
 135  
     {
 136  458
         switch( relationalOperator )
 137  
         {
 138  
             case Operator.LESS_THAN:
 139  
                 {
 140  122
                     return new DefaultLessThanExpr( lhs,
 141  
                                                     rhs );
 142  
                 }
 143  
             case Operator.GREATER_THAN:
 144  
                 {
 145  124
                     return new DefaultGreaterThanExpr( lhs,
 146  
                                                        rhs );
 147  
                 }
 148  
             case Operator.LESS_THAN_EQUALS:
 149  
                 {
 150  96
                     return new DefaultLessThanEqualExpr( lhs,
 151  
                                                          rhs );
 152  
                 }
 153  
             case Operator.GREATER_THAN_EQUALS:
 154  
                 {
 155  116
                     return new DefaultGreaterThanEqualExpr( lhs,
 156  
                                                             rhs );
 157  
                 }
 158  
         }
 159  0
         throw new JaxenException( "Unhandled operator in createRelationalExpr(): " + relationalOperator );
 160  
     }
 161  
 
 162  
     public BinaryExpr createAdditiveExpr( Expr lhs,
 163  
                                           Expr rhs,
 164  
                                           int additiveOperator ) throws JaxenException
 165  
     {
 166  504
         switch( additiveOperator )
 167  
         {
 168  
             case Operator.ADD:
 169  
                 {
 170  296
                     return new DefaultPlusExpr( lhs,
 171  
                                                 rhs );
 172  
                 }
 173  
             case Operator.SUBTRACT:
 174  
                 {
 175  208
                     return new DefaultMinusExpr( lhs,
 176  
                                                  rhs );
 177  
                 }
 178  
         }
 179  0
         throw new JaxenException( "Unhandled operator in createAdditiveExpr(): " + additiveOperator );
 180  
     }
 181  
 
 182  
     public BinaryExpr createMultiplicativeExpr( Expr lhs,
 183  
                                                 Expr rhs,
 184  
                                                 int multiplicativeOperator ) throws JaxenException
 185  
     {
 186  378
         switch( multiplicativeOperator )
 187  
         {
 188  
             case Operator.MULTIPLY:
 189  
                 {
 190  122
                     return new DefaultMultiplyExpr( lhs,
 191  
                                                     rhs );
 192  
                 }
 193  
             case Operator.DIV:
 194  
                 {
 195  186
                     return new DefaultDivExpr( lhs,
 196  
                                                rhs );
 197  
                 }
 198  
             case Operator.MOD:
 199  
                 {
 200  70
                     return new DefaultModExpr( lhs,
 201  
                                                rhs );
 202  
                 }
 203  
         }
 204  0
         throw new JaxenException( "Unhandled operator in createMultiplicativeExpr(): " + multiplicativeOperator );
 205  
     }
 206  
 
 207  
     public Expr createUnaryExpr( Expr expr,
 208  
                                  int unaryOperator ) throws JaxenException
 209  
     {
 210  136
         switch( unaryOperator )
 211  
         {
 212  
             case Operator.NEGATIVE:
 213  
                 {
 214  136
                     return new DefaultUnaryExpr( expr );
 215  
                 }
 216  
         }
 217  0
         return expr;
 218  
     }
 219  
 
 220  
     public UnionExpr createUnionExpr( Expr lhs,
 221  
                                       Expr rhs ) throws JaxenException
 222  
     {
 223  40
         return new DefaultUnionExpr( lhs,
 224  
                                      rhs );
 225  
     }
 226  
 
 227  
     public FilterExpr createFilterExpr( Expr expr ) throws JaxenException
 228  
     {
 229  9460
         return new DefaultFilterExpr( expr, createPredicateSet() );
 230  
     }
 231  
 
 232  
     public FunctionCallExpr createFunctionCallExpr( String prefix,
 233  
                                                     String functionName ) throws JaxenException
 234  
     {
 235  2644
         return new DefaultFunctionCallExpr( prefix,
 236  
                                             functionName );
 237  
     }
 238  
 
 239  
     public NumberExpr createNumberExpr( int number ) throws JaxenException
 240  
     {
 241  0
         return new DefaultNumberExpr( new Double( number ) );
 242  
     }
 243  
 
 244  
     public NumberExpr createNumberExpr( double number ) throws JaxenException
 245  
     {
 246  3150
         return new DefaultNumberExpr( new Double( number ) );
 247  
     }
 248  
 
 249  
     public LiteralExpr createLiteralExpr( String literal ) throws JaxenException
 250  
     {
 251  2196
         return new DefaultLiteralExpr( literal );
 252  
     }
 253  
 
 254  
     public VariableReferenceExpr createVariableReferenceExpr( String prefix,
 255  
                                                               String variable ) throws JaxenException
 256  
     {
 257  78
         return new DefaultVariableReferenceExpr( prefix,
 258  
                                                  variable );
 259  
     }
 260  
 
 261  
     public Step createNameStep( int axis,
 262  
                                 String prefix,
 263  
                                 String localName ) throws JaxenException
 264  
     {
 265  7548
         IterableAxis iter = getIterableAxis( axis );
 266  7548
         return new DefaultNameStep( iter,
 267  
                                     prefix,
 268  
                                     localName,
 269  
                                     createPredicateSet() );
 270  
     }
 271  
 
 272  
     public Step createTextNodeStep( int axis ) throws JaxenException
 273  
     {
 274  156
         IterableAxis iter = getIterableAxis( axis );
 275  156
         return new DefaultTextNodeStep( iter, createPredicateSet() );
 276  
     }
 277  
 
 278  
     public Step createCommentNodeStep( int axis ) throws JaxenException
 279  
     {
 280  90
         IterableAxis iter = getIterableAxis( axis );
 281  90
         return new DefaultCommentNodeStep( iter, createPredicateSet() );
 282  
     }
 283  
 
 284  
     public Step createAllNodeStep( int axis ) throws JaxenException
 285  
     {
 286  1278
         IterableAxis iter = getIterableAxis( axis );
 287  1276
         return new DefaultAllNodeStep( iter, createPredicateSet() );
 288  
     }
 289  
 
 290  
     public Step createProcessingInstructionNodeStep( int axis,
 291  
                                                      String piName ) throws JaxenException
 292  
     {
 293  140
         IterableAxis iter = getIterableAxis( axis );
 294  140
         return new DefaultProcessingInstructionNodeStep( iter,
 295  
                                                          piName,
 296  
                                                          createPredicateSet() );
 297  
     }
 298  
 
 299  
     public Predicate createPredicate( Expr predicateExpr ) throws JaxenException
 300  
     {
 301  1346
         return new DefaultPredicate( predicateExpr );
 302  
     }
 303  
 
 304  
     protected IterableAxis getIterableAxis( int axis ) throws JaxenException
 305  
     {
 306  
 
 307  9212
         switch( axis )
 308  
         {
 309  
             case Axis.CHILD:
 310  6178
                  return new IterableChildAxis( axis );
 311  
             case Axis.DESCENDANT:
 312  322
                  return  new IterableDescendantAxis( axis );
 313  
             case Axis.PARENT:
 314  238
                 return new IterableParentAxis( axis );
 315  
             case Axis.FOLLOWING_SIBLING:
 316  34
                 return  new IterableFollowingSiblingAxis( axis );
 317  
             case Axis.PRECEDING_SIBLING:
 318  180
                 return new IterablePrecedingSiblingAxis( axis );
 319  
             case Axis.FOLLOWING:
 320  64
                 return new IterableFollowingAxis( axis );
 321  
             case Axis.PRECEDING:
 322  138
                 return new IterablePrecedingAxis( axis );
 323  
             case Axis.ATTRIBUTE:
 324  732
                 return new IterableAttributeAxis( axis );
 325  
             case Axis.NAMESPACE:
 326  274
                 return new IterableNamespaceAxis( axis );
 327  
             case Axis.SELF:
 328  304
                 return new IterableSelfAxis( axis );
 329  
             case Axis.DESCENDANT_OR_SELF:
 330  652
                 return new IterableDescendantOrSelfAxis( axis );
 331  
             case Axis.ANCESTOR_OR_SELF:
 332  34
                 return new IterableAncestorOrSelfAxis( axis );
 333  
             case Axis.ANCESTOR:
 334  60
                 return new IterableAncestorAxis( axis );
 335  
             default:
 336  2
                 throw new JaxenException("Unrecognized axis code: " + axis);
 337  
         }
 338  
 
 339  
     }
 340  
 
 341  
     public PredicateSet createPredicateSet() throws JaxenException
 342  
     {
 343  18670
         return new PredicateSet();
 344  
     }
 345  
     
 346  
 }