1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package org.apache.geronimo.console.jmsmanager; 19 20 import java.util.Map; 21 22 import javax.jms.Queue; 23 import javax.jms.Topic; 24 25 import org.apache.geronimo.gbean.AbstractName; 26 import org.apache.geronimo.gbean.AbstractNameQuery; 27 import org.apache.geronimo.gbean.GBeanData; 28 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 29 import org.apache.geronimo.kernel.GBeanNotFoundException; 30 import org.apache.geronimo.kernel.Kernel; 31 import org.apache.geronimo.kernel.KernelRegistry; 32 import org.apache.geronimo.kernel.config.Configuration; 33 import org.apache.geronimo.kernel.config.ConfigurationManager; 34 import org.apache.geronimo.kernel.config.ConfigurationUtil; 35 import org.apache.geronimo.kernel.repository.Artifact; 36 37 public abstract class AbstractJMSManager { 38 39 protected static final Artifact ACTIVEMQ_BROKER_ARTIFACT = new Artifact("geronimo", "activemq-broker", org.apache.geronimo.system.serverinfo.ServerConstants.getVersion(), "car"); 40 protected static final Artifact ACTIVEMQ_ARTIFACT = new Artifact("geronimo", "activemq", org.apache.geronimo.system.serverinfo.ServerConstants.getVersion(), "car"); 41 protected static final Kernel kernel = KernelRegistry.getSingleKernel(); 42 43 protected static final ConfigurationManager configurationManager = ConfigurationUtil.getConfigurationManager(kernel); 44 protected final Configuration BROKER_CONFIGURATION = configurationManager.getConfiguration(ACTIVEMQ_BROKER_ARTIFACT); 45 protected final Configuration CONNECTOR_CONFIGURATION = configurationManager.getConfiguration(ACTIVEMQ_ARTIFACT); 46 47 private static final AbstractName earName = kernel.getNaming().createRootName(ACTIVEMQ_ARTIFACT, NameFactory.NULL, NameFactory.J2EE_APPLICATION); 48 protected static final AbstractName RESOURCE_ADAPTER_MODULE_NAME = kernel.getNaming().createChildName(earName, ACTIVEMQ_ARTIFACT.toString(), NameFactory.RESOURCE_ADAPTER_MODULE); 49 protected static final AbstractName RESOURCE_ADAPTER_NAME = kernel.getNaming().createChildName(RESOURCE_ADAPTER_MODULE_NAME, ACTIVEMQ_ARTIFACT.toString(), NameFactory.RESOURCE_ADAPTER); 50 protected static final AbstractName JCA_RESOURCE_NAME = kernel.getNaming().createChildName(RESOURCE_ADAPTER_NAME, ACTIVEMQ_ARTIFACT.toString(), NameFactory.JCA_RESOURCE); 51 protected static final AbstractName JCA_CONNECTION_FACTORY_NAME = kernel.getNaming().createChildName(JCA_RESOURCE_NAME, "DefaultActiveMQConnectionFactory", NameFactory.JCA_CONNECTION_FACTORY); 52 protected static final AbstractName JCA_MANAGED_CONNECTION_FACTORY_NAME = kernel.getNaming().createChildName(JCA_CONNECTION_FACTORY_NAME, "DefaultActiveMQConnectionFactory", NameFactory.JCA_MANAGED_CONNECTION_FACTORY); 53 54 55 protected static final String GET_BROKER_ADMIN_FUNCTION = "getBrokerAdmin"; 56 57 public static final String TOPIC_TYPE = "Topic"; 58 59 public static final String QUEUE_TYPE = "Queue"; 60 61 //ViewDestinations attribute names 62 protected static final String DESTINATION_LIST = "destinations"; 63 64 protected static final String DESTINATION_MSG = "destinationsMsg"; 65 66 //CreateDestinations attribute names 67 protected static final String DESTINATION_NAME = "destinationMessageDestinationName"; 68 69 protected static final String DESTINATION_PHYSICAL_NAME = "destinationPhysicalName"; 70 71 protected static final String DESTINATION_TYPE = "destinationType"; 72 73 protected static final String DESTINATION_APPLICATION_NAME = "destinationApplicationName"; 74 75 protected static final String DESTINATION_MODULE_NAME = "destinationModuleName"; 76 77 protected static final String DESTINATION_CONFIG_URI = "destinationConfigURI"; 78 79 protected static Object[] no_args = new Object[0]; 80 81 protected static String[] no_params = new String[0]; 82 83 84 protected static final String BASE_CONFIG_URI = "runtimedestination/"; 85 86 protected GBeanData getResourceAdapterModuleData() throws GBeanNotFoundException { 87 return CONNECTOR_CONFIGURATION.findGBeanData(new AbstractNameQuery(RESOURCE_ADAPTER_MODULE_NAME)); 88 } 89 90 protected GBeanData getQueueGBeanData() throws GBeanNotFoundException { 91 GBeanData moduleData = getResourceAdapterModuleData(); 92 Map adminObjects = (Map) moduleData.getAttribute("adminObjectInfoMap"); 93 GBeanData queueData = (GBeanData) adminObjects.get(Queue.class.getName()); 94 return new GBeanData(queueData); 95 } 96 97 protected GBeanData getTopicGBeanData() throws GBeanNotFoundException { 98 GBeanData moduleData = getResourceAdapterModuleData(); 99 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 }