private static void invokeServiceListenerCallback(Bundle bundle,
        final EventListener l, Filter filter, Object acc,
        final EventObject event, final Dictionary<String, Object> oldProps)
    {
        // Service events should be delivered to STARTING,
        // STOPPING, and ACTIVE bundles.
        if ((bundle.getState() != Bundle.STARTING)
            && (bundle.getState() != Bundle.STOPPING)
            && (bundle.getState() != Bundle.ACTIVE))
        {
            return;
        }

        // Check that the bundle has permission to get at least
        // one of the service interfaces; the objectClass property
        // of the service stores its service interfaces.
        ServiceReference<?> ref = ((ServiceEvent) event).getServiceReference();

        boolean hasPermission = true;
        if (hasPermission)
        {
            // Dispatch according to the filter.
            boolean matched = (filter == null)
                || filter.match(((ServiceEvent) event).getServiceReference());

            if (matched)
            {
                ((ServiceListener) l)
                    .serviceChanged((ServiceEvent) event);
            }
            // We need to send an MODIFIED_ENDMATCH event if the listener
            // matched previously.
            else if (((ServiceEvent) event).getType() == ServiceEvent.MODIFIED)
            {
                if (filter.match(oldProps))
                {
                    final ServiceEvent se = new ServiceEvent(
                        ServiceEvent.MODIFIED_ENDMATCH,
                        ((ServiceEvent) event).getServiceReference());
                    ((ServiceListener) l).serviceChanged(se);

                }
            }
        }
    }