Class BaseMethod<P extends BaseParameter,T>
- java.lang.Object
-
- org.apache.felix.scr.impl.inject.methods.BaseMethod<P,T>
-
- Direct Known Subclasses:
ActivateMethod
,BindMethod
public abstract class BaseMethod<P extends BaseParameter,T> extends Object
Component method to be invoked on service (un)binding.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
BaseMethod.MethodInfo<T>
-
Constructor Summary
Constructors Modifier Constructor Description protected
BaseMethod(String methodName, boolean methodRequired, Class<?> componentClass, DSVersion dsVersion, boolean configurableServiceProperties)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected static boolean
accept(Method method, boolean acceptPrivate, boolean acceptPackage, boolean allowReturnValue)
Returnstrue
if the method is acceptable to be returned from thegetMethod(Class, String, Class[], boolean, boolean, ComponentLogger)
and also makes the method accessible.protected abstract BaseMethod.MethodInfo<T>
doFindMethod(Class<?> targetClass, boolean acceptPrivate, boolean acceptPackage, ComponentLogger logger)
protected Class<?>
getComponentClass()
protected DSVersion
getDSVersion()
Method
getMethod(Class<?> clazz, String name, Class[] parameterTypes, boolean acceptPrivate, boolean acceptPackage, ComponentLogger logger)
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 abstract Object[]
getParameters(Method method, P rawParameter)
Returns the parameter array created from therawParameter
using the actual parameter type list of themethod
.MethodResult
invoke(Object componentInstance, P rawParameter, MethodResult methodCallFailureResult)
Calls the declared method on the given component with the provided method call arguments.protected boolean
isDS12Felix()
boolean
methodExists(ComponentLogger logger)
protected boolean
returnValue()
protected abstract void
setTypes(T types)
-
-
-
Method Detail
-
getDSVersion
protected final DSVersion getDSVersion()
-
isDS12Felix
protected final boolean isDS12Felix()
-
getMethodName
protected final String getMethodName()
-
getComponentClass
protected final Class<?> getComponentClass()
-
setTypes
protected abstract void setTypes(T types)
-
doFindMethod
protected abstract BaseMethod.MethodInfo<T> doFindMethod(Class<?> targetClass, boolean acceptPrivate, boolean acceptPackage, ComponentLogger logger) throws SuitableMethodNotAccessibleException, InvocationTargetException
-
returnValue
protected boolean returnValue()
-
getParameters
protected abstract Object[] getParameters(Method method, P rawParameter)
Returns the parameter array created from therawParameter
using the actual parameter type list of themethod
.- Parameters:
method
-rawParameter
-- Returns:
- Throws:
IllegalStateException
- If the required parameters cannot be extracted from therawParameter
-
getMethodNamePrefix
protected String getMethodNamePrefix()
-
getMethod
public Method getMethod(Class<?> clazz, String name, Class[] parameterTypes, boolean acceptPrivate, boolean acceptPackage, ComponentLogger logger) 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 theMethod.setAccessible
method if required and the method is returned. Enforcing accessibility is required to support invocation of protected methods.- Parameters:
clazz
- TheClass
which provides the method.name
- The name of the method.parameterTypes
- The parameters to the method. Passingnull
is equivalent to using an empty array.logger
-- 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, boolean allowReturnValue)
Returnstrue
if the method is acceptable to be returned from thegetMethod(Class, String, Class[], boolean, boolean, ComponentLogger)
and also makes the method accessible.This method returns
true
iff:- The method has
void
return type - Is not static
- Is public or protected
- Is private and
acceptPrivate
istrue
- Is package private and
acceptPackage
istrue
This method is package private for unit testing purposes. It is not meant to be called from client code.
- Parameters:
method
- The method to checkacceptPrivate
- Whether a private method is acceptableacceptPackage
- Whether a package private method is acceptableallowReturnValue
- whether the method can return a value (to update service registration properties)- Returns:
- whether the method is acceptable
- The method has
-
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 MethodResult invoke(Object componentInstance, P rawParameter, MethodResult 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 methodrawParameter
- The parameter container providing the actual parameters to provide to the called methodmethodCallFailureResult
- The result to return from this method if calling the method resulted in an exception.logger
-- 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(ComponentLogger logger)
-
-