Example usage for java.util Hashtable put

List of usage examples for java.util Hashtable put

Introduction

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

Prototype

public synchronized V put(K key, V value) 

Source Link

Document

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

Usage

From source file:com.openkm.principal.LdapPrincipalAdapter.java

/**
 * Create static LDAP configuration environment.
 *//*from  www . j  av  a  2s  .  c  om*/
private static Hashtable<String, String> getEnvironment() {
    Hashtable<String, String> env = new Hashtable<String, String>();

    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.PROVIDER_URL, Config.PRINCIPAL_LDAP_SERVER);

    // Enable connection pooling
    // @see http://docs.oracle.com/javase/jndi/tutorial/ldap/connect/pool.html
    env.put("com.sun.jndi.ldap.connect.pool", "true");

    /**
     * Referral values: ignore, follow or throw.
     * 
     * @see http://docs.oracle.com/javase/jndi/tutorial/ldap/referral/jndi.html
     * @see http://java.sun.com/products/jndi/jndi-ldap-gl.html
     */
    if (!"".equals(Config.PRINCIPAL_LDAP_REFERRAL)) {
        env.put(Context.REFERRAL, Config.PRINCIPAL_LDAP_REFERRAL);
    }

    // Optional is some cases (Max OS/X)
    if (!Config.PRINCIPAL_LDAP_SECURITY_PRINCIPAL.equals("")) {
        env.put(Context.SECURITY_PRINCIPAL, Config.PRINCIPAL_LDAP_SECURITY_PRINCIPAL);
    }

    if (!Config.PRINCIPAL_LDAP_SECURITY_CREDENTIALS.equals("")) {
        env.put(Context.SECURITY_CREDENTIALS, Config.PRINCIPAL_LDAP_SECURITY_CREDENTIALS);
    }

    return env;
}

From source file:com.attentec.ServerContact.java

/**
 * Puts user name and phone key together to hashTable with key phone_auth.
 * @param username The name of the user that is suppose to login.
 * @param key the key to authenticate the user.
 * @return Hashtable with user name and phone key.
 *//*from www  .  j  a va  2s.  c o m*/
public static Hashtable<String, List<NameValuePair>> getLogin(final String username, final String key) {

    Hashtable<String, List<NameValuePair>> postdata = new Hashtable<String, List<NameValuePair>>();

    List<NameValuePair> logindata = new ArrayList<NameValuePair>();

    logindata.add(new BasicNameValuePair("username", username));
    logindata.add(new BasicNameValuePair("phone_key", key));

    postdata.put("phone_auth", logindata);
    return postdata;

}

From source file:com.projity.configuration.Dictionary.java

public static void add(NamedItem namedItem, boolean replace) {
    String categories[] = namedItem.getCategory().split(";"); // can belong to more than one if separated by ;

    for (int i = 0; i < categories.length; i++) {
        String category = categories[i];
        Hashtable subMap = (Hashtable) getInstance().mainMap.get(category);
        if (subMap == null) {
            subMap = new Hashtable();
            getInstance().mainMap.put(category, subMap);
        }/*  ww  w . j  av  a 2 s .c om*/
        if (!subMap.contains(namedItem)) {
            subMap.put(namedItem.getName(), namedItem);
        } else {
            if (replace)
                subMap.put(namedItem.getName(), namedItem);

            //this is actually normal if overriding with another xml file            ConfigurationReader.log.warn("named item " + namedItem + " already in category " + category);
        }
    }
}

From source file:com.clican.pluto.common.util.JndiUtils.java

/**
 * Unbind the rsource manager instance from the JNDI directory.
 * <p>//from w w  w. ja v a  2 s .  c  om
 * After this method is called, it is no longer possible to obtain the
 * resource manager instance from the JNDI directory.
 * <p>
 * Note that this method will not remove the JNDI contexts corresponding to
 * the individual path segments of the full resource manager JNDI path.
 * 
 * @param jndiName
 *            The full JNDI path at which the resource manager instance was
 *            previously bound.
 * @return <b>true</b> if the resource manager was successfully unbound
 *         from JNDI; otherwise <b>false</b>.
 * 
 * @see #bind(String, Object)
 */
