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.geronimo.console.jmsmanager.server; 018 019 import org.apache.geronimo.console.BasePortlet; 020 import org.apache.geronimo.console.util.PortletManager; 021 import org.apache.geronimo.gbean.AbstractName; 022 import org.apache.geronimo.management.geronimo.JMSBroker; 023 import org.apache.geronimo.management.geronimo.JMSManager; 024 025 import javax.portlet.PortletException; 026 import javax.portlet.RenderRequest; 027 028 import java.util.ArrayList; 029 import java.util.List; 030 031 /** 032 * Common methods for JMS portlets 033 * 034 * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $ 035 */ 036 public class BaseJMSPortlet extends BasePortlet { 037 /** 038 * Gets a Map relating broker name to JMSBroker instance 039 */ 040 protected static List getBrokerList(RenderRequest renderRequest, JMSManager manager) throws PortletException { 041 042 JMSBroker[] brokers = (JMSBroker[]) manager.getContainers(); 043 List beans = new ArrayList(); 044 try { 045 for (int i = 0; i < brokers.length; i++) { 046 AbstractName abstractName = PortletManager.getNameFor(renderRequest, brokers[i]); 047 String displayName = abstractName.getName().get("name").toString(); 048 beans.add(new BrokerWrapper(displayName, abstractName.toString(), brokers[i])); 049 } 050 } catch (Exception e) { 051 throw new PortletException(e); 052 } 053 return beans; 054 } 055 056 public static class BrokerWrapper { 057 private String brokerName; 058 private String brokerURI; 059 private JMSBroker broker; 060 061 public BrokerWrapper(String brokerName, String brokerURI, JMSBroker broker) { 062 this.brokerName = brokerName; 063 this.brokerURI = brokerURI; 064 this.broker = broker; 065 } 066 067 public String getBrokerName() { 068 return brokerName; 069 } 070 071 public JMSBroker getBroker() { 072 return broker; 073 } 074 075 public String getBrokerURI() { 076 return brokerURI; 077 } 078 } 079 }