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:org.eclipse.gyrex.persistence.storage.Repository.java

/**
 * Registers the metrics on behalf of the bundle which loaded this class.
 * /*from w  w w  . j  av  a2  s.  c  o  m*/
 * @throws IllegalArgumentException
 *             if the class was not loaded by a bundle class loader
 * @throws IllegalStateException
 *             if the bundle which loaded the class has no valid bundle
 *             context
 */
private void registerMetrics() throws IllegalArgumentException, IllegalStateException {
    // get bundle context
    final BundleContext bundleContext = getBundleContext();

    // create metrics properties
    final Dictionary<String, Object> metricsProps = new Hashtable<String, Object>(4);
    metricsProps.put(Constants.SERVICE_VENDOR, getName() + "[" + getRepositoryId() + "]");
    metricsProps.put(Constants.SERVICE_DESCRIPTION, "Metrics for repository '" + getRepositoryId() + "'.");
    metricsProps.put(SERVICE_PROPERTY_REPOSITORY_ID, getRepositoryId());
    try {
        final String description = getDescription();
        if (StringUtils.isNotBlank(description)) {
            metricsProps.put(SERVICE_PROPERTY_REPOSITORY_DESCRIPTION, description);
        }
    } catch (final Exception e) {
        // registerMetrics is called during object construction, therefore #getDescription might not be ready yet.
    }

    // register metrics
    metricsRegistration = bundleContext.registerService(MetricSet.SERVICE_NAME, metrics, metricsProps);
}

From source file:org.solmix.runtime.cm.support.SpringConfigureUnitManager.java

private Dictionary<String, ?> toDictionary(Properties properties) {
    Dictionary<String, Object> dic = new Hashtable<String, Object>();
    if (properties != null) {
        Enumeration<Object> en = properties.keys();
        while (en.hasMoreElements()) {
            Object key = en.nextElement();
            dic.put(key.toString(), properties.get(key));
        }/*  w  w w.  j  a va 2s . co  m*/
    }
    return dic;
}

From source file:org.apache.sling.auth.xing.login.impl.XingLoginAuthenticationHandler.java

protected void configure(final ComponentContext context) {
    final Dictionary properties = context.getProperties();
    consumerKey = PropertiesUtil.toString(properties.get(CONSUMER_KEY_PARAMETER), "").trim();
    userCookie = PropertiesUtil.toString(properties.get(USER_COOKIE_PARAMETER), DEFAULT_USER_COOKIE).trim();
    userIdCookie = PropertiesUtil.toString(properties.get(USERID_COOKIE_PARAMETER), DEFAULT_USERID_COOKIE)
            .trim();/*from ww  w  .  j  av a 2 s.  c o m*/
    maxCookieSize = PropertiesUtil.toInteger(properties.get(MAX_COOKIE_SIZE_PARAMETER),
            DEFAULT_MAX_COOKIE_SIZE);
    loginPath = PropertiesUtil.toString(properties.get(LOGIN_PATH_PARAMETER), "").trim();
    logoutPath = PropertiesUtil.toString(properties.get(LOGOUT_PATH_PARAMETER), "").trim();

    if (StringUtils.isEmpty(consumerKey)) {
        logger.warn("configured consumer key is empty");
        xingCookie = "";
    } else {
        xingCookie = XingLogin.XING_COOKIE_PREFIX.concat(consumerKey);
    }

    if (loginPageRegistration != null) {
        loginPageRegistration.unregister();
    }

    if (StringUtils.isEmpty(loginPath)) {
        logger.warn("configured login path is empty");
    } else {
        final Dictionary<String, Object> loginPathProperties = new Hashtable<String, Object>();
        final String[] authRequirements = new String[] { "-".concat(loginPath) };
        loginPathProperties.put(AuthConstants.AUTH_REQUIREMENTS, authRequirements);
        loginPageRegistration = context.getBundleContext().registerService(Object.class.getName(), new Object(),
                loginPathProperties);
    }

    if (StringUtils.isEmpty(logoutPath)) {
        logger.warn("configured logout path is empty");
    }

    logger.info("configured with consumer key '{}', cookie name '{}', login path '{}' and logout path '{}'",
            consumerKey, xingCookie, loginPath, logoutPath);
}

From source file:org.sakaiproject.nakamura.files.servlets.SparseTagOperation.java

/**
 * Update tag counts and send events for tags that were used.
 *
 * @param request//from   w w  w  . ja v  a2 s. co  m
 * @param session
 * @param user
 * @param content
 * @param addedTags
 * @throws ClientPoolException
 * @throws StorageClientException
 * @throws AccessDeniedException
 */
private void updateCounts(SlingHttpServletRequest request, Session session, String user, Content content,
        List<Content> addedTags) throws ClientPoolException, StorageClientException, AccessDeniedException {
    Session adminSession = null;
    try {
        adminSession = session.getRepository().loginAdministrative();
        ContentManager cm = adminSession.getContentManager();
        for (Content addedTag : addedTags) {
            Content adminTag = cm.get(addedTag.getPath());
            String[] tagNames = PropertiesUtil.toStringArray(content.getProperty(SAKAI_TAGS));
            TagUtils.bumpTagCounts(adminTag, tagNames, true, false, cm);

            // Send an OSGi event.
            String tagName = String.valueOf(addedTag.getProperty(SAKAI_TAG_NAME));
            Dictionary<String, String> properties = new Hashtable<String, String>();
            properties.put(UserConstants.EVENT_PROP_USERID, user);
            properties.put("tag-name", tagName);
            EventUtils.sendOsgiEvent(request.getResource(), properties, TOPIC_FILES_TAG, eventAdmin);
        }
    } finally {
        if (adminSession != null) {
            try {
                adminSession.logout();
            } catch (ClientPoolException e) {
                // noop; nothing to do
            }
        }
    }
}

