Search in sources :

Example 1 with ConfigurationPlugin

use of org.osgi.service.cm.ConfigurationPlugin in project aries by apache.

the class CmUtils method callPlugins.

private static void callPlugins(final BundleContext bundleContext, final Dictionary<String, Object> props, final ServiceReference sr, final String configPid, final String factoryPid) {
    ServiceReference[] plugins = null;
    try {
        final String targetPid = (factoryPid == null) ? configPid : factoryPid;
        String filter = "(|(!(cm.target=*))(cm.target=" + targetPid + "))";
        plugins = bundleContext.getServiceReferences(ConfigurationPlugin.class.getName(), filter);
    } catch (InvalidSyntaxException ise) {
    // no filter, no exception ...
    }
    // abort early if there are no plugins
    if (plugins == null || plugins.length == 0) {
        return;
    }
    // sort the plugins by their service.cmRanking
    if (plugins.length > 1) {
        Arrays.sort(plugins, CM_RANKING);
    }
    // call the plugins in order
    for (ServiceReference pluginRef : plugins) {
        ConfigurationPlugin plugin = (ConfigurationPlugin) bundleContext.getService(pluginRef);
        if (plugin != null) {
            try {
                plugin.modifyConfiguration(sr, props);
            } catch (Throwable t) {
            // Ignore
            } finally {
                // ensure ungetting the plugin
                bundleContext.ungetService(pluginRef);
            }
            setAutoProperties(props, configPid, factoryPid);
        }
    }
}
Also used : ConfigurationPlugin(org.osgi.service.cm.ConfigurationPlugin) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 ServiceReference (org.osgi.framework.ServiceReference)1 ConfigurationPlugin (org.osgi.service.cm.ConfigurationPlugin)1