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