Java Code Examples for java.util.Hashtable

The following are top voted examples for showing how to use java.util.Hashtable. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: jentrata-msh   File: PartnershipPageletAdaptor.java View source code 8 votes vote down vote up
public Hashtable getHashtable(HttpServletRequest request)
        throws FileUploadException, IOException {
    Hashtable ht = new Hashtable();
    DiskFileUpload upload = new DiskFileUpload();
    List fileItems = upload.parseRequest(request);
    Iterator iter = fileItems.iterator();
    while (iter.hasNext()) {
        FileItem item = (FileItem) iter.next();
        if (item.isFormField()) {
            ht.put(item.getFieldName(), item.getString());
        } else {
            if (item.getName().equals("")) {
                //ht.put(item.getFieldName(), null);
            } else if (item.getSize() == 0) {
                //ht.put(item.getFieldName(), null);
            } else {
                ht.put(item.getFieldName(), item.getInputStream());
            }
        }
    }
    return ht;
}
 
Example 2
Project: iot-server-appliances   File: DeviceManagementDAOUtil.java View source code 8 votes vote down vote up
public static DataSource lookupDataSource(String dataSourceName,
                                          final Hashtable<Object, Object> jndiProperties) {
	try {
		if (jndiProperties == null || jndiProperties.isEmpty()) {
			return (DataSource) InitialContext.doLookup(dataSourceName);
		}
		final InitialContext context = new InitialContext(jndiProperties);
		return (DataSource) context.lookup(dataSourceName);
	} catch (Exception e) {
		throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e);
	}
}
 
Example 3
Project: p1keyboard   File: HIDReaderBase.java View source code 7 votes vote down vote up
@Override
protected int parseInputData(byte[] data, int read) {
	
	int offset = 0;
	int remaining = read;

	Hashtable<Byte, Integer> supportedReports = getSupportedReportCodes();

	if (remaining <= 2)
		return remaining;

	//If we get a HID A or C data package, process it
	if (data[offset] == (byte)0xa1 || data[offset] == (byte)0xb1) {
		
		if (supportedReports.containsKey(data[offset + 1]))
		{
			int neededBytes = supportedReports.get(data[offset + 1]);
			
			//Safeguard, if we get too little data, wait for some more
			if (neededBytes > remaining - 2) {
				if (D) Log.w(getDriverName(), "Got " + (remaining - 2) + " bytes for report " + data[offset + 1] + ", but need " + neededBytes);
				return remaining;
			}
			
			if (!m_readBuffers.containsKey(neededBytes))
				m_readBuffers.put(neededBytes, new byte[neededBytes]);
			
			byte[] buffer = m_readBuffers.get(neededBytes);
			System.arraycopy(data, offset + 2, buffer, 0, neededBytes);
			
			try {
				handleHIDMessage(data[offset], data[offset + 1], buffer);
			} catch (Exception ex) {
				Log.e(getDriverName(), "Handling HID message " + data[offset + 1] + " failed: " + ex.toString());
			}
		}
		else
		{
			if (D) Log.w(getDriverName(), "Got an unsupported HID report: " + data[offset + 1] + ", length: " + (remaining - 2) + ", data: " + getHexString(data, offset, offset + (remaining)));
		}
	}
	
	//Since we cannot get the underlying L2CAP "field length", we
	// *assume* that a single read delivers a single package
	//As "an error is the result of an assumption" this may break :( 
	return 0;
}
 
Example 4
Project: jentrata-msh   File: PartnershipPageletAdaptor.java View source code 6 votes vote down vote up
protected Source getCenterSource(HttpServletRequest request) {

        PropertyTree dom = new PropertyTree();
        dom.setProperty("/partnerships", "");
        dom.setProperty("add_partnership/", "");

        try {
            boolean isMultipart = FileUpload.isMultipartContent(request);
            if (isMultipart) {
                Hashtable ht = getHashtable(request);
                String partnershipId = null;

	            if (((String) ht.get("request_action")).equalsIgnoreCase("change")) {
	                partnershipId = (String) ht.get("selected_partnership_id");
	            } else {
	                partnershipId = (String) ht.get("partnership_id");
                  	updatePartnership(ht, request, dom);	                    
	            }
                getSelectedPartnership(partnershipId, dom);                
            }
            getAllPartnerships(dom);
        } catch (Exception e) {
            EbmsProcessor.core.log.debug("Unable to process the partnership page request", e);
            throw new RuntimeException("Unable to process the partnership page request", e);
        }
              
        return dom.getSource();
    }
 
Example 5
Project: aipo   File: MetaData.java View source code 6 votes vote down vote up
/**
Merges the properties defined in the param MetaData into the current one.
If values are defined in both object for the same key,the one passed as 
parameter updates the previous one
*/
public void merge(MetaData meta)
{
    Map map = meta.getProperties();
    Hashtable params = (Hashtable) map;
    Enumeration en = params.keys();

    while (en.hasMoreElements())
    {
        Object key = en.nextElement();
        String value = (String) params.get(key);
        
        if (value != null)
        {
            this.data.put(key, value);
        }
    }
}
 
Example 6
Project: fiji   File: MenuItemDiverter.java View source code 6 votes vote down vote up
public void setActions() {
	ij = IJ.getInstance();
	if (ij == null)
		return;

	actions = new Hashtable();
	Hashtable table = Menus.getCommands();
	if (table.size() == 0) {
		IJ.error("No menu items found!");
		return;
	}

	if (!"ij.plugin.Commands(\"quit\")".equals(table.get("Quit"))) {
		IJ.error("Cannot install another menu item diverter!");
		return;
	}
	for (Object key : table.keySet()) {
		actions.put(key, table.get(key));
		table.put(key, getAction(key));
	}
	cursor = ij.getCursor();
	if (diversionCursor == null) {
		Toolkit toolkit = Toolkit.getDefaultToolkit();
		URL url = getCursorPath();
		Image diversion = toolkit.getImage(url);
		Point hotSpot = new Point(6, 7);
		diversionCursor = toolkit.createCustomCursor(diversion, hotSpot, "cursor-" + getTitle().replace(' ', '-'));
	}
	ij.setCursor(diversionCursor);

	ij.addKeyListener(this);
	for (Component component : ij.getComponents())
		component.addKeyListener(this);
	ij.addWindowFocusListener(this);
	IJ.showStatus("Click menu entry for " + getTitle() + " (Esc to abort)");
}
 
Example 7
Project: wso2-synapse   File: EnterpriseIntitalContext.java View source code 6 votes vote down vote up
/**
 * Constructs an initial context using the supplied environment.
 * Environment properties are discussed in the class description.
 * 
 * <p>
 * This constructor will not modify <tt>environment</tt> or save a reference
 * to it, but may save a clone.
 * 
 * @param environment
 *            environment used to create the initial context.
 *            Null indicates an empty environment.
 * 
 * @throws NamingException
 *             if a naming exception is encountered
 */
public EnterpriseIntitalContext(Hashtable<?, ?> environment) throws NamingException {
	if (environment != null) {
		environment = (Hashtable) environment.clone();
	}
	init(environment);
}
 
Example 8
Project: proxima   File: NativeTools.java View source code 6 votes vote down vote up
private static HashSet<String> getPids(String processName) throws Exception
{

    String pid = null;
    Hashtable<String, String> tmpRunningProcesses = getRunningProcesses();
    HashSet<String> pids = new HashSet<String>();
    String cmdLine = null;
    for (String fileName : tmpRunningProcesses.keySet())
    {
        cmdLine = tmpRunningProcesses.get(fileName);

        // Checking if processName matches
        if (cmdLine.contains(processName))
        { // equals() / contains()
            pid = fileName.substring(fileName
                    .lastIndexOf(File.separatorChar) + 1);
            pids.add(pid);
        }
    }
    return pids;
}
 
Example 9
Project: netty3.9-note   File: LogFactory.java View source code 6 votes vote down vote up
/**
 * Release any internal references to previously created [email protected] LogFactory}
 * instances, after calling the instance method <code>release()</code> on
 * each of them.  This is useful in environments like servlet containers,
 * which implement application reloading by throwing away a ClassLoader.
 * Dangling references to objects in that class loader would prevent
 * garbage collection.
 */
public static void releaseAll() {
    if (isDiagnosticsEnabled()) {
        logDiagnostic("Releasing factory for all classloaders.");
    }
    // factories is not final and could be replaced in this block.
    final Hashtable factories = LogFactory.factories;
    synchronized (factories) {
        final Enumeration elements = factories.elements();
        while (elements.hasMoreElements()) {
            LogFactory element = (LogFactory) elements.nextElement();
            element.release();
        }
        factories.clear();

        if (nullClassLoaderFactory != null) {
            nullClassLoaderFactory.release();
            nullClassLoaderFactory = null;
        }
    }
}
 
Example 10
Project: windtalk   File: ServiceInfoImpl.java View source code 6 votes vote down vote up
synchronized Map<String, byte[]> getProperties() {
    if ((_props == null) && (this.getText() != null)) {
        Hashtable<String, byte[]> properties = new Hashtable<String, byte[]>();
        try {
            int off = 0;
            while (off < getText().length) {
                // length of the next key value pair
                int len = getText()[off++] & 0xFF;
                if ((len == 0) || (off + len > getText().length)) {
                    properties.clear();
                    break;
                }
                // look for the '='
                int i = 0;
                for (; (i < len) && (getText()[off + i] != '='); i++) {
                    /* Stub */
                }

                // get the property name
                String name = readUTF(getText(), off, i);
                if (name == null) {
                    properties.clear();
                    break;
                }
                if (i == len) {
                    properties.put(name, NO_VALUE);
                } else {
                    byte value[] = new byte[len - ++i];
                    System.arraycopy(getText(), off + i, value, 0, len - i);
                    properties.put(name, value);
                    off += len;
                }
            }
        } catch (Exception exception) {
            // We should get better logging.
            logger.log(Level.WARNING, "Malformed TXT Field ", exception);
        }
        this._props = properties;
    }
    return (_props != null ? _props : Collections.<String, byte[]> emptyMap());
}
 
Example 11
Project: OsmUi   File: mxGraphComponent.java View source code 6 votes vote down vote up
/**
 * 
 */
public Hashtable<Object, Component[]> updateComponents(Object cell)
{
	Hashtable<Object, Component[]> result = new Hashtable<Object, Component[]>();
	Component[] c = components.remove(cell);
	mxCellState state = getGraph().getView().getState(cell);

	if (state != null)
	{
		if (c == null)
		{
			c = createComponents(state);

			if (c != null)
			{
				for (int i = 0; i < c.length; i++)
				{
					insertComponent(state, c[i]);
				}
			}
		}

		if (c != null)
		{
			result.put(cell, c);

			for (int i = 0; i < c.length; i++)
			{
				updateComponent(state, c[i]);
			}
		}
	}
	// Puts the component back into the map so that it will be removed
	else if (c != null)
	{
		components.put(cell, c);
	}

	int childCount = getGraph().getModel().getChildCount(cell);

	for (int i = 0; i < childCount; i++)
	{
		result.putAll(updateComponents(getGraph().getModel().getChildAt(
				cell, i)));
	}

	return result;
}
 
Example 12
Project: socom   File: HSQLGameDatabase.java View source code 6 votes vote down vote up
@Override
public List<GameContext> getGameContextRelations(long gameInstId) throws SQLException {
	Hashtable<String, GameContext> table = new Hashtable<String, GameContext>();
	PreparedStatement statement = db.getPreparedStatement("SELECT parent.externalid AS parentID, parent.name AS parentName, parent.autogenerated, "
			+ "child.externalid AS childID, child.name AS childName, child.autogenerated FROM "
			+ "(gamecontextrelations INNER JOIN gamecontexts AS parent ON gamecontextrelations.parentid = parent.id) "
			+ "INNER JOIN gamecontexts AS child ON gamecontextrelations.childid = child.id WHERE parent.gameinstid = ? "
			+ "AND child.gameinstid = ?;");
	statement.setLong(1, gameInstId);
	statement.setLong(2, gameInstId);
	ResultSet result = statement.executeQuery();

	String parentId, childId;
	while (result.next()) {
		parentId = result.getString("parentID");
		childId = result.getString("childID");
		if (!table.containsKey(parentId))
			table.put(parentId, new GameContext(parentId, result.getString("parentName"), result.getBoolean("autogenerated"), new ArrayList<String>(),
					new ArrayList<String>()));
		if (!table.containsKey(childId))
			table.put(childId, new GameContext(childId, result.getString("childName"), result.getBoolean("autogenerated"), new ArrayList<String>(),
					new ArrayList<String>()));

		table.get(parentId).addNext(childId);
		table.get(childId).addPrevious(parentId);
	}

	List<GameContext> list = new ArrayList<GameContext>();
	for (GameContext context : table.values())
		list.add(context);

	return list;
}
 
