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     */
017    package org.apache.activemq;
018    
019    import java.util.Enumeration;
020    import java.util.Vector;
021    import java.util.regex.Matcher;
022    import java.util.regex.Pattern;
023    
024    import javax.jms.ConnectionMetaData;
025    
026    /**
027     * A <CODE>ConnectionMetaData</CODE> object provides information describing
028     * the <CODE>Connection</CODE> object.
029     */
030    public 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                    Pattern pattern = Pattern.compile("(\\d+)\\.(\\d+).*");
047                    Matcher m = pattern.matcher(version);
048                    if (m.matches()) {
049                        major = Integer.parseInt(m.group(1));
050                        minor = Integer.parseInt(m.group(2));
051                    }
052                }
053            } catch (Throwable e) {
054            }
055            PROVIDER_VERSION = version;
056            PROVIDER_MAJOR_VERSION = major;
057            PROVIDER_MINOR_VERSION = minor;
058        }
059    
060        private ActiveMQConnectionMetaData() {
061        }
062    
063        /**
064         * Gets the JMS API version.
065         *
066         * @return the JMS API version
067         */
068        @Override
069        public String getJMSVersion() {
070            return "1.1";
071        }
072    
073        /**
074         * Gets the JMS major version number.
075         *
076         * @return the JMS API major version number
077         */
078        @Override
079        public int getJMSMajorVersion() {
080            return 1;
081        }
082    
083        /**
084         * Gets the JMS minor version number.
085         *
086         * @return the JMS API minor version number
087         */
088        @Override
089        public int getJMSMinorVersion() {
090            return 1;
091        }
092    
093        /**
094         * Gets the JMS provider name.
095         *
096         * @return the JMS provider name
097         */
098        @Override
099        public String getJMSProviderName() {
100            return "ActiveMQ";
101        }
102    
103        /**
104         * Gets the JMS provider version.
105         *
106         * @return the JMS provider version
107         */
108        @Override
109        public String getProviderVersion() {
110            return PROVIDER_VERSION;
111        }
112    
113        /**
114         * Gets the JMS provider major version number.
115         *
116         * @return the JMS provider major version number
117         */
118        @Override
119        public int getProviderMajorVersion() {
120            return PROVIDER_MAJOR_VERSION;
121        }
122    
123        /**
124         * Gets the JMS provider minor version number.
125         *
126         * @return the JMS provider minor version number
127         */
128        @Override
129        public int getProviderMinorVersion() {
130            return PROVIDER_MINOR_VERSION;
131        }
132    
133        /**
134         * Gets an enumeration of the JMSX property names.
135         *
136         * @return an Enumeration of JMSX property names
137         */
138        @Override
139        public Enumeration<String> getJMSXPropertyNames() {
140            Vector<String> jmxProperties = new Vector<String>();
141            jmxProperties.add("JMSXUserID");
142            jmxProperties.add("JMSXGroupID");
143            jmxProperties.add("JMSXGroupSeq");
144            jmxProperties.add("JMSXDeliveryCount");
145            jmxProperties.add("JMSXProducerTXID");
146            return jmxProperties.elements();
147        }
148    }