List of usage examples for java.util Dictionary get
public abstract V get(Object key);
From source file:org.eclipse.gemini.blueprint.extender.support.internal.ConfigUtils.java
/** * Return the {@value #SPRING_CONTEXT_HEADER} if present from the given * dictionary.//from www. jav a 2 s . co m * * @param headers * @return */ public static String getSpringContextHeader(Dictionary headers) { Object header = null; if (headers != null) header = headers.get(SPRING_CONTEXT_HEADER); return (header != null ? header.toString().trim() : null); }
From source file:org.godotengine.godot.Utils.java
public static void putAllInDict(Bundle bundle, Dictionary keyValues) { String[] keys = keyValues.get_keys(); for (int i = 0; i < keys.length; i++) { String key = keys[i];// w w w . j av a 2 s .c om Utils.putGodotValue(bundle, key, keyValues.get(key)); } }
From source file:org.jahia.utils.ScriptEngineUtils.java
/** * Determines whether the specified {@link ScriptEngineFactory} supports at least one of the script names * declared by the given OSGi headers assuming they provide a value for the * {@link BundleScriptingConfigurationConstants#JAHIA_MODULE_SCRIPTING_VIEWS} header. * * @param scriptFactory the ScriptEngineFactory whose support for views defined in the specified bundle is to be * determined/*from w w w.j a v a 2 s. c o m*/ * @param headers the OSGi headers to be checked if declared view technologies defined by the {@link * BundleScriptingConfigurationConstants#JAHIA_MODULE_SCRIPTING_VIEWS} OSGI header are * supported by the specified ScriptEngineFactory * @return {@code true} if the specified ScriptEngineFactory can handle at least one of the specified script names, * {@code false} otherwise. Note that if the headers contain the {@link BundleScriptingConfigurationConstants#JAHIA_MODULE_HAS_VIEWS} * header with a "{@code no}" value, we won't look at other headers since the module has indicated that it shouldn't * contain any views so the factory shouldn't attempt to process any it might find. */ public static boolean canFactoryProcessViews(ScriptEngineFactory scriptFactory, Dictionary<String, String> headers) { if (scriptFactory == null) { throw new IllegalArgumentException("ScriptEngineFactory is null"); } if (headers != null) { final String hasViews = headers.get(BundleScriptingConfigurationConstants.JAHIA_MODULE_HAS_VIEWS); if ("no".equalsIgnoreCase(StringUtils.trim(hasViews))) { // if the bundle indicated that it doesn't provide views, the factory shouldn't process it regardless // of other configuration return false; } else { final String commaSeparatedScriptNames = headers .get(BundleScriptingConfigurationConstants.JAHIA_MODULE_SCRIPTING_VIEWS); // check if the bundle provided a list of of comma-separated scripting language names for the views it provides // the bundle should only be scanned if it defined the header and the header contains the name or language of the factory associated with the extension final String[] split = StringUtils.split(commaSeparatedScriptNames, ','); if (split != null) { // check extensions final List<String> extensions = scriptFactory.getExtensions(); List<String> scriptNames = new ArrayList<>(split.length); for (String scriptName : split) { String script = scriptName.trim().toLowerCase(); scriptNames.add(script); if (extensions.contains(script)) { return true; } } return scriptNames.contains(scriptFactory.getEngineName().trim().toLowerCase()) || scriptNames.contains(scriptFactory.getLanguageName().trim().toLowerCase()); } } } return false; }
From source file:org.eclipse.virgo.snaps.SnapsTagTests.java
private static ServiceReference<?> createServiceReference(Dictionary<?, ?> properties) { ServiceReference<?> serviceReference = createMock(ServiceReference.class); String[] keys = toArray(properties.keys()); expect(serviceReference.getPropertyKeys()).andReturn(keys); for (String key : keys) { expect(serviceReference.getProperty(key)).andReturn(properties.get(key)); }/*from w w w.j a v a 2s . co m*/ return serviceReference; }
From source file:Main.java
/** * Dictionary does not have an equals.//from w w w. j a v a2s. c o m * Please use Map.equals() * * <p>Follows the equals contract of Java 2's Map.</p> * * @since Ant 1.5 * @deprecated */ public static boolean equals(Dictionary d1, Dictionary d2) { if (d1 == d2) { return true; } if (d1 == null || d2 == null) { return false; } if (d1.size() != d2.size()) { return false; } Enumeration e1 = d1.keys(); while (e1.hasMoreElements()) { Object key = e1.nextElement(); Object value1 = d1.get(key); Object value2 = d2.get(key); if (value2 == null || !value1.equals(value2)) { return false; } } // don't need the opposite check as the Dictionaries have the // same size, so we've also covered all keys of d2 already. return true; }
From source file:org.eclipse.gemini.blueprint.util.DebugUtils.java
private static Version hasExport(Bundle bundle, String packageName) { Dictionary dict = bundle.getHeaders(); return getVersion((String) dict.get(Constants.EXPORT_PACKAGE), packageName); }
From source file:org.eclipse.smarthome.config.core.ConfigDispatcher.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private static void processConfigFile(File configFile) throws IOException, FileNotFoundException { ConfigurationAdmin configurationAdmin = (ConfigurationAdmin) ConfigActivator.configurationAdminTracker .getService();/*from w w w. ja va 2s. com*/ if (configurationAdmin != null) { // we need to remember which configuration needs to be updated because values have changed. Map<Configuration, Dictionary> configsToUpdate = new HashMap<Configuration, Dictionary>(); // also cache the already retrieved configurations for each pid Map<Configuration, Dictionary> configMap = new HashMap<Configuration, Dictionary>(); List<String> lines = IOUtils.readLines(new FileInputStream(configFile)); for (String line : lines) { String[] contents = parseLine(configFile.getPath(), line); // no valid configuration line, so continue if (contents == null) continue; String pid = contents[0]; String property = contents[1]; String value = contents[2]; Configuration configuration = configurationAdmin.getConfiguration(pid, null); if (configuration != null) { Dictionary configProperties = configMap.get(configuration); if (configProperties == null) { configProperties = new Properties(); configMap.put(configuration, configProperties); } if (!value.equals(configProperties.get(property))) { configProperties.put(property, value); configsToUpdate.put(configuration, configProperties); } } } for (Entry<Configuration, Dictionary> entry : configsToUpdate.entrySet()) { entry.getKey().update(entry.getValue()); } } }
From source file:org.openhab.binding.onewire.internal.connection.OneWireConnection.java
public static synchronized void updated(Dictionary<String, ?> pvConfig) throws ConfigurationException { if (pvConfig != null) { logger.debug("OneWire configuration present. Setting up owserver connection."); cvIp = (String) pvConfig.get("ip"); String lvPortConfig = (String) pvConfig.get("port"); if (StringUtils.isNotBlank(lvPortConfig)) { cvPort = Integer.parseInt(lvPortConfig); }/*from ww w . j av a 2s.c om*/ String lvTempScaleString = (String) pvConfig.get("tempscale"); if (StringUtils.isNotBlank(lvTempScaleString)) { try { cvTempScale = OwTemperatureScale.valueOf(lvTempScaleString); } catch (IllegalArgumentException iae) { String lvFehlertext = "Unknown temperature scale '" + lvTempScaleString + "'. Valid values are CELSIUS, FAHRENHEIT, KELVIN or RANKINE."; logger.error(lvFehlertext, iae); throw new ConfigurationException("onewire:tempscale", lvFehlertext); } } String lvRetryString = (String) pvConfig.get("retry"); if (StringUtils.isNotBlank(lvRetryString)) { cvRetry = Integer.parseInt(lvRetryString); } if (cvOwConnection == null) { logger.debug("Not connected to owserver yet. Trying to connect..."); if (!connect()) { logger.warn("Inital connection to owserver failed!"); } else { logger.debug("Success: connected to owserver."); } } } else { logger.info( "OneWireBinding configuration is not present. Please check your configuration file or if not needed remove the OneWireBinding addon."); } }
From source file:Main.java
/** * Dictionary does not have an equals.// w w w . j a va2 s . com * Please use Map.equals(). * * <p>Follows the equals contract of Java 2's Map.</p> * @param d1 the first directory. * @param d2 the second directory. * @return true if the directories are equal. * @since Ant 1.5 * @deprecated since 1.6.x. */ public static boolean equals(Dictionary<?, ?> d1, Dictionary<?, ?> d2) { if (d1 == d2) { return true; } if (d1 == null || d2 == null) { return false; } if (d1.size() != d2.size()) { return false; } Enumeration<?> e1 = d1.keys(); while (e1.hasMoreElements()) { Object key = e1.nextElement(); Object value1 = d1.get(key); Object value2 = d2.get(key); if (value2 == null || !value1.equals(value2)) { return false; } } // don't need the opposite check as the Dictionaries have the // same size, so we've also covered all keys of d2 already. return true; }
From source file:org.eclipse.gemini.blueprint.util.DebugUtils.java
/** * Tries (through a best-guess attempt) to figure out why a given class * could not be found. This method will search the given bundle and its * classpath to determine the reason for which the class cannot be loaded. * /*from w ww . ja va2 s .c o m*/ * <p/> This method tries to be effective especially when the dealing with * {@link NoClassDefFoundError} caused by failure of loading transitive * classes (such as getting a NCDFE when loading <code>foo.A</code> * because <code>bar.B</code> cannot be found). * * @param bundle the bundle to search for (and which should do the loading) * @param className the name of the class that failed to be loaded in dot * format (i.e. java.lang.Thread) * @param rootClassName the name of the class that triggered the loading * (i.e. java.lang.Runnable) */ public static void debugClassLoading(Bundle bundle, String className, String rootClassName) { boolean trace = log.isTraceEnabled(); if (!trace) return; Dictionary dict = bundle.getHeaders(); String bname = dict.get(Constants.BUNDLE_NAME) + "(" + dict.get(Constants.BUNDLE_SYMBOLICNAME) + ")"; if (trace) log.trace("Could not find class [" + className + "] required by [" + bname + "] scanning available bundles"); BundleContext context = OsgiBundleUtils.getBundleContext(bundle); int pkgIndex = className.lastIndexOf('.'); // Reject global packages if (pkgIndex < 0) { if (trace) log.trace("Class is not in a package, its unlikely that this will work"); return; } String packageName = className.substring(0, pkgIndex); Version iversion = hasImport(bundle, packageName); if (iversion != null && context != null) { if (trace) log.trace("Class is correctly imported as version [" + iversion + "], checking providing bundles"); Bundle[] bundles = context.getBundles(); for (int i = 0; i < bundles.length; i++) { if (bundles[i].getBundleId() != bundle.getBundleId()) { Version exported = checkBundleForClass(bundles[i], className, iversion); // Everything looks ok, but is the root bundle importing the // dependent class also? if (exported != null && exported.equals(iversion) && rootClassName != null) { for (int j = 0; j < bundles.length; j++) { Version rootexport = hasExport(bundles[j], rootClassName.substring(0, rootClassName.lastIndexOf('.'))); if (rootexport != null) { // TODO -- this is very rough, check the bundle // classpath also. Version rootimport = hasImport(bundles[j], packageName); if (rootimport == null || !rootimport.equals(iversion)) { if (trace) log.trace("Bundle [" + OsgiStringUtils.nullSafeNameAndSymName(bundles[j]) + "] exports [" + rootClassName + "] as version [" + rootexport + "] but does not import dependent package [" + packageName + "] at version [" + iversion + "]"); } } } } } } } if (hasExport(bundle, packageName) != null) { if (trace) log.trace("Class is exported, checking this bundle"); checkBundleForClass(bundle, className, iversion); } }