Java Code Examples for java.util.Dictionary#remove()

The following examples show how to use java.util.Dictionary#remove() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PropertyConglomerate.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
void savePropertyDefault(TransactionController tc, String key, Serializable value)
	 throws StandardException
{
	if (saveServiceProperty(key,value)) return;

	Dictionary defaults = (Dictionary)readProperty(tc,AccessFactoryGlobals.DEFAULT_PROPERTY_NAME);
	if (defaults == null) defaults = new FormatableHashtable();
	if (value==null)
		defaults.remove(key);
	else
		defaults.put(key,value);
	if (defaults.size() == 0) defaults = null;
	saveProperty(tc,AccessFactoryGlobals.DEFAULT_PROPERTY_NAME,(Serializable)defaults);
}
 
Example 2
Source File: ConfigurationService.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Creates or updates a configuration for a config id.
 *
 * @param configId config id
 * @param newConfiguration the configuration
 * @param override if true, it overrides the old config completely. means it deletes all parameters even if they are
 *            not defined in the given configuration.
 * @return old config or null if no old config existed
 * @throws IOException if configuration can not be stored
 */
public Configuration update(String configId, Configuration newConfiguration, boolean override) throws IOException {
    org.osgi.service.cm.Configuration configuration = null;
    if (newConfiguration.containsKey(ConfigConstants.SERVICE_CONTEXT)) {
        try {
            configuration = getConfigurationWithContext(configId);
        } catch (InvalidSyntaxException e) {
            logger.error("Failed to lookup config for PID '{}'", configId);
        }
        if (configuration == null) {
            configuration = configurationAdmin.createFactoryConfiguration(configId, null);
        }
    } else {
        configuration = configurationAdmin.getConfiguration(configId, null);
    }

    Configuration oldConfiguration = toConfiguration(configuration.getProperties());
    Dictionary<String, Object> properties = getProperties(configuration);
    Set<Entry<String, Object>> configurationParameters = newConfiguration.getProperties().entrySet();
    if (override) {
        Set<String> keySet = oldConfiguration.keySet();
        for (String key : keySet) {
            properties.remove(key);
        }
    }
    for (Entry<String, Object> configurationParameter : configurationParameters) {
        Object value = configurationParameter.getValue();
        if (value == null) {
            properties.remove(configurationParameter.getKey());
        } else if (value instanceof String || value instanceof Integer || value instanceof Boolean
                || value instanceof Object[] || value instanceof Collection) {
            properties.put(configurationParameter.getKey(), value);
        } else {
            // the config admin does not support complex object types, so let's store the string representation
            properties.put(configurationParameter.getKey(), value.toString());
        }
    }
    configuration.update(properties);
    return oldConfiguration;
}
 
Example 3
Source File: PrefsStorageFile.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void removeKey(final String path, final String key) {
  synchronized(lock) {
    try {
      final Dictionary<String, String> props = loadProps(path);
      props.remove(key);
      propsMap.put(path, props);
      dirtySet.add(path);
      //        saveProps(path, props);
    } catch (final Exception e) {
      logWarn("Failed to remove " + path + ", key=" + key, e);
    }
  }
}
 
Example 4
Source File: CMCommands.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public int cmdUnset(Dictionary<?, ?> opts,
                    Reader in,
                    PrintWriter out,
                    Session session)
{
  int retcode = 1; // 1 initially not set to 0 until end of try block
  try {
    if (getCurrent(session) == null) {
      throw new Exception("No configuration open currently");
    }
    final String p = (String) opts.get("property");
    final Dictionary<String, Object> dict = getEditingDict(session);
    final Object o = dict.remove(p);
    if (o == null) {
      throw new Exception("No property named " + p
                          + " in current configuration.");
    }
    retcode = 0; // Success!
  } catch (final Exception e) {
    out.print("Unset failed. Details:");
    final String reason = e.getMessage();
    out.println(reason == null ? "<unknown>" : reason);
  } finally {

  }

  return retcode;
}
 
Example 5
Source File: PropertyConglomerate.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
void savePropertyDefault(TransactionController tc, String key, Serializable value)
	 throws StandardException
{
	if (saveServiceProperty(key,value)) return;

	Dictionary defaults = (Dictionary)readProperty(tc,AccessFactoryGlobals.DEFAULT_PROPERTY_NAME);
	if (defaults == null) defaults = new FormatableHashtable();
	if (value==null)
		defaults.remove(key);
	else
		defaults.put(key,value);
	if (defaults.size() == 0) defaults = null;
	saveProperty(tc,AccessFactoryGlobals.DEFAULT_PROPERTY_NAME,(Serializable)defaults);
}
 
Example 6
Source File: EventFilterTest.java    From karaf-decanter with Apache License 2.0 5 votes vote down vote up
@Test
public void propertyNameFilter() {
    Dictionary<String, Object> config = new Hashtable<>();
    config.put(EventFilter.PROPERTY_NAME_EXCLUDE_CONFIG, "key.*");
    // exclude
    Assert.assertFalse(EventFilter.match(prepareTestEvent(), config));
    // exclude first
    config.put(EventFilter.PROPERTY_NAME_INCLUDE_CONFIG, "other");
    Assert.assertFalse(EventFilter.match(prepareTestEvent(), config));
    // include
    config.remove(EventFilter.PROPERTY_NAME_EXCLUDE_CONFIG);
    Assert.assertTrue(EventFilter.match(prepareTestEvent(), config));
}
 
Example 7
Source File: EventFilterTest.java    From karaf-decanter with Apache License 2.0 5 votes vote down vote up
@Test
public void propertyValueFilter() {
    Dictionary<String, Object> config = new Hashtable<>();
    config.put(EventFilter.PROPERTY_VALUE_EXCLUDE_CONFIG, "value.*");
    // exclude
    Assert.assertFalse(EventFilter.match(prepareTestEvent(), config));
    // exclude first
    config.put(EventFilter.PROPERTY_VALUE_INCLUDE_CONFIG, "other");
    Assert.assertFalse(EventFilter.match(prepareTestEvent(), config));
    // include
    config.remove(EventFilter.PROPERTY_VALUE_EXCLUDE_CONFIG);
    Assert.assertTrue(EventFilter.match(prepareTestEvent(), config));
}
 
Example 8
Source File: ConfigurationService.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Creates or updates a configuration for a config id.
 *
 * @param configId config id
 * @param newConfiguration the configuration
 * @param override if true, it overrides the old config completely. means it deletes all parameters even if they are
 *            not defined in the given configuration.
 * @return old config or null if no old config existed
 * @throws IOException if configuration can not be stored
 */
public Configuration update(String configId, Configuration newConfiguration, boolean override) throws IOException {
    org.osgi.service.cm.Configuration configuration = null;
    if (newConfiguration.containsKey(ConfigConstants.SERVICE_CONTEXT)) {
        try {
            configuration = getConfigurationWithContext(configId);
        } catch (InvalidSyntaxException e) {
            logger.error("Failed to lookup config for PID '{}'", configId);
        }
        if (configuration == null) {
            configuration = configurationAdmin.createFactoryConfiguration(configId, null);
        }
    } else {
        configuration = configurationAdmin.getConfiguration(configId, null);
    }

    Configuration oldConfiguration = toConfiguration(configuration.getProperties());
    Dictionary<String, Object> properties = getProperties(configuration);
    Set<Entry<String, Object>> configurationParameters = newConfiguration.getProperties().entrySet();
    if (override) {
        Set<String> keySet = oldConfiguration.keySet();
        for (String key : keySet) {
            properties.remove(key);
        }
    }
    for (Entry<String, Object> configurationParameter : configurationParameters) {
        Object value = configurationParameter.getValue();
        if (value == null) {
            properties.remove(configurationParameter.getKey());
        } else if (value instanceof String || value instanceof Integer || value instanceof Boolean
                || value instanceof Object[] || value instanceof Collection) {
            properties.put(configurationParameter.getKey(), value);
        } else {
            // the config admin does not support complex object types, so let's store the string representation
            properties.put(configurationParameter.getKey(), value.toString());
        }
    }
    configuration.update(properties);
    return oldConfiguration;
}
 
Example 9
Source File: SetTimeAction.java    From fuchsia with Apache License 2.0 5 votes vote down vote up
public Dictionary invoke(Dictionary args) throws Exception {
	Long newValue = (Long) args.get(NEW_TIME_VALUE);
       Long oldValue = (Long) ((TimeStateVariable) time).getCurrentValue();
	((TimeStateVariable) time).setCurrentTime(newValue.longValue());
       ClockDevice.notifier.propertyChange(new PropertyChangeEvent(time,"Time",oldValue,newValue));        
	args.remove(NEW_TIME_VALUE);
	args.put(NEW_RESULT_VALUE,((TimeStateVariable) time).getCurrentTime());
	return args;
}