List of usage examples for java.util Dictionary put
public abstract V put(K key, V value);
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();/*w w w .j a v a2 s .c o m*/ 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:Main.java
/** * Return a Dictionary object which is a subset of the given Dictionary, * where the tags all <b>begin</b> with the given tag. * //from w ww .j a va 2s. c om * Hastables and Properties can be used as they are Dictionaries. * * @param superset * . * * * @param tag * String * @param result * Dictionary<String,Object> */ public static void getSubset(Dictionary<String, Object> superset, String tag, Dictionary<String, Object> result) { if ((result == null) || (tag == null) || (superset == null)) { throw new IllegalArgumentException("Invalid arguments specified : superset = " + superset + " tag = " + tag + " result = " + result); } String key; Enumeration<String> enumKey = superset.keys(); while (enumKey.hasMoreElements()) { key = enumKey.nextElement(); if (key.startsWith(tag)) { result.put(key, superset.get(key)); } } }
From source file:org.eclipse.virgo.ide.manifest.core.BundleManifestUtils.java
public static void createNewParManifest(IProject project, String symbolicName, String version, String name, String description) {/*from w ww.j a v a 2s. co m*/ Dictionary<String, String> manifest = BundleManifestFactory.createBundleManifest().toDictionary(); if (StringUtils.isNotBlank(symbolicName)) { manifest.put("Application-SymbolicName", symbolicName); } if (StringUtils.isNotBlank(version)) { manifest.put("Application-Version", version); } if (StringUtils.isNotBlank(name)) { manifest.put("Application-Name", name); } if (StringUtils.isNotBlank(description)) { manifest.put("Application-Description", description); } Writer writer = null; try { writer = new FileWriter(getFirstPossibleManifestFile(project, false).getRawLocation().toFile()); BundleManifest bundleManifest = BundleManifestFactory.createBundleManifest(manifest); bundleManifest.write(writer); } catch (IOException e) { } finally { if (writer != null) { try { writer.flush(); writer.close(); } catch (IOException e) { } } } }
From source file:org.eclipse.virgo.ide.manifest.core.BundleManifestUtils.java
/** * Dumps a new MANIFEST.MF into the given {@link IJavaProject}. *//*from w w w . ja va 2s. c o m*/ public static void createNewBundleManifest(IJavaProject javaProject, String symbolicName, String bundleVersion, String providerName, String bundleName, String serverModule, Map<String, String> properties) { BundleManifest manifest = null; File existingManifestFile = locateManifestFile(javaProject, false); if (existingManifestFile != null) { FileReader reader = null; try { reader = new FileReader(existingManifestFile); manifest = BundleManifestFactory.createBundleManifest(new FileReader(existingManifestFile)); } catch (FileNotFoundException e) { } catch (IOException e) { } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { } } } } else { manifest = BundleManifestFactory.createBundleManifest(); } manifest.setBundleManifestVersion(2); Dictionary<String, String> dictonary = manifest.toDictionary(); if (StringUtils.isNotBlank(symbolicName)) { dictonary.put(Constants.BUNDLE_SYMBOLICNAME, symbolicName); } if (StringUtils.isNotBlank(bundleVersion)) { dictonary.put(Constants.BUNDLE_VERSION, bundleVersion); } if (StringUtils.isNotBlank(bundleName)) { dictonary.put(Constants.BUNDLE_NAME, bundleName); } if (StringUtils.isNotBlank(providerName)) { dictonary.put(Constants.BUNDLE_DESCRIPTION, providerName); } for (Map.Entry<String, String> entry : properties.entrySet()) { if (StringUtils.isNotEmpty(entry.getValue()) && StringUtils.isNotEmpty(entry.getKey())) { dictonary.put(entry.getKey(), entry.getValue()); } } Writer writer = null; try { if (existingManifestFile != null) { writer = new FileWriter(existingManifestFile); } else { writer = new FileWriter( getFirstPossibleManifestFile(javaProject.getProject(), false).getRawLocation().toFile()); } BundleManifest bundleManifest = BundleManifestFactory.createBundleManifest(dictonary); bundleManifest.write(writer); } catch (IOException e) { } finally { if (writer != null) { try { writer.flush(); writer.close(); } catch (IOException e) { } } } }
From source file:org.apache.felix.http.itest.BaseIntegrationTest.java
protected static Dictionary<String, ?> createDictionary(Object... entries) { Dictionary<String, Object> props = new Hashtable<String, Object>(); for (int i = 0; i < entries.length; i += 2) { String key = (String) entries[i]; Object value = entries[i + 1]; props.put(key, value); }/* www . jav a 2 s .c o m*/ return props; }
From source file:org.sourcepit.common.utils.props.PropertiesUtils.java
@SuppressWarnings("rawtypes") public static void load(File propertiesFile, final Dictionary/* <String, String> */ properties) { final Properties delegate = new Properties() { private static final long serialVersionUID = 1L; @Override/* w ww .jav a 2 s. c om*/ @SuppressWarnings("unchecked") public synchronized Object put(Object key, Object value) { properties.put(key.toString(), value.toString()); return super.put(key, value); } }; load(propertiesFile, delegate); }
From source file:org.sourcepit.common.utils.props.PropertiesUtils.java
@SuppressWarnings("rawtypes") public static void load(InputStream inputStream, final Dictionary/* <String, String> */ properties) { final Properties delegate = new Properties() { private static final long serialVersionUID = 1L; @Override/*from w w w . j av a 2s .co m*/ @SuppressWarnings("unchecked") public synchronized Object put(Object key, Object value) { properties.put(key.toString(), value.toString()); return super.put(key, value); } }; load(inputStream, delegate); }
From source file:net.commerce.zocalo.freechart.ChartGenerator.java
static public void initializeSeries(Dictionary<String, TimePeriodValues> positions, TimePeriodValuesCollection allValues, Claim claim) { Position[] allPositions = claim.positions(); if (allPositions.length == 2) { int less = allPositions[0].comparePersistentId(allPositions[1]); Position pos = allPositions[less < 0 ? 0 : 1]; // pick one stably TimePeriodValues values = new TimePeriodValues(pos.getName()); positions.put(pos.getName(), values); allValues.addSeries(values);/*from w ww .j a va 2s . c o m*/ } else { SortedSet<Position> sortedPositions = claim.sortPositions(); for (Iterator<Position> positionIterator = sortedPositions.iterator(); positionIterator.hasNext();) { Position pos = positionIterator.next(); TimePeriodValues values = new TimePeriodValues(pos.getName()); positions.put(pos.getName(), values); allValues.addSeries(values); } } }
From source file:org.wso2.carbon.ui.deployment.ComponentBuilder.java
/** * Processes the following XML segment/*from w w w. j a v a2 s .c om*/ * <p/> * <osgiServices> * <service> * <classes> * <class>org.wso2.carbon.ui.UIExtender</class> * </classes> * <object> * org.wso2.carbon.service.mgt.ui.ServiceManagementUIExtender * </object> * <properties> * <property name="service-mgt">true</property> * </properties> * </service> * </osgiServices> * * @param document The document * @param bundleContext The OSGi bundle context * @throws CarbonException If an error occurs while instantiating a service object */ private static void processOSGiServices(OMElement document, BundleContext bundleContext) throws CarbonException { OMElement osgiServiceEle = document.getFirstChildWithName(new QName(WSO2CARBON_NS, "osgiServices")); if (osgiServiceEle == null) { return; } for (Iterator services = osgiServiceEle.getChildrenWithName(new QName(WSO2CARBON_NS, "service")); services .hasNext();) { OMElement service = (OMElement) services.next(); OMElement objectEle = service.getFirstChildWithName(new QName(WSO2CARBON_NS, "object")); Object obj; String objClazz = objectEle.getText().trim(); try { Class objectClazz = Class.forName(objClazz, true, ComponentBuilder.class.getClassLoader()); obj = objectClazz.newInstance(); } catch (Exception e) { String msg = "Cannot instantiate OSGi service class " + objClazz; log.error(msg, e); throw new CarbonException(msg, e); } OMElement classesEle = service.getFirstChildWithName(new QName(WSO2CARBON_NS, "classes")); List<String> classList = new ArrayList<String>(); for (Iterator classes = classesEle.getChildElements(); classes.hasNext();) { OMElement clazz = (OMElement) classes.next(); classList.add(clazz.getText().trim()); } OMElement propertiesEle = service.getFirstChildWithName(new QName(WSO2CARBON_NS, "properties")); Dictionary<String, String> props = new Hashtable<String, String>(); for (Iterator properties = propertiesEle.getChildElements(); properties.hasNext();) { OMElement prop = (OMElement) properties.next(); props.put(prop.getAttribute(new QName("name")).getAttributeValue().trim(), prop.getText().trim()); } bundleContext.registerService(classList.toArray(new String[classList.size()]), obj, props); if (log.isDebugEnabled()) { log.debug("Registered OSGi service " + objClazz); } } }
From source file:org.openhab.binding.modbus.internal.TestCaseSupport.java
protected static void putSlaveConfigParameter(Dictionary<String, Object> config, ServerType serverType, String slaveName, String paramName, String paramValue) { String protocol = null;//from ww w. j a v a2s .co m if (ServerType.TCP.equals(serverType)) { protocol = "tcp"; } else if (ServerType.UDP.equals(serverType)) { protocol = "udp"; } else if (ServerType.SERIAL.equals(serverType)) { protocol = "serial"; } config.put(String.format("%s.%s.%s", protocol, slaveName, paramName), paramValue); }