org.picocontainer.defaults
Class MethodCallingVisitor

java.lang.Object
  extended by org.picocontainer.defaults.AbstractPicoVisitor
      extended by org.picocontainer.defaults.TraversalCheckingVisitor
          extended by org.picocontainer.defaults.MethodCallingVisitor
All Implemented Interfaces:
java.io.Serializable, PicoVisitor
Direct Known Subclasses:
LifecycleVisitor

public class MethodCallingVisitor
extends TraversalCheckingVisitor
implements java.io.Serializable

A PicoVisitor implementation, that calls methods on the components of a specific type.

Since:
1.2
Author:
Aslak Hellesøy, Jörg Schaible
See Also:
Serialized Form

Field Summary
private  java.lang.Object[] arguments
           
private  java.util.List componentInstances
           
private  java.lang.reflect.Method method
           
private  java.lang.Class type
           
private  boolean visitInInstantiationOrder
           
 
Constructor Summary
MethodCallingVisitor(java.lang.reflect.Method method, java.lang.Class ofType, java.lang.Object[] arguments)
          Construct a MethodCallingVisitor for standard methods visiting the component in instantiation order.
MethodCallingVisitor(java.lang.reflect.Method method, java.lang.Class ofType, java.lang.Object[] arguments, boolean visitInInstantiationOrder)
          Construct a MethodCallingVisitor for a method with arguments.
 
Method Summary
protected  java.lang.Object[] getArguments()
           
protected  java.lang.reflect.Method getMethod()
           
protected  java.lang.Object invoke(java.lang.Object target)
           
protected  void invoke(java.lang.Object[] targets)
           
 java.lang.Object traverse(java.lang.Object node)
          Entry point for the PicoVisitor traversal.
 void visitContainer(PicoContainer pico)
          Visit a PicoContainer that has to accept the visitor.
 
Methods inherited from class org.picocontainer.defaults.TraversalCheckingVisitor
visitComponentAdapter, visitParameter
 
Methods inherited from class org.picocontainer.defaults.AbstractPicoVisitor
checkTraversal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

method

private transient java.lang.reflect.Method method

arguments

private final java.lang.Object[] arguments

type

private final java.lang.Class type

visitInInstantiationOrder

private final boolean visitInInstantiationOrder

componentInstances

private final java.util.List componentInstances
Constructor Detail

MethodCallingVisitor

public MethodCallingVisitor(java.lang.reflect.Method method,
                            java.lang.Class ofType,
                            java.lang.Object[] arguments,
                            boolean visitInInstantiationOrder)
Construct a MethodCallingVisitor for a method with arguments.

Parameters:
method - the Method to invoke
ofType - the type of the components, that will be invoked
visitInInstantiationOrder - true if components are visited in instantiation order
arguments - the arguments for the method invocation (may be null)
Throws:
java.lang.NullPointerException - if method, or ofType is null
Since:
1.2

MethodCallingVisitor

public MethodCallingVisitor(java.lang.reflect.Method method,
                            java.lang.Class ofType,
                            java.lang.Object[] arguments)
Construct a MethodCallingVisitor for standard methods visiting the component in instantiation order.

Parameters:
method - the method to invoke
ofType - the type of the components, that will be invoked
arguments - the arguments for the method invocation (may be null)
Throws:
java.lang.NullPointerException - if method, or ofType is null
Since:
1.2
Method Detail

traverse

public java.lang.Object traverse(java.lang.Object node)
Description copied from interface: PicoVisitor
Entry point for the PicoVisitor traversal. The given node is the first object, that is asked for acceptance. Only objects of type PicoContainer, ComponentAdapter, or Parameter are valid.

Specified by:
traverse in interface PicoVisitor
Overrides:
traverse in class AbstractPicoVisitor
Parameters:
node - the start node of the traversal.
Returns:
a visitor-specific value.

visitContainer

public void visitContainer(PicoContainer pico)
Description copied from interface: PicoVisitor
Visit a PicoContainer that has to accept the visitor.

Specified by:
visitContainer in interface PicoVisitor
Overrides:
visitContainer in class TraversalCheckingVisitor
Parameters:
pico - the visited container.

getMethod

protected java.lang.reflect.Method getMethod()

getArguments

protected java.lang.Object[] getArguments()

invoke

protected void invoke(java.lang.Object[] targets)

invoke

protected java.lang.Object invoke(java.lang.Object target)