public abstract class BaseMethod<P extends BaseParameter,T> extends Object
Modifier and Type | Class and Description |
---|---|
protected static class |
BaseMethod.MethodInfo<T> |
Modifier | Constructor and Description |
---|---|
protected |
BaseMethod(String methodName,
boolean methodRequired,
Class<?> componentClass,
DSVersion dsVersion,
boolean configurableServiceProperties) |
Modifier and Type | Method and Description |
---|---|
protected static boolean |
accept(Method method,
boolean acceptPrivate,
boolean acceptPackage,
boolean allowReturnValue)
Returns
true if the method is acceptable to be returned from the
getMethod(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 the
rawParameter
using the actual parameter type list of the method . |
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) |
protected final DSVersion getDSVersion()
protected final boolean isDS12Felix()
protected final String getMethodName()
protected final Class<?> getComponentClass()
protected abstract void setTypes(T types)
protected abstract BaseMethod.MethodInfo<T> doFindMethod(Class<?> targetClass, boolean acceptPrivate, boolean acceptPackage, ComponentLogger logger) throws SuitableMethodNotAccessibleException, InvocationTargetException
protected boolean returnValue()
protected abstract Object[] getParameters(Method method, P rawParameter)
rawParameter
using the actual parameter type list of the method
.method
- rawParameter
- IllegalStateException
- If the required parameters cannot be
extracted from the rawParameter
protected String getMethodNamePrefix()
public Method getMethod(Class<?> clazz, String name, Class[] parameterTypes, boolean acceptPrivate, boolean acceptPackage, ComponentLogger logger) throws SuitableMethodNotAccessibleException, InvocationTargetException
Method.setAccessible
method if required and
the method is returned. Enforcing accessibility is required to support
invocation of protected methods.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.logger
- null
if no such method exists in the class.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.protected static boolean accept(Method method, boolean acceptPrivate, boolean acceptPackage, boolean allowReturnValue)
true
if the method is acceptable to be returned from the
getMethod(Class, String, Class[], boolean, boolean, ComponentLogger)
and also
makes the method accessible.
This method returns true
iff:
void
return typeacceptPrivate
is true
acceptPackage
is true
This method is package private for unit testing purposes. It is not meant to be called from client code.
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)public static String getPackageName(Class<?> clazz)
public MethodResult invoke(Object componentInstance, P rawParameter, MethodResult methodCallFailureResult)
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
- 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.public boolean methodExists(ComponentLogger logger)
Copyright © 2006–2020 The Apache Software Foundation. All rights reserved.