Example usage for java.util Hashtable entrySet

List of usage examples for java.util Hashtable entrySet

Introduction

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

Prototype

Set entrySet

To view the source code for java.util Hashtable entrySet.

Click Source Link

Usage

From source file:org.wso2.carbon.custom.connector.EJB2Init.java

@Override
public void connect(MessageContext messageContext) throws ConnectException {
    try {/*from  www .j a v  a 2  s. c o m*/
        Hashtable dyValues = ejbFactory.getParameters(messageContext, EJBConstance.INIT);
        Set set = dyValues.entrySet();
        for (Object aSet : set) {
            Map.Entry entry = (Map.Entry) aSet;
            prop.setProperty(entry.getKey().toString(), entry.getValue().toString());
        }
    } catch (Exception e) {
        handleException("error while set the properties", e, messageContext);
    }

}

From source file:com.riotgames.mondev.JMXDiscovery.java

protected String discoverMBeans(String key) throws Exception {
    try {/*from   w w  w.  j a v  a 2s. c om*/
        HashMap<String, String[]> env = null;
        if (null != username && null != password) {
            env = new HashMap<String, String[]>();
            env.put(JMXConnector.CREDENTIALS, new String[] { username, password });
        }

        jmxc = JMXConnectorFactory.connect(jmxServerUrl, env);
        mbsc = jmxc.getMBeanServerConnection();

        ObjectName filter = new ObjectName(key);
        JSONArray beanList = new JSONArray();
        JSONObject mapping = new JSONObject();

        Set beans = mbsc.queryMBeans(filter, null);
        for (Object obj : beans) {
            JSONObject bean = new JSONObject();
            ObjectName beanName;

            // Return the ObjectName instance correctly for both Objects and Instances
            if (obj instanceof ObjectName)
                beanName = (ObjectName) obj;
            else if (obj instanceof ObjectInstance)
                beanName = ((ObjectInstance) obj).getObjectName();
            else
                throw new RuntimeException("Unexpected object type: " + obj);

            // Build the standing info, description and object path
            MBeanInfo mbi = mbsc.getMBeanInfo(beanName);
            bean.put("{#JMXDESC}", mbi.getDescription());
            bean.put("{#JMXOBJ}", beanName.getCanonicalName());

            // Build a list of all the MBean properties as {#PROP<NAME>}
            Hashtable<String, String> pt = beanName.getKeyPropertyList();
            for (Map.Entry<String, String> prop : pt.entrySet())
                bean.put(String.format("{#PROP%s}", prop.getKey().toUpperCase()), prop.getValue());

            beanList.put(bean);
        }

        mapping.put("data", beanList);
        return mapping.toString();
    } catch (Exception e) {
        JSONArray data = new JSONArray();
        JSONObject out = new JSONObject();
        out.put("data", data);

        return out.toString();
    } finally {
        try {
            if (null != jmxc)
                jmxc.close();
        } catch (java.io.IOException exception) {
        }

        jmxc = null;
        mbsc = null;
    }
}

From source file:org.wso2.carbon.custom.connector.EJBFactory.java

public Object[] buildArguments(MessageContext synCtx, String methodName) {
    log.info("inside build arg");
    Hashtable dyValues = getParameters(synCtx, methodName);
    Object[] args = new Object[dyValues.size()];
    Set set = dyValues.entrySet();
    int i = 0;/* ww  w  .j av a 2 s  .c o m*/
    for (Object aSet : set) {
        Map.Entry entry = (Map.Entry) aSet;
        args[i] = entry.getValue();
        i++;
    }
    return args;

}

From source file:edu.vt.middleware.ldap.props.AbstractPropertyConfig.java

/**
 * See {@link #setEnvironmentProperties(String,String)}.
 *
 * @param  properties  <code>Hashtable</code> of environment properties
 *//*w ww .j a v a2  s .c om*/
