001    /*****************************************************************************
002     * Copyright (C) PicoContainer Organization. All rights reserved.            *
003     * ------------------------------------------------------------------------- *
004     * The software in this package is published under the terms of the BSD      *
005     * style license a copy of which has been included with this distribution in *
006     * the LICENSE.txt file.                                                     *
007     *****************************************************************************/
008    package org.picocontainer.visitors;
009    
010    import org.picocontainer.ComponentAdapter;
011    import org.picocontainer.Parameter;
012    import org.picocontainer.PicoContainer;
013    import org.picocontainer.ComponentFactory;
014    import org.picocontainer.visitors.AbstractPicoVisitor;
015    
016    
017    /**
018     * Concrete implementation of Visitor which simply checks traversals.
019     * This can be a useful class for other Visitor implementations to extend, 
020     * as it provides a default implementation in case you one is only interested
021     * in one PicoVisitor type.  Example:
022     *
023     *<pre>
024     * PicoContainer container = new DefaultPicoContainer();
025     * PicoContainer child = container.makeChildContainer();
026     *
027     * final List allContainers = new ArrayList();
028     *
029     * PicoVisitor visitor = new TraversalCheckingVisitor() {
030     *     public boolean visitContainer(PicoContainer pico) {
031     *         super.visitContainer(pico);  //Calls checkTraversal for us.
032     *         allContainers.add(pico);
033     *         return true;
034     *     }
035     * }
036     * </pre>
037     *
038     * @author Michael Rimov
039     */
040    public class TraversalCheckingVisitor
041            extends AbstractPicoVisitor {
042    
043            /** {@inheritDoc} **/
044        public boolean visitContainer(PicoContainer pico) {
045            checkTraversal();
046            return CONTINUE_TRAVERSAL;
047        }
048    
049            /** {@inheritDoc} **/
050        public void visitComponentAdapter(ComponentAdapter<?> componentAdapter) {
051            checkTraversal();
052        }
053    
054            /** {@inheritDoc} **/
055        public void visitComponentFactory(ComponentFactory componentFactory) {
056            checkTraversal();
057        }
058    
059            /** {@inheritDoc} **/
060        public void visitParameter(Parameter parameter) {
061            checkTraversal();
062        }
063    
064    }