001    /*
002    @license.text@
003     */
004    package biz.hammurapi.util;
005    
006    import java.util.Collection;
007    import java.util.Iterator;
008    import java.util.LinkedList;
009    
010    /**
011     * Takes collection of visitors and piggy-backs them. 
012     * Visitor's unwillingnes to navigate further is ignored.
013     * @author Pavel Vlasov 
014     * @version $Revision: 1.3 $
015     */
016    public class CompositeVisitor implements PoliteVisitor {
017            private LinkedList visitors;
018    
019            /**
020             * 
021             */
022            public CompositeVisitor(Collection visitors) {
023                    this.visitors=new LinkedList(visitors);
024            }
025    
026            public boolean visit(Object target) {
027                    Iterator it=visitors.iterator();
028                    while (it.hasNext()) {                  
029                            ((Visitor) it.next()).visit(target);
030                    }
031                    return !visitors.isEmpty();
032            }
033    
034            public void leave(Object target) {
035                    Iterator it=visitors.iterator();
036                    while (it.hasNext()) {
037                            
038                            Object next = it.next();
039                            if (next instanceof PoliteVisitor) {
040                                    ((PoliteVisitor) next).leave(target);
041                            }
042                    }
043            }
044    }