@Override public synchronized void removeService ( final String id, final S service ) { if ( this.disposed ) { return; } logger.debug ( "Removing service: {} -> {}", id, service ); final Map<S, Dictionary<?, ?>> serviceMap = this.services.get ( id ); if ( serviceMap == null ) { return; } final Dictionary<?, ?> properties = serviceMap.remove ( service ); if ( properties != null ) { if ( serviceMap.isEmpty () ) { this.services.remove ( id ); } fireRemoveService ( id, service, properties ); } }
@Modified protected void modified(ComponentContext context) { log.info("Received configuration change..."); Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); String newIp = get(properties, "aliasIp"); String newMask = get(properties, "aliasMask"); String newAdapter = get(properties, "aliasAdapter"); // Process any changes in the parameters... if (!Objects.equals(newIp, aliasIp) || !Objects.equals(newMask, aliasMask) || !Objects.equals(newAdapter, aliasAdapter)) { synchronized (this) { log.info("Reconfiguring with aliasIp={}, aliasMask={}, aliasAdapter={}, wasLeader={}", newIp, newMask, newAdapter, wasLeader); if (wasLeader) { removeIpAlias(aliasIp, aliasMask, aliasAdapter); addIpAlias(newIp, newMask, newAdapter); } aliasIp = newIp; aliasMask = newMask; aliasAdapter = newAdapter; } } }
private void activate ( final DataSourceFactory dataSourceFactory ) throws Exception { logger.debug ( "Activate storage" ); this.scheduler = ScheduledExportedExecutorService.newSingleThreadExportedScheduledExecutor ( "org.eclipse.scada.ae.server.storage.postgresql/ScheduledExecutor" ); final Properties dbProperties = DataSourceHelper.getDataSourceProperties ( SPECIFIC_PREFIX, DataSourceHelper.DEFAULT_PREFIX ); final String schema = getSchema (); final String instance = getInstance (); this.jdbcStorage = new JdbcStorage ( dataSourceFactory, this.scheduler, dbProperties, DataSourceHelper.isConnectionPool ( SPECIFIC_PREFIX, DataSourceHelper.DEFAULT_PREFIX, false ), schema, instance ); this.jdbcStorage.start (); final Dictionary<String, Object> properties = new Hashtable<String, Object> ( 2 ); properties.put ( Constants.SERVICE_DESCRIPTION, "PostgreSQL specific JDBC implementation for org.eclipse.scada.ae.server.storage.Storage" ); properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" ); this.jdbcStorageHandle = context.registerService ( new String[] { JdbcStorage.class.getName (), Storage.class.getName () }, this.jdbcStorage, properties ); logger.debug ( "Storage activated - {}", this.jdbcStorageHandle ); }
private void createPool ( final Storage storage, final EventManager eventManager ) { logger.info ( "Create pool: {}", this.id ); try { this.pool = new EventPoolImpl ( this.executor, storage, eventManager, this.filter, this.size ); this.pool.start (); logger.info ( "pool {} created", this.id ); final Dictionary<String, String> properties = new Hashtable<String, String> (); properties.put ( Constants.SERVICE_PID, this.id ); this.poolHandle = this.context.registerService ( EventQuery.class.getName (), this.pool, properties ); } catch ( final Exception e ) { logger.warn ( "Failed to create event pool: " + this.id, e ); } }
/** * Loads the image from the URL <code>getImageURL</code>. This should * only be invoked from <code>refreshImage</code>. */ private void loadImage() { URL src = getImageURL(); Image newImage = null; if (src != null) { Dictionary cache = (Dictionary)getDocument(). getProperty(IMAGE_CACHE_PROPERTY); if (cache != null) { newImage = (Image)cache.get(src); } else { newImage = Toolkit.getDefaultToolkit().createImage(src); if (newImage != null && getLoadsSynchronously()) { // Force the image to be loaded by using an ImageIcon. ImageIcon ii = new ImageIcon(); ii.setImage(newImage); } } } image = newImage; }
@Override public StoredPerProvider addingService(ServiceReference<PersistenceProvider> reference) { String providerName = (String)reference.getProperty(JAVAX_PERSISTENCE_PROVIDER); // FIXME should be set when creating the EMF was successful if (punit.getPersistenceProviderClassName() == null) { punit.setProviderClassName(providerName); } StoredPerProvider stored = new StoredPerProvider(); LOGGER.info("Found provider for " + punit.getPersistenceUnitName() + " " + punit.getPersistenceProviderClassName()); PersistenceProvider provider = context.getService(reference); createAndCloseDummyEMF(provider); stored.builder = new AriesEntityManagerFactoryBuilder(context, provider, reference.getBundle(), punit); Dictionary<String, ?> props = AriesEntityManagerFactoryBuilder.createBuilderProperties(punit, punit.getBundle()); stored.reg = context.registerService(EntityManagerFactoryBuilder.class, stored.builder , props); return stored; }
protected void setUp() throws Exception { classes = new String[] { Object.class.getName(), Cloneable.class.getName(), Serializable.class.getName() }; // lowest service reference Dictionary dict1 = new Hashtable(); dict1.put(Constants.SERVICE_RANKING, Integer.MIN_VALUE); ref1 = new MockServiceReference(null, dict1, null); // neutral service reference Dictionary dict2 = new Hashtable(); dict2.put(Constants.SERVICE_ID, (long) 20); ref2 = new MockServiceReference(null, dict2, null); // neutral service reference Dictionary dict3 = new Hashtable(); dict3.put(Constants.SERVICE_ID, (long) 30); ref3 = new MockServiceReference(null, dict3, null); ctrl = createStrictControl(); context = ctrl.createMock(BundleContext.class); }
public static void addSuffixToSliderLabels(JSlider slider, String suffix) { assert (slider != null && suffix != null); Dictionary oldLabels = slider.getLabelTable(); Enumeration oldKeys = oldLabels.keys(); Hashtable newLabelTable = new Hashtable(); while (oldKeys.hasMoreElements()) { Object key = oldKeys.nextElement(); Object value = oldLabels.get(key); assert (value instanceof String); String str = ((String)value).concat(suffix); JLabel label = new JLabel(str); newLabelTable.put(key, label); } slider.setLabelTable(newLabelTable); }
/** * Constructs a servlet invocation context for a specified servlet container, * request, and cookie headers. **/ InvocationContextImpl( ServletUnitClient client, ServletRunner runner, String target, WebRequest request, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException { _client = client; _application = runner.getApplication(); _requestURL = request.getURL(); _target = target; final ServletUnitHttpRequest suhr = new ServletUnitHttpRequest( _application.getServletRequest( _requestURL ), request, runner.getContext(), clientHeaders, messageBody ); _request = suhr; Cookie[] cookies = getCookies( clientHeaders ); for (int i = 0; i < cookies.length; i++) suhr.addCookie( cookies[i] ); if (_application.usesBasicAuthentication()) suhr.readBasicAuthentication(); else if (_application.usesFormAuthentication()) suhr.readFormAuthentication(); HttpSession session = _request.getSession( /* create */ false ); if (session != null) ((ServletUnitHttpSession) session).access(); }
@Override public void start ( final BundleContext context ) throws Exception { Activator.instance = this; this.context = context; this.executor = Executors.newSingleThreadExecutor ( new NamedThreadFactory ( context.getBundle ().getSymbolicName () ) ); this.factory = new SumSourceFactory ( context, this.executor ); final Dictionary<String, String> properties = new Hashtable<String, String> (); properties.put ( Constants.SERVICE_DESCRIPTION, "A summary data source" ); properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" ); properties.put ( ConfigurationAdministrator.FACTORY_ID, context.getBundle ().getSymbolicName () ); context.registerService ( ConfigurationFactory.class.getName (), this.factory, properties ); }
/** * Returns the biggest value that has an entry in the label table. * * @return biggest value that has an entry in the label table, or * null. * @since 1.6 */ protected Integer getHighestValue() { Dictionary dictionary = slider.getLabelTable(); if (dictionary == null) { return null; } Enumeration keys = dictionary.keys(); Integer max = null; while (keys.hasMoreElements()) { Integer i = (Integer) keys.nextElement(); if (max == null || i > max) { max = i; } } return max; }
private void handlePotentialEclipseLink(Bundle b) { if (!ECLIPSELINK_JPA_PROVIDER_BUNDLE_SYMBOLIC_NAME.equals(b.getSymbolicName())) { return; } if (registeredProviders.containsKey(b)) { return; } PersistenceProvider provider = createEclipselinkProvider(b); if (provider == null) { return; } LOG.debug("Adding new EclipseLink provider for bundle {}", b); PersistenceProvider proxiedProvider = new EclipseLinkPersistenceProvider(provider, b); Dictionary<String, Object> props = new Hashtable<String, Object>(); // NOSONAR props.put("org.apache.aries.jpa.container.weaving.packages", getJPAPackages(b)); props.put("javax.persistence.provider", ECLIPSELINK_JPA_PROVIDER_CLASS_NAME); ServiceRegistration<?> reg = context.registerService(PersistenceProvider.class, proxiedProvider, props); ServiceRegistration<?> old = registeredProviders.putIfAbsent(b, reg); if (old != null) { reg.unregister(); } }
public Dictionary<String, ?> getProperties () { try { final Dictionary<String, Object> result = new Hashtable<String, Object> (); final Map<?, ?> properties = new BeanUtilsBean2 ().describe ( this.targetBean ); for ( final Map.Entry<?, ?> entry : properties.entrySet () ) { if ( entry.getValue () != null ) { result.put ( entry.getKey ().toString (), entry.getValue () ); } } return result; } catch ( final Exception e ) { logger.warn ( "Failed to get dictionary", e ); return new Hashtable<String, Object> ( 1 ); } }
private synchronized void connect () throws InvalidSyntaxException { if ( this.configuration.masterId == null ) { setUnsafe (); throw new RuntimeException ( String.format ( "'%s' is not set", MasterItem.MASTER_ID ) ); } logger.debug ( "Setting up for master item: {}", this.configuration.masterId ); this.tracker = new SingleObjectPoolServiceTracker<MasterItem> ( this.poolTracker, this.configuration.masterId, new ServiceListener<MasterItem> () { @Override public void serviceChange ( final MasterItem service, final Dictionary<?, ?> properties ) { AbstractMasterItemMonitor.this.setMasterItem ( service ); } } ); this.tracker.open (); }
@Override public void start ( final BundleContext context ) throws Exception { Activator.context = context; this.scheduler = ScheduledExportedExecutorService.newSingleThreadExportedScheduledExecutor ( context.getBundle ().getSymbolicName () + ".scheduler" ); this.factory = new MovingAverageDataSourceFactory ( context, this.scheduler ); final Dictionary<String, String> properties = new Hashtable<String, String> (); properties.put ( Constants.SERVICE_DESCRIPTION, "An averaging data source over time" ); properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" ); properties.put ( ConfigurationAdministrator.FACTORY_ID, context.getBundle ().getSymbolicName () ); context.registerService ( ConfigurationFactory.class.getName (), this.factory, properties ); }
private MockServiceReference createReference(Long id, Integer ranking) { Dictionary dict = new Properties(); dict.put(Constants.SERVICE_ID, id); if (ranking != null) dict.put(Constants.SERVICE_RANKING, ranking); return new MockServiceReference(null, dict, null); }
/** * Returns the width of the widest label. * @return the width of the widest label */ protected int getWidthOfWidestLabel() { @SuppressWarnings("rawtypes") Dictionary dictionary = slider.getLabelTable(); int widest = 0; if ( dictionary != null ) { Enumeration<?> keys = dictionary.keys(); while ( keys.hasMoreElements() ) { JComponent label = (JComponent) dictionary.get(keys.nextElement()); widest = Math.max( label.getPreferredSize().width, widest ); } } return widest; }
public void start ( final BundleContext context ) throws Exception { this.factory = new ProxyDataSourceFactory ( context ); final Dictionary<String, String> properties = new Hashtable<String, String> (); properties.put ( Constants.SERVICE_DESCRIPTION, "Proxy data sources" ); properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" ); properties.put ( ConfigurationAdministrator.FACTORY_ID, "da.datasource.proxy" ); context.registerService ( ConfigurationFactory.class.getName (), this.factory, properties ); }
public void tstConfigLocationsInMetaInfWithHeaderAndDependencies() throws Exception { Dictionary headers = new Hashtable(); headers.put("Spring-Context", "META-INF/spring/context.xml;wait-for-dependencies:=false"); EntryLookupControllingMockBundle aBundle = new EntryLookupControllingMockBundle(headers); aBundle.setResultsToReturnOnNextCallToFindEntries(META_INF_SPRING_CONTENT); aBundle.setEntryReturnOnNextCallToGetEntry(new URL(META_INF_SPRING_CONTENT[0])); ApplicationContextConfiguration config = new ApplicationContextConfiguration(aBundle); String[] configFiles = config.getConfigurationLocations(); assertTrue("bundle should be Spring powered", config.isSpringPoweredBundle()); assertEquals("2 config files", 1, configFiles.length); assertEquals("osgibundle:META-INF/spring/context.xml", configFiles[0]); }
private void GenerateTermFrequency() { for(int i=0; i < _numDocs ; i++) { String curDoc=_docs[i]; Dictionary freq=GetWordFrequency(curDoc); Enumeration enums=freq.keys(); while(enums.hasMoreElements()){ String word=(String) enums.nextElement(); int wordFreq=(Integer)freq.get(word); int termIndex=GetTermIndex(word); if(termIndex == -1) continue; _termFreq [termIndex][i]=wordFreq; _docFreq[termIndex] ++; if (wordFreq > _maxTermFreq[i]) _maxTermFreq[i]=wordFreq; } //DictionaryEnumerator enums=freq.GetEnumerator() ; _maxTermFreq[i]=Integer.MIN_VALUE ; /*freq.elements() Object ele=null; while ((ele=enums.nextElement())!=null) { String word=(String)ele. int wordFreq=(int)enums.Value ; int termIndex=GetTermIndex(word); if(termIndex == -1) continue; _termFreq [termIndex][i]=wordFre/q; _docFreq[termIndex] ++; if (wordFreq > _maxTermFreq[i]) _maxTermFreq[i]=wordFreq; }*/ } }
public void testCreateAsynchronouslyDefaultTrueIfGarbage() { // *;flavour Dictionary headers = new Hashtable(); headers.put("Spring-Context", "*;favour:=false"); EntryLookupControllingMockBundle aBundle = new EntryLookupControllingMockBundle(headers); aBundle.setResultsToReturnOnNextCallToFindEntries(META_INF_SPRING_CONTENT); ApplicationContextConfiguration config = new ApplicationContextConfiguration(aBundle); assertTrue("bundle should have create-asynchronously = true", config.isCreateAsynchronously()); }
/** * Returns true if all the labels from the label table have the same * baseline. * * @return true if all the labels from the label table have the * same baseline * @since 1.6 */ protected boolean labelsHaveSameBaselines() { if (!checkedLabelBaselines) { checkedLabelBaselines = true; Dictionary dictionary = slider.getLabelTable(); if (dictionary != null) { sameLabelBaselines = true; Enumeration elements = dictionary.elements(); int baseline = -1; while (elements.hasMoreElements()) { JComponent label = (JComponent) elements.nextElement(); Dimension pref = label.getPreferredSize(); int labelBaseline = label.getBaseline(pref.width, pref.height); if (labelBaseline >= 0) { if (baseline == -1) { baseline = labelBaseline; } else if (baseline != labelBaseline) { sameLabelBaselines = false; break; } } else { sameLabelBaselines = false; break; } } } else { sameLabelBaselines = false; } } return sameLabelBaselines; }
protected void registerItem ( final DataItem newItem, final String localId, final Map<String, Variant> properties ) { final Dictionary<String, String> props = new Hashtable<String, String> (); fillProperties ( properties, props ); final ServiceRegistration<DataItem> handle = this.context.registerService ( DataItem.class, newItem, props ); this.items.put ( localId, newItem ); this.itemRegs.put ( localId, handle ); }
private ServiceReference createReference(Long id, Integer ranking) { Dictionary dict = new Properties(); dict.put(Constants.SERVICE_ID, id); if (ranking != null) dict.put(Constants.SERVICE_RANKING, ranking); return new MockServiceReference(null, dict, null); }
public void testCreateAsynchronouslyDefaultTrueIfAbsent() { // *;flavour Dictionary headers = new Hashtable(); EntryLookupControllingMockBundle aBundle = new EntryLookupControllingMockBundle(headers); aBundle.setResultsToReturnOnNextCallToFindEntries(META_INF_SPRING_CONTENT); ApplicationContextConfiguration config = new ApplicationContextConfiguration(aBundle); assertTrue("bundle should have create-asynchronously = true", config.isCreateAsynchronously()); }
private void registerRemoteExporter ( final BundleContext context ) { // TODO: create clientConnection final Dictionary<String, Object> props = new Hashtable<String, Object> ( 1 ); props.put ( Constants.SERVICE_RANKING, 10 ); context.registerService ( HttpExporter.class.getName (), new RemoteHttpExporter (), props ); }
public void refreshFailure(BlueprintEvent event) { Dictionary<String, Object> props = init(event); Throwable th = event.getCause(); props.put(EXCEPTION, th); props.put(CAUSE, th); props.put(EXCEPTION_CLASS, th.getClass().getName()); String msg = th.getMessage(); props.put(EXCEPTION_MESSAGE, (msg != null ? msg : "")); initDependencies(props, event); sendEvent(new Event(TOPIC_FAILURE, props)); }
@Override public void start ( final BundleContext context ) throws Exception { this.factory = new DriverFactoryImpl (); final Dictionary<String, String> properties = new Hashtable<String, String> (); properties.put ( org.eclipse.scada.core.client.DriverFactory.INTERFACE_NAME, "da" ); properties.put ( org.eclipse.scada.core.client.DriverFactory.DRIVER_NAME, "sfp" ); properties.put ( Constants.SERVICE_DESCRIPTION, "Eclipse SCADA DA SFP Adapter" ); properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" ); this.handle = context.registerService ( org.eclipse.scada.core.client.DriverFactory.class, this.factory, properties ); }
public void registerCustomEditors(PropertyEditorRegistry registry) { // Date registry.registerCustomEditor(Date.class, new DateEditor()); // Collection concrete types registry.registerCustomEditor(Stack.class, new BlueprintCustomCollectionEditor(Stack.class)); registry.registerCustomEditor(Vector.class, new BlueprintCustomCollectionEditor(Vector.class)); // Spring creates a LinkedHashSet for Collection, RFC mandates an ArrayList // reinitialize default editors registry.registerCustomEditor(Collection.class, new BlueprintCustomCollectionEditor(Collection.class)); registry.registerCustomEditor(Set.class, new BlueprintCustomCollectionEditor(Set.class)); registry.registerCustomEditor(SortedSet.class, new BlueprintCustomCollectionEditor(SortedSet.class)); registry.registerCustomEditor(List.class, new BlueprintCustomCollectionEditor(List.class)); registry.registerCustomEditor(SortedMap.class, new CustomMapEditor(SortedMap.class)); registry.registerCustomEditor(HashSet.class, new BlueprintCustomCollectionEditor(HashSet.class)); registry.registerCustomEditor(LinkedHashSet.class, new BlueprintCustomCollectionEditor(LinkedHashSet.class)); registry.registerCustomEditor(TreeSet.class, new BlueprintCustomCollectionEditor(TreeSet.class)); registry.registerCustomEditor(ArrayList.class, new BlueprintCustomCollectionEditor(ArrayList.class)); registry.registerCustomEditor(LinkedList.class, new BlueprintCustomCollectionEditor(LinkedList.class)); // Map concrete types registry.registerCustomEditor(HashMap.class, new CustomMapEditor(HashMap.class)); registry.registerCustomEditor(LinkedHashMap.class, new CustomMapEditor(LinkedHashMap.class)); registry.registerCustomEditor(Hashtable.class, new CustomMapEditor(Hashtable.class)); registry.registerCustomEditor(TreeMap.class, new CustomMapEditor(TreeMap.class)); registry.registerCustomEditor(Properties.class, new PropertiesEditor()); // JDK 5 types registry.registerCustomEditor(ConcurrentMap.class, new CustomMapEditor(ConcurrentHashMap.class)); registry.registerCustomEditor(ConcurrentHashMap.class, new CustomMapEditor(ConcurrentHashMap.class)); registry.registerCustomEditor(Queue.class, new BlueprintCustomCollectionEditor(LinkedList.class)); // Legacy types registry.registerCustomEditor(Dictionary.class, new CustomMapEditor(Hashtable.class)); }
@Test public void testConstructor() throws Exception { final ModuleInfoRegistry reg = mock(ModuleInfoRegistry.class); final SchemaContextProvider prov = mock(SchemaContextProvider.class); doReturn("string").when(prov).toString(); final BundleContext ctxt = mock(BundleContext.class); final ServiceRegistration<?> servReg = mock(ServiceRegistration.class); doReturn(servReg).when(ctxt).registerService(any(Class.class), any(SchemaContextProvider.class), any(Dictionary.class)); doReturn(servReg).when(ctxt).registerService(Mockito.anyString(), any(Object.class), any(Dictionary.class)); doNothing().when(servReg).setProperties(any(Dictionary.class)); final ClassLoadingStrategy classLoadingStrat = mock(ClassLoadingStrategy.class); final BindingContextProvider codecRegistryProvider = mock(BindingContextProvider.class); doNothing().when(codecRegistryProvider).update(classLoadingStrat, prov); final BindingRuntimeContext bindingRuntimeContext = mock(BindingRuntimeContext.class); doReturn("B-runtime-context").when(bindingRuntimeContext).toString(); doReturn(bindingRuntimeContext).when(codecRegistryProvider).getBindingContext(); final RefreshingSCPModuleInfoRegistry scpreg = new RefreshingSCPModuleInfoRegistry(reg, prov, classLoadingStrat, this.sourceProvider, codecRegistryProvider, ctxt); doNothing().when(servReg).unregister(); final YangModuleInfo modInfo = mock(YangModuleInfo.class); doReturn("").when(modInfo).toString(); final ObjectRegistration<YangModuleInfo> ymi = mock(ObjectRegistration.class); doReturn(ymi).when(reg).registerModuleInfo(modInfo); scpreg.registerModuleInfo(modInfo); scpreg.updateService(); verify(codecRegistryProvider).update(classLoadingStrat, prov); scpreg.close(); Mockito.verify(servReg, Mockito.times(1)).setProperties(any(Dictionary.class)); Mockito.verify(servReg, Mockito.times(1)).unregister(); }
@Override public void start ( final BundleContext context ) throws Exception { Activator.context = context; this.executor = Executors.newSingleThreadExecutor ( new NamedThreadFactory ( context.getBundle ().getSymbolicName () ) ); this.factory = new AverageDataSourceFactory ( context, this.executor ); final Dictionary<String, String> properties = new Hashtable<String, String> (); properties.put ( Constants.SERVICE_DESCRIPTION, "An averaging data source over multiple sources" ); properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" ); properties.put ( ConfigurationAdministrator.FACTORY_ID, context.getBundle ().getSymbolicName () ); context.registerService ( ConfigurationFactory.class.getName (), this.factory, properties ); }
public void start ( final BundleContext context ) throws Exception { this.executor = Executors.newSingleThreadExecutor ( new NamedThreadFactory ( context.getBundle ().getSymbolicName () ) ); this.factory = new MemorySourceFactory ( context, this.executor ); final Dictionary<String, String> properties = new Hashtable<String, String> (); properties.put ( Constants.SERVICE_DESCRIPTION, "A memory data source" ); properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" ); properties.put ( ConfigurationAdministrator.FACTORY_ID, context.getBundle ().getSymbolicName () ); context.registerService ( ConfigurationFactory.class.getName (), this.factory, properties ); }
/** * Sets all the provided settings. */ public Builder put(Dictionary<Object,Object> properties) { for (Object key : Collections.list(properties.keys())) { map.put(Objects.toString(key), Objects.toString(properties.get(key))); } return this; }
/** * Shortcut method for retrieving the directive values. Different then * {@link #getDirectiveValue(Dictionary, String)} since it looks at the Bundle-Symbolic header and not at * Spring-Context. * * @param headers * @param directiveName * @return */ private static String getBlueprintDirectiveValue(Dictionary headers, String directiveName) { String header = getSymNameHeader(headers); if (header != null) { String directive = ConfigUtils.getDirectiveValue(header, directiveName); if (directive != null) return directive; } return null; }
@Override public synchronized void update ( final UserInformation userInformation, final String configurationId, final Map<String, String> properties ) throws Exception { DefaultDataSource source = this.dataSources.get ( configurationId ); if ( source == null ) { source = createDataSource (); this.dataSources.put ( configurationId, source ); final Dictionary<String, String> props = new Hashtable<String, String> (); props.put ( DataSource.DATA_SOURCE_ID, configurationId ); this.regs.put ( configurationId, this.context.registerService ( DataSource.class, source, props ) ); } source.update ( properties ); }
@Override protected Entry<BundleMonitorQuery> createService ( final UserInformation userInformation, final String configurationId, final BundleContext context, final Map<String, String> parameters ) throws Exception { final BundleMonitorQuery query = new BundleMonitorQuery ( this.executor, context, this.poolTracker ); query.update ( parameters ); final Dictionary<String, String> properties = new Hashtable<String, String> (); properties.put ( Constants.SERVICE_PID, configurationId ); properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" ); return new Entry<BundleMonitorQuery> ( configurationId, query, context.registerService ( MonitorQuery.class, query, properties ) ); }
@SuppressWarnings("unchecked") @Before public void setup() throws Exception { when(punit.getPersistenceUnitName()).thenReturn("test-props"); when(punit.getPersistenceProviderClassName()) .thenReturn(ECLIPSE_PERSISTENCE_PROVIDER); when(punit.getTransactionType()).thenReturn(PersistenceUnitTransactionType.JTA); when(punit.getBundle()).thenReturn(punitBundle); when(punit.getProperties()).thenReturn(punitProperties); when(punitBundle.getBundleContext()).thenReturn(punitContext); when(punitBundle.getVersion()).thenReturn(Version.parseVersion("1.2.3")); when(containerContext.registerService(eq(ManagedService.class), any(ManagedService.class), any(Dictionary.class))).thenReturn(msReg); when(containerContext.getService(dsfRef)).thenReturn(dsf); when(containerContext.getService(dsRef)).thenReturn(ds); when(containerContext.createFilter(Mockito.anyString())) .thenAnswer(new Answer<Filter>() { @Override public Filter answer(InvocationOnMock i) throws Throwable { return FrameworkUtil.createFilter(i.getArguments()[0].toString()); } }); when(punitContext.registerService(eq(EntityManagerFactory.class), any(EntityManagerFactory.class), any(Dictionary.class))).thenReturn(emfReg); when(emf.isOpen()).thenReturn(true); Properties jdbcProps = new Properties(); jdbcProps.setProperty("url", JDBC_URL); jdbcProps.setProperty("user", JDBC_USER); jdbcProps.setProperty("password", JDBC_PASSWORD); when(dsf.createDataSource(jdbcProps)).thenReturn(ds); }
/** * Check property name is defined as set to true. * * @param properties properties to be looked up * @param propertyName the name of the property to look up * @param defaultValue the default value that to be assigned * @return value when the propertyName is defined or return the default value */ public static boolean isPropertyEnabled(Dictionary<?, ?> properties, String propertyName, boolean defaultValue) { try { String s = get(properties, propertyName); return Strings.isNullOrEmpty(s) ? defaultValue : Boolean.valueOf(s); } catch (ClassCastException e) { return defaultValue; } }
public void testManagedServiceProperties() { assertTrue(services.isEmpty()); assertNotNull(cam.getConfiguration()); Dictionary props = (Dictionary) services.values().iterator().next(); assertEquals(pid, props.get(Constants.SERVICE_PID)); }
private static Integer getMaxSliderValue(JSlider slider) { Dictionary dictionary = slider.getLabelTable(); if (dictionary != null) { Enumeration keys = dictionary.keys(); int max = slider.getMinimum() - 1; while (keys.hasMoreElements()) { max = Math.max(max, ((Integer)keys.nextElement()).intValue()); } if (max == slider.getMinimum() - 1) { return null; } return new Integer(max); } return null; }