List of usage examples for java.util Dictionary get
public abstract V get(Object key);
From source file:org.jahia.services.usermanager.mongo.JahiaMongoConfig.java
/** * defines or update the context of the provider * @param context the Spring application context object * @param dictionary configuration parameters *///from w w w . j a va 2 s . c o m public void setContext(final ApplicationContext context, final Dictionary<String, ?> dictionary) { final Properties userMongoProperties = new Properties(); final UserConfig userConfig = new UserConfig(); final Enumeration<String> keys = dictionary.keys(); String fileName = null; while (keys.hasMoreElements()) { final String key = keys.nextElement(); if (Constants.SERVICE_PID.equals(key) || ConfigurationAdmin.SERVICE_FACTORYPID.equals(key)) { continue; } else if ("felix.fileinstall.filename".equals(key)) { fileName = (String) dictionary.get(key); continue; } final Object value = dictionary.get(key); if (key.startsWith("user.")) { buildConfig(userMongoProperties, userConfig, key, value, true); } else { userMongoProperties.put(transformPropKeyToBeanAttr(key), value); } } try { // populate config beans BeanUtils.populate(userConfig, userMongoProperties); // handle defaults values userConfig.handleDefaults(); final String host = userConfig.getHost(); final String database = userConfig.getDatabase(); final MongoClient mongoClient = new MongoClient(host); final MongoDatabase mongoDatabase = mongoClient.getDatabase(database); if (mongoUserGroupProvider == null) { mongoUserGroupProvider = (MongoUserGroupProvider) context.getBean("mongoUserGroupProvider"); } else { // Deactivate the provider before reconfiguring it. mongoUserGroupProvider.unregister(); } mongoUserGroupProvider.setKey(providerKey); mongoUserGroupProvider.setUserConfig(userConfig); mongoUserGroupProvider.setMongoTemplateWrapper(new MongoTemplateWrapper(mongoDatabase)); // Activate (again). mongoUserGroupProvider.register(); } catch (IllegalAccessException | InvocationTargetException e) { LOGGER.error("Invalid Mongo configuration:" + fileName + ", " + "please refer to the Mongo configuration documentation", e); } }
From source file:org.opencastproject.capture.admin.impl.CaptureAgentStateServiceImpl.java
/** * {@inheritDoc}//from w ww .jav a2s . c o m * * @see org.osgi.service.cm.ManagedServiceFactory#updated(java.lang.String, java.util.Dictionary) */ @Override public void updated(String pid, Dictionary properties) throws ConfigurationException { // Get the agent properties String nameConfig = (String) properties.get("id"); if (isBlank(nameConfig)) throw new ConfigurationException("id", "must be specified"); nameConfig = nameConfig.trim(); String urlConfig = (String) properties.get("url"); if (isBlank(urlConfig)) throw new ConfigurationException("url", "must be specified"); urlConfig = urlConfig.trim(); String orgConfig = (String) properties.get("organization"); if (isBlank(orgConfig)) throw new ConfigurationException("organization", "must be specified"); orgConfig = orgConfig.trim(); String schedulerRolesConfig = (String) properties.get("schedulerRoles"); if (isBlank(schedulerRolesConfig)) throw new ConfigurationException("schedulerRoles", "must be specified"); String[] schedulerRoles = schedulerRolesConfig.trim().split(","); // If we don't already have a mapping for this PID, create one if (!pidMap.containsKey(pid)) { pidMap.put(pid, nameConfig); } AgentImpl agent; try { agent = getAgent(nameConfig, orgConfig); agent.setUrl(urlConfig); agent.setState(UNKNOWN); } catch (NotFoundException e) { agent = new AgentImpl(nameConfig, orgConfig, UNKNOWN, urlConfig, new Properties()); } for (String role : schedulerRoles) { agent.schedulerRoles.add(role.trim()); } // Update the database logger.info("Roles '{}' may schedule '{}'", schedulerRolesConfig, agent.name); updateAgentInDatabase(agent); }
From source file:org.openhab.binding.canopen.internal.CANOpenBinding.java
/** * @{inheritDoc}/*w w w .ja v a 2 s . com*/ */ @Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { if (config != null) { // to override the default refresh interval one has to add a // parameter to openhab.cfg like <bindingName>:refresh=<intervalInMs> refreshInterval = 60000; String refreshIntervalString = (String) config.get("refresh"); if (StringUtils.isNotBlank(refreshIntervalString)) { refreshInterval = Long.parseLong(refreshIntervalString); } sdoResponseTimeout = 1000; String sdoResponseTimeoutString = (String) config.get("sdo_timeout"); if (StringUtils.isNotBlank(sdoResponseTimeoutString)) { sdoResponseTimeout = Integer.parseInt(sdoResponseTimeoutString); } autoStartNodes.clear(); autoStartAll = false; String autoStartString = (String) config.get("auto_start_nodes"); if (StringUtils.isNotBlank(autoStartString)) { String[] nodes = autoStartString.split(","); for (String node : nodes) { if (node.trim().toLowerCase().equals("all")) autoStartAll = true; try { autoStartNodes.add(Integer.decode(node)); } catch (NumberFormatException e) { } } } syncInterfaces.clear(); String syncInterfaceString = (String) config.get("sync_master_for"); if (StringUtils.isNotBlank(syncInterfaceString)) { if (syncInterfaceString.contains(",")) syncInterfaces.addAll(Arrays.asList(syncInterfaceString.split("\\s*,\\s*"))); else syncInterfaces.add(syncInterfaceString.trim()); logger.debug("Sync master for: " + syncInterfaces); } syncMaxVal = 0; String syncMaxValString = (String) config.get("sync_max_val"); if (StringUtils.isNotBlank(syncMaxValString)) { try { syncMaxVal = Integer.parseInt(syncMaxValString); if (syncMaxVal > 255) syncMaxVal = 255; if (syncMaxVal < 0) syncMaxVal = 0; } catch (NumberFormatException e) { logger.error("Could not parse sync_max_val from string " + syncMaxValString); } } setProperlyConfigured(true); } }
From source file:org.openhab.binding.obd.internal.OBDBinding.java
/** * @{inheritDoc//from ww w. ja va2 s.c om */ @Override public synchronized void updated(Dictionary config) throws ConfigurationException { logger.trace("OBD Updated"); if (config != null) { logger.trace("OBD Configuration not null"); if (config != null) { String deviceString = (String) config.get("device"); if (StringUtils.isNotBlank(deviceString)) { device = deviceString; logger.trace("device setting is {} ", device); } String speedString = (String) config.get("speed"); if (StringUtils.isNotBlank(speedString)) { speed = Integer.parseInt(speedString); logger.trace("speed setting is{} ", speed); } String readDelay = (String) config.get("delay"); if (StringUtils.isNotBlank(readDelay)) { delay = Integer.parseInt(readDelay); logger.trace("comm delay setting is {} ", delay); } //setProperlyConfigured(true); } HashMap<String, OBDParserRule> parsingRules = new HashMap<String, OBDParserRule>(); Enumeration<String> 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; } if ("simulate".equals(key)) { continue; } String value = (String) config.get(key); if ("device".equals(key)) { if (StringUtils.isNotBlank(value)) { device = value; logger.trace("Using serial device {}", device.toString()); } } else if ("speed".equals(key)) { speed = Integer.parseInt(value); logger.trace("Speed set to {}", speed); } else if ("refresh".equals(key)) { refresh = Integer.parseInt(value); logger.trace("Refresh set to {}", refresh); } else if ("retry".equals(key)) { retry = Integer.parseInt(value); logger.trace("Retry set to {}", retry); } else if ("delay".equals(key)) { delay = Integer.parseInt(value); logger.trace("Delay set to {}", retry); } else { // process all data parsing rules try { OBDParserRule rule = new OBDParserRule(value); parsingRules.put(key, rule); } catch (OBDException e) { throw new ConfigurationException(key, "invalid parser rule", e); } continue; } } if (parsingRules != null) { logger.trace("OBD Data Parser called"); dataParser = new OBDDataParser(parsingRules); } if (messageListener != null) { logger.trace("Close previous message listener"); messageListener.setInterrupted(true); try { messageListener.join(); } catch (InterruptedException e) { logger.info("Previous message listener closing interrupted", e); } } if (!running) { messageListener = new MessageListener(this); messageListener.start(); } } }
From source file:org.openhab.binding.km200.internal.KM200Binding.java
/** * {@inheritDoc}/*from www.j a v a2 s .c om*/ */ @Override @SuppressWarnings("rawtypes") public void updated(Dictionary config) throws ConfigurationException { if (config == null) { return; } else { if (config.isEmpty()) { return; } logger.info("Update KM200 Binding configuration, it takes a minute...."); String ip = Objects.toString(config.get("ip4_address"), null); if (StringUtils.isNotBlank(ip)) { try { InetAddresses.forString(ip); } catch (IllegalArgumentException e) { logger.error("IP4_address in openhab.cfg is not valid!"); throw new ConfigurationException("ip4_address", "ip4_address in openhab.cfg is not valid!"); } device.setIP4Address(ip); } else { logger.error("No ip4_address in openhab.cfg set!"); throw new ConfigurationException("ip4_address", "No ip4_address in openhab.cfg set!"); } /* There a two possibilities of configuratiom */ /* 1. With a private key */ String PrivKey = Objects.toString(config.get("PrivKey"), null); if (StringUtils.isNotBlank(PrivKey)) { device.setCryptKeyPriv(PrivKey); } else { /* 2. With the MD5Salt, the device and user private password */ String MD5Salt = Objects.toString(config.get("MD5Salt"), null); if (StringUtils.isNotBlank(MD5Salt)) { device.setMD5Salt(MD5Salt); } else { logger.error("No MD5Salt in openhab.cfg set!"); throw new ConfigurationException("MD5Salt", "No MD5Salt in openhab.cfg set!"); } String gpassword = Objects.toString(config.get("GatewayPassword"), null); if (StringUtils.isNotBlank(gpassword)) { device.setGatewayPassword(gpassword); } else { logger.error("No GatewayPassword in openhab.cfg set!"); throw new ConfigurationException("GatewayPassword", "No GatewayPassword in openhab.cfg set!"); } String ppassword = Objects.toString(config.get("PrivatePassword"), null); if (StringUtils.isNotBlank(ppassword)) { device.setPrivatePassword(ppassword); } else { logger.error("No PrivatePassword in openhab.cfg set!"); throw new ConfigurationException("PrivatePassword", "No PrivatePassword in openhab.cfg set!"); } } logger.info("Starting communication test.."); /* Get HTTP Data from device */ byte[] recData = comm.getDataFromService("/gateway/DateTime"); if (recData == null) { throw new RuntimeException("Communication is not possible!"); } if (recData.length == 0) { throw new RuntimeException("No reply from KM200!"); } logger.info("Received data.."); /* Derypt the message */ String decodedData = comm.decodeMessage(recData); if (decodedData == null) { throw new RuntimeException("Decoding of the KM200 message is not possible!"); } if (decodedData == "SERVICE NOT AVAILABLE") { logger.error("/gateway/DateTime: SERVICE NOT AVAILABLE"); } else { logger.info("Test of the communication to the gateway was successful.."); } logger.info("Init services.."); /* communication is working */ /* Checking of the devicespecific services and creating of a service list */ for (KM200ServiceTypes service : KM200ServiceTypes.values()) { try { logger.debug(service.getDescription()); comm.initObjects(service.getDescription()); } catch (Exception e) { logger.error("Couldn't init service: {} error: {}", service, e.getMessage()); } } /* Now init the virtual services */ logger.debug("init Virtual Objects"); try { comm.initVirtualObjects(); } catch (Exception e) { logger.error("Couldn't init virtual services: {}", e.getMessage()); } /* Output all availible services in the log file */ /* Now init the virtual services */ logger.debug("list All Services"); device.listAllServices(); logger.info("... Update of the KM200 Binding configuration completed"); device.setInited(true); setProperlyConfigured(true); } }
From source file:org.codice.ddf.admin.core.impl.ConfigurationAdminImpl.java
public ConfigurationStatus enableManagedServiceFactoryConfiguration(String servicePid, Configuration disabledConfig) throws IOException { Dictionary<String, Object> properties = disabledConfig.getProperties(); String disabledFactoryPid = (String) properties .get(org.osgi.service.cm.ConfigurationAdmin.SERVICE_FACTORYPID); if (disabledFactoryPid == null) { throw new IOException("Configuration does not belong to a managed service factory."); }/* w w w. j av a 2s . co m*/ if (!StringUtils.endsWith(disabledFactoryPid, ConfigurationStatus.DISABLED_EXTENSION)) { throw new IOException("Configuration is already enabled."); } String enabledFactoryPid = StringUtils.removeEnd(disabledFactoryPid, ConfigurationStatus.DISABLED_EXTENSION); Dictionary<String, Object> enabledProperties = copyConfigProperties(properties, enabledFactoryPid); enabledProperties.put(org.osgi.service.cm.ConfigurationAdmin.SERVICE_FACTORYPID, enabledFactoryPid); Configuration enabledConfiguration = configurationAdmin.createFactoryConfiguration(enabledFactoryPid, null); enabledConfiguration.update(enabledProperties); disabledConfig.delete(); return new ConfigurationStatusImpl(enabledFactoryPid, enabledConfiguration.getPid(), disabledFactoryPid, servicePid); }
From source file:org.openhab.io.caldav.internal.CalDavEventDownloader.java
@Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { if (config != null) { String usernameString = (String) config.get("username"); username = usernameString;//from w w w . j a va 2 s.co m if (StringUtils.isBlank(username)) { throw new ConfigurationException("caldav:username", "username must not be blank - please configure an aproppriate username in openhab.cfg"); } logger.trace("username: {}", username); String passwordString = (String) config.get("password"); password = passwordString; if (StringUtils.isBlank(password)) { throw new ConfigurationException("caldav:password", "password must not be blank - please configure an aproppriate password in openhab.cfg"); } logger.trace("password: {}", password); String hostString = (String) config.get("host"); host = hostString; if (StringUtils.isBlank(host)) { throw new ConfigurationException("caldav:host", "host must not be blank - please configure an aproppriate host in openhab.cfg"); } logger.trace("host: {}", host); String tlsString = (String) config.get("tls"); if (StringUtils.isNotBlank(tlsString)) { try { tls = Boolean.parseBoolean(tlsString); } catch (IllegalArgumentException iae) { logger.warn("couldn't parse caldav:tls '{}' to a boolean"); } } else { tls = true; } logger.trace("tls: {}", tls); String strictTlsString = (String) config.get("strict-tls"); if (StringUtils.isNotBlank(strictTlsString)) { try { strictTls = Boolean.parseBoolean(strictTlsString); } catch (IllegalArgumentException iae) { logger.warn("couldn't parse caldav:strict-tls '{}' to a boolean"); } } else { strictTls = true; } logger.trace("strictTls: {}", strictTls); if (!tls) { logger.warn( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); logger.warn( "!! You have disabled tls/ssl for CalDav-EventDownloader. Calendar data is exchanged unencrypted. !!"); logger.warn( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } if (!strictTls && tls) { logger.warn( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); logger.warn( "!! You have disabled strict certificate checking by setting strict-tls to false. !!"); logger.warn( "!! Actually all checking for certificates in CalDav-EventDownloader is disabled now !!"); logger.warn( "!! - which means that there is no real security - as you accept any certificate, !!"); logger.warn( "!! even those which might be injected for Man-In The Middle-Attacks - try to !!"); logger.warn( "!! Register your certificate to your java certificate store and set strict-tls to !!"); logger.warn( "!! true. Disable the tls checking is just meant for debugging purposes. !!"); logger.warn( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } String portString = (String) config.get("port"); if (StringUtils.isNotBlank(portString)) { try { port = Integer.valueOf(portString); } catch (IllegalArgumentException iae) { logger.warn("couldn't parse caldav:port '{}' to an integer"); } } else { if (tls) { port = 443; } else { port = 80; } } logger.trace("port: {}", port); String urlString = (String) config.get("url"); url = urlString; if (StringUtils.isBlank(url)) { throw new ConfigurationException("caldav:url", "url must not be blank - please configure an aproppriate url in openhab.cfg"); } logger.trace("url: {}", url); // filter = (String) config.get("filter"); String refreshString = (String) config.get("refresh"); if (StringUtils.isNotBlank(refreshString)) { refreshInterval = Integer.parseInt(refreshString); refreshInterval *= 1000; } logger.trace("refreshInterval: {}ms", refreshInterval); setProperlyConfigured(true); logger.debug("CalDav event downloader successfuly configured"); } }
From source file:org.paxle.core.filter.impl.FilterManager.java
/** * @see ManagedService#updated(Dictionary) *//*from w w w.j a v a 2 s.co m*/ @SuppressWarnings("unchecked") public synchronized void updated(Dictionary properties) throws ConfigurationException { if (properties == null) return; // getting default filter statis Boolean defaultStatus = (Boolean) properties.get(CM_FILTER_DEFAULT_STATUS); if (defaultStatus != null) this.enableNewFilters = defaultStatus; // getting filter-status settings Enumeration<String> keys = properties.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); if (!key.startsWith(CM_FILTER_ENABLED_FILTERS)) continue; String[] enabledFiltes = (String[]) properties.get(key); if (enabledFiltes != null) { String queueID = key.substring(CM_FILTER_ENABLED_FILTERS.length()); // remember enabled filters Set<String> enabledFilters = this.getEnabledFilters(queueID); enabledFilters.clear(); enabledFilters.addAll(Arrays.asList(enabledFiltes)); // getting all filters registered for the queue Set<FilterContext> knownFilters = this.getRegisteredFilters(queueID); // updating filter-context status for (FilterContext fContext : knownFilters) { boolean enabled = enabledFilters.contains(fContext.getFilterContextPID()); fContext.setEnabled(enabled); } // getting the queue IFilterQueue queue = this.getQueue(queueID); if (this.queues.containsKey(queueID)) { // apply filters to the queue this.setFilters(queue, knownFilters, enabledFilters); } } } }
From source file:ch.entwine.weblounge.contentrepository.impl.fs.FileSystemContentRepository.java
/** * {@inheritDoc}/* w w w . j av a2 s. c om*/ * * @see org.osgi.service.cm.ManagedService#updated(java.util.Dictionary) */ public void updated(Dictionary properties) throws ConfigurationException { // Detect the filesystem root directory String fsRootDir = null; if (StringUtils.isNotBlank(System.getProperty(PROP_ROOT_DIR))) fsRootDir = System.getProperty(PROP_ROOT_DIR); else if (properties != null && StringUtils.isNotBlank((String) properties.get(OPT_ROOT_DIR))) fsRootDir = (String) properties.get(OPT_ROOT_DIR); else fsRootDir = PathUtils.concat(System.getProperty("java.io.tmpdir"), ROOT_DIR_DEFAULT); repositoryRoot = new File(fsRootDir); if (site != null) repositorySiteRoot = new File(repositoryRoot, site.getIdentifier()); logger.debug("Content repository storage root is located at {}", repositoryRoot); // Make sure we can create a temporary index try { FileUtils.forceMkdir(repositoryRoot); } catch (IOException e) { throw new ConfigurationException(OPT_ROOT_DIR, "Unable to create repository storage at " + repositoryRoot, e); } logger.debug("Content repository configured"); }
From source file:org.codice.ddf.admin.core.impl.ConfigurationAdminImpl.java
public ConfigurationStatus disableManagedServiceFactoryConfiguration(String servicePid, Configuration originalConfig) throws IOException { Dictionary<String, Object> properties = originalConfig.getProperties(); String originalFactoryPid = (String) properties .get(org.osgi.service.cm.ConfigurationAdmin.SERVICE_FACTORYPID); if (originalFactoryPid == null) { throw new IOException("Configuration does not belong to a managed service factory."); }/*from w w w .ja v a 2 s . c o m*/ if (StringUtils.endsWith(originalFactoryPid, ConfigurationStatus.DISABLED_EXTENSION)) { throw new IOException("Configuration is already disabled."); } // Copy configuration from the original configuration and change its factory PID to end with // "disabled" Dictionary<String, Object> disabledProperties = copyConfigProperties(properties, originalFactoryPid); String disabledServiceFactoryPid = originalFactoryPid + ConfigurationStatus.DISABLED_EXTENSION; disabledProperties.put(org.osgi.service.cm.ConfigurationAdmin.SERVICE_FACTORYPID, disabledServiceFactoryPid); Configuration disabledConfig = configurationAdmin.createFactoryConfiguration(disabledServiceFactoryPid, null); disabledConfig.update(disabledProperties); // remove original configuration originalConfig.delete(); return new ConfigurationStatusImpl(disabledServiceFactoryPid, disabledConfig.getPid(), originalFactoryPid, servicePid); }