List of usage examples for java.util Dictionary get
public abstract V get(Object key);
From source file:org.openhab.binding.irtrans.internal.IRtransBinding.java
/** * {@inheritDoc}// w w w .j a va 2 s . co m */ @SuppressWarnings({ "rawtypes", "restriction" }) public void updated(Dictionary config) throws ConfigurationException { super.updated(config); if (config != null) { String timeOutString = (String) config.get("timeout"); if (StringUtils.isNotBlank(timeOutString)) { timeOut = Integer.parseInt((timeOutString)); } else { logger.info( "The maximum time out for blocking write operations will be set to the default vaulue of {}", timeOut); } } // Prevent users from doing funny stuff with this binding useAddressMask = false; itemShareChannels = true; bindingShareChannels = true; directionsShareChannels = false; maximumBufferSize = 1024; setProperlyConfigured(true); }
From source file:org.codice.ddf.registry.federationadmin.impl.FederationAdmin.java
@Override public List<Service> allRegistryInfo() { List<Service> metatypes = helper.getMetatypes(); for (Service metatype : metatypes) { try {/*w ww . j a va 2s . com*/ List<Configuration> configs = helper.getConfigurations(metatype); List<ConfigurationDetails> configurations = new ArrayList<>(); if (configs != null) { for (Configuration config : configs) { ConfigurationDetails registry = new ConfigurationDetailsImpl(); boolean disabled = config.getPid().endsWith(DISABLED); registry.setId(config.getPid()); registry.setEnabled(!disabled); registry.setFactoryPid(config.getFactoryPid()); if (!disabled) { registry.setName(helper.getName(config)); registry.setBundleName(helper.getBundleName(config)); registry.setBundleLocation(config.getBundleLocation()); registry.setBundle(helper.getBundleId(config)); } else { registry.setName(config.getPid()); } Dictionary<String, Object> properties = config.getProperties(); ConfigurationProperties plist = new ConfigurationPropertiesImpl(); for (String key : Collections.list(properties.keys())) { plist.put(key, properties.get(key)); } registry.setConfigurationProperties(plist); configurations.add(registry); } metatype.setConfigurations(configurations); } } catch (InvalidSyntaxException | IOException e) { LOGGER.info("Error getting registry info:", e); } } Collections.sort(metatypes, (o1, o2) -> ((String) o1.get("id")).compareToIgnoreCase((String) o2.get("id"))); return metatypes; }
From source file:org.openhab.binding.modbus.internal.ModbusConfiguration.java
@Override @SuppressWarnings("rawtypes") public void updated(Dictionary config) throws ConfigurationException { // remove all known items if configuration changed Collections.synchronizedMap(modbusSlaves).clear(); if (config != null) { Enumeration 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; }/*ww w . ja v a2 s . c om*/ Matcher matcher = EXTRACT_MODBUS_CONFIG_PATTERN.matcher(key); if (!matcher.matches()) { if ("poll".equals(key)) { poll = Integer.valueOf((String) config.get(key)); } else if ("writemultipleregisters".equals(key)) { ModbusSlave.setWriteMultipleRegisters(Boolean.valueOf(config.get(key).toString())); } else { logger.debug("given modbus-slave-config-key '" + key + "' does not follow the expected pattern 'poll' or '<slaveId>.<connection|id|start|length|type>'"); } continue; } matcher.reset(); matcher.find(); String slave = matcher.group(2); ModbusSlave modbusSlave = Collections.synchronizedMap(modbusSlaves).get(slave); if (modbusSlave == null) { if (matcher.group(1).equals(TCP_PREFIX)) { modbusSlave = new ModbusTcpSlave(slave); } else if (matcher.group(1).equals(SERIAL_PREFIX)) { modbusSlave = new ModbusSerialSlave(slave); } else throw new ConfigurationException(slave, "the given slave type '" + slave + "' is unknown"); Collections.synchronizedMap(modbusSlaves).put(slave, modbusSlave); } String configKey = matcher.group(3); String value = (String) config.get(key); if ("connection".equals(configKey)) { String[] chunks = value.split(":"); if (modbusSlave instanceof ModbusTcpSlave) { ((ModbusTcpSlave) modbusSlave).setHost(chunks[0]); if (chunks.length == 2) { ((ModbusTcpSlave) modbusSlave).setPort(Integer.valueOf(chunks[1])); } } else if (modbusSlave instanceof ModbusSerialSlave) { ((ModbusSerialSlave) modbusSlave).setPort(chunks[0]); if (chunks.length == 2) { ((ModbusSerialSlave) modbusSlave).setBaud(Integer.valueOf(chunks[1])); } } } else if ("start".equals(configKey)) { modbusSlave.setStart(Integer.valueOf(value)); } else if ("length".equals(configKey)) { modbusSlave.setLength(Integer.valueOf(value)); } else if ("id".equals(configKey)) { modbusSlave.setId(Integer.valueOf(value)); } else if ("type".equals(configKey)) { if (ArrayUtils.contains(ModbusBindingProvider.SLAVE_DATA_TYPES, value)) { modbusSlave.setType(value); } else { throw new ConfigurationException(configKey, "the given slave type '" + value + "' is invalid"); } } else { throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown"); } } } // connect instances to modbus slaves for (ModbusSlave slave : Collections.synchronizedMap(modbusSlaves).values()) { slave.connect(); } }
From source file:net.solarnetwork.node.settings.ca.CASettingsService.java
/** * Callback when a {@link SettingSpecifierProvider} has been registered. * //w ww . java 2 s . c o m * @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); }
From source file:org.ops4j.pax.web.service.tomcat.internal.TomcatServerWrapper.java
private Context createContext(final ContextModel contextModel) { final Bundle bundle = contextModel.getBundle(); final BundleContext bundleContext = BundleUtils.getBundleContext(bundle); final Context context = server.addContext(contextModel.getContextParams(), getContextAttributes(bundleContext), contextModel.getContextName(), contextModel.getHttpContext(), contextModel.getAccessControllerContext(), contextModel.getContainerInitializers(), contextModel.getJettyWebXmlURL(), contextModel.getVirtualHosts(), null /*contextModel.getConnectors() */, server.getBasedir()); context.setParentClassLoader(contextModel.getClassLoader()); // TODO: is the context already configured? // TODO: how about security, classloader? // TODO: compare with JettyServerWrapper.addContext // TODO: what about the init parameters? configureJspConfigDescriptor(context, contextModel); final LifecycleState state = context.getState(); if (state != LifecycleState.STARTED && state != LifecycleState.STARTING && state != LifecycleState.STARTING_PREP) { LOG.debug("Registering ServletContext as service. "); final Dictionary<String, String> properties = new Hashtable<String, String>(); properties.put("osgi.web.symbolicname", bundle.getSymbolicName()); final Dictionary<String, String> headers = bundle.getHeaders(); final String version = (String) headers.get(Constants.BUNDLE_VERSION); if (version != null && version.length() > 0) { properties.put("osgi.web.version", version); }//from w w w. j av a2s . c o m String webContextPath = (String) headers.get(WEB_CONTEXT_PATH); final String webappContext = (String) headers.get("Webapp-Context"); final ServletContext servletContext = context.getServletContext(); // This is the default context, but shouldn't it be called default? // See PAXWEB-209 if ("/".equalsIgnoreCase(context.getPath()) && (webContextPath == null || webappContext == null)) { webContextPath = context.getPath(); } // makes sure the servlet context contains a leading slash webContextPath = webContextPath != null ? webContextPath : webappContext; if (webContextPath != null && !webContextPath.startsWith("/")) { webContextPath = "/" + webContextPath; } if (webContextPath == null) { LOG.warn("osgi.web.contextpath couldn't be set, it's not configured"); } properties.put("osgi.web.contextpath", webContextPath); servletContextService = bundleContext.registerService(ServletContext.class, servletContext, properties); LOG.debug("ServletContext registered as service. "); } contextMap.put(contextModel.getHttpContext(), context); return context; }
From source file:org.apache.felix.webconsole.internal.servlet.OsgiManager.java
private Dictionary toStringConfig(Dictionary config) { Dictionary stringConfig = new Hashtable(); for (Enumeration ke = config.keys(); ke.hasMoreElements();) { Object key = ke.nextElement(); stringConfig.put(key.toString(), String.valueOf(config.get(key))); }/*from w w w . j a v a2s.c o m*/ return stringConfig; }
From source file:org.energy_home.jemma.internal.device.zgd.StreamGobbler.java
/** * This function copy the whole content of the passed path (that refers to a * folder that is in the bundle) in the storage area reserved to the bundle, * by the OSGi framework. The original path is reproduced. If, for instance, * bundlePath is /gal/windows, all the files in <code>/gal/windows</code> * are copied under <code>bundle data path/gal/windows</code> * /*from w ww .j a v a 2s . c om*/ * * @param bundleResourcePath * path to a folder packaged into the bundle jar */ private String alignFiles(String bundleResourcePath) { byte[] buffer = new byte[20480]; log.debug("bundleResourcePath is " + bundleResourcePath); Enumeration entries = null; Dictionary headers = bc.getBundle(0).getHeaders(); String vendor = ((String) headers.get("Bundle-Vendor")); boolean isEquinox = false; if ((vendor != null) && vendor.startsWith("Eclipse")) isEquinox = true; if (isEquinox) { entries = bc.getBundle().findEntries(bundleResourcePath, "*", false); } else { // On Felix it seems that the fragment resources are not MERGED with // the host bundle so we access them by using fragmentBundle if (fragmentBundle != null) { entries = fragmentBundle.findEntries(bundleResourcePath, "*", false); } else { log.fatal("fragmentBundle is unexpectly null!!"); return null; } } File root = bc.getDataFile(bundleResourcePath); if (entries == null) { log.fatal("no entries in bundle resource path '" + bundleResourcePath + "'"); return null; } while (entries.hasMoreElements()) { URL entry = (URL) entries.nextElement(); File entryFile = new File(entry.getPath()); String path = entryFile.getPath(); // NOTE: Apache Felix requires that the path specified in // getDataFile is relative. Equinox accepts both relative or // absolute paths. // TODO: what about Prosyst? File f = bc.getDataFile("." + File.separator + path); if (path.endsWith(".svn")) { continue; } f.getParentFile().mkdirs(); boolean update = needsRefresh(entryFile, f); if (!update) { log.debug("file " + f.getName() + " already up-to-date"); continue; } try { log.debug("extracting file = " + entry.toString()); FileOutputStream fos = new FileOutputStream(f); InputStream is = entry.openStream(); for (int read = is.read(buffer, 0, buffer.length); read > 0; read = is.read(buffer, 0, buffer.length)) { fos.write(buffer, 0, read); } fos.flush(); fos.close(); } catch (IOException e) { log.error("error extracting file " + path + " " + e.getMessage() + ". Probably the file is used by another process."); return null; } } // TODO: remove those elements from the data area that are not into the // bundle anymore return root.getAbsolutePath(); }
From source file:org.openhab.binding.omnilink.internal.OmniLinkBinding.java
/** * @{inheritDoc/*from w w w . j av a 2 s. co m*/ */ @Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { if (omniWorker != null) omniWorker.setRunning(false); if (config != null) { String host = (String) config.get("host"); int port = Integer.parseInt((String) config.get("port")); String key1 = (String) config.get("key1"); String key2 = (String) config.get("key2"); boolean generateItems = Boolean.parseBoolean((String) config.get("generateItems")); if (StringUtils.isEmpty(host) || StringUtils.isEmpty(key1) || StringUtils.isEmpty(key2)) throw new ConfigurationException("omnilink", "host, key1 or key2 was not found"); logger.debug("Starting update"); omniWorker = new OmniConnectionThread(host, port, key1 + ":" + key2, generateItems, this); omniWorker.start(); } }
From source file:org.apache.felix.webconsole.internal.core.BundlesServlet.java
private void listHeaders(JSONWriter jsonWriter, Bundle bundle) throws JSONException { JSONArray val = new JSONArray(); Dictionary headers = bundle.getHeaders(); Enumeration headerKey = headers.keys(); while (headerKey.hasMoreElements()) { Object header = headerKey.nextElement(); String value = String.valueOf(headers.get(header)); // Package headers may be long, support line breaking by // ensuring blanks after comma and semicolon. value = value.replaceAll("([;,])", "$1 "); val.put(header + ": " + value); }//from w w w . java 2 s . c o m jsonKeyVal(jsonWriter, "Manifest Headers", val); }
From source file:org.codice.ddf.registry.source.configuration.SourceConfigurationHandler.java
private DictionaryMap<String, Object> getConfigurationsFromDictionary(Dictionary<String, Object> properties) { DictionaryMap<String, Object> configProperties = new DictionaryMap<>(); Enumeration<String> enumeration = properties.keys(); while (enumeration.hasMoreElements()) { String key = enumeration.nextElement(); configProperties.put(key, properties.get(key)); }/* ww w .j a v a 2 s .c o m*/ return configProperties; }