From source file:org.apache.clerezza.platform.testing.blackbox.osgi.FelixClerezzaPlatformTest.java

private void testJaxRsRegistration() throws InterruptedException, IOException {
    final Dictionary<String, Object> jaxRsResourceProperty = new Hashtable<String, Object>();
    {//from  w w w  . ja va  2 s  .  com
        jaxRsResourceProperty.put("javax.ws.rs", Boolean.TRUE);
        jaxRsResourceProperty.put("service.pid", SimpleRootResource.class.getName());
    }
    bundleContext.registerService(Object.class.getName(), new SimpleRootResource(), jaxRsResourceProperty);
    URL url = new URL("http://localhost:" + testHttpPort + "/foo");
    Thread.sleep(4000);
    requestUrl(url);//"/admin/users/list-users"));
    runRequestThreads(url);
}

From source file:org.ops4j.pax.web.extender.war.internal.WebXmlObserver.java

private void fireEvent(String topic, Bundle bundle, Dictionary<String, Object> failure) {
    if (eventAdminService != null) {
        Dictionary<String, Object> properties = new Hashtable<String, Object>();
        properties.put("bundle.symbolicName", bundle.getSymbolicName());
        properties.put("bundle.id", bundle.getBundleId());
        properties.put("bundle", bundle);
        properties.put("bundle.version", bundle.getHeaders().get(Constants.BUNDLE_VERSION));
        String webContextPath = (String) bundle.getHeaders().get("Web-ContextPath");
        if (webContextPath == null || webContextPath.length() == 0)
            webContextPath = (String) bundle.getHeaders().get("Webapp-Context"); //PAX fallback

        properties.put("context.path", webContextPath);
        properties.put("timestamp", System.currentTimeMillis());
        properties.put("extender.bundle", bundleContext.getBundle());
        properties.put("extender.bundle.id", bundleContext.getBundle().getBundleId());
        properties.put("extender.bundle.symbolicName", bundleContext.getBundle().getSymbolicName());
        properties.put("extender.bundle.version",
                bundleContext.getBundle().getHeaders().get(Constants.BUNDLE_VERSION));

        if (failure != null) {
            Enumeration<String> keys = failure.keys();
            while (keys.hasMoreElements()) {
                String key = keys.nextElement();
                properties.put(key, failure.get(key));
            }//from   w w w . ja v  a  2 s. c  o m
        }

        Event event = new Event(topic, properties);
        this.eventAdminService.postEvent(event);
    }

    if (logService != null) {
        this.logService.log(LogService.LOG_DEBUG, topic);
    }
}

From source file:org.ms123.common.nucleus.NucleusServiceImpl.java

protected void activate(BundleContext bundleContext, Map<?, ?> props) {
    try {//from w ww . j  a va2 s  .co  m
        m_bc = bundleContext;
        debug("NucleusServiceImpl.activate:" + bundleContext);
        Dictionary d = new Hashtable();
        d.put(EventConstants.EVENT_TOPIC, topics);
        m_bc.registerService(EventHandler.class.getName(), this, d);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.apache.clerezza.platform.testing.blackbox.osgi.FelixClerezzaPlatformTest.java

private void testWithScalaServerPage() throws InterruptedException, IOException {
    registerRDFListRootResource();/*from w  ww  . ja  va2  s .  com*/
    final Dictionary<String, Object> webRenderingServiceProperty = new Hashtable<String, Object>();
    {
        webRenderingServiceProperty.put("service.pid", SomeContentWebRenderingService.class.getName());
    }
    bundleContext.registerService(SomeContentWebRenderingService.class.getName(),
            new SomeContentWebRenderingService(), webRenderingServiceProperty);
    RenderletManager renderletManager = waitFor(RenderletManager.class, 20000);
    renderletManager.registerRenderlet(ScalaServerPagesRenderlet.class.getName(),
            new UriRef(getClass().getResource("renderingServiceTest.ssp").toString()),
            RDFListRootResource.testType, null, MediaType.TEXT_PLAIN_TYPE, false);
    URL url = new URL("http://localhost:" + testHttpPort + "/list");
    Thread.sleep(4000);
    String returnedString = new String(requestUrl(url), "utf-8");
    Assert.assertEquals("some content", returnedString);

}

From source file:org.ops4j.pax.web.extender.war.internal.WebXmlObserver.java

private void fireFailedEvent(Bundle bundle, Exception exception, String context, Long... ids) {
    String faileEvent = "org/osgi/service/web/FAILED";
    Dictionary<String, Object> failedProperties = new Hashtable<String, Object>();
    if (exception != null)
        failedProperties.put("exception", exception);
    if (context != null) {
        failedProperties.put("collision", context);
        failedProperties.put("collision.bundles", ids);
    }/*from ww w .ja  v a  2  s .c o m*/
    fireEvent(faileEvent, bundle, failedProperties);
}

From source file:org.codice.alliance.test.itests.ImagingTest.java

private void configureNitfRenderPlugin(int maxNitfSize, boolean overview, boolean original)
        throws IOException, InterruptedException {
    Configuration config = configAdmin.getConfiguration("NITF_Render_Plugin", null);

    Dictionary<String, Object> properties = new Hashtable<>();

    properties.put("maxNitfSizeMB", maxNitfSize);
    properties.put("createOverview", overview);
    properties.put("storeOriginalImage", original);
    config.update(properties);/*from w  ww.  j  a v  a 2  s .  c o m*/
    getServiceManager().waitForAllBundles();
}