Example usage for java.util Dictionary keys

List of usage examples for java.util Dictionary keys

Introduction

In this page you can find the example usage for java.util Dictionary keys.

Prototype

public abstract Enumeration<K> keys();

Source Link

Document

Returns an enumeration of the keys in this dictionary.

Usage

From source file:org.codice.ddf.admin.core.impl.AdminConsoleService.java

/** @see AdminConsoleServiceMBean#getPropertiesForLocation(java.lang.String, java.lang.String) */
public Map<String, Object> getPropertiesForLocation(String pid, String location) throws IOException {
    if (pid == null || pid.length() < 1) {
        throw new IOException(ILLEGAL_PID_MESSAGE);
    }/*from w  ww  .ja  v a 2  s . c o  m*/
    Map<String, Object> propertiesTable = new HashMap<>();
    Configuration config = configurationAdmin.getConfiguration(pid, location);

    if (isPermittedToViewService(config.getPid())) {
        Dictionary<String, Object> properties = config.getProperties();
        if (properties != null) {
            Enumeration<String> keys = properties.keys();
            while (keys.hasMoreElements()) {
                String key = keys.nextElement();
                propertiesTable.put(key, properties.get(key));
            }
        }
    }
    return propertiesTable;
}

From source file:org.codice.ddf.ui.admin.api.ConfigurationAdmin.java

/**
 * @see ConfigurationAdminMBean#getPropertiesForLocation(java.lang.String, java.lang.String)
 *//*from   w  w w.  j av  a 2s.  co m*/
public Map<String, Object> getPropertiesForLocation(String pid, String location) throws IOException {
    if (pid == null || pid.length() < 1) {
        throw new IOException("Argument pid cannot be null or empty");
    }
    Map<String, Object> propertiesTable = new HashMap<>();
    Configuration config = configurationAdmin.getConfiguration(pid, location);
    Dictionary<String, Object> properties = config.getProperties();
    if (properties != null) {
        Enumeration<String> keys = properties.keys();
        while (keys.hasMoreElements()) {
            String key = keys.nextElement();
            propertiesTable.put(key, properties.get(key));
        }
    }
    return propertiesTable;
}

From source file:org.nuxeo.ecm.platform.web.common.requestcontroller.service.NuxeoCorsFilterDescriptor.java

public FilterConfig buildFilterConfig() {
    final Dictionary<String, String> parameters = buildDictionary();

    return new FilterConfig() {
        @Override//from   www .ja  v a2 s . c  om
        public String getFilterName() {
            return "NuxeoCorsFilterDescriptor";
        }

        @Override
        public ServletContext getServletContext() {
            // Not used with @see CORSFilter
            return null;
        }

        @Override
        public String getInitParameter(String name) {
            return parameters.get(name);
        }

        @Override
        public Enumeration getInitParameterNames() {
            return parameters.keys();
        }
    };
}

From source file:com.metaparadigm.jsonrpc.DictionarySerializer.java

