List of usage examples for java.util Dictionary put
public abstract V put(K key, V value);
From source file:org.codice.ddf.admin.core.impl.ConfigurationAdminImpl.java
private void copyIfDefined(String id, Dictionary<String, Object> source, Dictionary<String, Object> destination) { final Object value = source.get(id); if (value != null) { destination.put(id, value); }/*from ww w. ja v a2 s . c o m*/ }
From source file:ch.entwine.weblounge.kernel.site.SiteManager.java
/** * {@inheritDoc}/* www. j av a2 s .c o m*/ * * @see ch.entwine.weblounge.dispatcher.SiteDispatcherService#addSite(ch.entwine.weblounge.common.site.Site, * org.osgi.framework.ServiceReference) */ void addSite(Site site, ServiceReference reference) { synchronized (sites) { sites.add(site); siteBundles.put(site, reference.getBundle()); // Make sure we have an environment Environment env = environment; if (env == null) { logger.warn("No environment has been defined. Assuming '{}'", Environment.Production.toString().toLowerCase()); env = Environment.Production; } // Register the site urls and make sure we don't double book try { site.initialize(env); } catch (Throwable t) { logger.error("Error loading site '{}': {}", site.getIdentifier(), t.getMessage()); return; } for (SiteURL url : site.getHostnames()) { if (!env.equals(url.getEnvironment())) continue; String hostName = url.getURL().getHost(); Site registeredFirst = sitesByServerName.get(hostName); if (registeredFirst != null && !site.equals(registeredFirst)) { // Maybe a wildcard site has taken too many urls. Make sure concrete // sites are able to take over boolean replace = false; for (SiteURL siteUrl : registeredFirst.getHostnames()) { if (siteUrl.toExternalForm().contains("*")) { try { // convert the host wildcard (ex. *.domain.tld) to a valid regex // (ex. // .*\.domain\.tld) String registeredAlias = siteUrl.getURL().getHost().replace(".", "\\."); registeredAlias = registeredAlias.replace("*", ".*"); if (hostName.matches(registeredAlias)) { logger.info("Replacing wildcard registration for {} with exact match '{}'", url, site); replace = true; break; } } catch (PatternSyntaxException ex) { logger.warn("Error while trying to find a host wildcard match: " .concat(ex.getMessage())); } } } // This is a real conflict if (!replace) { logger.error("Another site is already registered to {}. Site is not registered", url); continue; } } logger.info("Site '{}' will be reachable on host {}", site.getIdentifier(), hostName); sitesByServerName.put(hostName, site); } } logger.debug("Site '{}' registered", site); // Look for content repositories ContentRepository repository = repositoriesBySite.get(site.getIdentifier()); if (repository != null && site.getContentRepository() == null) { try { repository.connect(site); site.setContentRepository(repository); logger.info("Site '{}' connected to content repository at {}", site, repository); } catch (ContentRepositoryException e) { logger.warn("Error connecting content repository " + repository + " to site '" + site + "'", e); } } else { try { Configuration config = configurationAdmin .createFactoryConfiguration("ch.entwine.weblounge.contentrepository.factory", null); Dictionary<Object, Object> properties = new Hashtable<Object, Object>(); properties.put(Site.class.getName().toLowerCase(), site.getIdentifier()); for (String name : site.getOptionNames()) { String[] values = site.getOptionValues(name); if (values.length == 1) { properties.put(name, values[0]); } else { properties.put(name, values); } } config.update(properties); repositoryConfigurations.put(site.getIdentifier(), config); } catch (IOException e) { logger.error("Unable to create configuration for content repository of site '" + site + "'", e); } } // Inform site listeners synchronized (listeners) { for (SiteServiceListener listener : listeners) { try { listener.siteAppeared(site, reference); } catch (Throwable t) { logger.error("Error during notifaction of site '{}': {}", site.getIdentifier(), t.getMessage()); return; } } } // Start the site if (site.isStartedAutomatically()) { try { logger.debug("Starting site '{}'", site); // TODO: Make sure there is a *running* content repository for this site // Alternatively, have the site implementation use a reference to the // repository and start itself once the repository switches to "running" // state (requires a repository listener) site.start(); } catch (IllegalStateException e) { logger.error("Site '{}' could not be started: {}", e.getMessage(), e); } catch (SiteException e) { logger.error("Site '{}' could not be started: {}", e.getMessage(), e); } } }
From source file:org.apache.servicemix.jbi.deployer.impl.Deployer.java
public SharedLibraryImpl registerSharedLibrary(Bundle bundle, SharedLibraryDesc sharedLibraryDesc, ClassLoader classLoader) throws Exception { // Create shared library SharedLibraryImpl sl = new SharedLibraryImpl(bundle, sharedLibraryDesc, classLoader); sharedLibraries.put(sl.getName(), sl); Dictionary<String, String> props = new Hashtable<String, String>(); // populate props from the library meta-data props.put(NAME, sharedLibraryDesc.getIdentification().getName()); LOGGER.debug("Registering JBI Shared Library"); registerService(bundle, SharedLibrary.class.getName(), sl, props); getManagementStrategy().manageObject(sl); // Check pending bundles checkPendingInstallers();/*from w w w .java 2 s .com*/ return sl; }
From source file:net.cellar.hazelcast.HazelcastGroupManager.java
/** * Copies the setup of a {@link Group}./*from w w w . ja va 2 s . c o m*/ * * @param sourceGroupName * @param targetGroupName */ public void copyGroupConfiguration(String sourceGroupName, String targetGroupName) { try { Configuration conf = configurationAdmin.getConfiguration(Configurations.GROUP); Dictionary dictionary = conf.getProperties(); Dictionary updatedProperties = new Properties(); Enumeration keyEnumeration = dictionary.keys(); while (keyEnumeration.hasMoreElements()) { String key = (String) keyEnumeration.nextElement(); String value = (String) dictionary.get(key); if (key.startsWith(sourceGroupName)) { String newKey = key.replace(sourceGroupName, targetGroupName); updatedProperties.put(newKey, value); } updatedProperties.put(key, value); } conf.update(updatedProperties); } catch (IOException e) { logger.error("Error reading group configuration ", e); } }
From source file:org.paxle.core.filter.impl.FilterManager.java
/** * Registering a new {@link IFilter}/*from w w w .j a v a 2 s. co m*/ * @param filterContext the context-object for the {@link IFilter} */ @SuppressWarnings("unchecked") public synchronized void addFilter(FilterContext filterContext) { if (filterContext == null) throw new NullPointerException("The filtercontext is null"); final String queueID = filterContext.getTargetID(); final String filterPID = filterContext.getFilterPID(); final String filterContextPID = filterContext.getFilterContextPID(); final boolean enabledPerDefault = filterContext.isEnabled(); try { /* disable context for now */ filterContext.setEnabled(false); /* * Getting the registered-filter-list of the target * and add the new filter to it */ final Set<FilterContext> knownFilters = this.getRegisteredFilters(queueID); knownFilters.add(filterContext); /* * getting the enabled-filter-list * and add the new filter-to it (if newly installed) */ final Set<String> enabledFilters = this.getEnabledFilters(queueID); // check if we have detected a newly installed filter if (!this.knownFilterContexts.contains(filterContextPID)) { this.knownFilterContexts.add(filterContextPID); /* If newly installed filters should be enabled per default and * the filter-provider has not disabled the filter per default * we enable the filter now */ if (this.enableNewFilters.booleanValue() && enabledPerDefault) { // mark filter-context as enabled filterContext.setEnabled(true); // remember enabled filter in list enabledFilters.add(filterContextPID); // updating CM if needed Dictionary<String, Object> props = this.config.getProperties(); if (props.get(CM_FILTER_ENABLED_FILTERS + queueID) != null) { // we need to update the list props.put(CM_FILTER_ENABLED_FILTERS + queueID, enabledFilters.toArray(new String[enabledFilters.size()])); this.config.update(props); } } else { filterContext.setEnabled(false); } } else if (props.get(CM_FILTER_ENABLED_FILTERS + queueID) != null) { boolean enabled = enabledFilters.contains(filterContextPID); filterContext.setEnabled(enabled); } // if the queue is already registered pass the filters to it if (this.queues.containsKey(queueID)) { /* * passing the changed filter-list to the filter-queue */ IFilterQueue queue = this.getQueue(queueID); this.setFilters(queue, knownFilters, enabledFilters); } } catch (Throwable e) { this.logger.error(String.format("Unexpected '%s' while registering a new filter '%s' for queue '%s'.", e.getClass().getName(), filterPID, queueID)); } }
From source file:org.opencastproject.capture.impl.SchedulerImplTest.java
@Test public void callingRefreshBeforeUpdateDoesntCauseNullPointerException() throws IOException, ConfigurationException, InterruptedException { String[] times = createThreeCaptures(-20, 5, 20); File testfile = setupCaptureAgentTestCalendar("calendars/ThreeCaptures.ics", times); configurationManager.setItem(CaptureParameters.CAPTURE_SCHEDULE_REMOTE_ENDPOINT_URL, null); configurationManager.setItem(CaptureParameters.CAPTURE_SCHEDULE_CACHE_URL, testfile.getAbsolutePath()); Dictionary<String, String> dictionary = new Hashtable<String, String>(); dictionary.put(CaptureParameters.CAPTURE_SCHEDULE_CACHE_URL, testfile.getAbsolutePath()); configurationManager.updated(dictionary); schedulerImpl.setConfigService(configurationManager); schedulerImpl = new SchedulerImpl(schedulerProperties, configurationManager, captureAgentImpl); captureAgentImpl.setConfigService(configurationManager); schedulerImpl.setConfigService(configurationManager); }
From source file:org.codice.ddf.registry.source.configuration.SourceConfigurationHandler.java
/** * Finds all source configurations associated with the registry metacard creates/updates them with * the information in the metacards service bindings. This method will enable/disable * configurations if the right conditions are met but will never delete a configuration other than * for switching a configuration from enabled to disabled or vice-versa * * @param metacard Registry metacard with new service binding info * @param activationHint Flag indicating if the created/updated configuration should be activated. * Configuration activation is not determined solely on this field but in conjunction with * {@see setActivateConfigurations} and {@see setPreserveActiveConfigurations}. * @throws IOException/* w w w.j ava 2 s . c om*/ * @throws InvalidSyntaxException * @throws ParserException */ @SuppressWarnings("squid:S1149" /* Confined by underlying contract */) private synchronized void updateRegistryConfigurations(Metacard metacard, boolean activationHint) throws IOException, InvalidSyntaxException, ParserException { if (RegistryUtility.isIdentityNode(metacard)) { return; } boolean autoActivateConfigurations = activateConfigurations && (activationHint || !preserveActiveConfigurations); List<ServiceBindingType> bindingTypes = registryTypeHelper .getBindingTypes(metacardMarshaller.getRegistryPackageFromMetacard(metacard)); String registryId = RegistryUtility.getRegistryId(metacard); String configId = getDeconflictedConfigId(metacard.getTitle(), registryId); Map<String, Configuration> fpidToConfigurationMap = getCurrentConfigurations(registryId); String bindingTypeToActivate = ""; if (autoActivateConfigurations) { bindingTypeToActivate = getBindingTypeToActivate(bindingTypes); if (StringUtils.isNotEmpty(bindingTypeToActivate)) { String fPidToActivate = bindingTypeToFactoryPidMap.get(bindingTypeToActivate); activateDeactivateExistingConfiguration(fPidToActivate, fpidToConfigurationMap, bindingTypeToActivate); } } for (ServiceBindingType bindingType : bindingTypes) { Map<String, Object> slotMap = this.getServiceBindingProperties(bindingType); String factoryPidMask = (String) slotMap.get(BINDING_TYPE); if (factoryPidMask == null) { continue; } String factoryPid = bindingTypeToFactoryPidMap.get(factoryPidMask); if (StringUtils.isBlank(factoryPid)) { continue; } Configuration curConfig = findOrCreateConfig(factoryPid, fpidToConfigurationMap, factoryPidMask, (autoActivateConfigurations && factoryPidMask.equals(bindingTypeToActivate))); DictionaryMap<String, Object> serviceConfigurationProperties = new DictionaryMap<>(); if (fpidToConfigurationMap.containsKey( curConfig.getFactoryPid().concat(getConfigStringProperty(curConfig, BINDING_TYPE)))) { serviceConfigurationProperties.putAll(getConfigurationsFromDictionary(curConfig.getProperties())); } else { serviceConfigurationProperties.putAll(getMetatypeDefaults(factoryPid)); } serviceConfigurationProperties.putAll(slotMap); serviceConfigurationProperties.put(ID, configId); serviceConfigurationProperties.put(SHORTNAME, configId); serviceConfigurationProperties.put(RegistryConstants.CONFIGURATION_REGISTRY_ID_PROPERTY, registryId); curConfig.update(serviceConfigurationProperties); LOGGER.debug("Updating source configuration {} with registry-id {}", configId, registryId); fpidToConfigurationMap.remove(curConfig.getFactoryPid().concat(factoryPidMask)); } // if a binding was removed the configuration could still exist, If the registry // entry gets renamed the non-binding configs will not get renamed appropriately so we // go through them here and make sure the name is set correctly. fpidToConfigurationMap.values().stream().forEach(config -> { try { Dictionary<String, Object> properties = config.getProperties(); properties.put(ID, configId); properties.put(SHORTNAME, configId); config.update(properties); } catch (IOException e) { LOGGER.debug("Could not remove configuration for {}:{}", config.getProperties().get(ID), config.getFactoryPid()); } }); }