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 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
protected  Method m_methodObj
          The method object.
 
Constructor Summary
Callback(MethodMetadata method, InstanceManager manager)
          Creates a Callback.
Callback(String method, Class[] args, boolean isStatic, InstanceManager manager)
          Creates a Callback.
Callback(String method, String[] args, boolean isStatic, InstanceManager manager)
          Creates a Callback.
 
Method Summary
 Object call()
          Invokes the method without arguments.
 Object call(Object instance)
          Invokes the method without arguments.
 Object call(Object[] arg)
          Invokes the method on every created objects with the specified arguments.
 Object call(Object instance, Object[] arg)
          Invokes the method on the given object with the specified arguments.
 String[] getArguments()
          Gets the method arguments.
 String getMethod()
          Gets the method name.
protected  void searchMethod()
          Searches the Method object in the POJO by analyzing implementation class methods.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_methodObj

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

Constructor Detail

Callback

public Callback(String method,
                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(String method,
                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

searchMethod

protected void searchMethod()
                     throws 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:
NoSuchMethodException - if the method cannot be found either in the implementation class or in parent classes.

call

public Object call()
            throws NoSuchMethodException,
                   IllegalAccessException,
                   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:
NoSuchMethodException - if Method is not found in the class
InvocationTargetException - if the method throws an exception
IllegalAccessException - if the method can not be invoked

call

public Object call(Object instance)
            throws NoSuchMethodException,
                   IllegalAccessException,
                   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:
NoSuchMethodException - if the method was not found
IllegalAccessException - if the method cannot be called
InvocationTargetException - if an error happens in the method

call

public Object call(Object[] arg)
            throws NoSuchMethodException,
                   IllegalAccessException,
                   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:
NoSuchMethodException - if the callback method is not found
IllegalAccessException - if the callback method cannot be called
InvocationTargetException - if an error is thrown by the called method

call

public Object call(Object instance,
                   Object[] arg)
            throws NoSuchMethodException,
                   IllegalAccessException,
                   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:
NoSuchMethodException - if the callback method is not found
IllegalAccessException - if the callback method cannot be called
InvocationTargetException - if an error is thrown by the called method

getMethod

public String getMethod()
Gets the method name.

Returns:
the method name

getArguments

public String[] getArguments()
Gets the method arguments.

Returns:
the arguments.


Copyright © 2013 The Apache Software Foundation. All Rights Reserved.