1 //---------------------------------------------------------------------- 2 // 3 // PerfectJPattern: "Design patterns are good but components are better!" 4 // PrintVisitor.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.slf4j.*; 24 25 /** 26 * Concrete Visitor implementation that exemplifies the case where your 27 * Visitor can directly extend PerfectJPattern's base reusable 28 * {@link AbstractVisitor} implementation 29 * 30 * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a> 31 * @version $Revision: 1.0 $Date: Jun 8, 2008 11:57:41 PM $ 32 */ 33 public 34 class PrintVisitor 35 extends AbstractVisitor<ICarPart> 36 { 37 //------------------------------------------------------------------------ 38 // public 39 //------------------------------------------------------------------------ 40 /** 41 * Visit Wheel 42 * 43 * @param aWheel 44 */ 45 public void 46 visitWheel(Wheel aWheel) 47 { 48 theLogger.debug("Visiting " + aWheel.getName() + " wheel"); 49 } 50 51 //------------------------------------------------------------------------ 52 /** 53 * Visit Engine 54 * 55 * @param anEngine 56 */ 57 public void 58 visitEngine(Engine anEngine) 59 { 60 theLogger.debug("Visiting engine"); 61 } 62 63 //------------------------------------------------------------------------ 64 /** 65 * Visit Body 66 * 67 * @param aBody 68 */ 69 public void 70 visitBody(Body aBody) 71 { 72 theLogger.debug("Visiting body"); 73 } 74 75 //------------------------------------------------------------------------ 76 /** 77 * Visit Car 78 * 79 * @param aCar 80 */ 81 public void 82 visitCar(Car aCar) 83 { 84 theLogger.debug("Visiting car"); 85 86 visit(aCar.getEngine()); 87 visit(aCar.getBody()); 88 89 for (Wheel myWheel : aCar.getWheels()) 90 { 91 visit(myWheel); 92 } 93 } 94 95 //------------------------------------------------------------------------ 96 // protected 97 //------------------------------------------------------------------------ 98 protected static void 99 setLogger(Logger aLogger) 100 { 101 theLogger = aLogger; 102 } 103 104 //------------------------------------------------------------------------ 105 // members 106 //------------------------------------------------------------------------ 107 /** 108 * Provides logging facilities for this class 109 */ 110 private static Logger theLogger = LoggerFactory.getLogger(DoVisitor. 111 class); 112 }