List of usage examples for java.util Dictionary get
public abstract V get(Object key);
From source file:org.apache.felix.webconsole.internal.core.BundlesServlet.java
private void printBundleDetails(JSONWriter jsonWriter, Bundle bundle) throws JSONException { Dictionary headers = bundle.getHeaders(); jsonWriter.key("props"); jsonWriter.array();//from w w w . ja v a 2s .co m jsonKeyVal(jsonWriter, "Symbolic Name", bundle.getSymbolicName()); jsonKeyVal(jsonWriter, "Version", headers.get(Constants.BUNDLE_VERSION)); jsonKeyVal(jsonWriter, "Location", bundle.getLocation()); jsonKeyVal(jsonWriter, "Last Modification", new Date(bundle.getLastModified())); String docUrl = (String) headers.get(Constants.BUNDLE_DOCURL); if (docUrl != null) { jsonKeyVal(jsonWriter, "Bundle Documentation", docUrl); } jsonKeyVal(jsonWriter, "Vendor", headers.get(Constants.BUNDLE_VENDOR)); jsonKeyVal(jsonWriter, "Copyright", headers.get(Constants.BUNDLE_COPYRIGHT)); jsonKeyVal(jsonWriter, "Description", headers.get(Constants.BUNDLE_DESCRIPTION)); jsonKeyVal(jsonWriter, "Start Level", getStartLevel(bundle)); jsonKeyVal(jsonWriter, "Bundle Classpath", headers.get(Constants.BUNDLE_CLASSPATH)); if (bundle.getState() == Bundle.INSTALLED) { listImportExportsUnresolved(jsonWriter, bundle); } else { listImportExport(jsonWriter, bundle); } listServices(jsonWriter, bundle); listHeaders(jsonWriter, bundle); jsonWriter.endArray(); }
From source file:org.codice.ddf.admin.core.impl.ConfigurationAdminImpl.java
private void addConfigurationData(Service service, Configuration[] configs, Map<String, ObjectClassDefinition> objectClassDefinitions) { for (Configuration config : configs) { // ignore configuration object if it is invalid final String pid = config.getPid(); if (!isAllowedPid(pid)) { continue; }/*from w w w .ja v a 2 s . c om*/ ConfigurationDetails configData = new ConfigurationDetailsImpl(); configData.setId(pid); String fpid = config.getFactoryPid(); if (fpid != null) { configData.setFactoryPid(fpid); } // insert an entry for the PID try { ObjectClassDefinition ocd = objectClassDefinitions.get(config.getPid()); if (ocd != null) { configData.setName(ocd.getName()); } else { // no object class definition, use plain PID configData.setName(pid); } } catch (IllegalArgumentException t) { // Catch exception thrown by getObjectClassDefinition so other configurations // are displayed // no object class definition, use plain PID configData.setName(pid); } final Bundle bundle = getBoundBundle(config); if (null != bundle) { configData.setBundle(bundle.getBundleId()); configData.setBundleName(getName(bundle)); configData.setBundleLocation(bundle.getLocation()); } ConfigurationProperties propertiesTable = new ConfigurationPropertiesImpl(); 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)); } } // If the configuration property is a password that has been set, // mask its value to "password" so that the real password value will be hidden. List<MetatypeAttribute> metatypeList = service.getAttributeDefinitions(); metatypeList.stream().filter(metatype -> AttributeDefinition.PASSWORD == metatype.getType()) .forEach(metatype -> { setPasswordMask(metatype, propertiesTable); }); configData.setConfigurationProperties(propertiesTable); Map<String, Object> pluginDataMap = getConfigurationPluginData(configData.getId(), Collections.unmodifiableMap(configData)); if (pluginDataMap != null && !pluginDataMap.isEmpty()) { configData.putAll(pluginDataMap); } List<ConfigurationDetails> configurationDetails; if (service.containsKey(Service.CONFIGURATIONS)) { configurationDetails = service.getConfigurations(); } else if (service.containsKey(Service.DISABLED_CONFIGURATIONS)) { configurationDetails = service.getDisabledConfigurations(); } else { configurationDetails = new ArrayList<>(); } configurationDetails.add(configData); if (configData.getId().contains(ConfigurationDetails.DISABLED_SERVICE_IDENTIFIER)) { configData.setEnabled(false); } else { configData.setEnabled(true); } service.setConfigurations(configurationDetails); } }
From source file:org.eclipse.vtp.framework.engine.http.HttpConnector.java
/** * Deploys a process into the engine.// w ww. j av a2 s.c o m * * @param key The key for the deployment. * @param properties The properties of the deployment. */ public synchronized void deploy(String key, @SuppressWarnings("rawtypes") Dictionary properties) { Deployment deployment = deploymentsByKey.remove(key); if (deployment != null) deploymentsByPath.remove(deployment.getPath()); String definitionID = (String) properties.get("definition.id"); //$NON-NLS-1$ String deploymentID = (String) properties.get("deployment.id"); String path = (String) properties.get("path"); IProcessDefinition definition = null; Bundle contributor = null; synchronized (definitionsByID) { definition = definitionsByID.get(definitionID); contributor = definitionContributors.get(definitionID); } if (definition == null) //race condition possible { try { Thread.sleep(15000); } catch (Exception ex) { } synchronized (definitionsByID) { definition = definitionsByID.get(definitionID); contributor = definitionContributors.get(definitionID); } } if (definition == null || contributor == null) return; try { deployment = new Deployment(engine, definition, properties, contributor, reporter); } catch (Exception e) { e.printStackTrace(); return; } synchronized (resourcesByID) { for (Map.Entry<String, ResourceGroup> entry : resourcesByID.entrySet()) { deployment.setResourceManager(entry.getKey(), entry.getValue()); } } if (deploymentID == null) return; if (deploymentsByID.containsKey(deploymentID)) return; deploymentsByKey.put(key, deployment); deploymentsByID.put(deploymentID, deployment); if (path == null) return; // if (deploymentsByPath.containsKey(path)) // return; deploymentsByPath.put(path, deployment); }
From source file:org.openhab.binding.stiebelheatpump.internal.StiebelHeatPumpBinding.java
/** * {@inheritDoc}/*from w w w . j a va 2s. c om*/ */ @Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { String serialPort = null; int baudRate = DEFAULT_BAUD_RATE; serialTimeout = DEFAULT_SERIAL_TIMEOUT; String host = null; int port = 0; logger.debug("Loading stiebelheatpump binding configuration."); if (config == null || config.isEmpty()) { logger.warn("Empty or null configuration. Ignoring."); return; } if (config != null) { // to override the default refresh interval one has to add a // parameter to openhab.cfg like // <bindingName>:refresh=<intervalInMs> if (StringUtils.isNotBlank((String) config.get("refresh"))) { refreshInterval = Long.parseLong((String) config.get("refresh")); } if (StringUtils.isNotBlank((String) config.get("serialPort"))) { serialPort = (String) config.get("serialPort"); } if (StringUtils.isNotBlank((String) config.get("baudRate"))) { baudRate = Integer.parseInt((String) config.get("baudRate")); } if (StringUtils.isNotBlank((String) config.get("host"))) { host = (String) config.get("host"); } if (StringUtils.isNotBlank((String) config.get("port"))) { port = Integer.parseInt((String) config.get("port")); } if (StringUtils.isNotBlank((String) config.get("serialTimeout"))) { serialTimeout = Integer.parseInt((String) config.get("serialTimeout")); } if (StringUtils.isNotBlank((String) config.get("version"))) { version = (String) config.get("version"); } try { if (host != null) { this.connector = new TcpConnector(host, port); } else { this.connector = new SerialPortConnector(serialPort, baudRate); } boolean isInitialized = getInitialHeatPumpSettings(); setTime(); if (host != null) { logger.info("Created heatpump configuration with tcp {}:{}, version:{} ", host, port, version); } else { logger.info("Created heatpump configuration with serialport:{}, baudrate:{}, version:{} ", serialPort, baudRate, version); } setProperlyConfigured(isInitialized); } catch (RuntimeException e) { logger.warn(e.getMessage(), e); throw e; } } }
From source file:org.openhab.binding.tinkerforge.internal.TinkerforgeBinding.java
/** * Updates the configuration of the managed service. * /*from w w w . j a v a 2 s . c o m*/ * Extracts the host and port configuration and connects the appropriate brickds. * * The device configuration from openhab.cfg is parsed into a {@code Map} based (temporary) * structure. This structure is used to generate the {@link OHConfig} EMF model configuration * store. */ @Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { if (config != null) { if (isConnected) { disconnectModel(); } connectModel(); String refreshIntervalString = (String) config.get("refresh"); if (StringUtils.isNotBlank(refreshIntervalString)) { refreshInterval = Long.parseLong(refreshIntervalString); } ConfigurationHandler configurationHandler = new ConfigurationHandler(); ohConfig = configurationHandler.createConfig(config); // read further config parameters here ... logger.debug("{} updated called", LoggerConstants.CONFIG); // must be done after all other config has been processed String cfgHostsLine = (String) config.get(CONFIG_KEY_HOSTS); parseCfgHostsAndConnect(cfgHostsLine); setProperlyConfigured(true); } }
From source file:org.jahia.services.usermanager.ldap.JahiaLDAPConfig.java
/** * defines or update the context of the provider * @param context the Spring application context object * @param dictionary configuration parameters *///from ww w . j a va 2 s . co m public void setContext(ApplicationContext context, Dictionary<String, ?> dictionary) { Properties userLdapProperties = new Properties(); Properties groupLdapProperties = new Properties(); UserConfig userConfig = new UserConfig(); GroupConfig groupConfig = new GroupConfig(); Enumeration<String> keys = dictionary.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); if (Constants.SERVICE_PID.equals(key) || ConfigurationAdmin.SERVICE_FACTORYPID.equals(key) || "felix.fileinstall.filename".equals(key)) { continue; } Object value = dictionary.get(key); if (key.startsWith("user.")) { buildConfig(userLdapProperties, userConfig, key, value, true); } else if (key.startsWith("group.")) { buildConfig(groupLdapProperties, groupConfig, key, value, false); } else { userLdapProperties.put(transformPropKeyToBeanAttr(key), value); groupLdapProperties.put(transformPropKeyToBeanAttr(key), value); } } try { // populate config beans BeanUtils.populate(userConfig, userLdapProperties); BeanUtils.populate(groupConfig, groupLdapProperties); // handle defaults values userConfig.handleDefaults(); groupConfig.handleDefaults(); // instantiate ldap context if (userConfig.isMinimalSettingsOk()) { LdapContextSource lcs = new LdapContextSource(); lcs.setUrl(userConfig.getUrl()); if (StringUtils.isNotEmpty(userConfig.getPublicBindDn())) { lcs.setUserDn(userConfig.getPublicBindDn()); } if (StringUtils.isNotEmpty(userConfig.getPublicBindPassword())) { lcs.setPassword(userConfig.getPublicBindPassword()); } Map<String, Object> publicEnv = new Hashtable<String, Object>(1); if (POOL_LDAP.equalsIgnoreCase(userConfig.getLdapConnectPool())) { lcs.setPooled(true); publicEnv.put("com.sun.jndi.ldap.connect.pool.authentication", "none simple"); if (userConfig.getLdapConnectPoolTimeout() != null && Long.valueOf(userConfig.getLdapConnectTimeout()) > 0) { publicEnv.put("com.sun.jndi.ldap.connect.pool.timeout", userConfig.getLdapConnectPoolTimeout()); } if (userConfig.getLdapConnectPoolDebug() != null) { publicEnv.put("com.sun.jndi.ldap.connect.pool.debug", userConfig.getLdapConnectPoolDebug()); } if (userConfig.getLdapConnectPoolInitSize() != null) { publicEnv.put("com.sun.jndi.ldap.connect.pool.initsize", userConfig.getLdapConnectPoolInitSize()); } if (userConfig.getLdapConnectPoolMaxSize() != null) { publicEnv.put("com.sun.jndi.ldap.connect.pool.maxsize", userConfig.getLdapConnectPoolMaxSize()); } if (userConfig.getLdapConnectPoolPrefSize() != null) { publicEnv.put("com.sun.jndi.ldap.connect.pool.prefsize", userConfig.getLdapConnectPoolPrefSize()); } } if (userConfig.getLdapReadTimeout() != null) { publicEnv.put("com.sun.jndi.ldap.read.timeout", userConfig.getLdapReadTimeout()); } if (userConfig.getLdapConnectTimeout() != null) { publicEnv.put("com.sun.jndi.ldap.connect.timeout", userConfig.getLdapConnectTimeout()); } lcs.setBaseEnvironmentProperties(publicEnv); lcs.setReferral(groupConfig.getRefferal()); lcs.setDirObjectFactory(DefaultDirObjectFactory.class); lcs.afterPropertiesSet(); LdapTemplate ldap; if (POOL_APACHE_COMMONS.equalsIgnoreCase(userConfig.getLdapConnectPool())) { PoolingContextSource poolingContextSource = new PoolingContextSource(); poolingContextSource.setContextSource(lcs); if (userConfig.getLdapConnectPoolMaxActive() != null) { poolingContextSource.setMaxActive(userConfig.getLdapConnectPoolMaxActive()); } if (userConfig.getLdapConnectPoolMaxIdle() != null) { poolingContextSource.setMaxIdle(userConfig.getLdapConnectPoolMaxIdle()); } if (userConfig.getLdapConnectPoolMaxTotal() != null) { poolingContextSource.setMaxTotal(userConfig.getLdapConnectPoolMaxTotal()); } if (userConfig.getLdapConnectPoolMaxWait() != null) { poolingContextSource.setMaxWait(userConfig.getLdapConnectPoolMaxWait()); } if (userConfig.getLdapConnectPoolMinEvictableIdleTimeMillis() != null) { poolingContextSource.setMinEvictableIdleTimeMillis( userConfig.getLdapConnectPoolMinEvictableIdleTimeMillis()); } if (userConfig.getLdapConnectPoolMinIdle() != null) { poolingContextSource.setMinIdle(userConfig.getLdapConnectPoolMinIdle()); } if (userConfig.getLdapConnectPoolNumTestsPerEvictionRun() != null) { poolingContextSource .setNumTestsPerEvictionRun(userConfig.getLdapConnectPoolNumTestsPerEvictionRun()); } if (userConfig.getLdapConnectPoolTestOnBorrow() != null) { poolingContextSource.setTestOnBorrow(userConfig.getLdapConnectPoolTestOnBorrow()); } if (userConfig.getLdapConnectPoolTestOnReturn() != null) { poolingContextSource.setTestOnReturn(userConfig.getLdapConnectPoolTestOnReturn()); } if (userConfig.getLdapConnectPoolTestWhileIdle() != null) { poolingContextSource.setTestWhileIdle(userConfig.getLdapConnectPoolTestWhileIdle()); } if (userConfig.getLdapConnectPoolTimeBetweenEvictionRunsMillis() != null) { poolingContextSource.setTimeBetweenEvictionRunsMillis( userConfig.getLdapConnectPoolTimeBetweenEvictionRunsMillis()); } if (WHEN_EXHAUSTED_BLOCK.equalsIgnoreCase(userConfig.getLdapConnectPoolWhenExhaustedAction())) { poolingContextSource.setWhenExhaustedAction(GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK); } else if (WHEN_EXHAUSTED_FAIL .equalsIgnoreCase(userConfig.getLdapConnectPoolWhenExhaustedAction())) { poolingContextSource.setWhenExhaustedAction(GenericKeyedObjectPool.WHEN_EXHAUSTED_FAIL); } else if (WHEN_EXHAUSTED_GROW .equalsIgnoreCase(userConfig.getLdapConnectPoolWhenExhaustedAction())) { poolingContextSource.setWhenExhaustedAction(GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW); } ldap = new LdapTemplate(poolingContextSource); } else { ldap = new LdapTemplate(lcs); } // AD workaround to ignore Exceptions ldap.setIgnorePartialResultException(true); ldap.setIgnoreNameNotFoundException(true); if (ldapUserGroupProvider == null) { ldapUserGroupProvider = (LDAPUserGroupProvider) context.getBean("ldapUserGroupProvider"); } ldapUserGroupProvider.setKey(providerKey); ldapUserGroupProvider.setUserConfig(userConfig); ldapUserGroupProvider.setGroupConfig(groupConfig); if (StringUtils.isNotEmpty(userConfig.getUidSearchName()) && StringUtils.isNotEmpty(groupConfig.getSearchName())) { ldapUserGroupProvider .setDistinctBase(!userConfig.getUidSearchName().startsWith(groupConfig.getSearchName()) && !groupConfig.getSearchName().startsWith(userConfig.getUidSearchName())); } ldapUserGroupProvider.setLdapTemplateWrapper(new LdapTemplateWrapper(ldap)); ldapUserGroupProvider.setContextSource(lcs); ldapUserGroupProvider.unregister(); ldapUserGroupProvider.register(); if (groupConfig.isPreload()) { new Thread(new Runnable() { @Override public void run() { List<String> l = ldapUserGroupProvider.searchGroups(new Properties(), 0, -1); for (String s : l) { List<Member> m = ldapUserGroupProvider.getGroupMembers(s); } } }, "LDAP Preload").start(); } } else { unregister(); } } catch (IllegalAccessException e) { logger.error("Config LDAP invalid, pls read the documentation on LDAP configuration", e); } catch (InvocationTargetException e) { logger.error("Config LDAP invalid, pls read the documentation on LDAP configuration", e); } }
From source file:org.opennaas.extensions.pdu.capability.AbstractNotQueueingCapability.java
/** * Register the capability like a web service through DOSGi * /*from w w w .j a va 2 s . c om*/ * @param name * @param resourceId * @return * @throws CapabilityException */ protected ServiceRegistration registerService(BundleContext bundleContext, String capabilityName, String resourceType, String resourceName, String ifaceName, Dictionary<String, String> props) throws CapabilityException { try { ConfigurationAdminUtil configurationAdmin = new ConfigurationAdminUtil(bundleContext); String url = configurationAdmin.getProperty("org.opennaas", "ws.rest.url"); if (props != null) { // Rest props.put("service.exported.interfaces", "*"); props.put("service.exported.configs", "org.apache.cxf.rs"); props.put("service.exported.intents", "HTTP"); props.put("org.apache.cxf.rs.httpservice.context", url + "/" + resourceType + "/" + resourceName + "/" + capabilityName); props.put("org.apache.cxf.rs.address", "/"); props.put("org.apache.cxf.httpservice.requirefilter", "true"); } log.info("Registering ws: \n " + "in url: " + props.get("org.apache.cxf.rs.address") + "\n" + "in context: " + props.get("org.apache.cxf.rs.httpservice.context")); registration = bundleContext.registerService(ifaceName, this, props); } catch (IOException e) { throw new CapabilityException(e); } return registration; }
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. ja v a 2 s . c o m 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.opencastproject.capture.impl.ConfigurationManager.java
@SuppressWarnings("unchecked") @Override//from www . jav a2 s . co m public void updated(Dictionary props) throws ConfigurationException { if (props == null) { logger.debug("Null properties in updated!"); return; } logger.debug("Merging new properties into in-memory structure."); // Filter out all of the non-string objects from the incoming dictionary // If we don't do this then serialization of the RecordingImpl in CaptureAgentImpl doesn't work Enumeration<Object> keys = props.keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); Object value = props.get(key); if (String.class.isInstance(key) && String.class.isInstance(value)) { // Trim the value before we allow it to end up in the properties. properties.put(key, ((String) value).trim()); } } // Attempt to parse the location of the configuration server try { url = new URL(properties.getProperty(CaptureParameters.CAPTURE_CONFIG_REMOTE_ENDPOINT_URL)); } catch (MalformedURLException e) { logger.warn("Malformed URL for {}, disabling polling.", CaptureParameters.CAPTURE_CONFIG_REMOTE_ENDPOINT_URL); } // If there's no URL then throw up an info just to be safe if (url == null) { logger.info("No remote configuration endpoint was found, relying on local config."); } createCoreDirectories(); // Grab the remote config file, dump it to disk and then merge it into the current config Properties server = retrieveConfigFromServer(); if (server != null) { writeConfigFileToDisk(); merge(server, true); } // Shut down the old timer if it exists if (timer != null) { timer.cancel(); } // if reload property specified, query server for update at that interval String reload = getItem(CaptureParameters.CAPTURE_CONFIG_REMOTE_POLLING_INTERVAL); if (url != null && reload != null) { long delay = 0; try { // Times in the config file are in seconds, so don't forget to multiply by 1000 later delay = Long.parseLong(reload); if (delay < 1) { logger.info("Polling time has been set to less than 1 second, polling disabled."); return; } delay = delay * 1000L; timer = new Timer(); timer.schedule(new UpdateConfig(), delay, delay); } catch (NumberFormatException e) { logger.warn("Invalid polling time for parameter {}.", CaptureParameters.CAPTURE_CONFIG_REMOTE_POLLING_INTERVAL); } } /** * This synchronized is required! If a new listener were to add itself to the list of observers such that it missed * getting called in the refreshes and initialization was still false, refresh would not be automatically called * when it registers. This would result in refresh never being called for that listener. **/ synchronized (listeners) { for (ConfigurationManagerListener listener : listeners) { RefreshRunner refreshRunner = new RefreshRunner(listener); Thread thread = new Thread(refreshRunner); thread.start(); } // Set initialized to true so that every listener registered after this point will be updated immediately. initialized = true; } }
From source file:org.openhab.binding.pilight.internal.PilightBinding.java
private Map<String, PilightConnection> parseConfig(Dictionary<String, ?> config) { Map<String, PilightConnection> connections = new HashMap<String, PilightConnection>(); Enumeration<String> keys = config.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); if ("service.pid".equals(key)) continue; String[] parts = key.split("\\."); String instance = parts[0]; PilightConnection connection = connections.get(instance); if (connection == null) { connection = new PilightConnection(); connection.setInstance(instance); }//from w w w . j a v a 2 s . com String value = ((String) config.get(key)).trim(); if ("host".equals(parts[1])) { connection.setHostname(value); } if ("port".equals(parts[1])) { connection.setPort(Integer.valueOf(value)); } if ("delay".equals(parts[1])) { connection.setDelay(Long.valueOf(value)); } connections.put(instance, connection); } return connections; }