use of org.apache.felix.scr.impl.inject.ActivatorParameter in project felix by apache.
the class ActivateMethod method getParameters.
@Override
protected Object[] getParameters(Method method, ActivatorParameter rawParameter) {
final Class<?>[] parameterTypes = method.getParameterTypes();
final ActivatorParameter ap = rawParameter;
final Object[] param = new Object[parameterTypes.length];
for (int i = 0; i < param.length; i++) {
if (parameterTypes[i] == ClassUtils.COMPONENT_CONTEXT_CLASS) {
param[i] = ap.getComponentContext();
} else if (parameterTypes[i] == ClassUtils.BUNDLE_CONTEXT_CLASS) {
param[i] = ap.getComponentContext().getBundleContext();
} else if (parameterTypes[i] == ClassUtils.MAP_CLASS) {
// note: getProperties() returns a ReadOnlyDictionary which is a Map
param[i] = ap.getComponentContext().getProperties();
} else if (parameterTypes[i] == ClassUtils.INTEGER_CLASS || parameterTypes[i] == Integer.TYPE) {
param[i] = ap.getReason();
} else {
param[i] = Annotations.toObject(parameterTypes[i], (Map<String, Object>) ap.getComponentContext().getProperties(), ap.getComponentContext().getBundleContext().getBundle(), m_supportsInterfaces);
}
}
return param;
}
use of org.apache.felix.scr.impl.inject.ActivatorParameter in project felix by apache.
the class ActivateMethodTest method checkMethod.
/**
* Checks whether a method with the given name can be found for the
* activate/deactivate method parameter list and whether the method returns
* the expected description when called.
*
* @param obj
* @param methodName
* @param methodDesc
* @param version DSVersion tested
*/
private void checkMethod(BaseObject obj, String methodName, String methodDesc, DSVersion version) {
ComponentContainer<?> container = newContainer();
SingleComponentManager<?> icm = new SingleComponentManager(container, new ComponentMethodsImpl());
ActivateMethod am = new ActivateMethod(methodName, methodName != null, obj.getClass(), version, false, false);
am.invoke(obj, new ActivatorParameter(new ComponentContextImpl(icm, m_bundle, null), -1), null);
Method m = am.getMethod();
assertNotNull(m);
assertEquals(methodName, m.getName());
assertEquals(methodDesc, obj.getCalledMethod());
}
use of org.apache.felix.scr.impl.inject.ActivatorParameter in project felix by apache.
the class ActivateMethodTest method ensureMethodNotFoundMethod.
/**
* Ensures no method with the given name accepting any of the
* activate/deactive method parameters can be found.
*
* @param obj
* @param methodName
* @param version DS version tested
* @throws InvocationTargetException
* @throws IllegalAccessException
*/
private void ensureMethodNotFoundMethod(BaseObject obj, String methodName, DSVersion version) {
ComponentContainer container = newContainer();
SingleComponentManager icm = new SingleComponentManager(container, new ComponentMethodsImpl());
ActivateMethod am = new ActivateMethod(methodName, methodName != null, obj.getClass(), version, false, false);
am.invoke(obj, new ActivatorParameter(new ComponentContextImpl(icm, m_bundle, null), -1), null);
Method m = am.getMethod();
assertNull(m);
assertNull(obj.getCalledMethod());
}
Aggregations