List of usage examples for java.util Dictionary get
public abstract V get(Object key);
From source file:org.apache.axis2.osgi.deployment.ServiceRegistry.java
/** * When a bundle is started this method will look for xml files that suffix with "services.xml". * Thus, a given bundle can have n number of *services.xml. * Ex: my1services.xml and my2_services.xml. * <p/>/*from ww w . jav a 2 s .c o m*/ * Due to security consideration, if one *services.xml fail, all the services will treated as fail. * * @param bundle registered bundle */ private void addServices(Bundle bundle) { if (!resolvedBundles.containsKey(bundle)) { Enumeration enumeration = bundle.findEntries("META-INF", "*services.xml", false); int i = 0; List<AxisServiceGroup> axisServiceGroupList = null; if (enumeration != null) { axisServiceGroupList = new ArrayList<AxisServiceGroup>(); } while (enumeration != null && enumeration.hasMoreElements()) { try { URL url = (URL) enumeration.nextElement(); AxisServiceGroup serviceGroup = new AxisServiceGroup(configCtx.getAxisConfiguration()); serviceGroup.addParameter("last.updated", bundle.getLastModified()); ClassLoader loader = new BundleClassLoader(bundle, Registry.class.getClassLoader()); serviceGroup.setServiceGroupClassLoader(loader); InputStream inputStream = url.openStream(); DescriptionBuilder builder = new DescriptionBuilder(inputStream, configCtx); OMElement rootElement = builder.buildOM(); String elementName = rootElement.getLocalName(); Dictionary headers = bundle.getHeaders(); String bundleSymbolicName = (String) headers.get("Bundle-SymbolicName"); bundleSymbolicName = bundleSymbolicName + "_" + i; serviceGroup.setServiceGroupName(bundleSymbolicName); HashMap wsdlServicesMap = new HashMap(); if (DeploymentConstants.TAG_SERVICE.equals(elementName)) { AxisService axisService = new AxisService(bundleSymbolicName); axisService.setParent(serviceGroup); axisService.setClassLoader(loader); ServiceBuilder serviceBuilder = new OSGiServiceBuilder(configCtx, axisService); serviceBuilder.setWsdlServiceMap(wsdlServicesMap); AxisService service = serviceBuilder.populateService(rootElement); ArrayList<AxisService> serviceList = new ArrayList<AxisService>(); serviceList.add(service); DeploymentEngine.addServiceGroup(serviceGroup, serviceList, null, null, configCtx.getAxisConfiguration()); log.info("[Axis2/OSGi] Deployed axis2 service:" + service.getName() + " in Bundle: " + bundle.getSymbolicName()); } else if (DeploymentConstants.TAG_SERVICE_GROUP.equals(elementName)) { ServiceGroupBuilder groupBuilder = new OSGiServiceGroupBuilder(rootElement, wsdlServicesMap, configCtx); ArrayList serviceList = groupBuilder.populateServiceGroup(serviceGroup); DeploymentEngine.addServiceGroup(serviceGroup, serviceList, null, null, configCtx.getAxisConfiguration()); log.info("[Axis2/OSGi] Deployed axis2 service group:" + serviceGroup.getServiceGroupName() + " in Bundle: " + bundle.getSymbolicName()); } //bundle Id keeps the association between bundle and axisService group for later use serviceGroup.addParameter(OSGi_BUNDLE_ID, bundle.getBundleId()); axisServiceGroupList.add(serviceGroup); //marked as resolved. if (unreslovedBundles.contains(bundle)) { unreslovedBundles.remove(bundle); } i++; } catch (Throwable e) { String msg = "Error while reading from the bundle"; if (e instanceof DeploymentException) { String message = e.getMessage(); if (message != null && message.length() != 0) { if (message.indexOf(MODULE_NOT_FOUND_ERROR) > -1) { if (!unreslovedBundles.contains(bundle)) { log.info("A service being found with unmeant module " + "dependency. Hence, moved it to UNRESOLVED state."); unreslovedBundles.add(bundle); } else { log.info("A service being found in UNRESOLVED state."); } } else { log.error(msg, e); break; } } else { log.error(msg, e); break; } } else { log.error(msg, e); break; } } } if (axisServiceGroupList != null && axisServiceGroupList.size() > 0) { resolvedBundles.put(bundle, axisServiceGroupList); } } }
From source file:org.fourthline.cling.osgi.test.integration.InitialIntegrationTest.java
private UPnPDevice findUPnPTestDevice() { String string = String.format("(%s=%s)", UPnPDevice.TYPE, DEVICE_TYPE); UPnPDevice dev = getOsgiService(UPnPDevice.class, string, 2000); assertNotNull(dev);/*from ww w . jav a2 s . c o m*/ Dictionary props = dev.getDescriptions(Locale.getDefault().toString()); assertEquals(props.get(UPnPDevice.TYPE), DEVICE_TYPE); return dev; }
From source file:org.openhab.action.googletts.internal.GoogleTTSActionService.java
/** * @{inheritDoc/* w ww .j a v a2s .c o m*/ */ @Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { if (config != null) { // set language code (default: LANG_US_ENGLISH) LanguageCode languageCode = LanguageCode.LANG_US_ENGLISH; String languagecodeStr = (String) config.get("languagecode"); if (StringUtils.isNotBlank(languagecodeStr)) { LanguageCode configuredLanguageCode = LanguageCode.fromString(languagecodeStr); if (languageCode != null) { languageCode = configuredLanguageCode; } else { logger.error("Languagecode not valid."); } } // create instance of StringToMP3Converter to use for TTS StringToMP3Converter stringToMP3Converter = new StringToMP3Converter(languageCode); GoogleTTS.stringToMP3Converter = stringToMP3Converter; isProperlyConfigured = true; } }
From source file:org.openhab.binding.neohub.internal.NeoHubBinding.java
/** * {@inheritDoc}/*from w ww.j a v a 2 s.co m*/ */ @Override public void updated(final Dictionary<String, ?> config) throws ConfigurationException { if (config != null) { final String refreshIntervalString = (String) config.get("refresh"); if (StringUtils.isNotBlank(refreshIntervalString)) { try { refreshInterval = Long.parseLong(refreshIntervalString); } catch (NumberFormatException e) { throw new ConfigurationException("refresh", String.format("Provided value (%s) cannot be parsed to an long integer.", port)); } } final String host = (String) config.get("hostname"); if (StringUtils.isNotBlank(host)) { this.hostname = host; } else { throw new ConfigurationException("hostname", "Required configuration parameter is not set."); } final String port = (String) config.get("port"); if (StringUtils.isNotBlank(port)) { try { this.port = Integer.parseInt(port); } catch (NumberFormatException e) { throw new ConfigurationException("port", String.format("Provided value (%s) cannot be parsed to an integer.", port)); } } setProperlyConfigured(true); } }
From source file:org.apache.axis2.osgi.deployment.ModuleRegistry.java
/** * When the bundle is activated, this method will look for xml files that ends with "module.xml". * Thus, a given bundle can have n number of Axis2 modules with differen names suffixed with module.xml. * Ex: rampart_module.xml; rahas_module.xml addressingmodule.xml * <p/>/*from w w w.j a v a 2s .c o m*/ * <p/> * If there are n number of *module.xml and out of which failed modules will be ignored and and all the * successful *module.xml files will use to crate the proper AxisModule. It is utmost important that * that if n number of *module.xml files are present, module should be give a proper name. * * @param bundle started bundle */ private void addModules(Bundle bundle) { if (!resolvedBundles.containsKey(bundle)) { Enumeration enumeration = bundle.findEntries("META-INF", "*module.xml", false); List<AxisModule> moduleList = null; if (enumeration != null) { moduleList = new ArrayList<AxisModule>(); } while (enumeration != null && enumeration.hasMoreElements()) { try { URL url = (URL) enumeration.nextElement(); AxisModule axismodule = new AxisModule(); ClassLoader loader = new BundleClassLoader(bundle, Registry.class.getClassLoader()); axismodule.setModuleClassLoader(loader); AxisConfiguration axisConfig = configCtx.getAxisConfiguration(); ModuleBuilder builder = new ModuleBuilder(url.openStream(), axismodule, axisConfig); Dictionary headers = bundle.getHeaders(); String bundleSymbolicName = (String) headers.get("Bundle-SymbolicName"); if (bundleSymbolicName != null && bundleSymbolicName.length() != 0) { axismodule.setName(bundleSymbolicName); } String bundleVersion = (String) headers.get("Bundle-Version"); if (bundleVersion != null && bundleVersion.length() != 0) { /* Bundle version is defined as version ::= major( '.' minor ( '.' micro ( '.' qualifier )? )? )? major ::= number minor ::= number micro ::= number qualifier ::= ( alphanum | _ | '-' )+ */ String[] versionSplit = bundleVersion.split("\\."); int[] components = new int[Math.min(versionSplit.length, 3)]; for (int i = 0; i < components.length; i++) { components[i] = Integer.parseInt(versionSplit[i]); } axismodule.setVersion( new Version(components, versionSplit.length > 3 ? versionSplit[3] : null)); } builder.populateModule(); axismodule.setParent(axisConfig); AxisModule module = axisConfig.getModule(axismodule.getName()); if (module == null) { DeploymentEngine.addNewModule(axismodule, axisConfig); //initialze the module if the module contains Module interface. Module moduleObj = axismodule.getModule(); if (moduleObj != null) { moduleObj.init(configCtx, axismodule); } moduleList.add(axismodule); log.info("[Axis2/OSGi] Starting any modules in Bundle - " + bundle.getSymbolicName() + " - Module Name : " + axismodule.getName() + " - Module Version : " + axismodule.getVersion()); } else { log.info("[ModuleRegistry] Module : " + axismodule.getName() + " is already available."); } // set in default map if necessary Utils.calculateDefaultModuleVersion(axisConfig.getModules(), axisConfig); serviceRegistry.resolve(); } catch (IOException e) { String msg = "Error while reading module.xml"; log.error(msg, e); } } if (moduleList != null && moduleList.size() > 0) { resolvedBundles.put(bundle, moduleList); } } }
From source file:org.openhab.binding.asterisk.internal.AsteriskBinding.java
/** * {@inheritDoc}//from ww w . j ava2 s . c o m */ @SuppressWarnings("rawtypes") public void updated(Dictionary config) throws ConfigurationException { if (config != null) { disconnect(); AsteriskBinding.host = (String) config.get("host"); AsteriskBinding.username = (String) config.get("username"); AsteriskBinding.password = (String) config.get("password"); if (StringUtils.isNotBlank(AsteriskBinding.host) && StringUtils.isNotBlank(AsteriskBinding.username)) { connect(AsteriskBinding.host, AsteriskBinding.username, AsteriskBinding.password); } else { logger.warn( "cannot connect to asterisk manager interface because of missing " + "parameters (host={}, username={})", AsteriskBinding.host, AsteriskBinding.username); } } }
From source file:com.adobe.acs.commons.wcm.impl.AemEnvironmentIndicatorFilter.java
@Activate @SuppressWarnings("squid:S1149") protected final void activate(ComponentContext ctx) { Dictionary<?, ?> config = ctx.getProperties(); color = PropertiesUtil.toString(config.get(PROP_COLOR), ""); cssOverride = PropertiesUtil.toString(config.get(PROP_CSS_OVERRIDE), ""); innerHTML = PropertiesUtil.toString(config.get(PROP_INNER_HTML), ""); innerHTML = new StrSubstitutor(StrLookup.systemPropertiesLookup()).replace(innerHTML); // Only write CSS variable if cssOverride or color is provided if (StringUtils.isNotBlank(cssOverride)) { css = cssOverride;/*from ww w. j a v a 2 s. co m*/ } else if (StringUtils.isNotBlank(color)) { css = createCss(color); } titlePrefix = xss.encodeForJSString(PropertiesUtil.toString(config.get(PROP_TITLE_PREFIX), "").toString()); if (StringUtils.isNotBlank(css) || StringUtils.isNotBlank(titlePrefix)) { Dictionary<String, String> filterProps = new Hashtable<String, String>(); filterProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_PATTERN, "/"); filterProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT, "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=*)"); filterRegistration = ctx.getBundleContext().registerService(Filter.class.getName(), this, filterProps); } excludedWCMModes = PropertiesUtil.toStringArray(config.get(PROP_EXCLUDED_WCMMODES), DEFAULT_EXCLUDED_WCMMODES); }
From source file:org.opencastproject.kernel.scanner.AbstractBufferScanner.java
@SuppressWarnings("rawtypes") public void updated(Dictionary properties) throws ConfigurationException { String cronExpression;//from w w w . j a va2 s . c om boolean enabled; unschedule(); if (properties != null) { logger.debug("Updating configuration..."); enabled = BooleanUtils.toBoolean((String) properties.get(PARAM_KEY_ENABLED)); setEnabled(enabled); logger.debug("enabled = " + enabled); cronExpression = (String) properties.get(PARAM_KEY_CRON_EXPR); if (StringUtils.isBlank(cronExpression) || !CronExpression.isValidExpression(cronExpression)) throw new ConfigurationException(PARAM_KEY_CRON_EXPR, "Cron expression must be valid"); setCronExpression(cronExpression); logger.debug("cronExpression = '" + cronExpression + "'"); try { buffer = Long.valueOf((String) properties.get(PARAM_KEY_BUFFER)); if (buffer < 0) { throw new ConfigurationException(PARAM_KEY_BUFFER, "Buffer must be 0 or greater"); } } catch (NumberFormatException e) { throw new ConfigurationException(PARAM_KEY_BUFFER, "Buffer must be a valid integer", e); } logger.debug("buffer = " + buffer); } schedule(); }
From source file:org.apache.sling.auth.xing.oauth.impl.XingOauthAuthenticationHandler.java
protected synchronized void configure(final ComponentContext componentContext) { final Dictionary properties = componentContext.getProperties(); consumerKey = PropertiesUtil.toString(properties.get(CONSUMER_KEY_PARAMETER), "").trim(); consumerSecret = PropertiesUtil.toString(properties.get(CONSUMER_SECRET_PARAMETER), "").trim(); callbackUrl = PropertiesUtil.toString(properties.get(CALLBACK_URL_PARAMETER), "").trim(); usersMeUrl = PropertiesUtil.toString(properties.get(USERS_ME_URL_PARAMETER), DEFAULT_USERS_ME_URL).trim(); if (StringUtils.isEmpty(consumerKey)) { logger.warn("configured consumer key is empty"); }// w ww. jav a2s. c om if (StringUtils.isEmpty(consumerSecret)) { logger.warn("configured consumer secret is empty"); } if (StringUtils.isEmpty(callbackUrl)) { logger.warn("configured callback URL is empty"); } if (StringUtils.isEmpty(usersMeUrl)) { logger.warn("configured users me URL is empty"); } if (!StringUtils.isEmpty(consumerKey) && !StringUtils.isEmpty(consumerSecret) && !StringUtils.isEmpty(callbackUrl)) { oAuthService = new ServiceBuilder().provider(XingApi.class).apiKey(consumerKey) .apiSecret(consumerSecret).callback(callbackUrl).build(); } else { oAuthService = null; } logger.info("configured with consumer key '{}', callback url '{}' and users me url '{}'", consumerKey, callbackUrl, usersMeUrl); }
From source file:org.millr.slick.impl.services.OsgiServiceImpl.java
public String getStringProperty(final String pid, final String property, final String defaultValue) { try {/* w w w . j a v a2s . c om*/ Configuration conf = configAdmin.getConfiguration(pid); @SuppressWarnings("unchecked") Dictionary<String, Object> props = conf.getProperties(); if (props != null) { return PropertiesUtil.toString(props.get(property), defaultValue); } } catch (IOException e) { LOGGER.error("Could not get property", e); } return defaultValue; }