##### Coverage Report - org.jaxen.expr.DefaultXPathFactory

Classes in this File | Line Coverage | Branch Coverage | Complexity
DefaultXPathFactory |
93% |
100% |
| 2.576923076923077;2.577

1 |  |
     /*
2 |  |
      * $Header: /home/projects/jaxen/scm/jaxen/src/java/main/org/jaxen/expr/DefaultXPathFactory.java,v 1.14 2005/06/28 13:44:44 elharo Exp $
3 |  |
      * $Revision: 1.14 $
4 |  |
      * $Date: 2005/06/28 13:44:44 $
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: DefaultXPathFactory.java,v 1.14 2005/06/28 13:44:44 elharo Exp $
60 |  |
      */
61 |  |
     package org.jaxen.expr;
62 |  |
63 |  |
     import org.jaxen.JaxenException;
64 |  |
     import org.jaxen.expr.iter.IterableAncestorAxis;
65 |  |
     import org.jaxen.expr.iter.IterableAncestorOrSelfAxis;
66 |  |
     import org.jaxen.expr.iter.IterableAttributeAxis;
67 |  |
     import org.jaxen.expr.iter.IterableAxis;
68 |  |
     import org.jaxen.expr.iter.IterableChildAxis;
69 |  |
     import org.jaxen.expr.iter.IterableDescendantAxis;
70 |  |
     import org.jaxen.expr.iter.IterableDescendantOrSelfAxis;
71 |  |
     import org.jaxen.expr.iter.IterableFollowingAxis;
72 |  |
     import org.jaxen.expr.iter.IterableFollowingSiblingAxis;
73 |  |
     import org.jaxen.expr.iter.IterableNamespaceAxis;
74 |  |
     import org.jaxen.expr.iter.IterableParentAxis;
75 |  |
     import org.jaxen.expr.iter.IterablePrecedingAxis;
76 |  |
     import org.jaxen.expr.iter.IterablePrecedingSiblingAxis;
77 |  |
     import org.jaxen.expr.iter.IterableSelfAxis;
78 |  |
     import org.jaxen.saxpath.Axis;
79 |  |
     import org.jaxen.saxpath.Operator;
80 |  |
81 | 10872 |
     public class DefaultXPathFactory implements XPathFactory