Example 13
Project: ProjectLibre   File: Dictionary.java View source code 6 votes vote down vote up
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);
			}
			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);
			}
		}
	}
 
Example 14
Project: WS171-frameworks-base   File: HashtableTest.java View source code 6 votes vote down vote up
public void testHashtableToString() {
    String str;
    Hashtable<String, Integer> hTable = sTable;
    for (int i = ITERATIONS - 1; i >= 0; i--) {
        str = hTable.toString();
        str = hTable.toString();
        str = hTable.toString();
        str = hTable.toString();
        str = hTable.toString();
        str = hTable.toString();
        str = hTable.toString();
        str = hTable.toString();
        str = hTable.toString();
        str = hTable.toString();
    }
}
 
Example 15
Project: camel-trade   File: JMXHelper.java View source code 5 votes vote down vote up
/**
 * Returns a set of ObjectNames matching the passed wildcard object names
 * @param wildcardEq The ObjectName equals
 * @param wildcardWc The ObjectName wildcard
 * @param conn The MBeanServer connection
 * @return a set of ObjectNames matching the passed wildcard object name
 */
public static Set<ObjectName> getMatchingObjectNames(CharSequence wildcardEq, CharSequence wildcardWc, MBeanServerConnection conn) {
	ObjectName wildcardEquals = objectName(wildcardEq);
	ObjectName wildcard = objectName(wildcardWc);
	
	final String wc = new StringBuilder("(").append(wildcardEquals).append("$)").toString();
	Set<ObjectName> names = new HashSet<ObjectName>();
	// A map of regex patterns to match on, keyed by the actual property key
	Map<String, Pattern> wildcardQueryProps = new HashMap<String, Pattern>();
	// the original wildcard object's key properties
	Hashtable<String, String> wildcardProps = objectName(wildcard).getKeyPropertyList();
	// the non wildcarded property keys we will query the mbean server with
	Hashtable<String, String> queryProps = new Hashtable<String, String>();
	queryProps.putAll(wildcardProps);
	// Extract the wildcarded property keys, ie, where the key is KEY<wildcardEquals>
	for(Map.Entry<String, String> prop: wildcard.getKeyPropertyList().entrySet()) {
		if(prop.getKey().endsWith(wc)) {
			String actualKey = prop.getKey().replaceFirst(wc, "");
			wildcardQueryProps.put(actualKey, Pattern.compile(prop.getValue()));
			queryProps.remove(actualKey);
		}
	}
	// Build the lookup query
	StringBuilder b = new StringBuilder(wildcard.getDomain());
	b.append(":");
	// Append the non regex wildcarded properties
	for(Map.Entry<String, String> qp: queryProps.entrySet()) {
		b.append(qp.getKey()).append("=").append(qp.getValue()).append(",");
	}
	// Append the regex wildcarded property keys and "*" as the value
	for(String key: wildcardQueryProps.keySet()) {
		b.append(key).append("=*,");
	}
	// Append a property wild card if the wildcard objectName had:
	//	Property Pattern:true
	//	PropertyList Pattern:true
	//	PropertyValue Pattern:false
	if(wildcard.isPropertyPattern() && wildcard.isPropertyListPattern() && !wildcard.isPropertyValuePattern()) {
		b.append("*");
	}
	if(b.toString().endsWith(",")) {
		b.deleteCharAt(b.length()-1);
	}
	// Create the query object
	try {
		ObjectName queryObjectName = objectName(b);
		for(ObjectName qon: conn.queryNames(queryObjectName, null)) {
			boolean match = true;
			for(Map.Entry<String, Pattern> pattern: wildcardQueryProps.entrySet()) {
				match = pattern.getValue().matcher(qon.getKeyProperty(pattern.getKey())).matches();
				if(!match) break;
			}
			if(match) {
				names.add(qon);
			}
		}
	} catch (Exception e) {			
	}
	
	// Remove all the wildcarded properties from the wildcard objectname's props
	
	//ObjectName query = new ObjectName(wildcard.getDomain());
	
	
	return names;
}