public void setEnvironmentProperties(final Hashtable<String, String> properties) {
    if (properties != null) {
        final Map<String, String> props = new HashMap<String, String>();
        for (Map.Entry<String, String> e : properties.entrySet()) {
            if (this.hasEnvironmentProperty(e.getKey())) {
                props.put(e.getKey(), e.getValue());
            } else {
                this.setEnvironmentProperties(e.getKey(), e.getValue());
            }
        }
        for (Map.Entry<String, String> e : props.entrySet()) {
            this.setEnvironmentProperties(e.getKey(), e.getValue());
        }
    }
}

From source file:org.apache.torque.task.TorqueDataModelTask.java

/**
 * Override Texen's context properties to map the
 * torque.xxx properties (including defaults set by the
 * org/apache/torque/defaults.properties) to just xxx.
 *
 * <p>//from  w w w.ja  va2 s . c  om
 * Also, move xxx.yyy properties to xxxYyy as Velocity
 * doesn't like the xxx.yyy syntax.
 * </p>
 *
 * @param file the file to read the properties from
 */
public void setContextProperties(String file) {
    super.setContextProperties(file);

    // Map the torque.xxx elements from the env to the contextProperties
    Hashtable env = super.getProject().getProperties();
    for (Iterator i = env.entrySet().iterator(); i.hasNext();) {
        Map.Entry entry = (Map.Entry) i.next();
        String key = (String) entry.getKey();
        if (key.startsWith("torque.")) {
            String newKey = key.substring("torque.".length());
            int j = newKey.indexOf(".");
            while (j != -1) {
                newKey = newKey.substring(0, j) + StringUtils.capitalize(newKey.substring(j + 1));
                j = newKey.indexOf(".");
            }

            contextProperties.setProperty(newKey, entry.getValue());
        }
    }
}

From source file:org.hyperic.hq.product.jmx.ServiceTypeFactory.java

private String getObjectNameProperty(ObjectName objectName) {
    final StringBuffer objectNameProperty = new StringBuffer(objectName.getDomain()).append(':');
    Hashtable keyProperties = objectName.getKeyPropertyList();
    for (Iterator iterator = keyProperties.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry keyProperty = (Map.Entry) iterator.next();
        objectNameProperty.append(keyProperty.getKey()).append('=');
        // for now, recognize only type and subtype - replace all others
        // with variable placeholders
        if ("type".equals(keyProperty.getKey()) || "subtype".equals(keyProperty.getKey())) {
            objectNameProperty.append(keyProperty.getValue());
        } else {/*from  w  w  w.  j  a  v  a2s  . c om*/
            objectNameProperty.append('%').append(keyProperty.getKey()).append('%');
        }
        objectNameProperty.append(',');
    }
    objectNameProperty.deleteCharAt(objectNameProperty.length() - 1);
    return objectNameProperty.toString();
}

From source file:com.jaspersoft.ireport.jasperserver.ws.http.JSSCommonsHTTPSender.java

/**
 * Extracts info from message context.//from w w w  .j  a  va2  s.  c  om
 *
 * @param method
 *            Post method
 * @param httpClient
 *            The client used for posting
 * @param msgContext
 *            the message context
 * @param tmpURL
 *            the url to post to.
 *
 * @throws Exception
 */
