org.apache.felix.ipojo.util
Class Callback

java.lang.Object
  extended by org.apache.felix.ipojo.util.Callback
Direct Known Subclasses:
DependencyCallback

public class Callback
extends java.lang.Object

A callback allows invoking a method on a POJO. This class supports both public, protected and private methods of the implementation class. This class also supports public method from super class. The Method object is computed once and this computation is delayed to the first invocation.

Author:
Felix Project Team

Field Summary
private  java.lang.String[] m_args
          The argument classes.
private  boolean m_isStatic
          Is the method a static method ? This implies calling the method on null
private  InstanceManager m_manager
          The reference on the instance manager.
private  java.lang.String m_method
          The name of the method to call.
protected  java.lang.reflect.Method m_methodObj
          The method object.
 
Constructor Summary
Callback(MethodMetadata method, InstanceManager manager)
          Creates a Callback.
Callback(java.lang.String method, java.lang.Class[] args, boolean isStatic, InstanceManager manager)
          Creates a Callback.
Callback(java.lang.String method, java.lang.String[] args, boolean isStatic, InstanceManager manager)
          Creates a Callback.
 
Method Summary
 java.lang.Object call()
          Invokes the method without arguments.
 java.lang.Object call(java.lang.Object instance)
          Invokes the method without arguments.
 java.lang.Object call(java.lang.Object[] arg)
          Invokes the method on every created objects with the specified arguments.
 java.lang.Object call(java.lang.Object instance, java.lang.Object[] arg)
          Invokes the method on the given object with the specified arguments.
private  void computeArguments(java.lang.String[] args)
          Computes arguments of the method.
 java.lang.String getMethod()
          Gets the method name.
protected  void searchMethod()
          Searches the Method object in the POJO by analyzing implementation class methods.
private  java.lang.reflect.Method searchMethodInMethodArray(java.lang.reflect.Method[] methods)
          Searches the Method in the given method arrays.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_methodObj

protected java.lang.reflect.Method m_methodObj
The method object. Computed at the first call.


m_method

private java.lang.String m_method
The name of the method to call.


m_isStatic

private boolean m_isStatic
Is the method a static method ? This implies calling the method on null


m_manager

private InstanceManager m_manager
The reference on the instance manager. Used to get POJO objects.


m_args

private java.lang.String[] m_args
The argument classes. This array contains the list of argument class names.

Constructor Detail

Callback

public Callback(java.lang.String method,
                java.lang.String[] args,
                boolean isStatic,
                InstanceManager manager)
Creates a Callback. If the argument array is not null the reflection type are computed.

Parameters:
method - the name of the method to call
args - the argument type name, or null if no arguments
isStatic - is the method a static method
manager - the instance manager of the component containing the method
See Also:
Callback#computeArguments(String[])}

Callback

public Callback(java.lang.String method,
                java.lang.Class[] args,
                boolean isStatic,
                InstanceManager manager)
Creates a Callback.

Parameters:
method - the the name of the method to call
args - the argument classes
isStatic - the is the method a static method
manager - the the instance manager of the component containing the method

Callback

public Callback(MethodMetadata method,
                InstanceManager manager)
Creates a Callback.

Parameters:
method - the MethodMetadata obtained from manipulation metadata (PojoMetadata).
manager - the instance manager.
Method Detail

computeArguments

private void computeArguments(java.lang.String[] args)
Computes arguments of the method. This method computes "reflection type" from given argument.

Parameters:
args - the arguments of the method.
See Also:
FieldMetadata.getReflectionType(String)

searchMethodInMethodArray

private java.lang.reflect.Method searchMethodInMethodArray(java.lang.reflect.Method[] methods)
Searches the Method in the given method arrays.

Parameters:
methods - the method array in which the method should be found
Returns:
the method object or null if not found

searchMethod

protected void searchMethod()
                     throws java.lang.NoSuchMethodException
Searches the Method object in the POJO by analyzing implementation class methods. The name of the method and the argument type are checked.

Throws:
java.lang.NoSuchMethodException - if the method cannot be found either in the implementation class or in parent classes.

call

public java.lang.Object call()
                      throws java.lang.NoSuchMethodException,
                             java.lang.IllegalAccessException,
                             java.lang.reflect.InvocationTargetException
Invokes the method without arguments. If several the instance contains several objects, the method is invoked on every objects.

Returns:
the result of the invocation, null for void method, the last result for multi-object instance
Throws:
java.lang.NoSuchMethodException - if Method is not found in the class
java.lang.reflect.InvocationTargetException - if the method throws an exception
java.lang.IllegalAccessException - if the method can not be invoked

call

public java.lang.Object call(java.lang.Object instance)
                      throws java.lang.NoSuchMethodException,
                             java.lang.IllegalAccessException,
                             java.lang.reflect.InvocationTargetException
Invokes the method without arguments. The method is invokes on the specified object.

Parameters:
instance - the instance on which call the callback
Returns:
the result of the invocation, null for void method
Throws:
java.lang.NoSuchMethodException - if the method was not found
java.lang.IllegalAccessException - if the method cannot be called
java.lang.reflect.InvocationTargetException - if an error happens in the method

call

public java.lang.Object call(java.lang.Object[] arg)
                      throws java.lang.NoSuchMethodException,
                             java.lang.IllegalAccessException,
                             java.lang.reflect.InvocationTargetException
Invokes the method on every created objects with the specified arguments.

Parameters:
arg - the method arguments
Returns:
the result of the invocation, null for void method, the last result for instance containing several objects.
Throws:
java.lang.NoSuchMethodException - if the callback method is not found
java.lang.IllegalAccessException - if the callback method cannot be called
java.lang.reflect.InvocationTargetException - if an error is thrown by the called method

call

public java.lang.Object call(java.lang.Object instance,
                             java.lang.Object[] arg)
                      throws java.lang.NoSuchMethodException,
                             java.lang.IllegalAccessException,
                             java.lang.reflect.InvocationTargetException
Invokes the method on the given object with the specified arguments.

Parameters:
instance - the instance on which call the method
arg - the argument array
Returns:
the result of the invocation, null for void method
Throws:
java.lang.NoSuchMethodException - if the callback method is not found
java.lang.IllegalAccessException - if the callback method cannot be called
java.lang.reflect.InvocationTargetException - if an error is thrown by the called method

getMethod

public java.lang.String getMethod()
Gets the method name.

Returns:
the method name


Copyright © 2006-2010 The Apache Software Foundation. All Rights Reserved.