KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > console > jmsmanager > server > JMSBrokerPortlet


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.server;
18
19 import java.io.IOException JavaDoc;
20 import java.util.List JavaDoc;
21 import java.net.URI JavaDoc;
22 import javax.portlet.PortletRequestDispatcher;
23 import javax.portlet.ActionRequest;
24 import javax.portlet.ActionResponse;
25 import javax.portlet.PortletException;
26 import javax.portlet.RenderRequest;
27 import javax.portlet.RenderResponse;
28 import javax.portlet.WindowState;
29 import javax.portlet.PortletConfig;
30 import org.apache.geronimo.console.util.PortletManager;
31 import org.apache.geronimo.gbean.AbstractName;
32 import org.apache.geronimo.management.geronimo.JMSManager;
33 import org.apache.commons.logging.Log;
34 import org.apache.commons.logging.LogFactory;
35
36 /**
37  * Basic list of JMS brokers
38  *
39  * @version $Rev: 476321 $ $Date: 2006-11-17 16:18:49 -0500 (Fri, 17 Nov 2006) $
40  */

41 public class JMSBrokerPortlet extends BaseJMSPortlet {
42     private final static Log log = LogFactory.getLog(JMSBrokerPortlet.class);
43     private PortletRequestDispatcher normalView;
44
45     private PortletRequestDispatcher maximizedView;
46
47     private PortletRequestDispatcher helpView;
48
49     public void processAction(ActionRequest actionRequest,
50                               ActionResponse actionResponse) throws PortletException, IOException JavaDoc {
51         try {
52             String JavaDoc mode = actionRequest.getParameter("mode");
53             String JavaDoc brokerURI = actionRequest.getParameter("brokerURI");
54             if(mode.equals("start")) {
55                 try {
56                     //todo: this only goes into the "starting" state, doesn't make it to "running" -- what's up with that?
57
PortletManager.getManagedBean(actionRequest, new AbstractName(URI.create(brokerURI))).startRecursive();
58                 } catch (Exception JavaDoc e) {
59                     throw new PortletException(e);
60                 }
61             } else if(mode.equals("stop")) {
62                 try {
63                     PortletManager.getManagedBean(actionRequest, new AbstractName(URI.create(brokerURI))).stop();
64                 } catch (Exception JavaDoc e) {
65                     throw new PortletException(e);
66                 }
67             } else if(mode.equals("edit")) {
68                 //todo: is there anything to edit?
69
} else if(mode.equals("delete")) {
70                 //todo: add a method to JMSManager to handle this
71
} else if(mode.equals("new")) {
72                 //todo: add a method to JMSManager to handle this -- it needs to let you pick a configuration that has ActiveMQ on the path...
73
}
74             actionResponse.setRenderParameter("mode", "list");
75         } catch (Throwable JavaDoc e) {
76             log.error("Unable to process portlet action", e);
77             if(e instanceof PortletException) {
78                 throw (PortletException)e;
79             }
80         }
81     }
82
83     protected void doView(RenderRequest renderRequest,
84                           RenderResponse renderResponse) throws IOException JavaDoc, PortletException {
85         try {
86             if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) {
87                 return;
88             }
89             JMSManager manager = PortletManager.getCurrentServer(renderRequest).getJMSManagers()[0]; //todo: handle multiple
90
List JavaDoc beans = getBrokerList(renderRequest, manager);
91             renderRequest.setAttribute("brokers", beans);
92             if (WindowState.NORMAL.equals(renderRequest.getWindowState())) {
93                 normalView.include(renderRequest, renderResponse);
94             } else {
95                 maximizedView.include(renderRequest, renderResponse);
96             }
97         } catch (Throwable JavaDoc e) {
98             log.error("Unable to render portlet", e);
99         }
100     }
101
102     protected void doHelp(RenderRequest renderRequest,
103                           RenderResponse renderResponse) throws PortletException, IOException JavaDoc {
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 }
126
Popular Tags