Example usage for java.util Hashtable putAll

List of usage examples for java.util Hashtable putAll

Introduction

In this page you can find the example usage for java.util Hashtable putAll.

Prototype

public synchronized void putAll(Map<? extends K, ? extends V> t) 

Source Link

Document

Copies all of the mappings from the specified map to this hashtable.

Usage

From source file:org.mule.providers.ldap.util.DSManager.java

/**
 * Sets the system context root to null.
 * //from www  .  j  av a 2s. c  o  m
 * @see junit.framework.TestCase#tearDown()
 */
public synchronized void stop() throws Exception {
    logger.debug("DS is stopping ...");

    if (!running) {
        logger.debug("stop() called while is not running");

        if (checkSocketNotConnected()) {
            return;
        } else {
            logger.debug("stop() forced");
        }
    }

    // super.tearDown();
    Hashtable env = new Hashtable();
    env.put(Context.PROVIDER_URL, "ou=system");
    env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.directory.server.jndi.ServerContextFactory");
    env.putAll(new ShutdownConfiguration().toJndiEnvironment());
    env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system");
    env.put(Context.SECURITY_CREDENTIALS, "secret");

    try {
        new InitialContext(env);
    } catch (Exception e) {
        // ignored
        // dont remove try catch block!!
    }

    sysRoot = null;
    doDelete(configuration.getWorkingDirectory());
    configuration = new MutableServerStartupConfiguration();

    logger.debug("DS waiting for socket release ...");

    // wait for shutdown
    int i = 0;

    while (i < 20 && !checkSocketNotConnected()) {
        Thread.sleep(2000);
        i++;
        logger.debug("Try " + i);
    }

    if (!checkSocketNotConnected()) {
        throw new Exception("Shutdown of DS not successfull, server socket was not freed");
    }

    logger.debug("DS now stopped!");
    running = false;

}

From source file:org.mule.transport.jms.jndi.AbstractJndiNameResolver.java

protected Hashtable getContextProperties() {
    if ((jndiInitialFactory == null) && (jndiProviderProperties == null
            || !jndiProviderProperties.containsKey(Context.INITIAL_CONTEXT_FACTORY))) {
        throw new IllegalArgumentException("Undefined value for jndiInitialFactory property");
    }/*from w  w w .j  a  va  2 s  . com*/

    Hashtable<String, Object> props = new Hashtable<String, Object>();

    if (jndiInitialFactory != null) {
        props.put(Context.INITIAL_CONTEXT_FACTORY, jndiInitialFactory);
    }

    if (jndiProviderUrl != null) {
        props.put(Context.PROVIDER_URL, jndiProviderUrl);
    }

    if (jndiProviderProperties != null) {
        props.putAll(jndiProviderProperties);
    }

    return props;
}

From source file:org.opencms.workplace.tools.database.CmsHtmlImport.java

/**
 * Creates a folder in the VFS.<p>
 * //from w  w w .  j a  v a2 s .co  m
 * @param foldername the complete folder name in the real file system
 * @param position the default navigation position of this folder
 * @param properties the file properties
 */
private void createFolder(String foldername, int position, Hashtable properties) {

    String vfsFolderName = (String) m_fileIndex.get(foldername.replace('\\', '/'));

    m_report.print(Messages.get().container(Messages.RPT_CREATE_FOLDER_0), I_CmsReport.FORMAT_NOTE);
    m_report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_ARGUMENT_1,
            vfsFolderName));
    m_report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));

    if (vfsFolderName != null) {
        String path = vfsFolderName.substring(0,
                vfsFolderName.substring(0, vfsFolderName.length() - 1).lastIndexOf("/"));
        String folder = vfsFolderName.substring(path.length(), vfsFolderName.length());
        try {
            // try to find a meta.properties file in the folder
            String propertyFileName = foldername + File.separator + META_PROPERTIES;

            boolean metaPropertiesFound = false;
            CmsParameterConfiguration propertyFile = new CmsParameterConfiguration();
            try {
                propertyFile.load(new FileInputStream(new File(propertyFileName)));
                metaPropertiesFound = true;
            } catch (Exception e1) {
                // do nothing if the property file could not be loaded since it is not required
                // that such s file does exist
            }
            // now copy all values from the property file to the already found properties of the
            // new folder in OpenCms
            // only do this if we have found a meta.properties file          
            if (metaPropertiesFound) {
                properties.putAll(propertyFile);

                // check if we have to set the navpos property.
                if (properties.get(CmsPropertyDefinition.PROPERTY_NAVPOS) == null) {
                    // set the position in the folder as navpos
                    // we have to add one to the position, since it is counted from 0
                    properties.put(CmsPropertyDefinition.PROPERTY_NAVPOS, (position + 1) + "");
                }
                // check if we have to set the navpos property.
                if (properties.get(CmsPropertyDefinition.PROPERTY_NAVTEXT) == null) {
                    // set the foldername in the folder as navtext
                    String navtext = folder.substring(1, 2).toUpperCase()
                            + folder.substring(2, folder.length() - 1);
                    properties.put(CmsPropertyDefinition.PROPERTY_NAVTEXT, navtext);
                }
            } else {
                // if there was no meta.properties file, no properties should be added to the
                // folder
                properties = new Hashtable();
            }
            // try to read the folder, it its there we must not create it again
            try {
                m_cmsObject.readFolder(path + folder);
                m_cmsObject.lockResource(path + folder);
            } catch (CmsException e1) {
                // the folder was not there, so create it
                m_cmsObject.createResource(path + folder, OpenCms.getResourceManager()
                        .getResourceType(CmsResourceTypeFolder.getStaticTypeName()).getTypeId());
            }
            // create all properties and put them in an ArrayList
            Enumeration enu = properties.keys();
            List propertyList = new ArrayList();
            while (enu.hasMoreElements()) {
                // get property and value
                String propertyKey = (String) enu.nextElement();
                String propertyVal = (String) properties.get(propertyKey);
                CmsProperty property = new CmsProperty(propertyKey, propertyVal, propertyVal);
                // create implicitly if Property doesn't exist already
                property.setAutoCreatePropertyDefinition(true);
                // add new property to the list
                propertyList.add(property);
            }
            // try to write the property Objects
            try {
                m_cmsObject.writePropertyObjects(path + folder, propertyList);
            } catch (CmsException e1) {
                e1.printStackTrace();
            }
            m_report.println(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
                    I_CmsReport.FORMAT_OK);
        } catch (CmsException e) {
            m_report.println(e);
            LOG.error(e.getLocalizedMessage(), e);
        }
    }
}

From source file:org.rifidi.edge.configuration.RifidiService.java

/**
 * This method should be called to register the service to OSGi
 * //from  w w w .  j  av a 2 s  .co m
 * @param context
 *            The BundleContext to use to register the service
 * @param interfaces
 *            The Interfaces to register the service under
 * @param params
 *            OSGi service params
 */
protected void register(final BundleContext context, final Collection<String> interfaces,
        final Map<String, String> params) {
    interfaces.add(RifidiService.class.getName());
    String[] serviceInterfaces = new String[interfaces.size()];
    serviceInterfaces = interfaces.toArray(serviceInterfaces);
    Hashtable<String, String> parms = new Hashtable<String, String>();
    parms.put("serviceid", getID());
    parms.putAll(params);
    this.serviceRegistration = context.registerService(serviceInterfaces, this, parms);
}

From source file:org.sonatype.security.ldap.realms.DefaultLdapContextFactory.java

@VisibleForTesting
Hashtable<String, String> getSetupEnvironment(String username, final String password,
        final boolean systemContext) {
    Preconditions.checkNotNull(url, "No ldap URL specified (ldap://<hostname>:<port>)");

    if (username != null && principalSuffix != null) {
        username += principalSuffix;/* ww w.jav  a  2s .  c  om*/
    }

    Hashtable<String, String> env = new Hashtable<String, String>();

    if (additionalEnvironment != null) {
        env.putAll(additionalEnvironment);
    }

    // if the Authentication scheme is none, and this is not the system ctx we need to set the scheme to 'simple'
    if ("none".equals(authentication) && !systemContext) {
        env.put(Context.SECURITY_AUTHENTICATION, "simple");
    } else {
        env.put(Context.SECURITY_AUTHENTICATION, authentication);
    }

    if (username != null) {
        env.put(Context.SECURITY_PRINCIPAL, username);
    }
    if (password != null) {
        env.put(Context.SECURITY_CREDENTIALS, password);
    }
    env.put(Context.INITIAL_CONTEXT_FACTORY, contextFactoryClassName);
    env.put(Context.PROVIDER_URL, url);
    env.put(Context.REFERRAL, referral);

    // Only pool connections for system contexts
    if (usePooling && username != null && systemContext) {
        // Enable connection pooling
        env.put(SUN_CONNECTION_POOLING_PROPERTY, "true");
        // Enable pooling for plain and ssl connections
        env.put(SUN_CONNECTION_POOLING_PROTOCOL_PROPERTY, "plain ssl");
    }

    if (log.isDebugEnabled()) {
        log.debug("Initializing LDAP context using URL [" + url + "] and username [" + systemUsername + "] "
                + "with pooling [" + (usePooling ? "enabled" : "disabled") + "]");
    }
    return env;
}

From source file:org.theospi.utils.mvc.impl.MultiModelViewController.java

public ModelAndView handleRequest(Object requestModel, Map request, Map session, Map application,
        Errors errors) {/*w w  w  .ja v  a  2 s . c  o  m*/

    List currentList = (List) requestModel;
    Hashtable globalMap = new Hashtable();

    for (Iterator i = currentList.iterator(); i.hasNext();) {
        ControllerWrapper controller = (ControllerWrapper) i.next();
        ModelAndView controllerMv = controller.controller.handleRequest(controller.currentObject, request,
                session, application, errors);
        globalMap.putAll(controllerMv.getModel());
    }

    return new ModelAndView("success", globalMap);
}

From source file:org.wso2.carbon.event.output.adapter.jms.JMSEventAdapter.java

