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 */
030
031public final class ActiveMQConnectionMetaData implements ConnectionMetaData {
032
033    public static final String PROVIDER_VERSION;
034    public static final int PROVIDER_MAJOR_VERSION;
035    public static final int PROVIDER_MINOR_VERSION;
036
037    public static final ActiveMQConnectionMetaData INSTANCE = new ActiveMQConnectionMetaData();
038
039    static {
040        String version = null;
041        int major = 0;
042        int minor = 0;
043        try {
044            Package p = Package.getPackage("org.apache.activemq");
045            if (p != null) {
046                version = p.getImplementationVersion();
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        } catch (Throwable e) {
055        }
056        PROVIDER_VERSION = version;
057        PROVIDER_MAJOR_VERSION = major;
058        PROVIDER_MINOR_VERSION = minor;
059    }
060
061    private ActiveMQConnectionMetaData() {
062    }
063
064    /**
065     * Gets the JMS API version.
066     * 
067     * @return the JMS API version
068     */
069
070    public String getJMSVersion() {
071        return "1.1";
072    }
073
074    /**
075     * Gets the JMS major version number.
076     * 
077     * @return the JMS API major version number
078     */
079
080    public int getJMSMajorVersion() {
081        return 1;
082    }
083
084    /**
085     * Gets the JMS minor version number.
086     * 
087     * @return the JMS API minor version number
088     */
089
090    public int getJMSMinorVersion() {
091        return 1;
092    }
093
094    /**
095     * Gets the JMS provider name.
096     * 
097     * @return the JMS provider name
098     */
099
100    public String getJMSProviderName() {
101        return "ActiveMQ";
102    }
103
104    /**
105     * Gets the JMS provider version.
106     * 
107     * @return the JMS provider version
108     */
109
110    public String getProviderVersion() {
111        return PROVIDER_VERSION;
112    }
113
114    /**
115     * Gets the JMS provider major version number.
116     * 
117     * @return the JMS provider major version number
118     */
119
120    public int getProviderMajorVersion() {
121        return PROVIDER_MAJOR_VERSION;
122    }
123
124    /**
125     * Gets the JMS provider minor version number.
126     * 
127     * @return the JMS provider minor version number
128     */
129
130    public int getProviderMinorVersion() {
131        return PROVIDER_MINOR_VERSION;
132    }
133
134    /**
135     * Gets an enumeration of the JMSX property names.
136     * 
137     * @return an Enumeration of JMSX property names
138     */
139
140    public Enumeration<String> getJMSXPropertyNames() {
141        Vector<String> jmxProperties = new Vector<String>();
142        jmxProperties.add("JMSXGroupID");
143        jmxProperties.add("JMSXGroupSeq");
144        jmxProperties.add("JMSXDeliveryCount");
145        jmxProperties.add("JMSXProducerTXID");
146        return jmxProperties.elements();
147    }
148}