private void addContextInfo(Request req, MessageContext msgContext, URL tmpURL) throws Exception {
    String v = msgContext.getStrProp(MessageContext.HTTP_TRANSPORT_VERSION);
    if (v != null && v.equals(HTTPConstants.HEADER_PROTOCOL_V10))
        req.version(HttpVersion.HTTP_1_0);
    // optionally set a timeout for the request
    if (msgContext.getTimeout() != 0) {
        req.connectTimeout(msgContext.getTimeout());
        req.socketTimeout(msgContext.getTimeout());
    }

    // Get SOAPAction, default to ""
    String action = msgContext.useSOAPAction() ? msgContext.getSOAPActionURI() : "";

    if (action == null)
        action = "";

    Message msg = msgContext.getRequestMessage();
    if (msg != null)
        req.addHeader(HTTPConstants.HEADER_CONTENT_TYPE, msg.getContentType(msgContext.getSOAPConstants()));
    req.addHeader(HTTPConstants.HEADER_SOAP_ACTION, "\"" + action + "\"");
    req.addHeader(HTTPConstants.HEADER_USER_AGENT, Messages.getMessage("axisUserAgent"));

    // add compression headers if needed
    if (msgContext.isPropertyTrue(HTTPConstants.MC_ACCEPT_GZIP))
        req.addHeader(HTTPConstants.HEADER_ACCEPT_ENCODING, HTTPConstants.COMPRESSION_GZIP);
    if (msgContext.isPropertyTrue(HTTPConstants.MC_GZIP_REQUEST))
        req.addHeader(HTTPConstants.HEADER_CONTENT_ENCODING, HTTPConstants.COMPRESSION_GZIP);

    // Transfer MIME headers of SOAPMessage to HTTP headers.
    MimeHeaders mimeHeaders = msg.getMimeHeaders();
    if (mimeHeaders != null) {
        for (Iterator<?> i = mimeHeaders.getAllHeaders(); i.hasNext();) {
            MimeHeader mimeHeader = (MimeHeader) i.next();
            // HEADER_CONTENT_TYPE and HEADER_SOAP_ACTION are already set.
            // Let's not duplicate them.
            String headerName = mimeHeader.getName();
            if (headerName.equals(HTTPConstants.HEADER_CONTENT_TYPE)
                    || headerName.equals(HTTPConstants.HEADER_SOAP_ACTION))
                continue;
            req.addHeader(mimeHeader.getName(), mimeHeader.getValue());
        }
    }

    // process user defined headers for information.
    Hashtable<?, ?> userHeaderTable = (Hashtable<?, ?>) msgContext.getProperty(HTTPConstants.REQUEST_HEADERS);
    if (userHeaderTable != null)
        for (Map.Entry<?, ?> me : userHeaderTable.entrySet()) {
            Object keyObj = me.getKey();
            if (null == keyObj)
                continue;
            String key = keyObj.toString().trim();
            String value = me.getValue().toString().trim();

            if (key.equalsIgnoreCase(HTTPConstants.HEADER_EXPECT)
                    && value.equalsIgnoreCase(HTTPConstants.HEADER_EXPECT_100_Continue))
                req.useExpectContinue();
            else if (key.equalsIgnoreCase(HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED)) {
                req.removeHeader(new BasicHeader("Transfer-Encoding", "chunked"));
                if (Boolean.parseBoolean(value))
                    ;// req.setHeader("Transfer-Encoding", "chunked");
            } else
                req.addHeader(key, value);
        }
}

From source file:org.apache.synapse.transport.fix.FIXSessionFactory.java

/**
 * Extract the parameters embedded in the given EPR and initialize a new FIX session.
 * Create a new FIX initiator and a new FIX Application.Put the initiator into the
 * initiatorStore keyed by the EPR and start the initiator.
 *
 * @param fixEPR the EPR to send FIX messages
 * @param service the AxisService/*from  w  ww. jav  a 2s .c  om*/
 * @param sessionID the SessionID of the session created
 * @throws org.apache.axis2.AxisFault Exception thrown
 */
public void createFIXInitiator(String fixEPR, AxisService service, SessionID sessionID) throws AxisFault {

    if (log.isDebugEnabled()) {
        log.debug("Initializing a new FIX initiator for the service " + service.getName());
    }
    SessionSettings settings;
    InputStream fixConfigStream = getFIXConfigAsStream(service, false);

    if (fixConfigStream == null) {
        settings = new SessionSettings();
        settings.setLong(sessionID, FIXConstants.HEART_BY_INT, FIXConstants.DEFAULT_HEART_BT_INT_VALUE);
        settings.setString(sessionID, FIXConstants.START_TIME, FIXConstants.DEFAULT_START_TIME_VALUE);
        settings.setString(sessionID, FIXConstants.END_TIME, FIXConstants.DEFAULT_END_TIME_VALUE);
    } else {
        try {
            settings = new SessionSettings(fixConfigStream);
        } catch (ConfigError e) {
            throw new AxisFault("Error in the specified FIX configuration for the initiator. "
                    + "Unable to initialize a FIX session for the service " + service.getName(), e);
        }
    }

    Hashtable<String, String> properties = BaseUtils.getEPRProperties(fixEPR);
    for (Map.Entry<String, String> entry : properties.entrySet()) {
        settings.setString(sessionID, entry.getKey(), entry.getValue());
    }

    String[] socketAddressElements = FIXUtils.getSocketAddressElements(fixEPR);
    settings.setString(sessionID, FIXConstants.CONNECTION_TYPE, FIXConstants.FIX_INITIATOR);
    settings.setString(sessionID, FIXConstants.SOCKET_CONNECT_HOST, socketAddressElements[0]);
    settings.setString(sessionID, FIXConstants.SOCKET_CONNECT_PORT, socketAddressElements[1]);

    quickfix.LogFactory logFactory = getLogFactory(service, settings, false);
    MessageStoreFactory storeFactory = getMessageStoreFactory(service, settings, false);
    MessageFactory messageFactory = new DefaultMessageFactory();
    //Get a new FIX application
    Application messageHandler = applicationFactory.getFIXApplication(service, senderThreadPool, false);

    try {
        //Create a new FIX initiator
        Initiator initiator = new SocketInitiator(messageHandler, storeFactory, settings, logFactory,
                messageFactory);

        initiator.start();
        initJMX(initiator, service.getName());
        initiatorStore.put(fixEPR, initiator);
        applicationStore.put(fixEPR, messageHandler);

        FIXIncomingMessageHandler fixMessageHandler = (FIXIncomingMessageHandler) messageHandler;
        log.info("Waiting for logon procedure to complete...");
        fixMessageHandler.acquire();

    } catch (ConfigError e) {
        throw new AxisFault("Error in the specified FIX configuration for the initiator. Unable "
                + "to initialize a FIX initiator.", e);
    } catch (InterruptedException ignore) {
    }
}

From source file:com.jk.framework.util.FakeRunnable.java

/**
 * Sort hash table.//from w  ww .  j a  v  a2  s.com
 *
 * @param hash
 *            the hash
 * @param asc
 *            the asc
 * @return the array list
 */
public static ArrayList<Entry> sortHashTable(final Hashtable<?, ?> hash, final boolean asc) {
    // Put keys and values in to an arraylist using entryset
    final ArrayList<Entry> myArrayList = new ArrayList(hash.entrySet());
    // Sort the values based on values first and then keys.
    Collections.sort(myArrayList, new HashComparator(asc));
    return myArrayList;
}

From source file:org.wso2.carbon.context.CarbonContext.java

/**
 * Create filter from the bundle context adding class name and properties
 *
 * @param bundleContext BundleContext// w  ww  .j  a v  a 2s.  co m
 * @param clazz The type of the OSGi service
 * @param props attribute list that filter the service list
 * @return Filter
 * @throws InvalidSyntaxException
 */
protected Filter createFilter(BundleContext bundleContext, Class clazz, Hashtable<String, String> props)
        throws InvalidSyntaxException {
    StringBuilder buf = new StringBuilder();
    buf.append("(objectClass=" + clazz.getName() + ")");
    if (props != null && !props.isEmpty()) {
        buf.insert(0, "(&");
        for (Map.Entry<String, String> entry : props.entrySet()) {
            buf.append("(" + entry.getKey() + "=" + entry.getValue() + ")");
        }
        buf.append(")");
    }
    return bundleContext.createFilter(buf.toString());
}