82 |  |
     {
83 |  |
         public XPathExpr createXPath( Expr rootExpr ) throws JaxenException
84 |  |
         {
85 | 10764 |
             return new DefaultXPathExpr( rootExpr );
86 |  |
         }
87 |  |
88 |  |
         public PathExpr createPathExpr( FilterExpr filterExpr,
89 |  |
                                         LocationPath locationPath ) throws JaxenException
90 |  |
         {
91 | 23094 |
             return new DefaultPathExpr( filterExpr,
92 |  |
                                         locationPath );
93 |  |
         }
94 |  |
95 |  |
         public LocationPath createRelativeLocationPath() throws JaxenException
96 |  |
         {
97 | 3930 |
             return new DefaultRelativeLocationPath();
98 |  |
         }
99 |  |
100 |  |
         public LocationPath createAbsoluteLocationPath() throws JaxenException
101 |  |
         {
102 | 6036 |
             return new DefaultAbsoluteLocationPath();
103 |  |
         }
104 |  |
105 |  |
         public BinaryExpr createOrExpr( Expr lhs,
106 |  |
                                         Expr rhs ) throws JaxenException
107 |  |
         {
108 | 30 |
             return new DefaultOrExpr( lhs,
109 |  |
                                       rhs );
110 |  |
         }
111 |  |
112 |  |
         public BinaryExpr createAndExpr( Expr lhs,
113 |  |
                                          Expr rhs ) throws JaxenException
114 |  |
         {
115 | 390 |
             return new DefaultAndExpr( lhs,
116 |  |
                                        rhs );
117 |  |
         }
118 |  |
119 |  |
         public BinaryExpr createEqualityExpr( Expr lhs,
120 |  |
                                               Expr rhs,
121 |  |
                                               int equalityOperator ) throws JaxenException
122 |  |
         {
123 | 1902 |
             switch( equalityOperator )
124 |  |
             {
125 |  |
                 case Operator.EQUALS:
126 |  |
                     {
127 | 1698 |
                         return new DefaultEqualsExpr( lhs,
128 |  |
                                                       rhs );
129 |  |
                     }
130 |  |
                 case Operator.NOT_EQUALS:
131 |  |
                     {
132 | 204 |
                         return new DefaultNotEqualsExpr( lhs,
133 |  |
                                                          rhs );
134 |  |
                     }
135 |  |
             }
136 | 0 |
             throw new JaxenException( "Unhandled operator in createEqualityExpr(): " + equalityOperator );
137 |  |
         }
138 |  |
139 |  |
         public BinaryExpr createRelationalExpr( Expr lhs,
140 |  |
                                                 Expr rhs,
141 |  |
                                                 int relationalOperator ) throws JaxenException
142 |  |
         {
143 | 600 |
             switch( relationalOperator )
144 |  |
             {
145 |  |
                 case Operator.LESS_THAN:
146 |  |
                     {
147 | 150 |
                         return new DefaultLessThanExpr( lhs,
148 |  |
                                                         rhs );
149 |  |
                     }
150 |  |
                 case Operator.GREATER_THAN:
151 |  |
                     {
152 | 198 |
                         return new DefaultGreaterThanExpr( lhs,
153 |  |
                                                            rhs );
154 |  |
                     }
155 |  |
                 case Operator.LESS_THAN_EQUALS:
156 |  |
                     {
157 | 96 |
                         return new DefaultLessThanEqualExpr( lhs,
158 |  |
                                                              rhs );
159 |  |
                     }
160 |  |
                 case Operator.GREATER_THAN_EQUALS:
161 |  |
                     {
162 | 156 |
                         return new DefaultGreaterThanEqualExpr( lhs,
163 |  |
                                                                 rhs );
164 |  |
                     }
165 |  |
             }
166 | 0 |
             throw new JaxenException( "Unhandled operator in createRelationalExpr(): " + relationalOperator );
167 |  |
         }
168 |  |
169 |  |
         public BinaryExpr createAdditiveExpr( Expr lhs,
170 |  |
                                               Expr rhs,
171 |  |
                                               int additiveOperator ) throws JaxenException
172 |  |
         {
173 | 648 |
             switch( additiveOperator )
174 |  |
             {
175 |  |
                 case Operator.ADD:
176 |  |
                     {
177 | 432 |
                         return new DefaultPlusExpr( lhs,
178 |  |
                                                     rhs );
179 |  |
                     }
180 |  |
                 case Operator.SUBTRACT:
181 |  |
                     {
182 | 216 |
                         return new DefaultMinusExpr( lhs,
183 |  |
                                                      rhs );
184 |  |
                     }
185 |  |
             }
186 | 0 |
             throw new JaxenException( "Unhandled operator in createAdditiveExpr(): " + additiveOperator );
187 |  |
         }
188 |  |
189 |  |
         public BinaryExpr createMultiplicativeExpr( Expr lhs,
190 |  |
                                                     Expr rhs,
191 |  |
                                                     int multiplicativeOperator ) throws JaxenException
192 |  |
         {
193 | 510 |
             switch( multiplicativeOperator )
194 |  |
             {
195 |  |
                 case Operator.MULTIPLY:
196 |  |
                     {
197 | 150 |
                         return new DefaultMultiplyExpr( lhs,
198 |  |
                                                         rhs );
199 |  |
                     }
200 |  |
                 case Operator.DIV:
201 |  |
                     {
202 | 294 |
                         return new DefaultDivExpr( lhs,
203 |  |
                                                    rhs );
204 |  |
                     }
205 |  |
                 case Operator.MOD:
206 |  |
                     {
207 | 66 |
                         return new DefaultModExpr( lhs,
208 |  |
                                                    rhs );
209 |  |
                     }
210 |  |
             }
211 | 0 |
             throw new JaxenException( "Unhandled operator in createMultiplicativeExpr(): " + multiplicativeOperator );
212 |  |
         }
213 |  |
214 |  |
         public Expr createUnaryExpr( Expr expr,
215 |  |
                                      int unaryOperator ) throws JaxenException
216 |  |
         {
217 | 240 |
             switch( unaryOperator )
218 |  |
             {
219 |  |
                 case Operator.NEGATIVE:
220 |  |
                     {
221 | 240 |
                         return new DefaultUnaryExpr( expr );
222 |  |
                     }
223 |  |
             }
224 | 0 |
             return expr;
225 |  |
         }
226 |  |
227 |  |
         public UnionExpr createUnionExpr( Expr lhs,
228 |  |
                                           Expr rhs ) throws JaxenException
229 |  |
         {
230 | 120 |
             return new DefaultUnionExpr( lhs,
231 |  |
                                          rhs );
232 |  |
         }
233 |  |
234 |  |
         public FilterExpr createFilterExpr( Expr expr ) throws JaxenException
235 |  |
         {
236 | 13446 |
             return new DefaultFilterExpr( expr, createPredicateSet() );
237 |  |
         }
238 |  |
239 |  |
         public FunctionCallExpr createFunctionCallExpr( String prefix,
240 |  |
                                                         String functionName ) throws JaxenException
241 |  |
         {
242 | 4632 |
             return new DefaultFunctionCallExpr( prefix,
243 |  |
                                                 functionName );
244 |  |
         }
245 |  |
246 |  |
         public NumberExpr createNumberExpr( int number ) throws JaxenException
247 |  |
         {
248 | 4266 |
             return new DefaultNumberExpr( new Double( number ) );
249 |  |
         }
250 |  |
251 |  |
         public NumberExpr createNumberExpr( double number ) throws JaxenException
252 |  |
         {
253 | 276 |
             return new DefaultNumberExpr( new Double( number ) );
254 |  |
         }
255 |  |
256 |  |
         public LiteralExpr createLiteralExpr( String literal ) throws JaxenException
257 |  |
         {
258 | 3906 |
             return new DefaultLiteralExpr( literal );
259 |  |
         }
260 |  |
261 |  |
         public VariableReferenceExpr createVariableReferenceExpr( String prefix,
262 |  |
                                                                   String variable ) throws JaxenException
263 |  |
         {
264 | 126 |
             return new DefaultVariableReferenceExpr( prefix,
265 |  |
                                                      variable );
266 |  |
         }
267 |  |
268 |  |
         public Step createNameStep( int axis,
269 |  |
                                     String prefix,
270 |  |
                                     String localName ) throws JaxenException
271 |  |
         {
272 | 13158 |
             IterableAxis iter = getIterableAxis( axis );
273 | 13158 |
             return new DefaultNameStep( iter,
274 |  |
                                         prefix,
275 |  |
                                         localName,
276 |  |
                                         createPredicateSet() );
277 |  |
         }
278 |  |
279 |  |
         public Step createTextNodeStep( int axis ) throws JaxenException
280 |  |
         {
281 | 240 |
             IterableAxis iter = getIterableAxis( axis );
282 | 240 |
             return new DefaultTextNodeStep( iter, createPredicateSet() );
283 |  |
         }
284 |  |
285 |  |
         public Step createCommentNodeStep( int axis ) throws JaxenException
286 |  |
         {
287 | 150 |
             IterableAxis iter = getIterableAxis( axis );
288 | 150 |
             return new DefaultCommentNodeStep( iter, createPredicateSet() );
289 |  |
         }
290 |  |
291 |  |
         public Step createAllNodeStep( int axis ) throws JaxenException
292 |  |
         {
293 | 2268 |
             IterableAxis iter = getIterableAxis( axis );
294 | 2268 |
             return new DefaultAllNodeStep( iter, createPredicateSet() );
295 |  |
         }
296 |  |
297 |  |
         public Step createProcessingInstructionNodeStep( int axis,
298 |  |
                                                          String piName ) throws JaxenException
299 |  |
         {
300 | 210 |
             IterableAxis iter = getIterableAxis( axis );
301 | 210 |
             return new DefaultProcessingInstructionNodeStep( iter,
302 |  |
                                                              piName,
303 |  |
                                                              createPredicateSet() );
304 |  |
         }
305 |  |
306 |  |
         public Predicate createPredicate( Expr predicateExpr ) throws JaxenException
307 |  |
         {
308 | 2316 |
             return new DefaultPredicate( predicateExpr );
309 |  |
         }
310 |  |
311 |  |
         protected IterableAxis getIterableAxis( int axis )
312 |  |
         {
313 | 16026 |
             IterableAxis iter = null;
314 | 16026 |
             switch( axis )
315 |  |
             {
316 |  |
                 case Axis.CHILD:
317 |  |
                     {
318 | 10836 |
                         iter = new IterableChildAxis( axis );
319 | 10836 |
                         break;
320 |  |
                     }
321 |  |
                 case Axis.DESCENDANT:
322 |  |
                     {
323 | 510 |
                         iter = new IterableDescendantAxis( axis );
324 | 510 |
                         break;
325 |  |
                     }
326 |  |
                 case Axis.PARENT:
327 |  |
                     {
328 | 378 |
                         iter = new IterableParentAxis( axis );
329 | 378 |
                         break;
330 |  |
                     }
331 |  |
                 case Axis.FOLLOWING_SIBLING:
332 |  |
                     {
333 | 54 |
                         iter = new IterableFollowingSiblingAxis( axis );
334 | 54 |
                         break;
335 |  |
                     }
336 |  |
                 case Axis.PRECEDING_SIBLING:
337 |  |
                     {
338 | 270 |
                         iter = new IterablePrecedingSiblingAxis( axis );
339 | 270 |
                         break;
340 |  |
                     }
341 |  |
                 case Axis.FOLLOWING:
342 |  |
                     {
343 | 96 |
                         iter = new IterableFollowingAxis( axis );
344 | 96 |
                         break;
345 |  |
                     }
346 |  |
                 case Axis.PRECEDING:
347 |  |
                     {
348 | 222 |
                         iter = new IterablePrecedingAxis( axis );
349 | 222 |
                         break;
350 |  |
                     }
351 |  |
                 case Axis.ATTRIBUTE:
352 |  |
                     {
353 | 1320 |
                         iter = new IterableAttributeAxis( axis );
354 | 1320 |
                         break;
355 |  |
                     }
356 |  |
                 case Axis.NAMESPACE:
357 |  |
                     {
358 | 468 |
                         iter = new IterableNamespaceAxis( axis );
359 | 468 |
                         break;
360 |  |
                     }
361 |  |
                 case Axis.SELF:
362 |  |
                     {
363 | 486 |
                         iter = new IterableSelfAxis( axis );
364 | 486 |
                         break;
365 |  |
                     }
366 |  |
                 case Axis.DESCENDANT_OR_SELF:
367 |  |
                     {
368 | 1224 |
                         iter = new IterableDescendantOrSelfAxis( axis );
369 | 1224 |
                         break;
370 |  |
                     }
371 |  |
                 case Axis.ANCESTOR_OR_SELF:
372 |  |
                     {
373 | 54 |
                         iter = new IterableAncestorOrSelfAxis( axis );
374 | 54 |
                         break;
375 |  |
                     }
376 |  |
                 case Axis.ANCESTOR:
377 |  |
                     {
378 | 108 |
                         iter = new IterableAncestorAxis( axis );
379 |  |
                         break;
380 |  |
                     }
381 |  |
             }
382 | 16026 |
             return iter;
383 |  |
         }
384 |  |
385 |  |
         public PredicateSet createPredicateSet() throws JaxenException
386 |  |
         {
387 | 29472 |
             return new PredicateSet();
388 |  |
         }
389 |  |
     }