public static boolean unbind(String jndiName) {
    if (log.isDebugEnabled()) {
        log.debug("Unbinding object at path [" + jndiName + "] from the JNDI repository.");
    }
    Context ctx = null;
    try {
        Hashtable<String, String> ht = new Hashtable<String, String>();
        // If a special JNDI initial context factory was specified in the
        // constructor, then use it.
        if (jndiInitialContextFactory != null) {
            ht.put(Context.INITIAL_CONTEXT_FACTORY, jndiInitialContextFactory);
        }
        ctx = new InitialContext(ht);
        Object obj = lookupObject(jndiName);
        if (obj instanceof Serializable || jndiInitialContextFactory != null) {
            ctx.unbind(jndiName);
        } else {
            NonSerializableFactory.unbind(jndiName);
        }
    } catch (NamingException ex) {
        log.error("An error occured while unbinding [" + jndiName + "] from JNDI:", ex);
        return false;
    } finally {
        if (ctx != null) {
            try {
                ctx.close();
            } catch (NamingException ne) {
                log.error("Close context error:", ne);
            }
        }
    }
    return true;
}

From source file:io.card.development.recording.Recording.java

private static Hashtable<String, byte[]> findManifestFiles(Hashtable<String, byte[]> recordingFiles) {
    Hashtable<String, byte[]> manifestFiles = new Hashtable<String, byte[]>();
    Enumeration<String> fileNames = recordingFiles.keys();

    while (fileNames.hasMoreElements()) {
        String fileName = fileNames.nextElement();
        if (fileName.endsWith("manifest.json")) {
            manifestFiles.put(fileName, recordingFiles.get(fileName));
        }//w  w w  . j  a  v a 2 s  .c om
    }

    return manifestFiles;
}

From source file:com.clican.pluto.common.util.JndiUtils.java

/**
 * Look up the object with the specified JNDI name in the JNDI server.
 * //from   ww  w .j a v  a2 s  .com
 * @param jndiName
 *            the JNDI name specified
 * @return the object bound with the name specified, null if this method
 *         fails
 */
public static Object lookupObject(String jndiName) {
    Context ctx = null;
    try {
        Hashtable<String, String> ht = new Hashtable<String, String>();
        // If a special JNDI initial context factory was specified in the
        // constructor, then use it.
        if (jndiInitialContextFactory != null) {
            ht.put(Context.INITIAL_CONTEXT_FACTORY, jndiInitialContextFactory);
        }
        ctx = new InitialContext(ht);
        Object obj = null;
        try {
            obj = ctx.lookup(jndiName);
        } catch (Exception e) {
            if (log.isInfoEnabled()) {
                log.info(
                        "Lookup for an object from Non-Serializable JNDI (relookup from Serializable JNDI) using the JNDI name ["
                                + jndiName + "] : ");
            }
            obj = NonSerializableFactory.lookup(jndiName);
        }

        if (log.isDebugEnabled()) {
            log.debug("JNDI lookup with path [" + jndiName + "] returned object [" + obj + "].");
        }
        return obj;
    } catch (NamingException ex) {
        log.debug("Failed to lookup for an object using the JNDI name [" + jndiName + "] : " + ex);
        return null;
    } finally {
        if (ctx != null) {
            try {
                ctx.close();
            } catch (NamingException ne) {
                log.error("Close context error:", ne);
            }
        }
    }
}

From source file:com.modeln.build.ctrl.charts.CMnPatchCountChart.java

/**
 * Create a chart representing the number of patches per customer. 
 * The data is passed in as a hashtable where the key is the customer
 * information and the value is the number of patch requests.
 *
 * @param  data   Hashtable containing accounts and the corresponding counts
 * @param  label  Count label/* w w  w .jav  a 2s.  com*/
 *
 * @return Bar chart repesenting the customer and count information
 */
public static final JFreeChart getPatchesByCustomerChart(Hashtable<CMnAccount, Integer> data, String label) {
    Hashtable<String, Integer> hash = new Hashtable<String, Integer>();
    Enumeration accountList = data.keys();
    while (accountList.hasMoreElements()) {
        CMnAccount account = (CMnAccount) accountList.nextElement();
        Integer value = data.get(account);
        hash.put(account.getName(), value);
    }

    return getBarChart(hash, label + " by Customer", "Customer", label);
}

From source file:edu.ku.brc.specify.tasks.subpane.JasperReportsCache.java

/**
 * Checks to see if any files in the database need to be copied to the database. A file may not
 * exist or be out of date./*  w  w w.j  a  va 2  s .  c om*/
 */
