org.apache.felix.ipojo.util

## Class Callback

- java.lang.Object
- - 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

Fields
`protected java.lang.reflect.Method` `m_methodObj` The method object.

### Constructor Summary

Constructors
Constructor and Description
`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

All Methods Instance Methods Concrete Methods
`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.
`java.lang.String[]` `getArguments()` Gets the method arguments.
`java.lang.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 java.lang.reflect.Method m_methodObj

The method object. Computed at the first call.

### 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:
  `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

#### 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

#### getArguments

    public java.lang.String[] getArguments()

Gets the method arguments.

Returns:
  the arguments.