KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jibx > binding > model > ModelVisitor


1 /*
2 Copyright (c) 2004-2005, Dennis M. Sosnoski
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
7
8  * Redistributions of source code must retain the above copyright notice, this
9    list of conditions and the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright notice,
11    this list of conditions and the following disclaimer in the documentation
12    and/or other materials provided with the distribution.
13  * Neither the name of JiBX nor the names of its contributors may be used
14    to endorse or promote products derived from this software without specific
15    prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */

28
29 package org.jibx.binding.model;
30
31 /**
32  * Binding model visitor base class. This works with the {@link
33  * org.jibx.binding.model.TreeContext} class for handling tree-based
34  * operations on the binding definition. Subclasses can override any or all of
35  * the base class visit and exit methods, including both those for abstract base
36  * classes and those for concrete classes, but should normally call the base
37  * class implementation of the method in order to implement the class
38  * inheritance hierarchy handling. Elements in the binding definition are always
39  * visited in tree order (down and across).
40  *
41  * @author Dennis M. Sosnoski
42  * @version 1.0
43  */

44  
45 public abstract class ModelVisitor
46 {
47     //
48
// Visit methods for base classes
49

50     /**
51      * Visit element. This method will be called for every element in the model.
52      *
53      * @param node element being visited
54      * @return <code>true</code> if children to be processed, <code>false</code>
55      * if not
56      */

57     public boolean visit(ElementBase node) {
58         return true;
59     }
60     
61     /**
62      * Visit nesting element. This method will be called for any form of nesting
63      * element.
64      *
65      * @param node nesting element being visited
66      * @return <code>true</code> if children to be processed, <code>false</code>
67      * if not
68      */

69     public boolean visit(NestingElementBase node) {
70         return visit((ElementBase)node);
71     }
72     
73     /**
74      * Visit container element. This method will be called for any form of
75      * container element.
76      *
77      * @param node container element being visited
78      * @return <code>true</code> if children to be processed, <code>false</code>
79      * if not
80      */

81     public boolean visit(ContainerElementBase node) {
82         return visit((NestingElementBase)node);
83     }
84     
85     /**
86      * Visit structure element. This method will be called for any form of
87      * structure element.
88      *
89      * @param node structure element being visited
90      * @return <code>true</code> if children to be processed, <code>false</code>
91      * if not
92      */

93     public boolean visit(StructureElementBase node) {
94         return visit((ContainerElementBase)node);
95     }
96     
97     /**
98      * Visit template element. This method will be called for any form of
99      * template element.
100      *
101      * @param node template element being visited
102      * @return <code>true</code> if children to be processed, <code>false</code>
103      * if not
104      */

105     public boolean visit(TemplateElementBase node) {
106         return visit((NestingElementBase)node);
107     }
108     
109     //
110
// Visit methods for concrete classes
111

112     /**
113      * Visit <b>binding</b> element.
114      *
115      * @param node binding element being visited
116      * @return <code>true</code> if children to be processed, <code>false</code>
117      * if not
118      */

119     public boolean visit(BindingElement node) {
120         return visit((NestingElementBase)node);
121     }
122     
123     /**
124      * Visit <b>collection</b> element.
125      *
126      * @param node collection element being visited
127      * @return <code>true</code> if children to be processed, <code>false</code>
128      * if not
129      */

130     public boolean visit(CollectionElement node) {
131         return visit((StructureElementBase)node);
132     }
133     
134     /**
135      * Visit <b>format</b> element.
136      *
137      * @param node format element being visited
138      * @return <code>true</code> if children to be processed, <code>false</code>
139      * if not
140      */

141     public boolean visit(FormatElement node) {
142         return visit((ElementBase)node);
143     }
144     
145     /**
146      * Visit <b>include</b> element.
147      *
148      * @param node include element being visited
149      * @return <code>true</code> if children to be processed, <code>false</code>
150      * if not
151      */

152     public boolean visit(IncludeElement node) {
153         return visit((ElementBase)node);
154     }
155     
156     /**
157      * Visit <b>input</b> element.
158      *
159      * @param node input element being visited
160      * @return <code>true</code> if children to be processed, <code>false</code>
161      * if not
162      */

163     public boolean visit(InputElement node) {
164         return visit((NestingElementBase)node);
165     }
166     
167     /**
168      * Visit <b>mapping</b> element.
169      *
170      * @param node mapping element being visited
171      * @return <code>true</code> if children to be processed, <code>false</code>
172      * if not
173      */

174     public boolean visit(MappingElement node) {
175         return visit((TemplateElementBase)node);
176     }
177     
178     /**
179      * Visit <b>namespace</b> element.
180      *
181      * @param node namespace element being visited
182      * @return <code>true</code> if children to be processed, <code>false</code>
183      * if not
184      */

185     public boolean visit(NamespaceElement node) {
186         return visit((ElementBase)node);
187     }
188     
189     /**
190      * Visit <b>output</b> element.
191      *
192      * @param node output element being visited
193      * @return <code>true</code> if children to be processed, <code>false</code>
194      * if not
195      */

196     public boolean visit(OutputElement node) {
197         return visit((NestingElementBase)node);
198     }
199     
200     /**
201      * Visit <b>split</b> element.
202      *
203      * @param node split element being visited
204      * @return <code>true</code> if children to be processed, <code>false</code>
205      * if not
206      */

207     public boolean visit(SplitElement node) {
208         return visit((NestingElementBase)node);
209     }
210     
211     /**
212      * Visit <b>structure</b> element.
213      *
214      * @param node structure element being visited
215      * @return <code>true</code> if children to be processed, <code>false</code>
216      * if not
217      */

218     public boolean visit(StructureElement node) {
219         return visit((StructureElementBase)node);
220     }
221     
222     /**
223      * Visit <b>template</b> element.
224      *
225      * @param node template element being visited
226      * @return <code>true</code> if children to be processed, <code>false</code>
227      * if not
228      */

229     public boolean visit(TemplateElement node) {
230         return visit((TemplateElementBase)node);
231     }
232     
233     /**
234      * Visit <b>value</b> element.
235      *
236      * @param node value element being visited
237      * @return <code>true</code> if children to be processed, <code>false</code>
238      * if not
239      */

240     public boolean visit(ValueElement node) {
241         return visit((ElementBase)node);
242     }
243     
244     //
245
// Exit methods for base classes
246

247     /**
248      * Exit any element.
249      *
250      * @param node element being exited
251      */

252     public void exit(ElementBase node) {}
253     
254     /**
255      * Exit any nesting element.
256      *
257      * @param node nesting element being exited
258      */

259     public void exit(NestingElementBase node) {
260         exit((ElementBase)node);
261     }
262     
263     /**
264      * Exit any container element.
265      *
266      * @param node container element being exited
267      */

268     public void exit(ContainerElementBase node) {
269         exit((NestingElementBase)node);
270     }
271     
272     /**
273      * Exit any structure element.
274      *
275      * @param node structure element being exited
276      */

277     public void exit(StructureElementBase node) {
278         exit((ContainerElementBase)node);
279     }
280     
281     /**
282      * Exit any template element.
283      *
284      * @param node template element being exited
285      */

286     public void exit(TemplateElementBase node) {
287         exit((NestingElementBase)node);
288     }
289     
290     //
291
// Exit methods for concrete classes
292

293     /**
294      * Exit <b>binding</b> element.
295      *
296      * @param node binding element being exited
297      */

298     public void exit(BindingElement node) {
299         exit((NestingElementBase)node);
300     }
301     
302     /**
303      * Exit <b>collection</b> element.
304      *
305      * @param node collection element being exited
306      */

307     public void exit(CollectionElement node) {
308         exit((StructureElementBase)node);
309     }
310     
311     /**
312      * Exit <b>include</b> element.
313      *
314      * @param node input element being exited
315      */

316     public void exit(IncludeElement node) {
317         exit((ElementBase)node);
318     }
319     
320     /**
321      * Exit <b>input</b> element.
322      *
323      * @param node input element being exited
324      */

325     public void exit(InputElement node) {
326         exit((NestingElementBase)node);
327     }
328     
329     /**
330      * Exit <b>mapping</b> element.
331      *
332      * @param node mapping element being exited
333      */

334     public void exit(MappingElement node) {
335         exit((TemplateElementBase)node);
336     }
337     
338     /**
339      * Exit <b>output</b> element.
340      *
341      * @param node output element being exited
342      */

343     public void exit(OutputElement node) {
344         exit((NestingElementBase)node);
345     }
346     
347     /**
348      * Exit <b>split</b> element.
349      *
350      * @param node split element being exited
351      */

352     public void exit(SplitElement node) {
353         exit((NestingElementBase)node);
354     }
355     
356     /**
357      * Exit <b>structure</b> element.
358      *
359      * @param node structure element being exited
360      */

361     public void exit(StructureElement node) {
362         exit((StructureElementBase)node);
363     }
364     
365     /**
366      * Exit <b>template</b> element.
367      *
368      * @param node template element being exited
369      */

370     public void exit(TemplateElement node) {
371         exit((TemplateElementBase)node);
372     }
373     
374     /**
375      * Exit <b>value</b> element.
376      *
377      * @param node value element being exited
378      */

379     public void exit(ValueElement node) {
380         exit((ElementBase)node);
381     }
382 }
Popular Tags