1 //----------------------------------------------------------------------
2 //
3 // PerfectJPattern: "Design patterns are good but components are better!"
4 // DoVisitor.java Copyright (c) 2009 Giovanni Azua Garcia
5 // bravegag@hotmail.com
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 3
10 // of the License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, see <http://www.gnu.org/licenses/>.
19 //
20 //----------------------------------------------------------------------
21 package org.perfectjpattern.core.behavioral.visitor;
22
23 import org.perfectjpattern.core.api.behavioral.visitor.*;
24 import org.slf4j.*;
25
26 /**
27 * Concrete Visitor implementation that exemplifies the case where your Visitor
28 * already inherits from another class and thus can not extend PerfectJPattern's
29 * base reusable {@link AbstractVisitor} implementation.
30 *
31 * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a>
32 * @version $Revision: 1.0 $Date: Jun 8, 2008 11:59:05 PM $
33 */
34 public
35 class DoVisitor
36 implements IVisitor<ICarPart>
37 {
38 //------------------------------------------------------------------------
39 // public
40 //------------------------------------------------------------------------
41 /**
42 * {@inheritDoc}
43 */
44 public void
45 visit(ICarPart anElement)
46 {
47 AbstractVisitor.reusableVisit(this, anElement);
48 }
49
50 //------------------------------------------------------------------------
51 /**
52 * Visit Wheel
53 *
54 * @param aWheel
55 */
56 public void
57 visitWheel(Wheel aWheel)
58 {
59 theLogger.debug("Steering my wheel");
60 }
61
62 //------------------------------------------------------------------------
63 /**
64 * Visit Engine
65 *
66 * @param anEngine
67 */
68 public void
69 visitEngine(Engine anEngine)
70 {
71 theLogger.debug("Starting my engine");
72 }
73
74 //------------------------------------------------------------------------
75 /**
76 * Visit Body
77 *
78 * @param aBody
79 */
80 public void
81 visitBody(Body aBody)
82 {
83 theLogger.debug("Moving my body");
84 }
85
86 //------------------------------------------------------------------------
87 /**
88 * Visit Car
89 *
90 * @param aCar
91 */
92 public void
93 visitCar(Car aCar)
94 {
95 theLogger.debug("Vroom!");
96
97 visit(aCar.getEngine());
98 visit(aCar.getBody());
99 for (Wheel myWheel : aCar.getWheels())
100 {
101 visit(myWheel);
102 }
103 }
104
105 //------------------------------------------------------------------------
106 // protected
107 //------------------------------------------------------------------------
108 protected static void
109 setLogger(Logger aLogger)
110 {
111 theLogger = aLogger;
112 }
113
114 //------------------------------------------------------------------------
115 // members
116 //------------------------------------------------------------------------
117 /**
118 * Provides logging facilities for this class
119 */
120 private static Logger theLogger = LoggerFactory.getLogger(DoVisitor.
121 class);
122 }