Example usage for java.util Dictionary put

List of usage examples for java.util Dictionary put

Introduction

In this page you can find the example usage for java.util Dictionary put.

Prototype

public abstract V put(K key, V value);

Source Link

Document

Maps the specified key to the specified value in this dictionary.

Usage

From source file:ch.trustserv.soundbox.plugins.portals.jamendoplugin.JamendoPlugin.java

/**
 *
 * @param jamendoSong// w ww  .ja  v  a  2 s .co m
 * @param reciever
 */
private void getStreamFromSong(final JamendoSong jamendoSong, final String reciever) {
    URL streamLink = null;
    try {
        streamLink = new URL("http://api.jamendo.com/get2/stream/track/redirect/?id=" + jamendoSong.getId()
                + "&streamencoding=mp31");
    } catch (MalformedURLException ex) {
        Logger.getLogger(JamendoPlugin.class.getName()).log(Level.SEVERE, null, ex);
    }
    ServiceReference ref = cx.getServiceReference(EventAdmin.class.getName());

    if (ref != null) {
        EventAdmin eventAdmin = (EventAdmin) cx.getService(ref);
        Dictionary properties = new Hashtable();
        try {
            URLConnection con = streamLink.openConnection();
            jamendoSong.setContentLength(con.getContentLength());
            properties.put("stream", new BufferedInputStream(con.getInputStream()));
            properties.put("song", jamendoSong);
        } catch (IOException ex) {
            Logger.getLogger(JamendoPlugin.class.getName()).log(Level.SEVERE, null, ex);
        }
        Event reportGeneratedEvent = null;
        switch (reciever) {
        case GETSTREAMFROMSONGFORDOWNLOADER:
            reportGeneratedEvent = new Event(STREAMFROMSONGFORDOWNLOADER, properties);
            break;
        case GETSTREAMFROMSONGFORPLAYER:
            reportGeneratedEvent = new Event(STREAMFROMSONGFORPLAYER, properties);
            break;
        }
        eventAdmin.sendEvent(reportGeneratedEvent);
    }
}

From source file:org.apache.sling.event.it.AbstractJobHandlingTest.java

/**
 * Helper method to register an event handler
 *//*  ww  w.  java2  s  . c  om*/
protected ServiceRegistration<EventHandler> registerEventHandler(final String topic,
        final EventHandler handler) {
    final Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put(EventConstants.EVENT_TOPIC, topic);
    final ServiceRegistration<EventHandler> reg = this.bc.registerService(EventHandler.class, handler, props);
    this.registrations.add(reg);
    return reg;
}

From source file:org.apache.sling.event.it.AbstractJobHandlingTest.java

/**
 * Helper method to register a job consumer
 *//*from  w ww .j  ava2s . c o m*/
protected ServiceRegistration<JobConsumer> registerJobConsumer(final String topic, final JobConsumer handler) {
    long cc = this.getConsumerChangeCount();
    final Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put(JobConsumer.PROPERTY_TOPICS, topic);
    final ServiceRegistration<JobConsumer> reg = this.bc.registerService(JobConsumer.class, handler, props);
    this.registrations.add(reg);
    this.waitConsumerChangeCount(cc + 1);
    return reg;
}

From source file:org.apache.sling.event.it.AbstractJobHandlingTest.java

/**
 * Helper method to register a job executor
 *//*  w ww .java 2  s  . c  o  m*/
protected ServiceRegistration<JobExecutor> registerJobExecutor(final String topic, final JobExecutor handler) {
    long cc = this.getConsumerChangeCount();
    final Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put(JobConsumer.PROPERTY_TOPICS, topic);
    final ServiceRegistration<JobExecutor> reg = this.bc.registerService(JobExecutor.class, handler, props);
    this.registrations.add(reg);
    this.waitConsumerChangeCount(cc + 1);
    return reg;
}

From source file:com.oracle.osgi.jmx.compendium.ConfigAdminManager.java

@SuppressWarnings("unchecked")
public void addPropertyToConfigurations(String filter, String name, String value, String type)
        throws IOException {
    Object v = parse(value, type);
    Configuration[] confs;//  w  w w.j a va2  s  .  c o  m
    try {
        confs = admin.listConfigurations(filter);
    } catch (InvalidSyntaxException e) {
        log.error("Invalid filter argument: " + filter, e);
        throw new IllegalArgumentException("Invalid filter: " + e);
    }
    if (confs != null) {
        for (Configuration conf : confs) {
            Dictionary dic = conf.getProperties();
            if (dic == null) {
                dic = new Hashtable();
            }
            dic.put(name, v);
            conf.update(dic);
        }
    }

}

From source file:org.ms123.common.domainobjects.DomainObjectsServiceImpl.java

