List of usage examples for java.util Dictionary put
public abstract V put(K key, V value);
From source file:org.energy_home.jemma.ah.internal.hac.lib.HacService.java
private void manageMultiEndPointConfiguration(Dictionary props, Dictionary oldProps, String applianceProperty, String endPointsProperty) { String value = (String) props.get(applianceProperty); String[] values = (String[]) props.get(endPointsProperty); if (values == null) { values = (String[]) oldProps.get(endPointsProperty); }//from w w w .j a v a 2 s . c o m if (value == null && values != null && values.length > 0) { // If no appliance property is present and end point 0 property is present, the appliance property is created/aligned props.put(applianceProperty, values[0]); } if (value != null && values != null && values.length > 0 && !value.equals(values[0])) { // If appliance property is present and end point properties are already present or updated, // all end point corresponding properties are reset to appliance property for (int i = 0; i < values.length; i++) { values[i] = (String) value; } props.put(endPointsProperty, values); } }
From source file:org.liveSense.misc.configloader.ConfigurationLoader.java
/** * Set the configuration based on the config file. * * @param f/*from w w w . j a va 2s . com*/ * Configuration file * @return * @throws Exception */ @SuppressWarnings("unchecked") boolean setConfig(URL f) throws Exception { Properties p = new Properties(); @SuppressWarnings("rawtypes") Dictionary ht = new Hashtable(); InputStream in = new BufferedInputStream(f.openStream()); try { // If the file name ends with .config, we using the Felix configuration format if (f.getFile().endsWith(".config")) { ht = ConfigurationHandler.read(in); } else { in.mark(1); boolean isXml = in.read() == '<'; in.reset(); if (isXml) { p.loadFromXML(in); } else { p.load(in); } ((Hashtable) ht).putAll(p); } } finally { in.close(); } // Searching for templated config entry. // If we found one we get Java System properties // named as the macros. The config became activated if that // system proprty is set. Pattern macros = Pattern.compile("\\$\\{(.*?)\\}"); boolean valid = true; Enumeration enumr = ht.keys(); while (enumr.hasMoreElements()) { Object key = enumr.nextElement(); if (ht.get(key) instanceof String) { String str = (String) ht.get(key); if (str != null) { Matcher matcher = macros.matcher(str); HashSet<String> propNames = new HashSet<String>(); while (matcher.find()) { propNames.add(matcher.group(1)); } for (String prop : propNames) { String sysProp = System.getProperty(prop); if (sysProp == null) { valid = false; } if (valid) { str = StringUtils.replace(str, "${" + prop + "}", sysProp); //str = str.replaceAll("\\$\\{"+prop+"\\}", sysProp); } } if (valid) { ht.put(key, str); } } } } if (valid) { Util.performSubstitution(p); String pid[] = parsePid(getName(f.getFile())); ht.put(CONFIGURATION_PROPERTY_NAME, getPidName(pid[0], pid[1])); Configuration config = getConfiguration(pid[0], pid[1]); /* // Backuping parameters for restore String persistanceName = pid[0]+(pid[1] == null ? "" : "-" + pid[1]); if (config.getProperties() != null && config.getProperties().get(CONFIGURATION_PROPERTY_NAME) == null) { if (persistence.load(persistanceName).isEmpty()) { persistence.store(persistanceName, config.getProperties()); } } */ if (config.getBundleLocation() != null) { config.setBundleLocation(null); } // If the configuration does not created by configuration loader we update it // In other cases (for example the user modified the loaded config) there is no configuration overwrite if (config.getProperties() == null || config.getProperties().get(CONFIGURATION_PROPERTY_NAME) == null || !config.getProperties().get(CONFIGURATION_PROPERTY_NAME).equals(getName(f.getFile()))) { config.update(ht); } } return true; }
From source file:org.energy_home.jemma.ah.internal.hac.lib.HacService.java
/** * Checks and adds or updates some properties contained in * the configuration. The props dictionary is changed. * /*w ww . j a va2 s . co m*/ * @param c * The Configuration Admin configuration. * @param props * The new property set * @param name * The name of the property of c that must not be overridden. * @throws HacException */ private void checkAndUpdateProperties(IManagedAppliance managedAppliance, Configuration c, Dictionary props) throws HacException { // don't override the appliance type property. Fatal error if // this property is not set for the appliance Dictionary oldProps = c.getProperties(); String applianceType = (String) oldProps.get(IAppliance.APPLIANCE_TYPE_PROPERTY); if (applianceType == null) { // FIXME: nella configurazione NON compare mai la ah.app.type // property!!!!! Perche? LOG.warn(IAppliance.APPLIANCE_TYPE_PROPERTY + " property not found in record"); } // Restore some key properties: it seems it does not associate to new service registration properties // that are not included in last change to configuration (it also avoid to have some properties // can contains invalid values) props.put(IAppliance.APPLIANCE_TYPE_PROPERTY, managedAppliance.getDescriptor().getType()); props.put(IAppliance.APPLIANCE_PID, managedAppliance.getPid()); props.put(IAppliance.APPLIANCE_EPS_IDS_PROPERTY, managedAppliance.getEndPointIds()); props.put(IAppliance.APPLIANCE_EPS_TYPES_PROPERTY, managedAppliance.getEndPointTypes()); props.put(IAppliance.APPLIANCE_EPS_IDS_PROPERTY, managedAppliance.getEndPointIds()); props.put(IAppliance.APPLIANCE_EPS_TYPES_PROPERTY, managedAppliance.getEndPointTypes()); Dictionary customConfig = managedAppliance.getCustomConfiguration(); if (customConfig != null) { for (Enumeration e = customConfig.keys(); e.hasMoreElements();) { String key = (String) e.nextElement(); // Custom properties that are invalid are filtered if (key.startsWith(IAppliance.APPLIANCE_CUSTOM_PROPERTIES_PREXIF)) ; props.put(key, customConfig.get(key)); } } //TODO: check merge, 5 lines below were missing in 3.3.0 // For compatibility with old applications (i.e. green@home), appliance common property is always managed manageMultiEndPointConfiguration(props, oldProps, IAppliance.APPLIANCE_NAME_PROPERTY, IAppliance.END_POINT_NAMES_PROPERTY); manageMultiEndPointConfiguration(props, oldProps, IAppliance.APPLIANCE_CATEGORY_PID_PROPERTY, IAppliance.END_POINT_CATEGORY_PIDS_PROPERTY); manageMultiEndPointConfiguration(props, oldProps, IAppliance.APPLIANCE_LOCATION_PID_PROPERTY, IAppliance.END_POINT_LOCATION_PIDS_PROPERTY); manageMultiEndPointConfiguration(props, oldProps, IAppliance.APPLIANCE_ICON_PROPERTY, IAppliance.END_POINT_LOCATION_PIDS_PROPERTY); }
From source file:org.energy_home.jemma.ah.internal.hac.lib.HacService.java
/** * Create an appliance given its type (i.e. factory type) and properties. * The props dictionary may be filled with the properties that have to be * assigned to the new appliance./* ww w. ja v a 2 s. co m*/ * * @param factoryPid * The type of the new appliance * @param props * The properties of the new appliance * @return the pid of the newly created appliance. */ protected String createApplianceByFactory(String factoryPid, Dictionary props) throws HacException { synchronized (lockHacService) { ApplianceFactory applianceFactoryService = this.getApplianceFactory(factoryPid); if (applianceFactoryService == null) throw new HacException("unable to find an appliance factory for type '" + factoryPid + "'"); // check if the property dictionary contains the ah.app.name // property String friendlyName = applianceFactoryService.getDescriptor().getFriendlyName(); String pid; if (friendlyName != null) { pid = generateUniquePid(friendlyName); } else { pid = this.generatePid(); } if ((props.get(IAppliance.APPLIANCE_NAME_PROPERTY) == null) && (friendlyName != null)) { String name = createUniqueName(friendlyName); props.put(IAppliance.APPLIANCE_NAME_PROPERTY, name); } createConfiguration(factoryPid, pid, props); return pid; } }
From source file:org.energy_home.jemma.ah.internal.hac.lib.HacService.java
public void createAppliance(String appliancePid, Dictionary props) throws HacException { if (appliancePid.equals(IAppliancesProxy.PROXY_APPLIANCE_PID)) throw new IllegalArgumentException("Appliances proxy appliance cannot be created!"); synchronized (lockHacService) { IManagedAppliance managedAppliance = (IManagedAppliance) pid2appliance.get(appliancePid); if (managedAppliance != null) throw new HacException("appliance " + appliancePid + " already exists"); Configuration c;//from w w w. j av a 2 s .c o m try { c = this.getApplianceCAConfiguration(appliancePid); if (c != null) { throw new HacException("appliance " + appliancePid + " already exists"); } String factoryPid = (String) props.get(IAppliance.APPLIANCE_TYPE_PROPERTY); if (factoryPid != null) { c = this.configAdmin.createFactoryConfiguration(factoryPid, null); props.put("appliance.pid", appliancePid); LOG.debug("created factory configuration for appliance.pid " + appliancePid); } else { c = this.configAdmin.getConfiguration(appliancePid); props.put("appliance.pid", appliancePid); LOG.debug("created factory configuration for appliance.pid " + appliancePid); } c.update(props); } catch (Exception e) { LOG.debug(e.getMessage()); throw new HacException(e.getMessage()); } } }
From source file:ddf.catalog.impl.CatalogFrameworkImpl.java
private void registerBasicMetacard() { Bundle bundle = FrameworkUtil.getBundle(CatalogFrameworkImpl.class); if (bundle != null && bundle.getBundleContext() != null) { Dictionary<String, Object> properties = new Hashtable<>(); properties.put("name", BasicTypes.BASIC_METACARD.getName()); bundle.getBundleContext().registerService(MetacardType.class, BasicTypes.BASIC_METACARD, properties); }//ww w . ja v a 2 s .c o m }
From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java
public void test_Listener1() throws Exception { BaseServletContextListener scl1 = new BaseServletContextListener(); Dictionary<String, String> listenerProps = new Hashtable<String, String>(); listenerProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER, "true"); ServiceRegistration<ServletContextListener> registration = getBundleContext() .registerService(ServletContextListener.class, scl1, listenerProps); registration.unregister();/*from ww w . j a v a2 s .c o m*/ Assert.assertTrue(scl1.initialized.get()); Assert.assertTrue(scl1.destroyed.get()); }
From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java
public void test_ServletContext2() throws Exception { Servlet servlet = new HttpServlet() { private static final long serialVersionUID = 1L; @Override/*from w w w .ja v a 2s .c om*/ protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { getServletContext().setAttribute("name", null); } }; Dictionary<String, Object> props = new Hashtable<String, Object>(); props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "S1"); props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/S1/*"); registrations.add(getBundleContext().registerService(Servlet.class, servlet, props)); Map<String, List<String>> response = requestAdvisor.request("S1/a", null); String responseCode = response.get("responseCode").get(0); Assert.assertEquals("200", responseCode); }
From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java
public void test_ErrorPage11() throws Exception { Servlet servlet = new HttpServlet() { private static final long serialVersionUID = 1L; @Override/*from ww w . j ava 2s . c o m*/ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.sendError(403); resp.getOutputStream().flush(); } }; Dictionary<String, Object> props = new Hashtable<String, Object>(); props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "E10"); props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/TestErrorPage11/*"); registrations.add(getBundleContext().registerService(Servlet.class, servlet, props)); try { requestAdvisor.request("TestErrorPage11/a"); } catch (IOException e) { // This is expected because of old behavior // TODO is this really the correct behavior though } }
From source file:org.eclipse.equinox.http.servlet.tests.ServletTest.java
public void test_ErrorPage5() throws Exception { Dictionary<String, Object> errorProps = new Hashtable<String, Object>(); errorProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "E5.4xx"); errorProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ERROR_PAGE, "4xx"); registrations.add(getBundleContext().registerService(Servlet.class, new ErrorServlet("4xx"), errorProps)); errorProps = new Hashtable<String, Object>(); errorProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, "E5.5xx"); errorProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ERROR_PAGE, "5xx"); registrations.add(getBundleContext().registerService(Servlet.class, new ErrorServlet("5xx"), errorProps)); for (String expectedCode : Arrays.asList("400", "450", "499", "500", "550", "599")) { Map<String, List<String>> response = doRequestGetResponse(ERROR, Collections.singletonMap(TEST_ERROR_CODE, expectedCode)); String expectedResponse = expectedCode.charAt(0) + "xx : " + expectedCode + " : ERROR"; String actualCode = response.get("responseCode").get(0); String actualResponse = response.get("responseBody").get(0); Assert.assertEquals(expectedCode, actualCode); Assert.assertTrue("Expected <" + expectedResponse + "*> but got <" + actualResponse + ">", actualResponse.startsWith(expectedResponse)); }// w ww . j a v a 2 s . c om }