public abstract class BaseMethod<P extends BaseParameter,T>
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
protected static class |
BaseMethod.MethodInfo<T> |
private static class |
BaseMethod.NotApplicable |
private static class |
BaseMethod.NotFound |
private static class |
BaseMethod.NotResolved |
private static class |
BaseMethod.Resolved |
private static interface |
BaseMethod.State |
Modifier and Type | Field and Description |
---|---|
private boolean |
configurableServiceProperties |
private DSVersion |
dsVersion |
private java.lang.Class<?> |
m_componentClass |
private java.lang.reflect.Method |
m_method |
private java.lang.String |
m_methodName |
private boolean |
m_methodRequired |
private BaseMethod.State |
m_state |
Modifier | Constructor and Description |
---|---|
protected |
BaseMethod(java.lang.String methodName,
boolean methodRequired,
java.lang.Class<?> componentClass,
DSVersion dsVersion,
boolean configurableServiceProperties) |
Modifier and Type | Method and Description |
---|---|
protected static boolean |
accept(java.lang.reflect.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(java.lang.Class<?> targetClass,
boolean acceptPrivate,
boolean acceptPackage,
ComponentLogger logger) |
private BaseMethod.MethodInfo<T> |
findMethod(ComponentLogger logger)
Finds the method named in the
m_methodName field in the given
targetClass . |
protected java.lang.Class<?> |
getComponentClass() |
protected DSVersion |
getDSVersion() |
(package private) java.lang.reflect.Method |
getMethod() |
java.lang.reflect.Method |
getMethod(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.String |
getMethodName() |
protected java.lang.String |
getMethodNamePrefix() |
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.
|
protected abstract java.lang.Object[] |
getParameters(java.lang.reflect.Method method,
P rawParameter)
Returns the parameter array created from the
rawParameter
using the actual parameter type list of the method . |
(package private) BaseMethod.State |
getState() |
MethodResult |
invoke(java.lang.Object componentInstance,
P rawParameter,
MethodResult methodCallFailureResult)
Calls the declared method on the given component with the provided
method call arguments.
|
private MethodResult |
invokeMethod(java.lang.Object componentInstance,
P rawParameter) |
protected boolean |
isDS12Felix() |
boolean |
methodExists(ComponentLogger logger) |
protected boolean |
returnValue() |
private static void |
setAccessible(java.lang.reflect.Method method) |
(package private) void |
setMethod(BaseMethod.MethodInfo<T> methodInfo,
ComponentLogger logger) |
protected abstract void |
setTypes(T types) |
private final DSVersion dsVersion
private final boolean configurableServiceProperties
private final java.lang.String m_methodName
private final java.lang.Class<?> m_componentClass
private volatile java.lang.reflect.Method m_method
private final boolean m_methodRequired
private volatile BaseMethod.State m_state
protected BaseMethod(java.lang.String methodName, boolean methodRequired, java.lang.Class<?> componentClass, DSVersion dsVersion, boolean configurableServiceProperties)
protected final DSVersion getDSVersion()
protected final boolean isDS12Felix()
protected final java.lang.String getMethodName()
final java.lang.reflect.Method getMethod()
protected final java.lang.Class<?> getComponentClass()
protected abstract void setTypes(T types)
void setMethod(BaseMethod.MethodInfo<T> methodInfo, ComponentLogger logger)
BaseMethod.State getState()
private BaseMethod.MethodInfo<T> findMethod(ComponentLogger logger) throws java.lang.reflect.InvocationTargetException
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.logger
- null
if no acceptable method
can be found in the target class or any super class.java.lang.reflect.InvocationTargetException
- If an unexpected Throwable is caught
trying to find the requested method.protected abstract BaseMethod.MethodInfo<T> doFindMethod(java.lang.Class<?> targetClass, boolean acceptPrivate, boolean acceptPackage, ComponentLogger logger) throws SuitableMethodNotAccessibleException, java.lang.reflect.InvocationTargetException
SuitableMethodNotAccessibleException
java.lang.reflect.InvocationTargetException
private MethodResult invokeMethod(java.lang.Object componentInstance, P rawParameter) throws java.lang.reflect.InvocationTargetException
java.lang.reflect.InvocationTargetException
protected boolean returnValue()
protected abstract java.lang.Object[] getParameters(java.lang.reflect.Method method, P rawParameter)
rawParameter
using the actual parameter type list of the method
.method
- rawParameter
- java.lang.IllegalStateException
- If the required parameters cannot be
extracted from the rawParameter
protected java.lang.String getMethodNamePrefix()
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.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.java.lang.reflect.InvocationTargetException
- If an unexpected Throwable is caught
trying to access the desired method.protected static boolean accept(java.lang.reflect.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)private static void setAccessible(java.lang.reflect.Method method)
public static java.lang.String getPackageName(java.lang.Class<?> clazz)
public MethodResult invoke(java.lang.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)