KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jaxen > saxpath > base > ConformanceXPathHandler


1 /*
2  * $Header$
3  * $Revision$
4  * $Date$
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$
60  */

61
62
63
64
65 package org.jaxen.saxpath.base;
66
67 import java.util.Iterator JavaDoc;
68 import java.util.LinkedList JavaDoc;
69 import java.util.List JavaDoc;
70
71 import org.jaxen.saxpath.XPathHandler;
72
73 class ConformanceXPathHandler implements XPathHandler
74 {
75     private List JavaDoc events;
76
77     ConformanceXPathHandler()
78     {
79         this.events = new LinkedList JavaDoc();
80     }
81
82     public void startXPath()
83     {
84         addEvent( "startXPath()" );
85     }
86
87     public void endXPath()
88     {
89         addEvent( "endXPath()" );
90     }
91
92     public void startPathExpr()
93     {
94         addEvent( "startPathExpr()" );
95     }
96
97     public void endPathExpr()
98     {
99         addEvent( "endPathExpr()" );
100     }
101
102     public void startAbsoluteLocationPath()
103     {
104         addEvent( "startAbsoluteLocationPath()" );
105     }
106     public void endAbsoluteLocationPath()
107     {
108         addEvent( "endAbsoluteLocationPath()" );
109     }
110
111     public void startRelativeLocationPath()
112     {
113         addEvent( "startRelativeLocationPath()" );
114     }
115
116     public void endRelativeLocationPath()
117     {
118         addEvent( "endRelativeLocationPath()" );
119     }
120
121     public void startNameStep(int axis,
122                               String JavaDoc prefix,
123                               String JavaDoc localName)
124     {
125         addEvent( "startNameStep(" + axis + ", \"" + prefix + "\", \"" + localName + "\")" );
126     }
127
128     public void endNameStep()
129     {
130         addEvent( "endNameStep()" );
131     }
132
133     public void startTextNodeStep(int axis)
134     {
135         addEvent( "startTextNodeStep(" + axis + ")" );
136     }
137     public void endTextNodeStep()
138     {
139         addEvent( "endTextNodeStep()" );
140     }
141
142     public void startCommentNodeStep(int axis)
143     {
144         addEvent( "startCommentNodeStep(" + axis + ")" );
145     }
146
147     public void endCommentNodeStep()
148     {
149         addEvent( "endCommentNodeStep()" );
150     }
151
152     public void startAllNodeStep(int axis)
153     {
154         addEvent( "startAllNodeStep(" + axis + ")" );
155     }
156
157     public void endAllNodeStep()
158     {
159         addEvent( "endAllNodeStep()" );
160     }
161
162     public void startProcessingInstructionNodeStep(int axis,
163                                                    String JavaDoc name)
164     {
165         addEvent( "startProcessingInstructionNodeStep(" + axis + ", \"" + name + "\")" );
166     }
167     public void endProcessingInstructionNodeStep()
168     {
169         addEvent( "endProcessingInstructionNodeStep()" );
170     }
171
172     public void startPredicate()
173     {
174         addEvent( "startPredicate()" );
175     }
176
177     public void endPredicate()
178     {
179         addEvent( "endPredicate()" );
180     }
181
182     public void startFilterExpr()
183     {
184         addEvent( "startFilterExpr()" );
185     }
186
187     public void endFilterExpr()
188     {
189         addEvent( "endFilterExpr()" );
190     }
191
192     public void startOrExpr()
193     {
194         addEvent( "startOrExpr()" );
195     }
196
197     public void endOrExpr(boolean create)
198     {
199         addEvent( "endOrExpr(" + create + ")" );
200     }
201
202     public void startAndExpr()
203     {
204         addEvent( "startAndExpr()" );
205     }
206
207     public void endAndExpr(boolean create)
208     {
209         addEvent( "endAndExpr(" + create + ")" );
210     }
211
212     public void startEqualityExpr()
213     {
214         addEvent( "startEqualityExpr()" );
215     }
216
217     public void endEqualityExpr(int operator)
218     {
219         addEvent( "endEqualityExpr(" + operator + ")" );
220     }
221
222     public void startRelationalExpr()
223     {
224         addEvent( "startRelationalExpr()" );
225     }
226
227     public void endRelationalExpr(int operator)
228     {
229         addEvent( "endRelationalExpr(" + operator + ")" );
230     }
231
232     public void startAdditiveExpr()
233     {
234         addEvent( "startAdditiveExpr()" );
235     }
236
237     public void endAdditiveExpr(int operator)
238     {
239         addEvent( "endAdditiveExpr(" + operator + ")" );
240     }
241
242     public void startMultiplicativeExpr()
243     {
244         addEvent( "startMultiplicativeExpr()" );
245     }
246
247     public void endMultiplicativeExpr(int operator)
248     {
249         addEvent( "endMultiplicativeExpr(" + operator + ")" );
250     }
251
252     public void startUnaryExpr()
253     {
254         addEvent( "startUnaryExpr()" );
255     }
256
257     public void endUnaryExpr(int operator)
258     {
259         addEvent( "endUnaryExpr(" + operator + ")" );
260     }
261
262     public void startUnionExpr()
263     {
264         addEvent( "startUnionExpr()" );
265     }
266
267     public void endUnionExpr(boolean create)
268     {
269         addEvent( "endUnionExpr(" + create + ")" );
270     }
271
272     public void number(int number)
273     {
274         addEvent( "number(" + number + ")" );
275     }
276
277     public void number(double number)
278     {
279         addEvent( "number(" + number + ")" );
280     }
281
282     public void literal(String JavaDoc literal)
283     {
284         addEvent( "literal(\"" + literal + "\")" );
285     }
286
287     public void variableReference(String JavaDoc prefix,
288                                   String JavaDoc variableName)
289     {
290         addEvent( "variableReference(\"" + prefix + ":" + variableName + "\")" );
291     }
292
293     public void startFunction(String JavaDoc prefix,
294                               String JavaDoc functionName)
295     {
296         addEvent( "startFunction(\"" + prefix + ":" + functionName + "\")" );
297     }
298
299     public void endFunction()
300     {
301         addEvent( "endFunction()" );
302     }
303
304     private void addEvent(String JavaDoc eventStr)
305     {
306         this.events.add( eventStr );
307     }
308
309     public boolean equals(Object JavaDoc thatObj)
310     {
311         if ( thatObj instanceof ConformanceXPathHandler )
312         {
313             ConformanceXPathHandler that = (ConformanceXPathHandler) thatObj;
314
315             return ( this.events.equals( that.events ) );
316         }
317
318         return false;
319     }
320     
321     public int hashCode() {
322         return this.events.hashCode();
323     }
324     
325
326     public String JavaDoc toString()
327     {
328         Iterator JavaDoc eventIter = this.events.iterator();
329         int i = 0;
330
331         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
332
333         while( eventIter.hasNext() )
334         {
335             buf.append("(").append(i).append(") ").append( eventIter.next().toString() ).append("\n");
336             ++i;
337         }
338
339         return buf.toString();
340     }
341 }
342
Popular Tags