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

org.skyscreamer.nevado.jms.NevadoConnectionMetaData Maven / Gradle / Ivy

There is a newer version: 1.3.2
Show newest version
package org.skyscreamer.nevado.jms;

import org.apache.commons.lang.StringUtils;
import org.skyscreamer.nevado.jms.message.JMSXProperty;

import javax.jms.ConnectionMetaData;
import javax.jms.JMSException;
import java.util.Enumeration;
import java.util.List;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Nevado's implementation of ConnectionMetaData.  Uses the manifest to populate provider-specific information.
 *
 * Version parsing logic borrowed from Andrew Kutz's net.sf.nvn.commons.Version, which is licensed under Apache 2.0.
 *
 * @author Carter Page 
 */
public class NevadoConnectionMetaData implements ConnectionMetaData {
    private static Pattern STD_VERSION_PATT =
            Pattern.compile("^([^\\d]*?)(\\d+)(?:\\.(\\d+))?(?:\\.(\\d+))?(?:\\.(\\d+))?(.*)$");

    private static final NevadoConnectionMetaData INSTANCE = new NevadoConnectionMetaData();

    private final Package _package = getClass().getPackage();
    private final String _provider = _package.getImplementationTitle();
    private final ProviderVersion _version = new ProviderVersion(_package.getImplementationVersion());

    public static NevadoConnectionMetaData getInstance() {
        return INSTANCE;
    }

    public String getJMSVersion() throws JMSException {
        return "1.1";
    }

    public int getJMSMajorVersion() throws JMSException {
        return 1;
    }

    public int getJMSMinorVersion() throws JMSException {
        return 1;
    }

    public String getJMSProviderName() throws JMSException {
        return _provider;
    }

    public String getProviderVersion() throws JMSException {
        return _version.getVersion();
    }

    public int getProviderMajorVersion() throws JMSException {
        return _version.getMajorVersion();
    }

    public int getProviderMinorVersion() throws JMSException {
        return _version.getMinorVersion();
    }

    public Enumeration getJMSXPropertyNames() throws JMSException {
        List propertyList = JMSXProperty.getSupportedProperties();
        Vector propertyNames = new Vector(propertyList.size());
        for(JMSXProperty property : propertyList) {
            propertyNames.add(property.name());
        }
        return propertyNames.elements();
    }

    private class ProviderVersion {
        private String _version;
        private int _majorVersion;
        private int _minorVersion;

        private ProviderVersion(String version) {
            _version = version;
            if (_version != null && _version.indexOf(".") > 0) {
                Matcher m = STD_VERSION_PATT.matcher(version);

                if (!m.find())
                {
                    // No parsable version
                    return;
                }

                if (StringUtils.isNotEmpty(m.group(2)))
                {
                    _majorVersion = Integer.valueOf(m.group(2));
                }

                if (StringUtils.isNotEmpty(m.group(3)))
                {
                    _minorVersion = Integer.valueOf(m.group(3));
                }
            }
        }

        public String getVersion() {
            return _version;
        }

        public int getMajorVersion() {
            return _majorVersion;
        }

        public int getMinorVersion() {
            return _minorVersion;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy