@Override
 public SettingSpecifierProviderFactory getProviderFactory(String factoryUID) {
   synchronized (factories) {
     FactoryHelper helper = factories.get(factoryUID);
     if (helper != null) {
       return helper.getFactory();
     }
     return null;
   }
 }
 @Override
 public List<SettingSpecifierProviderFactory> getProviderFactories() {
   List<SettingSpecifierProviderFactory> results;
   synchronized (factories) {
     results = new ArrayList<SettingSpecifierProviderFactory>(factories.size());
     for (FactoryHelper helper : factories.values()) {
       results.add(helper.getFactory());
     }
     return results;
   }
 }
  /**
   * Callback when a {@link SettingSpecifierProvider} has been registered.
   *
   * @param provider the provider object
   * @param properties the service properties
   */
  public void onBind(SettingSpecifierProvider provider, Map<String, ?> properties) {
    log.debug("Bind called on {} with props {}", provider, properties);
    final String pid = provider.getSettingUID();

    List<SettingSpecifierProvider> factoryList = null;
    String factoryInstanceKey = null;
    synchronized (factories) {
      FactoryHelper helper = factories.get(pid);
      if (helper != null) {
        // Note: SERVICE_PID not normally provided by Spring: requires
        // custom SN implementation bundle
        String instancePid = (String) properties.get(Constants.SERVICE_PID);

        Configuration conf;
        try {
          conf = configurationAdmin.getConfiguration(instancePid, null);
          @SuppressWarnings("unchecked")
          Dictionary<String, ?> props = conf.getProperties();
          if (props != null) {
            factoryInstanceKey = (String) props.get(OSGI_PROPERTY_KEY_FACTORY_INSTANCE_KEY);
            log.debug("Got factory {} instance key {}", pid, factoryInstanceKey);

            factoryList = helper.getInstanceProviders(factoryInstanceKey);
            factoryList.add(provider);
          }
        } catch (IOException e) {
          log.error("Error getting factory instance configuration {}", instancePid, e);
        }
      }
    }

    if (factoryList == null) {
      synchronized (providers) {
        providers.put(pid, provider);
      }
    }

    final String settingKey = getFactoryInstanceSettingKey(pid, factoryInstanceKey);

    List<KeyValuePair> settings = settingDao.getSettings(settingKey);
    if (settings.size() < 1) {
      return;
    }
    SettingsCommand cmd = new SettingsCommand();
    for (KeyValuePair pair : settings) {
      SettingValueBean bean = new SettingValueBean();
      bean.setProviderKey(provider.getSettingUID());
      bean.setInstanceKey(factoryInstanceKey);
      bean.setKey(pair.getKey());
      bean.setValue(pair.getValue());
      cmd.getValues().add(bean);
    }
    updateSettings(cmd);
  }
  /**
   * Callback when a {@link SettingSpecifierProvider} has been un-registered.
   *
   * @param config the configuration object
   * @param properties the service properties
   */
  public void onUnbind(SettingSpecifierProvider provider, Map<String, ?> properties) {
    if (provider == null) {
      // gemini blueprint calls this when availability="optional" and there are no services
      return;
    }
    log.debug("Unbind called on {} with props {}", provider, properties);
    final String pid = provider.getSettingUID();

    synchronized (factories) {
      FactoryHelper helper = factories.get(pid);
      if (helper != null) {
        helper.removeProvider(provider);
        return;
      }
    }

    synchronized (providers) {
      providers.remove(pid);
    }
  }
 @Override
 public Map<String, List<FactorySettingSpecifierProvider>> getProvidersForFactory(
     String factoryUID) {
   Map<String, List<FactorySettingSpecifierProvider>> results =
       new LinkedHashMap<String, List<FactorySettingSpecifierProvider>>();
   synchronized (factories) {
     FactoryHelper helper = factories.get(factoryUID);
     if (helper != null) {
       for (Map.Entry<String, List<SettingSpecifierProvider>> me : helper.instanceEntrySet()) {
         String instanceUID = me.getKey();
         List<FactorySettingSpecifierProvider> list =
             new ArrayList<FactorySettingSpecifierProvider>(me.getValue().size());
         for (SettingSpecifierProvider provider : me.getValue()) {
           list.add(new BasicFactorySettingSpecifierProvider(instanceUID, provider));
         }
         results.put(instanceUID, list);
       }
     }
   }
   return results;
 }
 private List<ConfigNode> pickConfNodes(String jsonConf, Path location) throws IOException {
   ConfigurationReader reader = factoryHelper.getConfigurationReader(jsonConf);
   ConfigNode node = reader.getRootNode();
   List<ConfigNode> found = new ArrayList<>();
   for (Function<ConfigNode, List<ConfigNode>> action : location.getConfPath().getStack()) {
     found = action.apply(node);
     if (found.size() == 1) {
       node = found.get(0);
     } else {
       break;
     }
   }
   return found;
 }