Search in sources :

Example 1 with ActivatorParameter

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;
}
Also used : ActivatorParameter(org.apache.felix.scr.impl.inject.ActivatorParameter)

Example 2 with ActivatorParameter

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());
}
Also used : SingleComponentManager(org.apache.felix.scr.impl.manager.SingleComponentManager) ComponentContextImpl(org.apache.felix.scr.impl.manager.ComponentContextImpl) ActivatorParameter(org.apache.felix.scr.impl.inject.ActivatorParameter) ComponentMethodsImpl(org.apache.felix.scr.impl.inject.ComponentMethodsImpl) AcceptMethod(org.apache.felix.scr.impl.metadata.instances.AcceptMethod) Method(java.lang.reflect.Method)

Example 3 with ActivatorParameter

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());
}
Also used : SingleComponentManager(org.apache.felix.scr.impl.manager.SingleComponentManager) ComponentContextImpl(org.apache.felix.scr.impl.manager.ComponentContextImpl) ActivatorParameter(org.apache.felix.scr.impl.inject.ActivatorParameter) ComponentContainer(org.apache.felix.scr.impl.manager.ComponentContainer) ComponentMethodsImpl(org.apache.felix.scr.impl.inject.ComponentMethodsImpl) AcceptMethod(org.apache.felix.scr.impl.metadata.instances.AcceptMethod) Method(java.lang.reflect.Method)

Aggregations

ActivatorParameter (org.apache.felix.scr.impl.inject.ActivatorParameter)3 Method (java.lang.reflect.Method)2 ComponentMethodsImpl (org.apache.felix.scr.impl.inject.ComponentMethodsImpl)2 ComponentContextImpl (org.apache.felix.scr.impl.manager.ComponentContextImpl)2 SingleComponentManager (org.apache.felix.scr.impl.manager.SingleComponentManager)2 AcceptMethod (org.apache.felix.scr.impl.metadata.instances.AcceptMethod)2 ComponentContainer (org.apache.felix.scr.impl.manager.ComponentContainer)1