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 java.lang.ObjectComponent method to be invoked on service (un)binding.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classBaseMethod.MethodInfo<T>private static classBaseMethod.NotApplicableprivate static classBaseMethod.NotFoundprivate static classBaseMethod.NotResolvedprivate static classBaseMethod.Resolvedprivate static interfaceBaseMethod.State
-
Field Summary
Fields Modifier and Type Field Description private booleanconfigurableServicePropertiesprivate DSVersiondsVersionprivate java.lang.Class<?>m_componentClassprivate java.lang.reflect.Methodm_methodprivate java.lang.Stringm_methodNameprivate booleanm_methodRequiredprivate BaseMethod.Statem_state
-
Constructor Summary
Constructors Modifier Constructor Description protectedBaseMethod(java.lang.String methodName, boolean methodRequired, java.lang.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 booleanaccept(java.lang.reflect.Method method, boolean acceptPrivate, boolean acceptPackage, boolean allowReturnValue)Returnstrueif 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(java.lang.Class<?> targetClass, boolean acceptPrivate, boolean acceptPackage, ComponentLogger logger)private BaseMethod.MethodInfo<T>findMethod(ComponentLogger logger)Finds the method named in them_methodNamefield in the giventargetClass.protected java.lang.Class<?>getComponentClass()protected DSVersiongetDSVersion()(package private) java.lang.reflect.MethodgetMethod()java.lang.reflect.MethodgetMethod(java.lang.Class<?> clazz, java.lang.String name, java.lang.Class[] parameterTypes, boolean acceptPrivate, boolean acceptPackage, ComponentLogger logger)Finds the named public or protected method in the given class or any super class.protected java.lang.StringgetMethodName()protected java.lang.StringgetMethodNamePrefix()static java.lang.StringgetPackageName(java.lang.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 java.lang.Object[]getParameters(java.lang.reflect.Method method, P rawParameter)Returns the parameter array created from therawParameterusing the actual parameter type list of themethod.private java.lang.String[]getParametersForLogging(java.lang.Object[] params)(package private) BaseMethod.StategetState()MethodResultinvoke(java.lang.Object componentInstance, P rawParameter, MethodResult methodCallFailureResult)Calls the declared method on the given component with the provided method call arguments.private MethodResultinvokeMethod(java.lang.Object componentInstance, P rawParameter)protected booleanisDS12Felix()booleanmethodExists(ComponentLogger logger)protected booleanreturnValue()private static voidsetAccessible(java.lang.reflect.Method method)(package private) voidsetMethod(BaseMethod.MethodInfo<T> methodInfo, ComponentLogger logger)protected abstract voidsetTypes(T types)
-
-
-
Field Detail
-
dsVersion
private final DSVersion dsVersion
-
configurableServiceProperties
private final boolean configurableServiceProperties
-
m_methodName
private final java.lang.String m_methodName
-
m_componentClass
private final java.lang.Class<?> m_componentClass
-
m_method
private volatile java.lang.reflect.Method m_method
-
m_methodRequired
private final boolean m_methodRequired
-
m_state
private volatile BaseMethod.State m_state
-
-
Constructor Detail
-
BaseMethod
protected BaseMethod(java.lang.String methodName, boolean methodRequired, java.lang.Class<?> componentClass, DSVersion dsVersion, boolean configurableServiceProperties)
-
-
Method Detail
-
getDSVersion
protected final DSVersion getDSVersion()
-
isDS12Felix
protected final boolean isDS12Felix()
-
getMethodName
protected final java.lang.String getMethodName()
-
getMethod
final java.lang.reflect.Method getMethod()
-
getComponentClass
protected final java.lang.Class<?> getComponentClass()
-
setTypes
protected abstract void setTypes(T types)
-
setMethod
void setMethod(BaseMethod.MethodInfo<T> methodInfo, ComponentLogger logger)
-
getState
BaseMethod.State getState()
-
findMethod
private BaseMethod.MethodInfo<T> findMethod(ComponentLogger logger) throws java.lang.reflect.InvocationTargetException
Finds the method named in them_methodNamefield in the giventargetClass. 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:
logger-- Returns:
- The requested method or
nullif no acceptable method can be found in the target class or any super class. - Throws:
java.lang.reflect.InvocationTargetException- If an unexpected Throwable is caught trying to find the requested method.
-
doFindMethod
protected abstract BaseMethod.MethodInfo<T> doFindMethod(java.lang.Class<?> targetClass, boolean acceptPrivate, boolean acceptPackage, ComponentLogger logger) throws SuitableMethodNotAccessibleException, java.lang.reflect.InvocationTargetException
- Throws:
SuitableMethodNotAccessibleExceptionjava.lang.reflect.InvocationTargetException
-
getParametersForLogging
private java.lang.String[] getParametersForLogging(java.lang.Object[] params)
-
invokeMethod
private MethodResult invokeMethod(java.lang.Object componentInstance, P rawParameter) throws java.lang.reflect.InvocationTargetException
- Throws:
java.lang.reflect.InvocationTargetException
-
returnValue
protected boolean returnValue()
-
getParameters
protected abstract java.lang.Object[] getParameters(java.lang.reflect.Method method, P rawParameter)Returns the parameter array created from therawParameterusing the actual parameter type list of themethod.- Parameters:
method-rawParameter-- Returns:
- Throws:
java.lang.IllegalStateException- If the required parameters cannot be extracted from therawParameter
-
getMethodNamePrefix
protected java.lang.String getMethodNamePrefix()
-
getMethod
public java.lang.reflect.Method getMethod(java.lang.Class<?> clazz, java.lang.String name, java.lang.Class[] parameterTypes, boolean acceptPrivate, boolean acceptPackage, ComponentLogger logger) throws SuitableMethodNotAccessibleException, java.lang.reflect.InvocationTargetExceptionFinds 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.setAccessiblemethod if required and the method is returned. Enforcing accessibility is required to support invocation of protected methods.- Parameters:
clazz- TheClasswhich provides the method.name- The name of the method.parameterTypes- The parameters to the method. Passingnullis equivalent to using an empty array.logger-- Returns:
- The named method with enforced accessibility or
nullif 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.java.lang.reflect.InvocationTargetException- If an unexpected Throwable is caught trying to access the desired method.
-
accept
protected static boolean accept(java.lang.reflect.Method method, boolean acceptPrivate, boolean acceptPackage, boolean allowReturnValue)Returnstrueif the method is acceptable to be returned from thegetMethod(Class, String, Class[], boolean, boolean, ComponentLogger)and also makes the method accessible.This method returns
trueiff:- The method has
voidreturn type - Is not static
- Is public or protected
- Is private and
acceptPrivateistrue - Is package private and
acceptPackageistrue
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
-
setAccessible
private static void setAccessible(java.lang.reflect.Method method)
-
getPackageName
public static java.lang.String getPackageName(java.lang.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(java.lang.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:
trueif the method was called successfully or the method was not found and was not required.falseif the method was not found but required.methodCallFailureResultis returned if the method was found and called, but the method threw an exception.
-
methodExists
public boolean methodExists(ComponentLogger logger)
-
-