private List /* <Configuration> */ getConfigurations(
      String filterString, String callingBundleLocation, boolean checkLocation)
      throws IOException, InvalidSyntaxException {
    Filter filter = (filterString != null) ? context.createFilter(filterString) : null;
    Iterator /* <String> */ pids = configurationDictionaryManager.listPids();
    List /* <Configuration> */ matchingConfigurations = new ArrayList();
    while (pids.hasNext()) {

      String pid = (String) pids.next();
      ConfigurationDictionary config = configurationDictionaryManager.load(pid);
      if (filter == null) {
        matchingConfigurations.add(new ConfigurationImpl(this, config));
      } else {
        if (filter.matchCase(config.toSearchableProperties())) {
          if (!checkLocation) {
            matchingConfigurations.add(new ConfigurationImpl(this, config));
          } else {
            if (callingBundleLocation.equals(config.getLocation())) {
              matchingConfigurations.add(new ConfigurationImpl(this, config));
            }
          }
        }
      }
    }
    return matchingConfigurations;
  }
  public synchronized void update(
      String factoryPid, String servicePid, ConfigurationDictionary dictionary) throws IOException {
    configurationDictionaryManager.save(servicePid, dictionary);
    ConfigurationDictionary newDictionary = configurationDictionaryManager.load(servicePid);
    updateTargetServicesMatching(
        servicePid, factoryPid, newDictionary.getLocation(), newDictionary);

    if (cmRef == null) {
      LOG.error("update: Could not get service reference for event delivery");
    } else {
      sendConfigurationEvent(
          new ConfigurationEvent(cmRef, ConfigurationEvent.CM_UPDATED, factoryPid, servicePid));
    }
  }
  private ConfigurationDictionary bindLocationIfNecessary(
      ServiceReference[] servicePids, ConfigurationDictionary dictionary) throws IOException {
    if (servicePids == null || servicePids.length == 0) {
      return dictionary;
    }
    String configLocation = dictionary.getLocation();
    LOG.info(ArrayUtils.toString(servicePids, "[", "]", ", "));
    if (configLocation != null) {
      LOG.info(configLocation + " " + configLocation.getClass());
    }
    Enumeration e = dictionary.keys();
    while (e.hasMoreElements()) {
      String key = (String) e.nextElement();
      LOG.info(key + " -> " + dictionary.get(key));
    }

    if (isUnrealBundleLocation(configLocation)) {
      if (dictionary.isDynamic()) {
        configLocation = null;
        dictionary.setLocation(null);
      }
    }

    if (configLocation == null) {
      String pid = (String) dictionary.get(Constants.SERVICE_PID);
      String serviceLocation = servicePids[0].getBundle().getLocation();

      dictionary.setLocation(serviceLocation);
      configurationDictionaryManager.save(pid, dictionary);
    }
    return dictionary;
  }
  /**
   * Deletes the configuration from configuration admin
   *
   * @param configuration Configuration to delete
   * @throws IOException If any problem occurs while deleting the configuration
   */
  public synchronized void delete(ConfigurationImpl configuration, String servicePid)
      throws IOException {
    ConfigurationDictionary dictionary = configurationDictionaryManager.load(servicePid);
    String factoryPid = (String) dictionary.get(ConfigurationAdmin.SERVICE_FACTORYPID);
    String location = dictionary.getLocation();

    configurationDictionaryManager.delete(servicePid);

    dictionary = configurationDictionaryManager.load(servicePid);
    updateTargetServicesMatching(servicePid, factoryPid, location, dictionary);

    if (cmRef == null) {
      LOG.error("delete: Could not get service reference");
    } else {
      sendConfigurationEvent(
          new ConfigurationEvent(
              cmRef,
              (dictionary != null) ? ConfigurationEvent.CM_UPDATED : ConfigurationEvent.CM_DELETED,
              factoryPid,
              servicePid));
    }
  }
 private void updateManagedServiceFactory(ServiceReference serviceReference, String[] factoryPids)
     throws IOException {
   for (int j = 0; j < factoryPids.length; ++j) {
     String factoryPid = factoryPids[j];
     List /* <ConfigurationDictionary> */ cds = configurationDictionaryManager.loadAll(factoryPid);
     if (cds != null && cds.size() > 0) {
       ServiceReference[] srs = new ServiceReference[] {serviceReference};
       Iterator /* <ConfigurationDictionary> */ it = cds.iterator();
       ConfigurationDictionary dictionary = null;
       while (it.hasNext()) {
         dictionary = (ConfigurationDictionary) it.next();
         String servicePid = (String) dictionary.get(Constants.SERVICE_PID);
         updateManagedServiceFactories(srs, servicePid, factoryPid, dictionary);
       }
     }
   }
 }
  public synchronized Configuration createFactoryConfiguration(
      String factoryPid, String location, boolean checkLocation) throws IOException {
    if (checkLocation) {
      ConfigurationDictionary dictionary = configurationDictionaryManager.loadOne(factoryPid);

      String locationFactoryPidIsBoundTo = null;
      if (dictionary != null && dictionary.size() > 0) {
        locationFactoryPidIsBoundTo = dictionary.getLocation();
      }
      if (locationFactoryPidIsBoundTo != null && !location.equals(locationFactoryPidIsBoundTo)) {
        throw new SecurityException("Not owner of the factoryPid");
      }
    }
    // TODO should check and ensure availability
    String pid = factoryPid + "-" + UUID.randomUUID(8);
    return new ConfigurationImpl(this, location, factoryPid, pid);
  }
 private void updateManagedService(ServiceReference serviceReference, String[] servicePids)
     throws IOException {
   for (int j = 0; j < servicePids.length; ++j) {
     String servicePid = servicePids[j];
     ServiceReference[] srs = new ServiceReference[] {serviceReference};
     ConfigurationDictionary cd = configurationDictionaryManager.load(servicePid);
     if (cd == null) {
       for (int i = 0; i < srs.length; ++i) {
         sendUpdateEvent(srs[i], servicePid, null, null);
       }
     } else {
       cd = bindLocationIfNecessary(srs, cd);
       String boundLocation = cd.getLocation();
       srs = filterOnMatchingLocations(srs, boundLocation);
       for (int i = 0; i < srs.length; ++i) {
         sendUpdateEvent(srs[i], servicePid, null, cd);
       }
     }
   }
 }
 public synchronized Configuration getConfiguration(
     String servicePid, String location, boolean checkLocation) throws IOException {
   ConfigurationDictionary dictionary = configurationDictionaryManager.load(servicePid);
   if (checkLocation) {
     String locationPidIsBoundTo = null;
     if (dictionary != null && dictionary.size() > 0) {
       locationPidIsBoundTo = dictionary.getLocation();
     }
     if (locationPidIsBoundTo != null && !location.equals(locationPidIsBoundTo)) {
       throw new SecurityException("Not owner of the servicePid");
     }
   }
   ConfigurationImpl configuration = null;
   if (dictionary == null) {
     configuration = new ConfigurationImpl(this, location, null, servicePid);
   } else {
     configuration = new ConfigurationImpl(this, dictionary);
   }
   return configuration;
 }
 public synchronized void delete(String servicePid) {
   configurationDictionaryManager.delete(servicePid);
 }