Search in sources :

Example 1 with MethodResult

use of org.apache.felix.scr.impl.inject.MethodResult in project felix by apache.

the class BaseMethod method invokeMethod.

private MethodResult invokeMethod(final Object componentInstance, final P rawParameter) throws InvocationTargetException {
    try {
        if (componentInstance != null) {
            final Object[] params = getParameters(m_method, rawParameter);
            rawParameter.getComponentContext().getLogger().log(LogService.LOG_DEBUG, "invoking {0}: {1}: parameters {2}", null, getMethodNamePrefix(), getMethodName(), Arrays.asList(params));
            Object result = m_method.invoke(componentInstance, params);
            rawParameter.getComponentContext().getLogger().log(LogService.LOG_DEBUG, "invoked {0}: {1}", null, getMethodNamePrefix(), getMethodName());
            return new MethodResult((m_method.getReturnType() != Void.TYPE), (Map<String, Object>) result);
        } else {
            rawParameter.getComponentContext().getLogger().log(LogService.LOG_WARNING, "Method {0}: {1} cannot be called on null object", null, getMethodNamePrefix(), getMethodName());
        }
    } catch (IllegalStateException ise) {
        rawParameter.getComponentContext().getLogger().log(LogService.LOG_DEBUG, ise.getMessage(), null);
        return null;
    } catch (IllegalAccessException ex) {
        // 112.3.1 If the method is not is not declared protected or
        // public, SCR must log an error message with the log service,
        // if present, and ignore the method
        rawParameter.getComponentContext().getLogger().log(LogService.LOG_DEBUG, "Method {0} cannot be called", ex, getMethodName());
    } catch (InvocationTargetException ex) {
        throw ex;
    } catch (Throwable t) {
        throw new InvocationTargetException(t);
    }
    // assume success (also if the method is not available or accessible)
    return MethodResult.VOID;
}
Also used : InvocationTargetException(java.lang.reflect.InvocationTargetException) MethodResult(org.apache.felix.scr.impl.inject.MethodResult)

Example 2 with MethodResult

use of org.apache.felix.scr.impl.inject.MethodResult in project felix by apache.

the class DependencyManager method doInvokeBindMethod.

private boolean doInvokeBindMethod(ComponentContextImpl<S> componentContext, final ReferenceMethod bindMethod, RefPair<S, T> refPair, int trackingCount) {
    if (!getServiceObject(componentContext, bindMethod, refPair)) {
        m_componentManager.getLogger().log(LogService.LOG_WARNING, "DependencyManager : invokeBindMethod : Service not available from service registry for ServiceReference {0} for reference {1}", null, refPair.getRef(), getName());
        return false;
    }
    MethodResult result = bindMethod.invoke(componentContext.getImplementationObject(false), new BindParameters(componentContext, refPair), MethodResult.VOID);
    if (result == null) {
        return false;
    }
    m_componentManager.setServiceProperties(result, trackingCount);
    return true;
}
Also used : BindParameters(org.apache.felix.scr.impl.inject.BindParameters) MethodResult(org.apache.felix.scr.impl.inject.MethodResult)

Aggregations

MethodResult (org.apache.felix.scr.impl.inject.MethodResult)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 BindParameters (org.apache.felix.scr.impl.inject.BindParameters)1