Clover coverage report - PicoContainer - 1.1
Coverage timestamp: Thu Nov 4 2004 11:55:45 CST
file stats: LOC: 59   Methods: 2
NCLOC: 32   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
AbstractPicoVisitor.java 83.3% 100% 100% 95.5%
coverage coverage
 1   
 /*****************************************************************************
 2   
  * Copyright (C) PicoContainer Organization. All rights reserved.            *
 3   
  * ------------------------------------------------------------------------- *
 4   
  * The software in this package is published under the terms of the BSD      *
 5   
  * style license a copy of which has been included with this distribution in *
 6   
  * the LICENSE.txt file.                                                     *
 7   
  *****************************************************************************/
 8   
 package org.picocontainer.defaults;
 9   
 
 10   
 import org.picocontainer.PicoVisitor;
 11   
 
 12   
 import java.lang.reflect.InvocationTargetException;
 13   
 import java.lang.reflect.Method;
 14   
 
 15   
 /**
 16   
  * Abstract PicoVisitor implementation. A generic traverse method is implemented, that 
 17   
  * accepts any object with a method named "accept", that takes a 
 18   
  * {@link PicoVisitor}  as argument and and invokes it. Additionally it provides the 
 19   
  * {@link #checkTraversal()} method, that throws a {@link PicoVisitorTraversalException},
 20   
  * if currently no traversal is running.
 21   
  * 
 22   
  * @author Jörg Schaible
 23   
  * @since 1.1
 24   
  */
 25   
 public abstract class AbstractPicoVisitor implements PicoVisitor {
 26   
     private boolean traversal;
 27   
     
 28  272
     public Object traverse(Object node) {
 29  272
         traversal = true;
 30  272
         try {
 31  272
             final Method accept = node.getClass().getMethod("accept", new Class[]{PicoVisitor.class});
 32  270
             accept.invoke(node, new Object[]{this});
 33  264
             return Void.TYPE;
 34   
         } catch (NoSuchMethodException e) {
 35   
         } catch (IllegalAccessException e) {
 36   
         } catch (InvocationTargetException e) {
 37  6
             Throwable cause = e.getTargetException();
 38  6
             if (cause instanceof RuntimeException) {
 39  4
                 throw (RuntimeException)cause;
 40  2
             } else if (cause instanceof Error) {
 41  2
                 throw (Error)cause;
 42   
             }
 43   
         } finally {
 44  272
             traversal = false;
 45   
         }
 46  2
         throw new IllegalArgumentException(node.getClass().getName() + " is not a valid type for traversal");
 47   
     }
 48   
 
 49   
     /**
 50   
      * Checks the traversal flag, indicating a currently running traversal of the visitor.
 51   
      * @throws PicoVisitorTraversalException if no traversal is active.
 52   
      */
 53  1168
     protected void checkTraversal() {
 54  1168
         if (!traversal) {
 55  2
             throw new PicoVisitorTraversalException(this);
 56   
         }
 57   
     }
 58   
 }
 59