1   /*
2    * $Header$
3    * $Revision$
4    * $Date$
5    *
6    * ====================================================================
7    *
8    * Copyright 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 are
13   * met:
14   * 
15   *   * Redistributions of source code must retain the above copyright
16   *     notice, this list of conditions and the following disclaimer.
17   * 
18   *   * Redistributions in binary form must reproduce the above copyright
19   *     notice, this list of conditions and the following disclaimer in the
20   *     documentation and/or other materials provided with the distribution.
21   * 
22   *   * Neither the name of the Jaxen Project nor the names of its
23   *     contributors may be used to endorse or promote products derived 
24   *     from this software without specific prior written permission.
25   * 
26   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
27   * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28   * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
29   * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
30   * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31   * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32   * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33   * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34   * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35   * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37   *
38   * ====================================================================
39   * This software consists of voluntary contributions made by many
40   * individuals on behalf of the Jaxen Project and was originally
41   * created by bob mcwhirter <bob@werken.com> and
42   * James Strachan <jstrachan@apache.org>.  For more information on the
43   * Jaxen Project, please see <http://www.jaxen.org/>.
44   *
45   * $Id$
46   */
47  
48  
49  
50  
51  package org.jaxen.test;
52  
53  import java.util.Iterator;
54  import java.util.LinkedList;
55  import java.util.List;
56  
57  import org.jaxen.saxpath.XPathHandler;
58  
59  class ConformanceXPathHandler implements XPathHandler
60  {
61      private List events;
62  
63      ConformanceXPathHandler()
64      {
65          this.events = new LinkedList();
66      }
67  
68      public void startXPath()
69      {
70          addEvent( "startXPath()" );
71      }
72  
73      public void endXPath()
74      {
75          addEvent( "endXPath()" );
76      }
77  
78      public void startPathExpr()
79      {
80          addEvent( "startPathExpr()" );
81      }
82  
83      public void endPathExpr()
84      {
85          addEvent( "endPathExpr()" );
86      }
87  
88      public void startAbsoluteLocationPath()
89      {
90          addEvent( "startAbsoluteLocationPath()" );
91      }
92      public void endAbsoluteLocationPath()
93      {
94          addEvent( "endAbsoluteLocationPath()" );
95      }
96  
97      public void startRelativeLocationPath()
98      {
99          addEvent( "startRelativeLocationPath()" );
100     }
101 
102     public void endRelativeLocationPath()
103     {
104         addEvent( "endRelativeLocationPath()" );
105     }
106 
107     public void startNameStep(int axis,
108                               String prefix,
109                               String localName)
110     {
111         addEvent( "startNameStep(" + axis + ", \"" + prefix + "\", \"" + localName + "\")" );
112     }
113 
114     public void endNameStep()
115     {
116         addEvent( "endNameStep()" );
117     }
118 
119     public void startTextNodeStep(int axis)
120     {
121         addEvent( "startTextNodeStep(" + axis + ")" );
122     }
123     public void endTextNodeStep()
124     {
125         addEvent( "endTextNodeStep()" );
126     }
127 
128     public void startCommentNodeStep(int axis)
129     {
130         addEvent( "startCommentNodeStep(" + axis + ")" );
131     }
132 
133     public void endCommentNodeStep()
134     {
135         addEvent( "endCommentNodeStep()" );
136     }
137 
138     public void startAllNodeStep(int axis)
139     {
140         addEvent( "startAllNodeStep(" + axis + ")" );
141     }
142 
143     public void endAllNodeStep()
144     {
145         addEvent( "endAllNodeStep()" );
146     }
147 
148     public void startProcessingInstructionNodeStep(int axis,
149                                                    String name)
150     {
151         addEvent( "startProcessingInstructionNodeStep(" + axis + ", \"" + name + "\")" );
152     }
153     public void endProcessingInstructionNodeStep()
154     {
155         addEvent( "endProcessingInstructionNodeStep()" );
156     }
157 
158     public void startPredicate()
159     {
160         addEvent( "startPredicate()" );
161     }
162 
163     public void endPredicate()
164     {
165         addEvent( "endPredicate()" );
166     }
167 
168     public void startFilterExpr()
169     {
170         addEvent( "startFilterExpr()" );
171     }
172 
173     public void endFilterExpr()
174     {
175         addEvent( "endFilterExpr()" );
176     }
177 
178     public void startOrExpr()
179     {
180         addEvent( "startOrExpr()" );
181     }
182 
183     public void endOrExpr(boolean create)
184     {
185         addEvent( "endOrExpr(" + create + ")" );
186     }
187 
188     public void startAndExpr()
189     {
190         addEvent( "startAndExpr()" );
191     }
192 
193     public void endAndExpr(boolean create)
194     {
195         addEvent( "endAndExpr(" + create + ")" );
196     }
197 
198     public void startEqualityExpr()
199     {
200         addEvent( "startEqualityExpr()" );
201     }
202 
203     public void endEqualityExpr(int operator)
204     {
205         addEvent( "endEqualityExpr(" + operator + ")" );
206     }
207 
208     public void startRelationalExpr()
209     {
210         addEvent( "startRelationalExpr()" );
211     }
212 
213     public void endRelationalExpr(int operator)
214     {
215         addEvent( "endRelationalExpr(" + operator + ")" );
216     }
217 
218     public void startAdditiveExpr()
219     {
220         addEvent( "startAdditiveExpr()" );
221     }
222 
223     public void endAdditiveExpr(int operator)
224     {
225         addEvent( "endAdditiveExpr(" + operator + ")" );
226     }
227 
228     public void startMultiplicativeExpr()
229     {
230         addEvent( "startMultiplicativeExpr()" );
231     }
232 
233     public void endMultiplicativeExpr(int operator)
234     {
235         addEvent( "endMultiplicativeExpr(" + operator + ")" );
236     }
237 
238     public void startUnaryExpr()
239     {
240         addEvent( "startUnaryExpr()" );
241     }
242 
243     public void endUnaryExpr(int operator)
244     {
245         addEvent( "endUnaryExpr(" + operator + ")" );
246     }
247 
248     public void startUnionExpr()
249     {
250         addEvent( "startUnionExpr()" );
251     }
252 
253     public void endUnionExpr(boolean create)
254     {
255         addEvent( "endUnionExpr(" + create + ")" );
256     }
257 
258     public void number(int number)
259     {
260         addEvent( "number(" + number + ")" );
261     }
262 
263     public void number(double number)
264     {
265         addEvent( "number(" + number + ")" );
266     }
267 
268     public void literal(String literal)
269     {
270         addEvent( "literal(\"" + literal + "\")" );
271     }
272 
273     public void variableReference(String prefix,
274                                   String variableName)
275     {
276         addEvent( "variableReference(\"" + prefix + ":" + variableName + "\")" );
277     }
278 
279     public void startFunction(String prefix,
280                               String functionName)
281     {
282         addEvent( "startFunction(\"" + prefix + ":" + functionName + "\")" );
283     }
284 
285     public void endFunction()
286     {
287         addEvent( "endFunction()" );
288     }
289 
290     private void addEvent(String eventStr)
291     {
292         this.events.add( eventStr );
293     }
294 
295     public boolean equals(Object thatObj)
296     {
297         if ( thatObj instanceof ConformanceXPathHandler )
298         {
299             ConformanceXPathHandler that = (ConformanceXPathHandler) thatObj;
300 
301             return ( this.events.equals( that.events ) );
302         }
303 
304         return false;
305     }
306     
307     public int hashCode() {
308         return this.events.hashCode();
309     }
310     
311 
312     public String toString()
313     {
314         Iterator eventIter = this.events.iterator();
315         int      i = 0;
316 
317         StringBuffer buf = new StringBuffer();
318 
319         while( eventIter.hasNext() )
320         {
321             buf.append("(").append(i).append(") ").append( eventIter.next().toString() ).append("\n");
322             ++i;
323         }
324 
325         return buf.toString();
326     }
327 }