1 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 25 public abstract class AbstractPicoVisitor implements PicoVisitor { 26 private boolean traversal; 27 28 public Object traverse(Object node) { 29 traversal = true; 30 try { 31 final Method accept = node.getClass().getMethod("accept", new Class []{PicoVisitor.class}); 32 accept.invoke(node, new Object []{this}); 33 return Void.TYPE; 34 } catch (NoSuchMethodException e) { 35 } catch (IllegalAccessException e) { 36 } catch (InvocationTargetException e) { 37 Throwable cause = e.getTargetException(); 38 if (cause instanceof RuntimeException ) { 39 throw (RuntimeException )cause; 40 } else if (cause instanceof Error ) { 41 throw (Error )cause; 42 } 43 } finally { 44 traversal = false; 45 } 46 throw new IllegalArgumentException (node.getClass().getName() + " is not a valid type for traversal"); 47 } 48 49 53 protected void checkTraversal() { 54 if (!traversal) { 55 throw new PicoVisitorTraversalException(this); 56 } 57 } 58 } 59 | Popular Tags |