001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.activemq;
018
019import java.util.Enumeration;
020import java.util.Vector;
021import java.util.regex.Matcher;
022import java.util.regex.Pattern;
023
024import javax.jms.ConnectionMetaData;
025
026/**
027 * A <CODE>ConnectionMetaData</CODE> object provides information describing
028 * the <CODE>Connection</CODE> object.
029 */
030public final class ActiveMQConnectionMetaData implements ConnectionMetaData {
031
032    public static final String PROVIDER_VERSION;
033    public static final int PROVIDER_MAJOR_VERSION;
034    public static final int PROVIDER_MINOR_VERSION;
035
036    public static final ActiveMQConnectionMetaData INSTANCE = new ActiveMQConnectionMetaData();
037
038    static {
039        String version = null;
040        int major = 0;
041        int minor = 0;
042        try {
043            Package p = Package.getPackage("org.apache.activemq");
044            if (p != null) {
045                version = p.getImplementationVersion();
046                if (version != null) {
047                    Pattern pattern = Pattern.compile("(\\d+)\\.(\\d+).*");
048                    Matcher m = pattern.matcher(version);
049                    if (m.matches()) {
050                        major = Integer.parseInt(m.group(1));
051                        minor = Integer.parseInt(m.group(2));
052                    }
053                }
054            }
055        } catch (Throwable e) {
056        }
057        PROVIDER_VERSION = version;
058        PROVIDER_MAJOR_VERSION = major;
059        PROVIDER_MINOR_VERSION = minor;
060    }
061
062    private ActiveMQConnectionMetaData() {
063    }
064
065    /**
066     * Gets the JMS API version.
067     *
068     * @return the JMS API version
069     */
070    @Override
071    public String getJMSVersion() {
072        return "1.1";
073    }
074
075    /**
076     * Gets the JMS major version number.
077     *
078     * @return the JMS API major version number
079     */
080    @Override
081    public int getJMSMajorVersion() {
082        return 1;
083    }
084
085    /**
086     * Gets the JMS minor version number.
087     *
088     * @return the JMS API minor version number
089     */
090    @Override
091    public int getJMSMinorVersion() {
092        return 1;
093    }
094
095    /**
096     * Gets the JMS provider name.
097     *
098     * @return the JMS provider name
099     */
100    @Override
101    public String getJMSProviderName() {
102        return "ActiveMQ";
103    }
104
105    /**
106     * Gets the JMS provider version.
107     *
108     * @return the JMS provider version
109     */
110    @Override
111    public String getProviderVersion() {
112        return PROVIDER_VERSION;
113    }
114
115    /**
116     * Gets the JMS provider major version number.
117     *
118     * @return the JMS provider major version number
119     */
120    @Override
121    public int getProviderMajorVersion() {
122        return PROVIDER_MAJOR_VERSION;
123    }
124
125    /**
126     * Gets the JMS provider minor version number.
127     *
128     * @return the JMS provider minor version number
129     */
130    @Override
131    public int getProviderMinorVersion() {
132        return PROVIDER_MINOR_VERSION;
133    }
134
135    /**
136     * Gets an enumeration of the JMSX property names.
137     *
138     * @return an Enumeration of JMSX property names
139     */
140    @Override
141    public Enumeration<String> getJMSXPropertyNames() {
142        Vector<String> jmxProperties = new Vector<String>();
143        jmxProperties.add("JMSXUserID");
144        jmxProperties.add("JMSXGroupID");
145        jmxProperties.add("JMSXGroupSeq");
146        jmxProperties.add("JMSXDeliveryCount");
147        jmxProperties.add("JMSXProducerTXID");
148        return jmxProperties.elements();
149    }
150}