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 package org.apache.geronimo.console.jmsmanager.helper; 18 19 import java.net.URI; 20 import java.util.Map; 21 import java.util.concurrent.ConcurrentHashMap; 22 23 import javax.jms.JMSException; 24 import javax.portlet.PortletRequest; 25 26 import org.apache.geronimo.console.jmsmanager.DestinationStatistics; 27 import org.apache.geronimo.console.jmsmanager.JMSDestinationInfo; 28 import org.apache.geronimo.console.jmsmanager.JMSMessageInfo; 29 import org.apache.geronimo.console.util.PortletManager; 30 import org.apache.geronimo.gbean.AbstractName; 31 import org.apache.geronimo.management.geronimo.ResourceAdapterModule; 32 import org.slf4j.Logger; 33 import org.slf4j.LoggerFactory; 34 35 /** 36 * @version $Rev: 813742 $ $Date: 2009-09-11 02:38:26 -0700 (Fri, 11 Sep 2009) $ 37 */ 38 public class JMSMessageHelperFactory { 39 private static final Logger log = LoggerFactory.getLogger(JMSMessageHelperFactory.class); 40 41 private static final Map<String,JMSMessageHelper> vendorNameJMSMessageHelperMap = new ConcurrentHashMap<String,JMSMessageHelper>(); 42 43 public static final String DEFAULT_JMS_MESSAGEHELPER = "default_jms_messagehelper"; 44 45 public static final String ACTIVEMQ_JMS_MESSAGEHELPER = "activemq.org"; 46 47 static { 48 try { 49 vendorNameJMSMessageHelperMap.put(ACTIVEMQ_JMS_MESSAGEHELPER, new AmqJMSMessageHelper()); 50 vendorNameJMSMessageHelperMap.put(DEFAULT_JMS_MESSAGEHELPER, new JMSMessageHelper() { 51 52 @Override 53 public DestinationStatistics getDestinationStatistics(PortletRequest portletRequest, JMSDestinationInfo destinationInfo) throws JMSException { 54 return new DestinationStatistics(); 55 } 56 57 @Override 58 protected JMSMessageInfo[] getMessagesFromTopic(PortletRequest portletRequest, JMSDestinationInfo destinationInfo, String selector) throws JMSException { 59 return new JMSMessageInfo[0]; 60 } 61 62 @Override 63 public void purge(PortletRequest portletRequest, JMSDestinationInfo destinationInfo) throws JMSException { 64 throw new UnsupportedOperationException("purge action is not supported for current vendor"); 65 } 66 }); 67 } catch (Exception e) { 68 log.warn("Failed to init JMS message helpers"); 69 } 70 } 71 72 public static JMSMessageHelper getMessageHelper(PortletRequest renderRequest, String resourceAdapterModuleName) { 73 String vendorName = null; 74 ResourceAdapterModule module = (ResourceAdapterModule)PortletManager.getManagementHelper(renderRequest).getObject(new AbstractName(URI.create(resourceAdapterModuleName))); 75 if(module != null) { 76 vendorName = module.getVendorName(); 77 } 78 return getJMSMessageHelper(vendorName); 79 } 80 81 public static JMSMessageHelper getJMSMessageHelper(String vendorName) { 82 JMSMessageHelper messageHelper = vendorNameJMSMessageHelperMap.get(vendorName); 83 return messageHelper == null ? vendorNameJMSMessageHelperMap.get(DEFAULT_JMS_MESSAGEHELPER) : messageHelper; 84 } 85 86 public static void registerJMSMessageHelper(String vendorName, JMSMessageHelper jmsMessageHelper) { 87 vendorNameJMSMessageHelperMap.put(vendorName, jmsMessageHelper); 88 } 89 90 public static JMSMessageHelper unregisterJMSMessageHelper(String vendorName){ 91 return vendorNameJMSMessageHelperMap.remove(vendorName); 92 } 93 }