public Object marshall(SerializerState state, Object o) throws MarshallException {
    Dictionary ht = (Dictionary) o;
    JSONObject obj = new JSONObject();
    JSONObject mapdata = new JSONObject();
    if (ser.getMarshallClassHints())
        try {/* ww  w  .  j av  a 2s. c o  m*/
            obj.put("javaClass", o.getClass().getName());
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    try {
        obj.put("map", mapdata);
    } catch (JSONException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    Object key = null;
    Object val = null;
    try {
        Enumeration en = ht.keys();
        while (en.hasMoreElements()) {
            key = en.nextElement();
            val = ht.get(key);
            // only support String keys
            JSONObject put = mapdata.put(key.toString(), ser.marshall(state, val));
        }
    } catch (MarshallException e) {
        throw new MarshallException("map key " + key + " " + e.getMessage());
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return obj;
}

From source file:org.jabsorb.ng.serializer.impl.DictionarySerializer.java

@Override
public Object marshall(final SerializerState state, final Object p, final Object o) throws MarshallException {

    final Dictionary<?, ?> dictionary = (Dictionary<?, ?>) o;
    final JSONObject obj = new JSONObject();
    final JSONObject mapdata = new JSONObject();

    try {//from   w ww.  j  av  a2 s. c om
        if (ser.getMarshallClassHints()) {
            obj.put("javaClass", o.getClass().getName());
        }
        obj.put("map", mapdata);
        state.push(o, mapdata, "map");
    } catch (final JSONException e) {
        throw new MarshallException("Could not put data" + e.getMessage(), e);
    }

    Object key = null;
    try {
        final Enumeration<?> en = dictionary.keys();
        while (en.hasMoreElements()) {
            key = en.nextElement();
            final String keyString = key.toString(); // only support String
                                                     // keys

            final Object json = ser.marshall(state, mapdata, dictionary.get(key), keyString);

            // omit the object entirely if it's a circular reference or
            // duplicate
            // it will be regenerated in the fixups phase
            if (JSONSerializer.CIRC_REF_OR_DUPLICATE != json) {
                mapdata.put(keyString, json);
            }
        }
    } catch (final MarshallException e) {
        throw new MarshallException("map key " + key + " " + e.getMessage(), e);
    } catch (final JSONException e) {
        throw new MarshallException("map key " + key + " " + e.getMessage(), e);
    } finally {
        state.pop();
    }
    return obj;
}

From source file:org.openhab.binding.openpaths.internal.OpenPathsBinding.java

/**
 * @{inheritDoc/*from   ww w  .j  av  a  2  s .co m*/
 */
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    openPathsUsers = new HashMap<String, OpenPathsUser>();
    locations = new HashMap<String, Location>();
    if (config != null) {
        Enumeration<String> keys = config.keys();
        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();
            String value = (String) config.get(key);

            // the config-key enumeration contains additional keys that we
            // don't want to process here ...
            if ("service.pid".equals(key)) {
                continue;
            }

            if ("refresh".equals(key)) {
                if (StringUtils.isNotBlank(value)) {
                    refreshInterval = Long.parseLong(value);
                    logger.trace("Config: refresh=" + this.refreshInterval);
                }
            } else if ("geofence".equals(key)) {
                // only for backward compatibility / as fallback
                if (StringUtils.isNotBlank(value)) {
                    geoFence = Float.parseFloat(value);
                    logger.trace("Config: geofence=" + this.geoFence);
                }
            } else if (key.endsWith("lat")) {
                String[] keyParts = key.split("\\.");
                if (keyParts.length != 2) {
                    throw new ConfigurationException(key, "Invalid OpenPaths user location lattitude: " + key);
                }
                if (StringUtils.isNotBlank(value)) {
                    float lat = Float.parseFloat(value);

                    String name = keyParts[0];

                    if (locations.containsKey(name)) {
                        locations.get(name).setLatitude(lat);
                        logger.trace("Config: new Location " + name + "(" + locations.get(name) + ")");
                    } else {
                        Location loc = new Location();
                        loc.setLatitude(lat);
                        logger.trace("Config: update Location " + name + "(" + locations.get(name) + ")");
                        locations.put(name, loc);
                    }
                }
            } else if (key.endsWith("long")) {
                String[] keyParts = key.split("\\.");
                if (keyParts.length != 2) {
                    throw new ConfigurationException(key, "Invalid OpenPaths user location longitude: " + key);
                }
                if (StringUtils.isNotBlank(value)) {
                    float lon = Float.parseFloat(value);

                    String name = keyParts[0];

                    if (locations.containsKey(name)) {
                        locations.get(name).setLongitude(lon);
                        logger.trace("Config: new Location " + name + "(" + locations.get(name) + ")");
                    } else {
                        Location loc = new Location();
                        loc.setLongitude(lon);
                        logger.trace("Config: update Location " + name + "(" + locations.get(name) + ")");
                        locations.put(name, loc);
                    }
                }
            } else if (key.endsWith("geofence") && !key.equals("geofence")) {
                String[] keyParts = key.split("\\.");
                if (keyParts.length != 2) {
                    throw new ConfigurationException(key, "Invalid OpenPaths user location geofence: " + key);
                }
                if (StringUtils.isNotBlank(value)) {
                    float fence = Float.parseFloat(value);

                    String name = keyParts[0];

                    if (locations.containsKey(name)) {
                        locations.get(name).setGeofence(fence);
                        logger.trace("Config: new Location " + name + "(" + locations.get(name) + ")");
                    } else {
                        Location loc = new Location();
                        loc.setGeofence(fence);
                        logger.trace("Config: update Location " + name + "(" + locations.get(name) + ")");
                        locations.put(name, loc);
                    }
                }
            } else if (key.endsWith("key")) {
                String[] keyParts = key.split("\\.");
                if (keyParts.length != 2) {
                    throw new ConfigurationException(key, "Invalid OpenPaths user key: " + key);
                }

                String name = keyParts[0];
                String configKey = keyParts[1];

                if (!openPathsUsers.containsKey(name)) {
                    openPathsUsers.put(name, new OpenPathsUser(name));
                }

                OpenPathsUser openPathsUser = openPathsUsers.get(name);

                if (configKey.equalsIgnoreCase("accesskey")) {
                    openPathsUser.setAccessKey(value);
                } else if (configKey.equalsIgnoreCase("secretkey")) {
                    openPathsUser.setSecretKey(value);
                } else {
                    throw new ConfigurationException(key, "Unrecognised configuration parameter: " + configKey);
                }
            }
        }

        if (!locations.containsKey("home"))
            throw new ConfigurationException("home.lat", "No location specified for 'home'");

        setProperlyConfigured(true);
    }
}

From source file:net.wasdev.wlp.netflixoss.archaius.Activator.java

@Override
public void updated(Dictionary<String, ?> properties) throws ConfigurationException {
    LOGGER.entering(CLASSNAME, "updated", properties);

    try {//w  ww .  ja  va  2  s.  com

        if (properties != null) {

            ServiceReference configurationAdminReference = bContext
                    .getServiceReference(ConfigurationAdmin.class.getName());

            if (configurationAdminReference != null) {

                ConfigurationAdmin configAdmin = (ConfigurationAdmin) bContext
                        .getService(configurationAdminReference);

                Set<String> nestedKeys = new HashSet<String>();
                Enumeration<String> keys = properties.keys();
                while (keys.hasMoreElements()) {
                    String key = keys.nextElement();
                    Object val = properties.get(key);
                    if (val instanceof String[]) {
                        nestedKeys.addAll(generateKeyVals(configAdmin, key, (String[]) val));

                    }
                }

                for (Iterator<String> it = configuration.getKeys(); it.hasNext();) {
                    String key = it.next();
                    if (!nestedKeys.contains(key)) {
                        LOGGER.fine("Removing key \'" + key + "\'");
                        configuration.clearProperty(key);
                    }
                }
            }
        } else {
            LOGGER.fine("Removing all keys");
            configuration.clear();
        }

    } catch (Exception e) {
        RuntimeException re = new RuntimeException("Failed to retrieve properties", e);
        LOGGER.throwing(CLASSNAME, "updated", re);
        throw re;
    }

    LOGGER.exiting(CLASSNAME, "updated");
}

From source file:org.openhab.binding.squeezebox.internal.SqueezeboxBinding.java

@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    if (config != null) {
        disconnectSqueezeServer();//ww w . j a va2 s. c o m
        int cliport = DEFAULT_CLI_PORT;
        int webport = DEFAULT_WEB_PORT;
        String host = DEFAULT_HOST;

        Map<String, String> tmpPlayerMap = new HashMap<String, String>();

        Enumeration<String> keys = config.keys();
        while (keys.hasMoreElements()) {

            String key = (String) keys.nextElement();

            // the config-key enumeration contains additional keys that we
            // don't want to process here ...
            if ("service.pid".equals(key)) {
                continue;
            }

            Matcher serverMatcher = EXTRACT_SERVER_CONFIG_PATTERN.matcher(key);
            Matcher playerMatcher = EXTRACT_PLAYER_CONFIG_PATTERN.matcher(key);

            String value = (String) config.get(key);

            if (serverMatcher.matches()) {
                serverMatcher.reset();
                serverMatcher.find();

                if ("host".equals(serverMatcher.group(2))) {
                    host = value;
                } else if ("cliport".equals(serverMatcher.group(2))) {
                    cliport = Integer.valueOf(value);
                } else if ("webport".equals(serverMatcher.group(2))) {
                    webport = Integer.valueOf(value);
                }
            } else if (playerMatcher.matches()) {
                tmpPlayerMap.put(value.toString(), playerMatcher.group(1));
            }
        }

        connectSqueezeServer(host, cliport, webport, tmpPlayerMap);
    }
}

From source file:net.wasdev.wlp.netflixoss.archaius.Activator.java

private Set<String> generateKeyVals(ConfigurationAdmin configAdmin, String key, String[] values)
        throws IOException {

    Set<String> keys = new HashSet<String>();

    for (String value : values) {

        Configuration config = configAdmin.getConfiguration(value);
        Dictionary valueProps = config.getProperties();

        if (valueProps == null) {
            if (configuration.containsKey(key)) {
                if (!configuration.getProperty(key).equals(value)) {
                    LOGGER.fine("Updating key \'" + key + "\' to value \'" + value + "\'");
                    configuration.setProperty(key, value);
                }/*from   w  w  w  .j  a  v a  2s . c om*/
            } else {
                LOGGER.fine("Adding key \'" + key + "\' with value \'" + value + "\'");
                configuration.addProperty(key, value);
            }
            keys.add(key);
        } else {
            Enumeration<String> valuePropKeys = valueProps.keys();
            while (valuePropKeys.hasMoreElements()) {
                String valuePropKey = valuePropKeys.nextElement();
                Object valuePropValue = valueProps.get(valuePropKey);
                if (valuePropValue instanceof String[]) {
                    keys.addAll(
                            generateKeyVals(configAdmin, key + "." + valuePropKey, (String[]) valuePropValue));
                }
            }
        }

    }

    return keys;

}

