Example usage for java.util Hashtable clone

List of usage examples for java.util Hashtable clone

Introduction

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

Prototype

public synchronized Object clone() 

Source Link

Document

Creates a shallow copy of this hashtable.

Usage

From source file:Main.java

public static void main(String[] s) {
    Hashtable<String, String> table = new Hashtable<String, String>();
    table.put("key1", "value1");
    table.put("key2", "value2");
    table.put("key3", "value3");

    Hashtable tableCopy = (Hashtable) table.clone();

    System.out.println(tableCopy);

}

From source file:Main.java

public static void main(String args[]) {
    // create two hash tables 
    Hashtable<Integer, String> htableclone = new Hashtable<Integer, String>();
    Hashtable<Integer, String> htable = new Hashtable<Integer, String>();

    // put values into the table
    htable.put(1, "A");
    htable.put(2, "B");
    htable.put(3, "C");
    htable.put(4, "from java2s.com");

    // check table content
    System.out.println("Original hash table content: " + htable);

    // clone hash table
    htableclone = (Hashtable) htable.clone();

    // check content after clone
    System.out.println("Clone table content: " + htableclone);
}

From source file:Main.java

/**
 * Returns an enumeration of the hashtable elements that is not changed by parallel changes to the hashtable.
 * /*ww w  .  j  a v  a 2s. c o  m*/
 * @param hashtable
 * @return
 */
public static Enumeration getPersistentElementsEnumeration(Hashtable hashtable) {
    return ((Hashtable) hashtable.clone()).elements();
}

From source file:org.acegisecurity.ldap.DefaultInitialDirContextFactory.java

private InitialDirContext connect(Hashtable env) {
    if (logger.isDebugEnabled()) {
        Hashtable envClone = (Hashtable) env.clone();

        if (envClone.containsKey(Context.SECURITY_CREDENTIALS)) {
            envClone.put(Context.SECURITY_CREDENTIALS, "******");
        }/* w ww. j a v  a 2s  .com*/

        logger.debug("Creating InitialDirContext with environment " + envClone);
    }

    try {
        return useLdapContext ? new InitialLdapContext(env, null) : new InitialDirContext(env);
    } catch (NamingException ne) {
        if ((ne instanceof javax.naming.AuthenticationException)
                || (ne instanceof OperationNotSupportedException)) {
            throw new BadCredentialsException(
                    messages.getMessage("DefaultIntitalDirContextFactory.badCredentials", "Bad credentials"),
                    ne);
        }

        if (ne instanceof CommunicationException) {
            throw new LdapDataAccessException(
                    messages.getMessage("DefaultIntitalDirContextFactory.communicationFailure",
                            "Unable to connect to LDAP server"),
                    ne);
        }

        throw new LdapDataAccessException(
                messages.getMessage("DefaultIntitalDirContextFactory.unexpectedException",
                        "Failed to obtain InitialDirContext due to unexpected exception"),
                ne);
    }
}

From source file:org.apache.directory.server.jndi.ServerContextFactory.java

private void startLDAP0(ServerStartupConfiguration cfg, Hashtable env, int port,
        IoFilterChainBuilder chainBuilder) throws LdapNamingException, LdapConfigurationException {
    // Register all extended operation handlers.
    LdapProtocolProvider protocolProvider = new LdapProtocolProvider(cfg, (Hashtable) env.clone());

    for (Iterator i = cfg.getExtendedOperationHandlers().iterator(); i.hasNext();) {
        ExtendedOperationHandler h = (ExtendedOperationHandler) i.next();
        protocolProvider.addExtendedOperationHandler(h);
        log.info("Added Extended Request Handler: " + h.getOid());
        h.setLdapProvider(protocolProvider);
        PartitionNexus nexus = directoryService.getConfiguration().getPartitionNexus();
        nexus.registerSupportedExtensions(h.getExtensionOids());
    }/*w  w w. j  a va2 s . co  m*/

    try {
        // Disable the disconnection of the clients on unbind
        SocketAcceptorConfig acceptorCfg = new SocketAcceptorConfig();
        acceptorCfg.setDisconnectOnUnbind(false);
        acceptorCfg.setReuseAddress(true);
        acceptorCfg.setFilterChainBuilder(chainBuilder);
        acceptorCfg.setThreadModel(threadModel);

        ((SocketSessionConfig) (acceptorCfg.getSessionConfig())).setTcpNoDelay(true);
        ((SocketSessionConfig) (acceptorCfg.getSessionConfig())).setReuseAddress(true);

        tcpAcceptor.bind(new InetSocketAddress(port), protocolProvider.getHandler(), acceptorCfg);
        ldapStarted = true;

        if (log.isInfoEnabled()) {
            log.info("Successful bind of an LDAP Service (" + port + ") is complete.");
        }
    } catch (IOException e) {
        String msg = "Failed to bind an LDAP service (" + port + ") to the service registry.";
        LdapConfigurationException lce = new LdapConfigurationException(msg);
        lce.setRootCause(e);
        log.error(msg, e);
        throw lce;
    }
}

From source file:org.pepstock.jem.gwt.server.security.ExtendedJndiLdapRealm.java

/**
 * Performs the authorization by LDAP.// w  w  w  .  j  av a 2 s  . c  o  m
 */
@SuppressWarnings("unchecked")
@Override
protected AuthenticationInfo createAuthenticationInfo(AuthenticationToken token, Object ldapPrincipal,
        Object ldapCredentials, LdapContext ldapContext) throws NamingException {
    if (token instanceof FirstInstallationToken) {
        FirstInstallationToken upToken = (FirstInstallationToken) token;
        // Creates a user object
        User user = new User(upToken.getUsername());
        // creates account
        return new SimpleAccount(user, ldapCredentials, getName());
    }
    UsernamePasswordToken upToken = (UsernamePasswordToken) token;
    Collection<PrincipalAttribute> principals = null;
    try {
        // if environment null, uses the ldap context already prepared
        // this part is necessary to load attribtues from LDAP
        if (principalEnvironment == null) {
            LdapContext context = super.getContextFactory().getSystemLdapContext();
            Hashtable<String, String> currentEnvironment = (Hashtable<String, String>) context.getEnvironment();
            principalEnvironment = (Hashtable<String, String>) currentEnvironment.clone();
            // no authentication
            principalEnvironment.put(InitialDirContext.SECURITY_AUTHENTICATION, "none");
            // searchs attributes
        }
        principals = search(upToken.getUsername(), principalEnvironment);
    } catch (NamingException e) {
        LogAppl.getInstance().emit(UserInterfaceMessage.JEMG031E, e, upToken.getUsername());
    }
    // Creates a user object
    User user = new User(upToken.getUsername());
    // sets attribtues
    user.setAttributes(principals);
    if (principals != null) {
        for (PrincipalAttribute pa : principals) {
            if (orgUnitIdAttribute != null && pa.getName().equalsIgnoreCase(orgUnitIdAttribute)) {
                user.setOrgUnitId(pa.getValue().toString());
            }
            if (orgUnitNameAttribute != null && pa.getName().equalsIgnoreCase(orgUnitNameAttribute)) {
                user.setOrgUnitName(pa.getValue().toString());
            }
            if (userNameAttribute != null && pa.getName().equalsIgnoreCase(userNameAttribute)) {
                user.setName(pa.getValue().toString());
            }
        }
    }
    // creates account
    return new SimpleAccount(user, token.getCredentials(), getName());
}

From source file:org.wso2.carbon.deployment.notifier.internal.JMSConnectionFactory.java

/**
 * Digest a JMS CF definition  'Parameter' and construct
 *///from   w ww .j a v a2 s .co m
@SuppressWarnings("unchecked")
public JMSConnectionFactory(Hashtable<String, String> parameters, String name, String destination,
        int maxConcurrentConnections) {
    this.parameters = (Hashtable<String, String>) parameters.clone();
    this.name = name;
    this.destinationName = destination;

    if (maxConcurrentConnections > 0) {
        this.maxConnections = maxConcurrentConnections;
    }

    try {
        context = new InitialContext(parameters);
        conFactory = JMSUtils.lookup(context, ConnectionFactory.class,
                parameters.get(Constants.PARAM_CONFAC_JNDI_NAME));
        log.info("JMS ConnectionFactory : " + name + " initialized");

    } catch (NamingException e) {
        throw new DeploymentNotifierException("Cannot acquire JNDI context, JMS Connection factory : "
                + parameters.get(Constants.PARAM_CONFAC_JNDI_NAME) + " or default destinationName : "
                + parameters.get(Constants.PARAM_DESTINATION) + " for JMS CF : " + name + " using : "
                + parameters, e);
    }

    createConnectionPool();
}