List of usage examples for java.util Dictionary get
public abstract V get(Object key);
From source file:org.openhab.binding.mpd.internal.MpdBinding.java
@SuppressWarnings("rawtypes") public void updated(Dictionary config) throws ConfigurationException { if (config != null) { disconnectPlayersAndMonitors();/* w w w .ja va 2 s .c o m*/ cancelScheduler(); Enumeration 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; } Matcher matcher = EXTRACT_PLAYER_CONFIG_PATTERN.matcher(key); if (!matcher.matches()) { logger.debug("given mpd player-config-key '" + key + "' does not follow the expected pattern '<playername>.<host|port>'"); continue; } matcher.reset(); matcher.find(); String playerId = matcher.group(1); MpdPlayerConfig playerConfig = playerConfigCache.get(playerId); if (playerConfig == null) { playerConfig = new MpdPlayerConfig(); playerConfigCache.put(playerId, playerConfig); } String configKey = matcher.group(2); String value = (String) config.get(key); if ("host".equals(configKey)) { playerConfig.host = value; } else if ("port".equals(configKey)) { playerConfig.port = Integer.valueOf(value); } else if ("password".equals(configKey)) { playerConfig.password = value; } else { throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown"); } } connectAllPlayersAndMonitors(); scheduleReconnect(); } }
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); }//w w w . j ava 2 s .co 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.energy_home.jemma.ah.internal.hac.lib.HacService.java
public Vector browseAppliances(int key_type, String key_value) { synchronized (lockHacService) { Vector result = new Vector(); LOG.debug("called browseDevices"); IManagedAppliance d = null;/* ww w .ja v a 2 s . com*/ if (key_type == IAppliance.APPLIANCE_TYPE_PROPERTY_KEY) { if (key_value.compareTo("") == 0) { // return the list of devices as it is! return appliances; } Iterator it = appliances.iterator(); while (it.hasNext()) { d = (IManagedAppliance) it.next(); if ((d.getDescriptor().getType() != null) && (d.getDescriptor().getType().compareTo(key_value) == 0)) { result.add(d); } } } else if (key_type == IAppliance.APPLIANCE_LOCATION_PID_PROPERTY_KEY) { // returns the list of devices at the specific location if (key_value.compareTo("") == 0) { return appliances; } Iterator it = appliances.iterator(); while (it.hasNext()) { d = (IManagedAppliance) it.next(); if (d != null) { String locationPid = (String) d.getConfiguration() .get(IAppliance.APPLIANCE_LOCATION_PID_PROPERTY); if (locationPid != null && locationPid.equals(key_value)) result.add(d); } } } else if (key_type == IAppliance.APPLIANCE_CATEGORY_PID_PROPERTY_KEY) { // returns the list of devices at the specific location if (key_value.compareTo("") == 0) { return appliances; } Iterator it = appliances.iterator(); while (it.hasNext()) { d = (IManagedAppliance) it.next(); if (d != null) { String categoryPid = (String) d.getConfiguration() .get(IAppliance.APPLIANCE_CATEGORY_PID_PROPERTY); if (categoryPid != null && categoryPid.equals(key_value)) result.add(d); } } } else if (key_type == IAppliance.APPLIANCE_NAME_PROPERTY_KEY) { // returns the list of devices at the specific location if (key_value.compareTo("") == 0) { return appliances; } Iterator it = appliances.iterator(); while (it.hasNext()) { d = (IManagedAppliance) it.next(); if (d != null) { Dictionary c = d.getConfiguration(); String name = (String) c.get(IAppliance.APPLIANCE_NAME_PROPERTY); if (name != null && name.equals(key_value)) result.add(d); } } } else if (key_type == IAppliance.APPLIANCE_PID_PROPERTY_KEY) { IAppliance appliance = (IAppliance) this.pid2appliance.get(key_value); if (appliance != null) result.add(appliance); } return result; } }
From source file:it.txt.ens.client.subscriber.printer.osgi.Activator.java
@Override public void start(final BundleContext context) throws Exception { if (LOGGER.isLoggable(Level.INFO)) { LOGGER.log(Level.INFO,// w w w.j a va2 s . c o m "[ENS Subscriber - Event printer example] Bundle ID: " + context.getBundle().getBundleId()); } //retrieve the configuration admin service ServiceReference<ConfigurationAdmin> configAdminSR = context.getServiceReference(ConfigurationAdmin.class); if (configAdminSR == null) throw new Exception("No " + ConfigurationAdmin.class.getName() + " available"); ConfigurationAdmin configAdmin = context.getService(configAdminSR); File currentPropertiesFile; Properties currentProperties; Configuration config; FileInputStream stream = null; Dictionary<String, Object> configuration; int i = 1; while ((currentPropertiesFile = new File(DEFAULT_CONFIG_DIR + String.format(PROPERTY_NAME_FORMAT, i++))) .exists()) { currentProperties = new Properties(); try { stream = new FileInputStream(currentPropertiesFile); currentProperties.load(stream); config = configAdmin.createFactoryConfiguration( RegisteredServices.SUBSCRIBER_MANAGED_SERVICE_FACTORY_PID, null); } catch (IOException e) { LOGGER.log(Level.WARNING, MessageFormat.format(LOGGING_MESSAGES.getString("errorWhileReadingPropertiesFile"), currentPropertiesFile.getAbsolutePath()), e); continue; } finally { if (stream != null) try { stream.close(); } catch (Exception e) { } } configuration = MapConverter.convert(currentProperties); configuration.put(it.txt.ens.client.subscriber.osgi.FilterAttributes.SUBSCRIBER_OWNER_KEY, (Long) context.getBundle().getBundleId()); configuration.put(it.txt.ens.client.subscriber.osgi.FilterAttributes.SUBSCRIBER_IMPLEMENTATION_KEY, SUBSCRIBER_IMPLEMENTATION_ID); config.update(configuration); Object patternOBJ = configuration.get(ENSResourceFactory.PATTERN); String pattern; String namespace; if (patternOBJ == null) { Object resourceOBJ = configuration.get(ENSResourceFactory.URI); if (resourceOBJ == null) throw new ConfigurationException(ENSResourceFactory.URI, "Missing property"); else { ServiceReference<ENSResourceFactory> resourceFactorySR = context .getServiceReference(ENSResourceFactory.class); ENSResourceFactory resourceFactory = context.getService(resourceFactorySR); ENSResource resource; try { resource = resourceFactory.create(new URI(resourceOBJ.toString())); pattern = resource.getPattern(); namespace = resource.getNamespace(); } catch (IllegalArgumentException e) { throw new ConfigurationException(ENSResourceFactory.URI, e.getMessage(), e); } catch (URIParseException e) { throw new ConfigurationException(ENSResourceFactory.URI, e.getMessage(), e); } catch (URISyntaxException e) { throw new ConfigurationException(ENSResourceFactory.URI, e.getMessage(), e); } context.ungetService(resourceFactorySR); } } else { pattern = (String) patternOBJ; namespace = (String) configuration.get(ENSResourceFactory.NAMESPACE); } //this doesn't work because the escape doesn't work // EqualsFilter implementationFilter = new EqualsFilter( // it.txt.ens.client.subscriber.osgi.FilterAttributes.SUBSCRIBER_IMPLEMENTATION_KEY, // LdapEncoder.filterEncode(SUBSCRIBER_IMPLEMENTATION_ID)); // EqualsFilter ownershipFilter = new EqualsFilter( // it.txt.ens.client.subscriber.osgi.FilterAttributes.SUBSCRIBER_OWNER_KEY, // (int) context.getBundle().getBundleId()); // EqualsFilter patternFilter = new EqualsFilter(ENSResourceFactory.PATTERN,LdapEncoder.filterEncode(pattern)); // AndFilter filter = new AndFilter().and(implementationFilter).and(ownershipFilter).and(patternFilter); // Filter osgiFilter = FrameworkUtil.createFilter(filter.toString()); try { filters.put(new SubscriberFilter(SUBSCRIBER_IMPLEMENTATION_ID, context.getBundle().getBundleId(), namespace, pattern)); // } catch (InvalidSyntaxException e) { // throw new ConfigurationException(null, "An error occurred while tracking subscription services using filter " + // osgiFilter.toString(), e); } catch (InterruptedException e) { continue; } } tracker = new ConfiguredSubscriberTracker(context); tracker.start(); }
From source file:org.apache.geronimo.console.bundlemanager.BundleManagerPortlet.java
protected void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException { if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) { // minimal view return;/*from www . ja v a 2 s. co m*/ } else { // normal and maximal view String page = renderRequest.getParameter("page"); if (FIND_PACKAGES_PAGE.equals(page)) { BundleContext bundleContext = getBundleContext(renderRequest); ServiceReference reference = bundleContext.getServiceReference(PackageAdmin.class.getName()); PackageAdmin packageAdmin = (PackageAdmin) bundleContext.getService(reference); String packageString = renderRequest.getParameter("packageStringValue"); Map<PackageInfo, List<BundleInfo>> packageExportBundles = new HashMap<PackageInfo, List<BundleInfo>>(); Map<PackageInfo, List<BundleInfo>> packageImportBundles = new HashMap<PackageInfo, List<BundleInfo>>(); for (Bundle bundle : bundleContext.getBundles()) { ExportedPackage[] exportedPackages = packageAdmin.getExportedPackages(bundle); if (exportedPackages != null) { // construct the export bundle info BundleInfo exportBundleInfo = new SimpleBundleInfo(bundle); for (ExportedPackage exportedPackage : exportedPackages) { // filter by keyword and ignore case. if the keyword is null, then return all the packages if (packageString == null || exportedPackage.getName().toLowerCase() .indexOf(packageString.trim().toLowerCase()) != -1) { // construct the package info // fill in its export bundle PackageInfo packageInfo = new PackageInfo(exportedPackage.getName(), exportedPackage.getVersion().toString()); fillPackageBundlesMap(packageExportBundles, packageInfo, exportBundleInfo); Bundle[] importingBundles = exportedPackage.getImportingBundles(); if (importingBundles != null) { for (Bundle importingBundle : importingBundles) { // construct the import bundle info // fill in its import bundle BundleInfo importBundleInfo = new SimpleBundleInfo(importingBundle); fillPackageBundlesMap(packageImportBundles, packageInfo, importBundleInfo); } } } } } } List<PackageWiredBundles> packageWiredBundlesList = new ArrayList<PackageWiredBundles>(); BundleSymbolicComparator bsc = new BundleSymbolicComparator(); for (Entry<PackageInfo, List<BundleInfo>> entry : packageExportBundles.entrySet()) { PackageInfo pkg = entry.getKey(); List<BundleInfo> exportBundles = entry.getValue(); List<BundleInfo> importBundles = packageImportBundles.get(pkg) == null ? new ArrayList<BundleInfo>() : packageImportBundles.get(pkg); PackageWiredBundles pwb = new PackageWiredBundles(pkg, exportBundles, importBundles); pwb.sortBundleInfos(bsc); packageWiredBundlesList.add(pwb); } Collections.sort(packageWiredBundlesList); renderRequest.setAttribute("packageWiredBundlesList", packageWiredBundlesList); renderRequest.setAttribute("packageStringValue", packageString); findPackagesView.include(renderRequest, renderResponse); } else if (VIEW_MANIFEST_PAGE.equals(page)) { BundleContext bundleContext = getBundleContext(renderRequest); long id = Long.valueOf(renderRequest.getParameter("bundleId")); Bundle bundle = bundleContext.getBundle(id); List<ManifestHeader> manifestHeaders = new ArrayList<ManifestHeader>(); Dictionary<String, String> headers = bundle.getHeaders(); Enumeration<String> keys = headers.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); if (key.equals("Import-Package") || key.equals("Export-Package") || key.equals("Ignore-Package") || key.equals("Private-Package") || key.equals("Export-Service")) { manifestHeaders.add(new ManifestHeader(key, ManifestHeader.formatPackageHeader((String) headers.get(key)))); } else { manifestHeaders.add(new ManifestHeader(key, (String) headers.get(key))); } } SimpleBundleInfo bundleInfo = new SimpleBundleInfo(bundle); Collections.sort(manifestHeaders); renderRequest.setAttribute("manifestHeaders", manifestHeaders); renderRequest.setAttribute("bundleInfo", bundleInfo); showManifestView.include(renderRequest, renderResponse); } else if (VIEW_SERVICES_PAGE.equals(page)) { BundleContext bundleContext = getBundleContext(renderRequest); long id = Long.valueOf(renderRequest.getParameter("bundleId")); Bundle bundle = bundleContext.getBundle(id); // because this page should not be very complex ,so we only have a Service Perspective // if user wants 2 perspective like wired bundle page, we can extend this page to add a new Bundle Perspective. List<ServicePerspective> usingServicePerspectives = getUsingServicePerspectives(bundle); List<ServicePerspective> registeredServicePerspectives = getRegisteredServicePerspectives(bundle); Collections.sort(usingServicePerspectives); Collections.sort(registeredServicePerspectives); renderRequest.setAttribute("usingServicePerspectives", usingServicePerspectives); renderRequest.setAttribute("registeredServicePerspectives", registeredServicePerspectives); SimpleBundleInfo bundleInfo = new SimpleBundleInfo(bundle); renderRequest.setAttribute("bundleInfo", bundleInfo); showServicesView.include(renderRequest, renderResponse); } else if (VIEW_WIRED_BUNDLES_PAGE.equals(page)) { BundleContext bundleContext = getBundleContext(renderRequest); long id = Long.valueOf(renderRequest.getParameter("bundleId")); Bundle bundle = bundleContext.getBundle(id); String perspectiveType = renderRequest.getParameter("perspectiveTypeValue"); if (perspectiveType == null || perspectiveType == "") perspectiveType = "bundle"; //when we access this page with a renderURL, we need the default value ServiceReference reference = bundleContext.getServiceReference(PackageAdmin.class.getName()); PackageAdmin packageAdmin = (PackageAdmin) bundle.getBundleContext().getService(reference); Set<String> wiredPackages = new HashSet<String>(); Set<PackageBundlePair> importingPairs = getImportingPairs(packageAdmin, bundle, wiredPackages); Set<PackageBundlePair> dynamicImportingPairs = getDynamicImportingPairs(packageAdmin, bundle, wiredPackages); Set<PackageBundlePair> requireBundlesImportingPairs = getRequireBundlesImportingPairs(packageAdmin, bundle); Set<PackageBundlePair> exportingPairs = getExportingPairs(packageAdmin, bundle); if ("package".equals(perspectiveType)) { List<PackagePerspective> importingPackagePerspectives = getPackagePerspectives(importingPairs); List<PackagePerspective> dynamicImportingPackagePerspectives = getPackagePerspectives( dynamicImportingPairs); List<PackagePerspective> requireBundlesImportingPackagePerspectives = getPackagePerspectives( requireBundlesImportingPairs); List<PackagePerspective> exportingPackagePerspectives = getPackagePerspectives(exportingPairs); Collections.sort(importingPackagePerspectives); Collections.sort(dynamicImportingPackagePerspectives); Collections.sort(requireBundlesImportingPackagePerspectives); Collections.sort(exportingPackagePerspectives); renderRequest.setAttribute("importingPackagePerspectives", importingPackagePerspectives); renderRequest.setAttribute("dynamicImportingPackagePerspectives", dynamicImportingPackagePerspectives); renderRequest.setAttribute("requireBundlesImportingPackagePerspectives", requireBundlesImportingPackagePerspectives); renderRequest.setAttribute("exportingPackagePerspectives", exportingPackagePerspectives); } else { //"bundle".equals(perspectiveType)){ List<BundlePerspective> importingBundlePerspectives = getBundlePerspectives(importingPairs); List<BundlePerspective> dynamicImportingBundlePerspectives = getBundlePerspectives( dynamicImportingPairs); List<BundlePerspective> requireBundlesImportingBundlePerspectives = getBundlePerspectives( requireBundlesImportingPairs); List<BundlePerspective> exportingBundlePerspectives = getBundlePerspectives(exportingPairs); Collections.sort(importingBundlePerspectives); Collections.sort(dynamicImportingBundlePerspectives); Collections.sort(requireBundlesImportingBundlePerspectives); Collections.sort(exportingBundlePerspectives); renderRequest.setAttribute("importingBundlePerspectives", importingBundlePerspectives); renderRequest.setAttribute("dynamicImportingBundlePerspectives", dynamicImportingBundlePerspectives); renderRequest.setAttribute("requireBundlesImportingBundlePerspectives", requireBundlesImportingBundlePerspectives); renderRequest.setAttribute("exportingBundlePerspectives", exportingBundlePerspectives); } SimpleBundleInfo bundleInfo = new SimpleBundleInfo(bundle); renderRequest.setAttribute("bundleInfo", bundleInfo); renderRequest.setAttribute("perspectiveTypeValue", perspectiveType); showWiredBundlesView.include(renderRequest, renderResponse); } else { // main page String listType = renderRequest.getParameter("listTypeValue"); if (listType == null || listType == "") listType = "all"; //when we access this page with a renderURL, we need the default value String searchString = renderRequest.getParameter("searchStringValue"); if (searchString == null) searchString = ""; //when we access this page with a renderURL, we need the default value BundleContext bundleContext = getBundleContext(renderRequest); // retrieve bundle infos List<ExtendedBundleInfo> bundleInfos = new ArrayList<ExtendedBundleInfo>(); // get the StartLeval object ServiceReference startLevelRef = bundleContext .getServiceReference(StartLevel.class.getCanonicalName()); StartLevel startLevelService = (StartLevel) bundleContext.getService(startLevelRef); // get configured bundle Ids Set<Long> configurationBundleIds = getConfigurationBundleIds(); Bundle[] bundles = bundleContext.getBundles(); for (Bundle bundle : bundles) { if (searchString != "" && !matchBundle(bundle, searchString)) { continue; } // construct the result bundleInfos by listType if ("wab".equals(listType)) { if (checkWABBundle(bundle)) { ExtendedBundleInfo info = createExtendedBundleInfo(bundle, startLevelService, configurationBundleIds); info.addContextPath(getContextPath(bundle)); bundleInfos.add(info); } } else if ("blueprint".equals(listType)) { if (checkBlueprintBundle(bundle)) { ExtendedBundleInfo info = createExtendedBundleInfo(bundle, startLevelService, configurationBundleIds); // currently, we try get the the blueprintContainer service to determine if a blueprint bundle is created // TODO A better way is using a BlueprintListener to track all blueprint bundle events String filter = "(&(osgi.blueprint.container.symbolicname=" + bundle.getSymbolicName() + ")(osgi.blueprint.container.version=" + bundle.getVersion() + "))"; ServiceReference[] serviceReferences = null; try { serviceReferences = bundleContext .getServiceReferences(BlueprintContainer.class.getName(), filter); } catch (InvalidSyntaxException e) { throw new RuntimeException(e); } if (serviceReferences != null && serviceReferences.length > 0) { info.setBlueprintState(BlueprintState.CREATED); } bundleInfos.add(info); } } else if ("system".equals(listType)) { if (checkSysBundle(bundle, startLevelService)) { ExtendedBundleInfo info = createExtendedBundleInfo(bundle, startLevelService, configurationBundleIds); bundleInfos.add(info); } } else if ("configuration".equals(listType)) { if (checkConfigurationBundle(bundle, configurationBundleIds)) { ExtendedBundleInfo info = createExtendedBundleInfo(bundle, startLevelService, configurationBundleIds); bundleInfos.add(info); } } else { ExtendedBundleInfo info = createExtendedBundleInfo(bundle, startLevelService, configurationBundleIds); bundleInfos.add(info); } } Collections.sort(bundleInfos, new BundleIdDescComparator()); renderRequest.setAttribute("extendedBundleInfos", bundleInfos); // set the values to render attribute renderRequest.setAttribute("listTypeValue", listType); renderRequest.setAttribute("searchStringValue", searchString); renderRequest.setAttribute("initStartLevel", startLevelService.getInitialBundleStartLevel()); if (bundleInfos.size() == 0) { addWarningMessage(renderRequest, getLocalizedString(renderRequest, "consolebase.bundlemanager.warn.nobundlesfound")); } bundleManagerView.include(renderRequest, renderResponse); } } }
From source file:org.opencastproject.workflow.impl.WorkflowServiceImpl.java
/** * {@inheritDoc}/*from w w w .j a v a 2s . c o m*/ * * @see org.osgi.service.cm.ManagedService#updated(java.util.Dictionary) */ @Override @SuppressWarnings("rawtypes") public void updated(Dictionary properties) throws ConfigurationException { String maxConfiguration = StringUtils.trimToNull((String) properties.get(MAX_CONCURRENT_CONFIG_KEY)); if (maxConfiguration != null) { try { maxConcurrentWorkflows = Integer.parseInt(maxConfiguration); logger.info("Set maximum concurrent workflows to {}", maxConcurrentWorkflows); } catch (NumberFormatException e) { logger.warn("Can not set max concurrent workflows to {}. {} must be an integer", maxConfiguration, MAX_CONCURRENT_CONFIG_KEY); } } }
From source file:org.codice.ddf.ui.admin.api.ConfigurationAdminTest.java
private ConfigurationAdmin getConfigAdmin() throws IOException, InvalidSyntaxException { final BundleContext testBundleContext = mock(BundleContext.class); final MetaTypeService testMTS = mock(MetaTypeService.class); ConfigurationAdminExt configurationAdminExt = new ConfigurationAdminExt(CONFIGURATION_ADMIN) { @Override//from www .j a v a 2 s . c o m BundleContext getBundleContext() { return testBundleContext; } @Override MetaTypeService getMetaTypeService() { return testMTS; } }; ConfigurationAdmin configurationAdmin = new ConfigurationAdmin(CONFIGURATION_ADMIN, configurationAdminExt); Dictionary<String, Object> testProp = new Hashtable<>(); testProp.put(TEST_KEY, TEST_VALUE); when(testConfig.getPid()).thenReturn(TEST_PID); when(testConfig.getFactoryPid()).thenReturn(TEST_FACTORY_PID); when(testConfig.getBundleLocation()).thenReturn(TEST_LOCATION); when(testConfig.getProperties()).thenReturn(testProp); Bundle testBundle = mock(Bundle.class); Dictionary bundleHeaders = mock(Dictionary.class); MetaTypeInformation testMTI = mock(MetaTypeInformation.class); ObjectClassDefinition testOCD = mock(ObjectClassDefinition.class); ServiceReference testRef1 = mock(ServiceReference.class); ServiceReference[] testServRefs = { testRef1 }; ArrayList<AttributeDefinition> attDefs = new ArrayList<>(); for (int cardinality : CARDINALITIES) { for (TYPE type : TYPE.values()) { AttributeDefinition testAttDef = mock(AttributeDefinition.class); when(testAttDef.getCardinality()).thenReturn(cardinality); when(testAttDef.getType()).thenReturn(type.getType()); when(testAttDef.getID()).thenReturn(getKey(cardinality, type)); attDefs.add(testAttDef); } } when(testRef1.getProperty(Constants.SERVICE_PID)).thenReturn(TEST_PID); when(testRef1.getBundle()).thenReturn(testBundle); when(testBundle.getLocation()).thenReturn(TEST_LOCATION); when(testBundle.getHeaders(anyString())).thenReturn(bundleHeaders); when(bundleHeaders.get(Constants.BUNDLE_NAME)).thenReturn(TEST_BUNDLE_NAME); when(testOCD.getName()).thenReturn(TEST_OCD); when(testOCD.getAttributeDefinitions(ObjectClassDefinition.ALL)) .thenReturn(attDefs.toArray(new AttributeDefinition[attDefs.size()])); when(testMTI.getBundle()).thenReturn(testBundle); when(testMTI.getFactoryPids()).thenReturn(new String[] { TEST_FACTORY_PID }); when(testMTI.getPids()).thenReturn(new String[] { TEST_PID }); when(testMTI.getObjectClassDefinition(anyString(), anyString())).thenReturn(testOCD); when(testMTS.getMetaTypeInformation(testBundle)).thenReturn(testMTI); when(testBundleContext.getBundles()).thenReturn(new Bundle[] { testBundle }); when(CONFIGURATION_ADMIN.listConfigurations(anyString())).thenReturn(new Configuration[] { testConfig }); when(CONFIGURATION_ADMIN.getConfiguration(anyString(), anyString())).thenReturn(testConfig); when(testBundleContext.getAllServiceReferences(anyString(), anyString())).thenReturn(testServRefs); when(testBundleContext.getAllServiceReferences(anyString(), anyString())).thenReturn(testServRefs); return configurationAdmin; }
From source file:org.energy_home.jemma.ah.internal.greenathome.GreenathomeAppliance.java
public static Map convertToMap(Dictionary source) { Map sink = new HashMap(source.size()); for (Enumeration keys = source.keys(); keys.hasMoreElements();) { Object key = keys.nextElement(); sink.put(key, source.get(key)); }/*w w w . j av a2 s . c o m*/ return sink; }
From source file:org.codice.ddf.admin.core.impl.AdminConsoleServiceTest.java
private AdminConsoleService getConfigAdmin() throws IOException, InvalidSyntaxException, NotCompliantMBeanException { final BundleContext testBundleContext = mock(BundleContext.class); final MetaTypeService testMTS = mock(MetaTypeService.class); ConfigurationAdminImpl configurationAdminImpl = new ConfigurationAdminImpl(CONFIGURATION_ADMIN, new ArrayList<>()) { @Override//from w ww. j a va2 s . c o m BundleContext getBundleContext() { return testBundleContext; } @Override MetaTypeService getMetaTypeService() { return testMTS; } @Override public boolean isPermittedToViewService(String servicePid) { return true; } @Override public boolean isPermittedToViewService(String servicePid, Subject subject) { return true; } }; AdminConsoleService configurationAdmin = new AdminConsoleService(CONFIGURATION_ADMIN, configurationAdminImpl) { @Override public boolean isPermittedToViewService(String servicePid) { return true; } }; configurationAdmin.setGuestClaimsHandlerExt(mockGuestClaimsHandlerExt); Dictionary<String, Object> testProp = new Hashtable<>(); testProp.put(TEST_KEY, TEST_VALUE); when(testConfig.getPid()).thenReturn(TEST_PID); when(testConfig.getFactoryPid()).thenReturn(TEST_FACTORY_PID); when(testConfig.getBundleLocation()).thenReturn(TEST_LOCATION); when(testConfig.getProperties()).thenReturn(testProp); Bundle testBundle = mock(Bundle.class); Dictionary bundleHeaders = mock(Dictionary.class); MetaTypeInformation testMTI = mock(MetaTypeInformation.class); ObjectClassDefinition testOCD = mock(ObjectClassDefinition.class); ServiceReference testRef1 = mock(ServiceReference.class); ServiceReference[] testServRefs = { testRef1 }; ArrayList<AttributeDefinition> attDefs = new ArrayList<>(); for (int cardinality : CARDINALITIES) { for (AdminConsoleService.TYPE type : AdminConsoleService.TYPE.values()) { AttributeDefinition testAttDef = mock(AttributeDefinition.class); when(testAttDef.getCardinality()).thenReturn(cardinality); when(testAttDef.getType()).thenReturn(type.getType()); when(testAttDef.getID()).thenReturn(getKey(cardinality, type)); attDefs.add(testAttDef); } } when(testRef1.getProperty(Constants.SERVICE_PID)).thenReturn(TEST_PID); when(testRef1.getBundle()).thenReturn(testBundle); when(testBundle.getLocation()).thenReturn(TEST_LOCATION); when(testBundle.getHeaders(anyString())).thenReturn(bundleHeaders); when(bundleHeaders.get(Constants.BUNDLE_NAME)).thenReturn(TEST_BUNDLE_NAME); when(testOCD.getName()).thenReturn(TEST_OCD); when(testOCD.getAttributeDefinitions(ObjectClassDefinition.ALL)) .thenReturn(attDefs.toArray(new AttributeDefinition[attDefs.size()])); when(testMTI.getBundle()).thenReturn(testBundle); when(testMTI.getFactoryPids()).thenReturn(new String[] { TEST_FACTORY_PID }); when(testMTI.getPids()).thenReturn(new String[] { TEST_PID }); when(testMTI.getObjectClassDefinition(anyString(), anyString())).thenReturn(testOCD); when(testMTS.getMetaTypeInformation(testBundle)).thenReturn(testMTI); when(testBundleContext.getBundles()).thenReturn(new Bundle[] { testBundle }); when(CONFIGURATION_ADMIN.listConfigurations(anyString())).thenReturn(new Configuration[] { testConfig }); when(CONFIGURATION_ADMIN.getConfiguration(anyString(), anyString())).thenReturn(testConfig); when(testBundleContext.getAllServiceReferences(anyString(), anyString())).thenReturn(testServRefs); when(testBundleContext.getAllServiceReferences(anyString(), anyString())).thenReturn(testServRefs); return configurationAdmin; }
From source file:org.energy_home.jemma.ah.internal.hac.lib.HacService.java
public void installAppliance(String appliancePid, Dictionary props) throws HacException { synchronized (lockHacService) { IManagedAppliance appliance = (IManagedAppliance) this.pid2appliance.get(appliancePid); if (appliance == null) { throw new HacException("an appliance can be installed only if has been already created"); }/*w w w . j a va 2 s .c o m*/ if (!this.installingAppliances.contains(appliance)) { throw new HacException("an appliance can be installed only if has been already created"); } String factoryPid = (String) props.get(IAppliance.APPLIANCE_TYPE_PROPERTY); IApplianceFactory applianceFactory = this.getApplianceFactory(factoryPid); if (applianceFactory == null) { throw new HacException("unable to find a factory"); } try { Configuration c = this.getApplianceCAConfiguration(appliancePid); if (c == null) { c = this.configAdmin.createFactoryConfiguration(factoryPid, null); // FIXME: la seguente riga deve essere scommentata? // overwrite // any property service.pid // props.remove(Constants.SERVICE_PID); props.put("appliance.pid", appliancePid); LOG.debug("created configuration for appliance.pid " + appliancePid); } // remove the ah.status properties to force appliance // installation props.remove("ah.status"); c.update(props); this.installingAppliances.remove(appliance); } catch (Exception e) { LOG.debug(e.getMessage()); throw new HacException("unable to install appliance"); } } }