protected void activate(BundleContext bundleContext, Map<?, ?> props) {
    m_bc = bundleContext;/*from w  w  w  .java2 s .c  o m*/
    System.out.println("DomainObjectsServiceImpl.activate.props:" + props);
    try {
        m_logger.info("DomainObjectsServiceImpl.activate -->");
        Bundle b = bundleContext.getBundle();
        Dictionary d = new Hashtable();
        d.put(EventConstants.EVENT_TOPIC, topics);
        b.getBundleContext().registerService(EventHandler.class.getName(), this, d);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.inaetics.pubsub.impl.discovery.etcd.EtcdDiscoveryManager.java

/**
 * Send an event to the TopologyManager.
 * //from  w  ww .  j  a v a2s  . c o m
 * @param info
 * @param eventType
 */
private void sendEvent(Map<String, String> info, String eventType) {
    ServiceReference ref = myBundleContext.getServiceReference(EventAdmin.class.getName());
    if (ref != null) {
        EventAdmin eventAdmin = (EventAdmin) myBundleContext.getService(ref);

        Dictionary<String, Object> properties = new Hashtable<>();
        properties.put(Constants.DISCOVERY_EVENT_TYPE, eventType);
        properties.put(Constants.DISCOVERY_INFO, info);

        Event reportGeneratedEvent = new Event(Constants.DISCOVERY_EVENT, properties);

        eventAdmin.sendEvent(reportGeneratedEvent);

    }

}

From source file:ddf.ldap.ldaplogin.LdapLoginConfig.java

/**
 * Update method that receives new properties.
 *
 * @param props Map of properties./*  w w  w  .  j  a  v  a  2 s.co m*/
 */
public void update(Map<String, ?> props) {
    if (props != null) {
        LOGGER.debug("Received an updated set of configurations for the LDAP Login Config.");

        if (connectionPoolServiceRegistration != null) {
            connectionPoolServiceRegistration.unregister();
        }
        if (ldapConnectionPool != null) {
            ldapConnectionPool.close();
        }

        ConnectionFactory ldapConnectionFactory = null;

        List<String> urls = new ArrayList<>();
        Object urlsObj = props.get(LDAP_URL);
        if (urlsObj instanceof String[]) {
            urls.addAll(Arrays.asList((String[]) urlsObj));
        } else {
            urls.add(urlsObj.toString());
        }

        List<ConnectionFactory> connectionFactories = new ArrayList<>();

        Boolean startTls = props.get(START_TLS) != null
                && Boolean.parseBoolean(props.get(START_TLS).toString());

        for (String url : urls) {
            connectionFactories.add(createLdapConnectionFactory(url, startTls));
        }

        String loadBalancingAlgorithm = (String) props.get(LDAP_LOAD_BALANCING);
        Options options = Options.defaultOptions();
        if (FAILOVER.equalsIgnoreCase(loadBalancingAlgorithm)) {
            ldapConnectionFactory = Connections.newFailoverLoadBalancer(connectionFactories, options);
        } else {
            ldapConnectionFactory = Connections.newRoundRobinLoadBalancer(connectionFactories, options);
        }

        ldapConnectionPool = new GenericObjectPool<>(
                new LdapConnectionPooledObjectFactory(ldapConnectionFactory), createGenericPoolConfig(id),
                createGenericPoolAbandonConfig());

        Dictionary<String, String> serviceProps = new DictionaryMap<>();
        serviceProps.put("id", id);

        LOGGER.debug("Registering LdapConnectionPool");
        connectionPoolServiceRegistration = context.registerService(GenericObjectPool.class.getName(),
                ldapConnectionPool, serviceProps);

        // create modules from the newly updated config
        Module ldapModule = createLdapModule(props);
        ldapService.update(ldapModule);
    }
}

From source file:org.energy_home.jemma.hac.adapter.http.AhHttpAdapter.java

protected void activate(ComponentContext ctxt) {
    String[] topics = new String[] { "org/telecomitalia/HacEvent/*", };

    Dictionary d = new Hashtable();
    d.put(EventConstants.EVENT_TOPIC, topics);
    // d.put(EventConstants.EVENT_FILTER, "(bundle.symbolicName=com.acme.*)"
    // );//  w  ww. ja  v  a  2 s . c o m
    ctxt.getBundleContext().registerService(EventHandler.class.getName(), this, d);
    Bundle bundle = null;

    bundle = ctxt.getBundleContext().getBundle();

    if (contextType.equals("SecureBasicHttpContext")) {
        SecureBasicHttpContext c = (SecureBasicHttpContext) httpContext;

        URL resourceBase = bundle.getEntry("");
        URL configFile = bundle.getEntry("jaas_config.txt");

        c.setResourceBase(resourceBase);
        c.setConfigFile(configFile);
        c.setRealm("Prova!!");
    } else if (contextType.equals("UserAdminBasicHttpContext")) {
        UserAdminBasicHttpContext c = (UserAdminBasicHttpContext) httpContext;
        c.setUserAdmin(userAdmin);
    }

    log.debug("activated");
}