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 java.io.IOException; 020 import java.util.List; 021 import java.net.URI; 022 import javax.portlet.PortletRequestDispatcher; 023 import javax.portlet.ActionRequest; 024 import javax.portlet.ActionResponse; 025 import javax.portlet.PortletException; 026 import javax.portlet.RenderRequest; 027 import javax.portlet.RenderResponse; 028 import javax.portlet.WindowState; 029 import javax.portlet.PortletConfig; 030 import org.apache.geronimo.console.util.PortletManager; 031 import org.apache.geronimo.gbean.AbstractName; 032 import org.apache.geronimo.management.geronimo.JMSManager; 033 import org.apache.commons.logging.Log; 034 import org.apache.commons.logging.LogFactory; 035 036 /** 037 * Basic list of JMS brokers 038 * 039 * @version $Rev: 476321 $ $Date: 2006-11-17 16:18:49 -0500 (Fri, 17 Nov 2006) $ 040 */ 041 public class JMSBrokerPortlet extends BaseJMSPortlet { 042 private final static Log log = LogFactory.getLog(JMSBrokerPortlet.class); 043 private PortletRequestDispatcher normalView; 044 045 private PortletRequestDispatcher maximizedView; 046 047 private PortletRequestDispatcher helpView; 048 049 public void processAction(ActionRequest actionRequest, 050 ActionResponse actionResponse) throws PortletException, IOException { 051 try { 052 String mode = actionRequest.getParameter("mode"); 053 String brokerURI = actionRequest.getParameter("brokerURI"); 054 if(mode.equals("start")) { 055 try { 056 //todo: this only goes into the "starting" state, doesn't make it to "running" -- what's up with that? 057 PortletManager.getManagedBean(actionRequest, new AbstractName(URI.create(brokerURI))).startRecursive(); 058 } catch (Exception e) { 059 throw new PortletException(e); 060 } 061 } else if(mode.equals("stop")) { 062 try { 063 PortletManager.getManagedBean(actionRequest, new AbstractName(URI.create(brokerURI))).stop(); 064 } catch (Exception e) { 065 throw new PortletException(e); 066 } 067 } else if(mode.equals("edit")) { 068 //todo: is there anything to edit? 069 } else if(mode.equals("delete")) { 070 //todo: add a method to JMSManager to handle this 071 } else if(mode.equals("new")) { 072 //todo: add a method to JMSManager to handle this -- it needs to let you pick a configuration that has ActiveMQ on the path... 073 } 074 actionResponse.setRenderParameter("mode", "list"); 075 } catch (Throwable e) { 076 log.error("Unable to process portlet action", e); 077 if(e instanceof PortletException) { 078 throw (PortletException)e; 079 } 080 } 081 } 082 083 protected void doView(RenderRequest renderRequest, 084 RenderResponse renderResponse) throws IOException, PortletException { 085 try { 086 if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) { 087 return; 088 } 089 JMSManager manager = PortletManager.getCurrentServer(renderRequest).getJMSManagers()[0]; //todo: handle multiple 090 List beans = getBrokerList(renderRequest, manager); 091 renderRequest.setAttribute("brokers", beans); 092 if (WindowState.NORMAL.equals(renderRequest.getWindowState())) { 093 normalView.include(renderRequest, renderResponse); 094 } else { 095 maximizedView.include(renderRequest, renderResponse); 096 } 097 } catch (Throwable e) { 098 log.error("Unable to render portlet", e); 099 } 100 } 101 102 protected void doHelp(RenderRequest renderRequest, 103 RenderResponse renderResponse) throws PortletException, IOException { 104 helpView.include(renderRequest, renderResponse); 105 } 106 107 public void init(PortletConfig portletConfig) throws PortletException { 108 super.init(portletConfig); 109 110 normalView = portletConfig.getPortletContext().getRequestDispatcher( 111 "/WEB-INF/view/jmsmanager/server/normal.jsp"); 112 maximizedView = portletConfig.getPortletContext().getRequestDispatcher( 113 "/WEB-INF/view/jmsmanager/server/maximized.jsp"); 114 helpView = portletConfig.getPortletContext().getRequestDispatcher( 115 "/WEB-INF/view/jmsmanager/server/help.jsp"); 116 } 117 118 public void destroy() { 119 helpView = null; 120 normalView = null; 121 maximizedView = null; 122 super.destroy(); 123 } 124 125 }