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    
018    package org.apache.geronimo.console.jmsmanager;
019    
020    import java.util.Map;
021    
022    import javax.jms.Queue;
023    import javax.jms.Topic;
024    
025    import org.apache.geronimo.gbean.AbstractName;
026    import org.apache.geronimo.gbean.AbstractNameQuery;
027    import org.apache.geronimo.gbean.GBeanData;
028    import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
029    import org.apache.geronimo.kernel.GBeanNotFoundException;
030    import org.apache.geronimo.kernel.Kernel;
031    import org.apache.geronimo.kernel.KernelRegistry;
032    import org.apache.geronimo.kernel.config.Configuration;
033    import org.apache.geronimo.kernel.config.ConfigurationManager;
034    import org.apache.geronimo.kernel.config.ConfigurationUtil;
035    import org.apache.geronimo.kernel.repository.Artifact;
036    
037    public abstract class AbstractJMSManager {
038    
039        protected static final Artifact ACTIVEMQ_BROKER_ARTIFACT = new Artifact("geronimo", "activemq-broker", org.apache.geronimo.system.serverinfo.ServerConstants.getVersion(), "car");
040        protected static final Artifact ACTIVEMQ_ARTIFACT = new Artifact("geronimo", "activemq", org.apache.geronimo.system.serverinfo.ServerConstants.getVersion(), "car");
041        protected static final Kernel kernel = KernelRegistry.getSingleKernel();
042    
043        protected static final ConfigurationManager configurationManager = ConfigurationUtil.getConfigurationManager(kernel);
044        protected final Configuration BROKER_CONFIGURATION = configurationManager.getConfiguration(ACTIVEMQ_BROKER_ARTIFACT);
045        protected final Configuration CONNECTOR_CONFIGURATION = configurationManager.getConfiguration(ACTIVEMQ_ARTIFACT);
046    
047        private static final AbstractName earName = kernel.getNaming().createRootName(ACTIVEMQ_ARTIFACT, NameFactory.NULL, NameFactory.J2EE_APPLICATION);
048        protected static final AbstractName RESOURCE_ADAPTER_MODULE_NAME = kernel.getNaming().createChildName(earName, ACTIVEMQ_ARTIFACT.toString(), NameFactory.RESOURCE_ADAPTER_MODULE);
049        protected static final AbstractName RESOURCE_ADAPTER_NAME = kernel.getNaming().createChildName(RESOURCE_ADAPTER_MODULE_NAME, ACTIVEMQ_ARTIFACT.toString(), NameFactory.RESOURCE_ADAPTER);
050        protected static final AbstractName JCA_RESOURCE_NAME = kernel.getNaming().createChildName(RESOURCE_ADAPTER_NAME, ACTIVEMQ_ARTIFACT.toString(), NameFactory.JCA_RESOURCE);
051        protected static final AbstractName JCA_CONNECTION_FACTORY_NAME = kernel.getNaming().createChildName(JCA_RESOURCE_NAME, "DefaultActiveMQConnectionFactory", NameFactory.JCA_CONNECTION_FACTORY);
052        protected static final AbstractName JCA_MANAGED_CONNECTION_FACTORY_NAME = kernel.getNaming().createChildName(JCA_CONNECTION_FACTORY_NAME, "DefaultActiveMQConnectionFactory", NameFactory.JCA_MANAGED_CONNECTION_FACTORY);
053    
054    
055        protected static final String GET_BROKER_ADMIN_FUNCTION = "getBrokerAdmin";
056    
057        public static final String TOPIC_TYPE = "Topic";
058    
059        public static final String QUEUE_TYPE = "Queue";
060    
061        //ViewDestinations attribute names
062        protected static final String DESTINATION_LIST = "destinations";
063    
064        protected static final String DESTINATION_MSG = "destinationsMsg";
065    
066        //CreateDestinations attribute names
067        protected static final String DESTINATION_NAME = "destinationMessageDestinationName";
068    
069        protected static final String DESTINATION_PHYSICAL_NAME = "destinationPhysicalName";
070    
071        protected static final String DESTINATION_TYPE = "destinationType";
072    
073        protected static final String DESTINATION_APPLICATION_NAME = "destinationApplicationName";
074    
075        protected static final String DESTINATION_MODULE_NAME = "destinationModuleName";
076    
077        protected static final String DESTINATION_CONFIG_URI = "destinationConfigURI";
078    
079        protected static Object[] no_args = new Object[0];
080    
081        protected static String[] no_params = new String[0];
082    
083    
084        protected static final String BASE_CONFIG_URI = "runtimedestination/";
085    
086        protected GBeanData getResourceAdapterModuleData() throws GBeanNotFoundException {
087            return CONNECTOR_CONFIGURATION.findGBeanData(new AbstractNameQuery(RESOURCE_ADAPTER_MODULE_NAME));
088        }
089    
090        protected GBeanData getQueueGBeanData() throws GBeanNotFoundException {
091            GBeanData moduleData = getResourceAdapterModuleData();
092            Map adminObjects = (Map) moduleData.getAttribute("adminObjectInfoMap");
093            GBeanData queueData = (GBeanData) adminObjects.get(Queue.class.getName());
094            return new GBeanData(queueData);
095        }
096    
097        protected GBeanData getTopicGBeanData() throws GBeanNotFoundException {
098            GBeanData moduleData = getResourceAdapterModuleData();
099            Map adminObjects = (Map) moduleData.getAttribute("adminObjectInfoMap");
100            GBeanData queueData = (GBeanData) adminObjects.get(Topic.class.getName());
101            return new GBeanData(queueData);
102        }
103    
104    //    protected ObjectName mBeanName;
105    
106    //    public static final ObjectName DESTINATION_QUERY;
107    
108    //    public static final ObjectName ACTIVEMQJCA_RESOURCE_QUERY;
109    
110    //    public static final String ACTIVEMQJCA_RESOURCE;
111    
112    //    static {
113    //        try {
114    //
115    //            DESTINATION_QUERY = ObjectName
116    //                    .getInstance("geronimo.server:j2eeType="
117    //                            + NameFactory.JCA_ADMIN_OBJECT + ",*");
118    //            ACTIVEMQJCA_RESOURCE_QUERY = ObjectName
119    //                    .getInstance("*:j2eeType=JCAManagedConnectionFactory,name=DefaultActiveMQConnectionFactory,*");
120    //            ACTIVEMQJCA_RESOURCE = getActiveMQJCA_RESOURCE(ACTIVEMQJCA_RESOURCE_QUERY);
121    //
122    //            if (null == ACTIVEMQJCA_RESOURCE) {
123    //                throw new RuntimeException(
124    //                        "No JCA resource was found for DefaultActiveMQConnectionFactory");
125    //            }
126    //
127    //        } catch (MalformedObjectNameException e) {
128    //            throw new RuntimeException(e);
129    //        }
130    //    }
131    //
132    //    public static final J2eeContext baseContext = new J2eeContextImpl(
133    //            "geronimo.server", "geronimo", "null", ACTIVEMQJCA_RESOURCE, null,
134    //            null, NameFactory.JCA_ADMIN_OBJECT);
135    //
136        /**
137         * Get the JCA resource name of the activemq bean.
138         *
139         * @return JCA resource name
140         */
141    //    public static String getActiveMQJCA_RESOURCE(ObjectName obj) {
142    //
143    //        Set modules = kernel.listGBeans(obj);
144    //
145    //        String JCA_Resource = null;
146    //
147    //        for (Iterator iterator = modules.iterator(); iterator.hasNext();) {
148    //            ObjectName activemqObject = (ObjectName) iterator.next();
149    //            JCA_Resource = activemqObject
150    //                    .getKeyProperty(NameFactory.JCA_RESOURCE);
151    //        }
152    //
153    //        return JCA_Resource;
154    //    }
155    
156    }