001: /*
002: Copyright (c) 2004-2005, Dennis M. Sosnoski
003: All rights reserved.
004:
005: Redistribution and use in source and binary forms, with or without modification,
006: are permitted provided that the following conditions are met:
007:
008: * Redistributions of source code must retain the above copyright notice, this
009: list of conditions and the following disclaimer.
010: * Redistributions in binary form must reproduce the above copyright notice,
011: this list of conditions and the following disclaimer in the documentation
012: and/or other materials provided with the distribution.
013: * Neither the name of JiBX nor the names of its contributors may be used
014: to endorse or promote products derived from this software without specific
015: prior written permission.
016:
017: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
018: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
019: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
021: ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: */
028:
029: package org.jibx.binding.model;
030:
031: /**
032: * Binding model visitor base class. This works with the {@link
033: * org.jibx.binding.model.TreeContext} class for handling tree-based
034: * operations on the binding definition. Subclasses can override any or all of
035: * the base class visit and exit methods, including both those for abstract base
036: * classes and those for concrete classes, but should normally call the base
037: * class implementation of the method in order to implement the class
038: * inheritance hierarchy handling. Elements in the binding definition are always
039: * visited in tree order (down and across).
040: *
041: * @author Dennis M. Sosnoski
042: * @version 1.0
043: */
044: public abstract class ModelVisitor {
045: //
046: // Visit methods for base classes
047:
048: /**
049: * Visit element. This method will be called for every element in the model.
050: *
051: * @param node element being visited
052: * @return <code>true</code> if children to be processed, <code>false</code>
053: * if not
054: */
055: public boolean visit(ElementBase node) {
056: return true;
057: }
058:
059: /**
060: * Visit nesting element. This method will be called for any form of nesting
061: * element.
062: *
063: * @param node nesting element being visited
064: * @return <code>true</code> if children to be processed, <code>false</code>
065: * if not
066: */
067: public boolean visit(NestingElementBase node) {
068: return visit((ElementBase) node);
069: }
070:
071: /**
072: * Visit container element. This method will be called for any form of
073: * container element.
074: *
075: * @param node container element being visited
076: * @return <code>true</code> if children to be processed, <code>false</code>
077: * if not
078: */
079: public boolean visit(ContainerElementBase node) {
080: return visit((NestingElementBase) node);
081: }
082:
083: /**
084: * Visit structure element. This method will be called for any form of
085: * structure element.
086: *
087: * @param node structure element being visited
088: * @return <code>true</code> if children to be processed, <code>false</code>
089: * if not
090: */
091: public boolean visit(StructureElementBase node) {
092: return visit((ContainerElementBase) node);
093: }
094:
095: /**
096: * Visit template element. This method will be called for any form of
097: * template element.
098: *
099: * @param node template element being visited
100: * @return <code>true</code> if children to be processed, <code>false</code>
101: * if not
102: */
103: public boolean visit(TemplateElementBase node) {
104: return visit((ContainerElementBase) node);
105: }
106:
107: //
108: // Visit methods for concrete classes
109:
110: /**
111: * Visit <b>binding</b> element.
112: *
113: * @param node binding element being visited
114: * @return <code>true</code> if children to be processed, <code>false</code>
115: * if not
116: */
117: public boolean visit(BindingElement node) {
118: return visit((NestingElementBase) node);
119: }
120:
121: /**
122: * Visit <b>collection</b> element.
123: *
124: * @param node collection element being visited
125: * @return <code>true</code> if children to be processed, <code>false</code>
126: * if not
127: */
128: public boolean visit(CollectionElement node) {
129: return visit((StructureElementBase) node);
130: }
131:
132: /**
133: * Visit <b>format</b> element.
134: *
135: * @param node format element being visited
136: * @return <code>true</code> if children to be processed, <code>false</code>
137: * if not
138: */
139: public boolean visit(FormatElement node) {
140: return visit((ElementBase) node);
141: }
142:
143: /**
144: * Visit <b>include</b> element.
145: *
146: * @param node include element being visited
147: * @return <code>true</code> if children to be processed, <code>false</code>
148: * if not
149: */
150: public boolean visit(IncludeElement node) {
151: return visit((ElementBase) node);
152: }
153:
154: /**
155: * Visit <b>input</b> element.
156: *
157: * @param node input element being visited
158: * @return <code>true</code> if children to be processed, <code>false</code>
159: * if not
160: */
161: public boolean visit(InputElement node) {
162: return visit((NestingElementBase) node);
163: }
164:
165: /**
166: * Visit <b>mapping</b> element.
167: *
168: * @param node mapping element being visited
169: * @return <code>true</code> if children to be processed, <code>false</code>
170: * if not
171: */
172: public boolean visit(MappingElement node) {
173: return visit((TemplateElementBase) node);
174: }
175:
176: /**
177: * Visit <b>namespace</b> element.
178: *
179: * @param node namespace element being visited
180: * @return <code>true</code> if children to be processed, <code>false</code>
181: * if not
182: */
183: public boolean visit(NamespaceElement node) {
184: return visit((ElementBase) node);
185: }
186:
187: /**
188: * Visit <b>output</b> element.
189: *
190: * @param node output element being visited
191: * @return <code>true</code> if children to be processed, <code>false</code>
192: * if not
193: */
194: public boolean visit(OutputElement node) {
195: return visit((NestingElementBase) node);
196: }
197:
198: /**
199: * Visit <b>split</b> element.
200: *
201: * @param node split element being visited
202: * @return <code>true</code> if children to be processed, <code>false</code>
203: * if not
204: */
205: public boolean visit(SplitElement node) {
206: return visit((NestingElementBase) node);
207: }
208:
209: /**
210: * Visit <b>structure</b> element.
211: *
212: * @param node structure element being visited
213: * @return <code>true</code> if children to be processed, <code>false</code>
214: * if not
215: */
216: public boolean visit(StructureElement node) {
217: return visit((StructureElementBase) node);
218: }
219:
220: /**
221: * Visit <b>template</b> element.
222: *
223: * @param node template element being visited
224: * @return <code>true</code> if children to be processed, <code>false</code>
225: * if not
226: */
227: public boolean visit(TemplateElement node) {
228: return visit((TemplateElementBase) node);
229: }
230:
231: /**
232: * Visit <b>value</b> element.
233: *
234: * @param node value element being visited
235: * @return <code>true</code> if children to be processed, <code>false</code>
236: * if not
237: */
238: public boolean visit(ValueElement node) {
239: return visit((ElementBase) node);
240: }
241:
242: //
243: // Exit methods for base classes
244:
245: /**
246: * Exit any element.
247: *
248: * @param node element being exited
249: */
250: public void exit(ElementBase node) {
251: }
252:
253: /**
254: * Exit any nesting element.
255: *
256: * @param node nesting element being exited
257: */
258: public void exit(NestingElementBase node) {
259: exit((ElementBase) node);
260: }
261:
262: /**
263: * Exit any container element.
264: *
265: * @param node container element being exited
266: */
267: public void exit(ContainerElementBase node) {
268: exit((NestingElementBase) node);
269: }
270:
271: /**
272: * Exit any structure element.
273: *
274: * @param node structure element being exited
275: */
276: public void exit(StructureElementBase node) {
277: exit((ContainerElementBase) node);
278: }
279:
280: /**
281: * Exit any template element.
282: *
283: * @param node template element being exited
284: */
285: public void exit(TemplateElementBase node) {
286: exit((NestingElementBase) node);
287: }
288:
289: //
290: // Exit methods for concrete classes
291:
292: /**
293: * Exit <b>binding</b> element.
294: *
295: * @param node binding element being exited
296: */
297: public void exit(BindingElement node) {
298: exit((NestingElementBase) node);
299: }
300:
301: /**
302: * Exit <b>collection</b> element.
303: *
304: * @param node collection element being exited
305: */
306: public void exit(CollectionElement node) {
307: exit((StructureElementBase) node);
308: }
309:
310: /**
311: * Exit <b>include</b> element.
312: *
313: * @param node input element being exited
314: */
315: public void exit(IncludeElement node) {
316: exit((ElementBase) node);
317: }
318:
319: /**
320: * Exit <b>input</b> element.
321: *
322: * @param node input element being exited
323: */
324: public void exit(InputElement node) {
325: exit((NestingElementBase) node);
326: }
327:
328: /**
329: * Exit <b>mapping</b> element.
330: *
331: * @param node mapping element being exited
332: */
333: public void exit(MappingElement node) {
334: exit((TemplateElementBase) node);
335: }
336:
337: /**
338: * Exit <b>output</b> element.
339: *
340: * @param node output element being exited
341: */
342: public void exit(OutputElement node) {
343: exit((NestingElementBase) node);
344: }
345:
346: /**
347: * Exit <b>split</b> element.
348: *
349: * @param node split element being exited
350: */
351: public void exit(SplitElement node) {
352: exit((NestingElementBase) node);
353: }
354:
355: /**
356: * Exit <b>structure</b> element.
357: *
358: * @param node structure element being exited
359: */
360: public void exit(StructureElement node) {
361: exit((StructureElementBase) node);
362: }
363:
364: /**
365: * Exit <b>template</b> element.
366: *
367: * @param node template element being exited
368: */
369: public void exit(TemplateElement node) {
370: exit((TemplateElementBase) node);
371: }
372:
373: /**
374: * Exit <b>value</b> element.
375: *
376: * @param node value element being exited
377: */
378: public void exit(ValueElement node) {
379: exit((ElementBase) node);
380: }
381: }
|