@Override
public void testConnect() throws TestConnectionNotSupportedException {

    try {//from w  ww  .  ja va  2 s  . c o m
        Hashtable<String, String> adaptorProperties = new Hashtable<String, String>();
        adaptorProperties.putAll(eventAdapterConfiguration.getStaticProperties());
        JMSConnectionFactory jmsConnectionFactory = new JMSConnectionFactory(adaptorProperties,
                eventAdapterConfiguration.getName(),
                adaptorProperties.get(JMSEventAdapterConstants.ADAPTER_JMS_DESTINATION), 1);
        Connection connection = jmsConnectionFactory.createConnection();
        connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        connection.close();
        jmsConnectionFactory.close();
    } catch (Exception e) {
        throw new OutputEventAdapterRuntimeException(e);
    }
}

From source file:org.wso2.carbon.event.output.adapter.jms.JMSEventAdapter.java

private PublisherDetails initPublisher(OutputEventAdapterConfiguration outputEventAdaptorConfiguration,
        Map<String, String> messageConfig) {

    PublisherDetails publisherDetails;//w w  w.j a  v  a  2 s . co  m
    Hashtable<String, String> adapterProperties = convertMapToHashTable(
            outputEventAdaptorConfiguration.getStaticProperties());

    Map<String, String> jmsProperties = this.extractProperties(
            eventAdapterConfiguration.getStaticProperties().get(JMSEventAdapterConstants.ADAPTER_PROPERTIES));

    Map<String, String> jmsSecuredProperties = this.extractProperties(eventAdapterConfiguration
            .getStaticProperties().get(JMSEventAdapterConstants.ADAPTER_SECURED_PROPERTIES));

    if (jmsProperties != null) {
        adapterProperties.remove(JMSEventAdapterConstants.ADAPTER_PROPERTIES);
        adapterProperties.putAll(jmsProperties);
    }

    if (jmsSecuredProperties != null) {
        adapterProperties.remove(JMSEventAdapterConstants.ADAPTER_SECURED_PROPERTIES);
        adapterProperties.putAll(jmsSecuredProperties);
    }

    int maxConnections;
    if (JMSEventAdapterConstants.ADAPTER_JMS_ALLOW_CONCURRENT_CONNECTIONS_NOT_ALLOWED
            .equals(eventAdapterConfiguration.getStaticProperties()
                    .get(JMSEventAdapterConstants.ADAPTER_JMS_ALLOW_CONCURRENT_CONNECTIONS))) {
        maxConnections = 1;
    } else if (globalProperties.get(JMSEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE_NAME) != null) {
        maxConnections = Integer
                .parseInt(globalProperties.get(JMSEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE_NAME));
    } else {
        maxConnections = JMSEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE;
    }

    JMSConnectionFactory jmsConnectionFactory = new JMSConnectionFactory(adapterProperties,
            outputEventAdaptorConfiguration.getName(),
            messageConfig.get(JMSEventAdapterConstants.ADAPTER_JMS_DESTINATION), maxConnections);
    JMSMessageSender jmsMessageSender = new JMSMessageSender(jmsConnectionFactory);
    publisherDetails = new PublisherDetails(jmsConnectionFactory, jmsMessageSender, messageConfig);

    return publisherDetails;
}

From source file:org.wso2.carbon.event.output.adaptor.jms.JMSEventAdaptorType.java

private PublisherDetails initPublisher(OutputEventAdaptorConfiguration outputEventAdaptorConfiguration,
        ConcurrentHashMap<String, PublisherDetails> topicEventSender, String topicName,
        Map<String, String> messageConfig) {
    PublisherDetails publisherDetails;/*from ww w.j  ava  2s. c o m*/
    Hashtable<String, String> adaptorProperties = new Hashtable<String, String>();
    adaptorProperties.putAll(outputEventAdaptorConfiguration.getOutputProperties());

    JMSConnectionFactory jmsConnectionFactory = new JMSConnectionFactory(adaptorProperties,
            outputEventAdaptorConfiguration.getName());
    JMSMessageSender jmsMessageSender = new JMSMessageSender(jmsConnectionFactory, messageConfig);
    publisherDetails = new PublisherDetails(jmsConnectionFactory, jmsMessageSender);
    topicEventSender.put(topicName, publisherDetails);
    return publisherDetails;
}

From source file:org.wso2.carbon.event.output.adaptor.jms.JMSEventAdaptorType.java

@Override
public void testConnection(OutputEventAdaptorConfiguration outputEventAdaptorConfiguration, int tenantId) {
    try {/*w  ww.j av  a2  s .co m*/
        Hashtable<String, String> adaptorProperties = new Hashtable<String, String>();
        adaptorProperties.putAll(outputEventAdaptorConfiguration.getOutputProperties());

        JMSConnectionFactory jmsConnectionFactory = new JMSConnectionFactory(adaptorProperties,
                outputEventAdaptorConfiguration.getName());
        Connection connection = jmsConnectionFactory.getConnection();
        connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        connection.close();
        jmsConnectionFactory.stop();
    } catch (Exception e) {
        throw new OutputEventAdaptorEventProcessingException(e);
    }
}