All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.objectweb.jonas.jmx.utils.ConnectorUtils Maven / Gradle / Ivy

/**
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 2007 Bull S.A.S.
 * Contact: [email protected]
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * --------------------------------------------------------------------------
 * $Id: ConnectorUtils.java 10324 2007-05-02 11:35:15Z sauthieg $
 * --------------------------------------------------------------------------
 */

package org.objectweb.jonas.jmx.utils;

/**
 * JMX Connector related utility methods.
 * @author Guillaume Sauthier
 */
public class ConnectorUtils {

    /**
     * Private default constructor for utility class.
     */
    private ConnectorUtils() { }

    /**
     * Extract the protocol from a JMX connector URL
     * @param url JMX connector url to parse
     * @return protocol associated with the url
     */
    public static String getProtocolFromJmxConnectorUrl(String url) {

        int proIndMin = url.indexOf("/jndi/") + "/jndi/".length();
        int proIndMax = url.indexOf("://");
        String protocol = url.substring(proIndMin, proIndMax);

        // for the RMI protocol, we have to parse the connector name to identify
        // the underlaying
        // protocol : either jrmp or irmi
        if (protocol.equals("rmi")) {
            String subUrl = url.substring(proIndMax + "://".length());
            int subProIndMin = subUrl.indexOf("/") + "/".length();
            int subProIndMax = subUrl.indexOf("connector_");
            protocol = subUrl.substring(subProIndMin, subProIndMax);
        }

        return protocol;
    }

    /**
     * Get the provider url from a JMX connector URL
     * @param url JMX connector url to parse
     * @return provider url associated with the url
     */
    public static String getProviderUrlFromJmxConnectorUrl(String url) {

        int proIndMin = url.indexOf("/jndi/") + "/jndi/".length();
        String protocol = getProtocolFromJmxConnectorUrl(url);
        int urlIndMax = url.indexOf("/" + protocol + "connector");
        return url.substring(proIndMin, urlIndMax);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy