org.apache.felix.scr.impl.helper
Class BindMethod

java.lang.Object
  extended by org.apache.felix.scr.impl.helper.BindMethod
Direct Known Subclasses:
UnbindMethod, UpdatedMethod

public class BindMethod
extends Object

Component method to be invoked on service (un)binding.


Nested Class Summary
static interface BindMethod.Service
           
 
Field Summary
protected static Class BUNDLE_CONTEXT_CLASS
           
protected static Class COMPONENT_CONTEXT_CLASS
           
protected static Class INTEGER_CLASS
           
protected static Class MAP_CLASS
           
protected static Class SERVICE_REFERENCE_CLASS
           
 
Constructor Summary
BindMethod(AbstractComponentManager componentManager, String methodName, Class componentClass, String referenceName, String referenceClassName)
           
 
Method Summary
protected static boolean accept(Method method, boolean acceptPrivate, boolean acceptPackage)
          Returns true if the method is acceptable to be returned from the getMethod(Class, String, Class[], boolean, boolean) and also makes the method accessible.
protected  Method doFindMethod(Class targetClass, boolean acceptPrivate, boolean acceptPackage)
          Finds the method named in the m_methodName field in the given targetClass.
protected  Class getComponentClass()
           
protected  AbstractComponentManager getComponentManager()
           
 Method getMethod(Class clazz, String name, Class[] parameterTypes, boolean acceptPrivate, boolean acceptPackage)
          Finds the named public or protected method in the given class or any super class.
protected  String getMethodName()
           
protected  String getMethodNamePrefix()
           
static String getPackageName(Class clazz)
          Returns the name of the package to which the class belongs or an empty string if the class is in the default package.
protected  Object[] getParameters(Method method, Object rawParameter)
          Returns the parameter array created from the rawParameter using the actual parameter type list of the method.
 boolean invoke(Object componentInstance, Object rawParameter, boolean methodCallFailureResult)
          Calls the declared method on the given component with the provided method call arguments.
protected  boolean isDS11()
           
 boolean methodExists()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMPONENT_CONTEXT_CLASS

protected static final Class COMPONENT_CONTEXT_CLASS

BUNDLE_CONTEXT_CLASS

protected static final Class BUNDLE_CONTEXT_CLASS

SERVICE_REFERENCE_CLASS

protected static final Class SERVICE_REFERENCE_CLASS

MAP_CLASS

protected static final Class MAP_CLASS

INTEGER_CLASS

protected static final Class INTEGER_CLASS
Constructor Detail

BindMethod

public BindMethod(AbstractComponentManager componentManager,
                  String methodName,
                  Class componentClass,
                  String referenceName,
                  String referenceClassName)
Method Detail

doFindMethod

protected Method doFindMethod(Class targetClass,
                              boolean acceptPrivate,
                              boolean acceptPackage)
                       throws SuitableMethodNotAccessibleException,
                              InvocationTargetException
Finds the method named in the m_methodName field in the given targetClass. If the target class has no acceptable method the class hierarchy is traversed until a method is found or the root of the class hierarchy is reached without finding a method.

Parameters:
targetClass - The class in which to look for the method
acceptPrivate - true if private methods should be considered.
acceptPackage - true if package private methods should be considered.
Returns:
The requested method or null if no acceptable method can be found in the target class or any super class.
Throws:
InvocationTargetException - If an unexpected Throwable is caught trying to find the requested method.
SuitableMethodNotAccessibleException

getParameters

protected Object[] getParameters(Method method,
                                 Object rawParameter)
Returns the parameter array created from the rawParameter using the actual parameter type list of the method.

Returns:

getMethodNamePrefix

protected String getMethodNamePrefix()

getComponentManager

protected final AbstractComponentManager getComponentManager()

isDS11

protected final boolean isDS11()

getMethodName

protected final String getMethodName()

getComponentClass

protected final Class getComponentClass()

getMethod

public Method getMethod(Class clazz,
                        String name,
                        Class[] parameterTypes,
                        boolean acceptPrivate,
                        boolean acceptPackage)
                 throws SuitableMethodNotAccessibleException,
                        InvocationTargetException
Finds the named public or protected method in the given class or any super class. If such a method is found, its accessibility is enfored by calling the Method.setAccessible method if required and the method is returned. Enforcing accessibility is required to support invocation of protected methods.

Parameters:
clazz - The Class which provides the method.
name - The name of the method.
parameterTypes - The parameters to the method. Passing null is equivalent to using an empty array.
Returns:
The named method with enforced accessibility or null if no such method exists in the class.
Throws:
SuitableMethodNotAccessibleException - If method with the given name taking the parameters is found in the class but the method is not accessible.
InvocationTargetException - If an unexpected Throwable is caught trying to access the desired method.

accept

protected static boolean accept(Method method,
                                boolean acceptPrivate,
                                boolean acceptPackage)
Returns true if the method is acceptable to be returned from the getMethod(Class, String, Class[], boolean, boolean) and also makes the method accessible.

This method returns true iff:

This method is package private for unit testing purposes. It is not meant to be called from client code.

Parameters:
method - The method to check
acceptPrivate - Whether a private method is acceptable
acceptPackage - Whether a package private method is acceptable
Returns:

getPackageName

public static String getPackageName(Class clazz)
Returns the name of the package to which the class belongs or an empty string if the class is in the default package.


invoke

public boolean invoke(Object componentInstance,
                      Object rawParameter,
                      boolean methodCallFailureResult)
Calls the declared method on the given component with the provided method call arguments.

Parameters:
componentInstance - The component instance on which to call the method
rawParameter - The parameter container providing the actual parameters to provide to the called method
methodCallFailureResult - The result to return from this method if calling the method resulted in an exception.
Returns:
true if the method was called successfully or the method was not found and was not required. false if the method was not found but required. methodCallFailureResult is returned if the method was found and called, but the method threw an exception.

methodExists

public boolean methodExists()


Copyright © 2011 Apache Software Foundation. All Rights Reserved.