protected static void refreshCacheFromDatabase(final String mimeType) {
    File cachePath = getCachePath();

    Hashtable<String, File> hash = new Hashtable<String, File>();
    for (File f : cachePath.listFiles()) {
        //log.info("Report Cache File["+f.getName()+"]");
        hash.put(f.getName(), f);
    }

    for (AppResourceIFace ap : AppContextMgr.getInstance().getResourceByMimeType(mimeType)) {
        // Check to see if the resource or file has changed.
        boolean updateCache = false;
        File fileFromJasperCache = hash.get(ap.getName());
        if (fileFromJasperCache == null) {
            updateCache = true;

        } else {
            Date fileDate = new Date(fileFromJasperCache.lastModified());
            Timestamp apTime = ap.getTimestampModified() == null ? ap.getTimestampCreated()
                    : ap.getTimestampModified();
            updateCache = apTime == null || fileDate.getTime() < apTime.getTime();
        }

        // If it has changed then copy the contents into the cache and delete the compiled file
        // so it forces it to be recompiled.
        if (updateCache) {
            File localFilePath = new File(cachePath.getAbsoluteFile() + File.separator + ap.getName());
            try {
                XMLHelper.setContents(localFilePath, ap.getDataAsString());

                File compiledFile = getCompiledFile(localFilePath);
                if (compiledFile.exists()) {
                    compiledFile.delete();
                }

            } catch (Exception ex) {
                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(JasperReportsCache.class, ex);
                throw new RuntimeException(ex);
            }
        }
    }
}

From source file:com.clican.pluto.common.util.JndiUtils.java

/**
 * Bind the resource manager instance to the JNDI directory.
 * <p>//from w w w. j a  v a2  s  .  co m
 * This method will use the full JNDI path provided for the resource
 * manager, and will create if necessary the individual segments of that
 * path.
 * 
 * @param jndiName
 *            The full JNDI path at which the resource manager instance will
 *            be bound in the JNDI directory. JNDI clients can use that path
 *            to obtain the resource manager instance.
 * @param obj
 *            The object to be bound.
 * @return <b>true</b> if the resource manager was successfully bound to
 *         JNDI using the provided path; otherwise <b>false</b>.
 * 
 * @see #unbind(String)
 */
public static boolean bind(String jndiName, Object obj) {
    if (log.isDebugEnabled()) {
        log.debug("Binding object [" + obj + "] in JNDI at path [" + jndiName + "].");
    }
    Context ctx = null;

    try {
        // Create a binding that is local to this host only.
        Hashtable<String, String> ht = new Hashtable<String, String>();
        // If a special JNDI initial context factory was specified in the
        // constructor, then use it.
        if (jndiInitialContextFactory != null) {
            ht.put(Context.INITIAL_CONTEXT_FACTORY, jndiInitialContextFactory);
        }
        // Turn off binding replication .
        // ht.put(WLContext.REPLICATE_BINDINGS, "false");
        ctx = new InitialContext(ht);

        String[] arrJndiNames = jndiName.split("/");
        String subContext = "";

        for (int i = 0; i < arrJndiNames.length - 1; i++) {
            subContext = subContext + "/" + arrJndiNames[i];
            try {
                ctx.lookup(subContext);
            } catch (NameNotFoundException e) {
                ctx.createSubcontext(subContext);
            }

        }

        if (obj instanceof Serializable || jndiInitialContextFactory != null) {
            ctx.bind(jndiName, obj);
        } else {
            NonSerializableFactory.bind(jndiName, obj);
        }
    } catch (NamingException ex) {
        log.error("An error occured while binding [" + jndiName + "] to JNDI:", ex);
        return false;
    } finally {
        if (ctx != null) {
            try {
                ctx.close();
            } catch (NamingException ne) {
                log.error("Close context error:", ne);
            }
        }
    }
    return true;
}

From source file:Main.java

public static Hashtable<Integer, Set<Integer>> getNodeMembership(Hashtable<Integer, Set<Integer>> nIDComVH,
        final Vector<Set<Integer>> cmtyVV) {
    for (int i = 0; i < cmtyVV.size(); i++) {
        int CID = i;
        for (Integer NID : cmtyVV.get(i)) {
            if (nIDComVH.containsKey(NID)) {
                Set<Integer> x = nIDComVH.get(NID);
                x.add(CID);/*from   w w  w. ja va2 s  . c o m*/
            } else {
                Set<Integer> x = new HashSet<Integer>();
                x.add(CID);
                nIDComVH.put(NID, x);
            }

        }
    }
    return nIDComVH;
}