From source file:org.openhab.binding.yamahareceiver.internal.YamahaReceiverBinding.java

@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    logger.debug(BINDING_NAME + " updated");
    try {// w w w  . j av  a2s . c o m
        // Process device configuration
        if (config != null) {
            String refreshIntervalString = (String) config.get("refresh");
            if (StringUtils.isNotBlank(refreshIntervalString)) {
                refreshInterval = Long.parseLong(refreshIntervalString);
            }
            // parse all configured receivers
            // ( yamahareceiver:<uid>.host=10.0.0.2 )
            Enumeration<String> keys = config.keys();
            while (keys.hasMoreElements()) {
                String key = keys.nextElement();
                if (key.endsWith(CONFIG_KEY_HOST)) {
                    // parse host
                    String host = (String) config.get(key);
                    int separatorIdx = key.indexOf('.');
                    // no uid => one device => use default UID
                    String uid = separatorIdx == -1 ? DEFAULT_DEVICE_UID : key.substring(0, separatorIdx);
                    // proxy is stateless. keep them in a map in the
                    // binding.
                    proxies.put(uid, new YamahaReceiverProxy(host));
                }
            }
            setProperlyConfigured(true);
        }
    } catch (Throwable t) {
        logger.error("Error configuring " + getName(), t);
    }
}