List of usage examples for java.util Hashtable putAll
public synchronized void putAll(Map<? extends K, ? extends V> t)
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<String, String> table2 = new Hashtable<String, String>(); table2.put("key4", "value4"); table2.put("key5", "value5"); table2.put("key6", "value6"); table2.putAll(table); System.out.println(table2);/*from w ww . j av a2 s . c om*/ }
From source file:Main.java
public static void main(String[] args) { HashMap<String, String> hMap = new HashMap<String, String>(); hMap.put("1", "One"); hMap.put("2", "Two"); hMap.put("3", "Three"); Hashtable<String, String> ht = new Hashtable<String, String>(); ht.put("1", "REPLACED !!"); ht.put("4", "Four"); Enumeration e = ht.elements(); while (e.hasMoreElements()) { System.out.println(e.nextElement()); }//from w w w .j a va 2 s .c o m ht.putAll(hMap); e = ht.elements(); while (e.hasMoreElements()) { System.out.println(e.nextElement()); } }
From source file:Main.java
public static Hashtable parameterMapToHashtable(Map m) { Hashtable ret = new Hashtable(); ret.putAll(m); for (Iterator i = ret.keySet().iterator(); i.hasNext();) { Object key = i.next();/*from www . j a v a 2 s . c om*/ String[] value = (String[]) ret.get(key); try { ret.put(key, value[0]); } catch (ArrayIndexOutOfBoundsException e) { // This should not happen but if it does just continue // processing. } } return ret; }
From source file:com.flexive.shared.EJBLookup.java
/** * Lookup the EJB found under the given Class's name. Uses default flexive naming scheme. * * @param type EJB interface class instance * @param appName EJB application name * @param environment optional environment for creating the initial context * @param <T> EJB interface type * @return a reference to the given EJB//from ww w .jav a 2 s. co m */ protected static <T> T getInterface(Class<T> type, String appName, Hashtable<String, String> environment) { // Try to obtain interface from the lookup cache Object ointerface = ejbCache.get(type.getName()); if (ointerface != null) { return type.cast(ointerface); } // Cache miss: obtain interface and store it in the cache Hashtable<String, String> env; synchronized (EJBLookup.class) { String name; InitialContext ctx = null; env = new Hashtable<String, String>(10); try { if (environment != null) env.putAll(environment); if (used_strategy == null) { appName = discoverStrategy(appName, env, type); if (used_strategy != null) { LOG.info("Working lookup strategy: " + used_strategy); } else { LOG.error("No working lookup strategy found! Possibly because of pending redeployment."); } } prepareEnvironment(used_strategy, env); ctx = new InitialContext(env); name = buildName(appName, type); ointerface = ctx.lookup(name); ejbCache.putIfAbsent(type.getName(), ointerface); return type.cast(ointerface); } catch (Exception exc) { //try one more time with a strategy rediscovery for that bean //this can happen if some beans use mapped names and some not used_strategy = null; try { env.clear(); if (environment != null) env.putAll(environment); appName = discoverStrategy(appName, env, type); if (used_strategy != null) { prepareEnvironment(used_strategy, env); ctx = new InitialContext(env); name = buildName(appName, type); ointerface = ctx.lookup(name); ejbCache.putIfAbsent(type.getName(), ointerface); return type.cast(ointerface); } } catch (Exception e) { LOG.warn("Attempt to rediscover lookup strategy for " + type + " failed!", e); } throw new FxLookupException(LOG, exc, "ex.ejb.lookup.failure", type, exc).asRuntimeException(); } finally { if (ctx != null) try { ctx.close(); } catch (NamingException e) { LOG.error("Failed to close context: " + e.getMessage(), e); } } } }
From source file:gov.nih.nci.caintegrator.application.registration.RegistrationServiceImpl.java
/** * {@inheritDoc}// w ww .j a v a2 s .co m */ @Override public boolean ldapAuthenticate(Map<String, String> connectionProperties, String userID, String password) throws CSInternalConfigurationException, CSInternalInsufficientAttributesException { @SuppressWarnings("PMD.ReplaceHashtableWithMap") // LDAPHelper.authenticate uses a Hashtable. Hashtable<String, String> connectionPropertiesTable = new Hashtable<String, String>(); connectionPropertiesTable.putAll(connectionProperties); try { return LDAPHelper.authenticate(connectionPropertiesTable, userID, password.toCharArray(), null); } catch (CSInternalLoginException e) { // CSM throws this exception on valid user / wrong pass return false; } }
From source file:net.solarnetwork.node.util.BeanConfigurationServiceRegistrationListener.java
/** * Callback when an object has been registered. * // w ww .ja v a 2s .c o m * <p> * This method will instantiate a new instance of {@link #getServiceClass()} * and configure its properties via the Map returned by * {@link BeanConfiguration#getConfiguration()}. Afterwards it will register * the instance as a service, using the {@link #getServiceInterfaces()} as * the service interfaces and {@link #getServiceProperties()} as the service * properties (if available) combined with the * {@link BeanConfiguration#getAttributes()} (if available). * </p> * * @param config * the configuration object * @param properties * the service properties */ public void onBind(BeanConfiguration config, Map<String, ?> properties) { if (log.isDebugEnabled()) { log.debug("Bind called on [" + config + "] with props " + properties); } Object service; try { service = serviceClass.newInstance(); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } Hashtable<String, Object> props = new Hashtable<String, Object>(); if (serviceProperties != null) { props.putAll(serviceProperties); } if (config.getAttributes() != null) { props.putAll(config.getAttributes()); } props.put(org.osgi.framework.Constants.SERVICE_RANKING, config.getOrdering()); BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(service); wrapper.setPropertyValues(config.getConfiguration()); addRegisteredService(new BeanConfigurationRegisteredService(config, properties), service, serviceInterfaces, props); }
From source file:Flowchart.java
public ConnectionAnchor ConnectionAnchorAt(Point p) { ConnectionAnchor closest = null;//from ww w . ja v a2s. c o m long min = Long.MAX_VALUE; Hashtable conn = getSourceConnectionAnchors(); conn.putAll(getTargetConnectionAnchors()); Enumeration e = conn.elements(); while (e.hasMoreElements()) { ConnectionAnchor c = (ConnectionAnchor) e.nextElement(); Point p2 = c.getLocation(null); long d = p.getDistance2(p2); if (d < min) { min = d; closest = c; } } return closest; }
From source file:com.adito.language.LanguagePackManager.java
/** * Get all internationalisation categories. This includes all categories * registered using {@link #registerCategory(LanguageCategory)} and all * those found by looking for ApplicationResources.properties files in the * classpath./*ww w. j a va2 s.c o m*/ * <p> * This method returns a Hashtable of objects of type * {@link LanguageCategory}. * <p> * The first call to this method may take some time as all JARS and class * directories will be scanned. * * @return language category object * @throws IOException */ public Hashtable getHaCategories() throws IOException { checkCategories(); Hashtable<String, LanguageCategory> all = new Hashtable<String, LanguageCategory>(); all.putAll(detectedHaCategories); all.putAll(haCategories); return all; }
From source file:fr.xebia.management.ServletContextAwareMBeanServerFactory.java
public MBeanServer getObject() throws Exception { if (instance == null) { InvocationHandler invocationHandler = new InvocationHandler() { /**/*from www . j a v a2 s . c o m*/ * <p> * Copy the given <code>objectName</code> adding the extra * attributes. * </p> */ protected ObjectName addExtraAttributesToObjectName(ObjectName objectName) throws MalformedObjectNameException { Hashtable<String, String> table = new Hashtable<String, String>( objectName.getKeyPropertyList()); table.putAll(objectNameExtraAttributes); ObjectName result = ObjectName.getInstance(objectName.getDomain(), table); logger.trace("addExtraAttributesToObjectName({}): {}", objectName, result); return result; } public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Object[] modifiedArgs = args.clone(); for (int i = 0; i < modifiedArgs.length; i++) { Object arg = modifiedArgs[i]; if (arg instanceof ObjectName) { ObjectName objectName = (ObjectName) arg; modifiedArgs[i] = addExtraAttributesToObjectName(objectName); } } if (logger.isDebugEnabled()) { logger.debug(method + " : " + Arrays.asList(modifiedArgs)); } try { return method.invoke(server, modifiedArgs); } catch (InvocationTargetException ite) { throw ite.getCause(); } } }; instance = (MBeanServer) Proxy.newProxyInstance(ClassUtils.getDefaultClassLoader(), new Class[] { MBeanServer.class }, invocationHandler); } return instance; }
From source file:com.runwaysdk.dataaccess.database.BusinessDAOFactory.java
/** * Returns a new BusinessDAO instance of the given class name. Default values * are assigned attributes if specified by the metadata. * //from w w w. java 2 s . c om * <br/> * <b>Precondition:</b> type != null <br/> * <b>Precondition:</b> !type.trim().equals("") * * @param type * Class name of the new BusinessDAO to instantiate * @return new BusinessDAO of the given BusinessDAO * @throws DataAccessException * if the given class name is abstract * @throws DataAccessException * if metadata is not defined for the given class name */ public static BusinessDAO newInstance(String type) { // get the meta data for the given class MdEntityDAOIF mdEntityIF = MdEntityDAO.getMdEntityDAO(type); if (!(mdEntityIF instanceof MdBusinessDAOIF)) { throw new UnexpectedTypeException("Type [" + type + "] is not a BusinessDAO"); } MdBusinessDAOIF mdBusinessIF = (MdBusinessDAOIF) mdEntityIF; if (mdBusinessIF.isAbstract()) { String errMsg = "Class [" + mdBusinessIF.definesType() + "] is abstract and cannot be instantiated"; throw new AbstractInstantiationException(errMsg, mdBusinessIF); } Hashtable<String, Attribute> attributeMap = new Hashtable<String, Attribute>(); // get list of all classes in inheritance relationship List<MdBusinessDAOIF> superMdBusinessIFList = mdBusinessIF.getSuperClasses(); for (MdBusinessDAOIF superMdBusinessIF : superMdBusinessIFList) { attributeMap.putAll(EntityDAOFactory.createRecordsForEntity(superMdBusinessIF)); } // Create the businessDAO BusinessDAO newBusinessDAO = factoryMethod(attributeMap, mdBusinessIF.definesType(), true); newBusinessDAO.setIsNew(true); newBusinessDAO.setAppliedToDB(false); newBusinessDAO.setTypeName(mdBusinessIF.definesType()); // This used to be in EntityDAO.save(), but has been moved here to help with // distributed issues String newId = IdParser.buildId(ServerIDGenerator.nextID(), mdEntityIF.getId()); newBusinessDAO.getAttribute(EntityInfo.ID).setValue(newId); return newBusinessDAO; }