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;
017:
018: import java.io.IOException;
019: import java.util.HashMap;
020: import java.util.Map;
021:
022: import javax.jms.ConnectionFactory;
023: import javax.portlet.ActionRequest;
024: import javax.portlet.ActionResponse;
025: import javax.portlet.PortletConfig;
026: import javax.portlet.PortletContext;
027: import javax.portlet.PortletException;
028: import javax.portlet.PortletRequestDispatcher;
029: import javax.portlet.RenderRequest;
030: import javax.portlet.RenderResponse;
031: import javax.portlet.WindowState;
032:
033: import org.apache.geronimo.console.BasePortlet;
034: import org.apache.geronimo.console.jmsmanager.handlers.CreateDestinationHandler;
035: import org.apache.geronimo.console.jmsmanager.handlers.PortletResponseHandler;
036: import org.apache.geronimo.console.jmsmanager.handlers.RemoveDestinationHandler;
037: import org.apache.geronimo.console.jmsmanager.handlers.StatisticsHandler;
038: import org.apache.geronimo.console.jmsmanager.renderers.CreateDestinationRenderer;
039: import org.apache.geronimo.console.jmsmanager.renderers.PortletRenderer;
040: import org.apache.geronimo.console.jmsmanager.renderers.StatisticsRenderer;
041: import org.apache.geronimo.console.jmsmanager.renderers.ViewDLQRenderer;
042: import org.apache.geronimo.console.jmsmanager.renderers.ViewDestinationsRenderer;
043: import org.apache.geronimo.console.jmsmanager.renderers.ViewMessagesRenderer;
044:
045: public class JMSManagerPortlet extends BasePortlet {
046:
047: private PortletRequestDispatcher edit;
048:
049: private PortletRequestDispatcher help;
050:
051: private ConnectionFactory cf;
052:
053: private Map handlers;
054:
055: private Map renderers;
056:
057: private PortletContext context;
058:
059: public void init(PortletConfig portletConfig)
060: throws PortletException {
061: super .init(portletConfig);
062:
063: context = portletConfig.getPortletContext();
064:
065: help = context
066: .getRequestDispatcher("/WEB-INF/view/jmsmanager/help.jsp");
067: edit = context
068: .getRequestDispatcher("/WEB-INF/view/jmsmanager/edit.jsp");
069:
070: renderers = new HashMap();
071: renderers.put("createDestination",
072: new CreateDestinationRenderer());
073: renderers.put("viewDestinations",
074: new ViewDestinationsRenderer());
075: renderers.put("statistics", new StatisticsRenderer());
076: renderers.put("viewMessages", new ViewMessagesRenderer());
077: renderers.put("viewDLQ", new ViewDLQRenderer());
078:
079: handlers = new HashMap();
080: handlers.put("createDestination",
081: new CreateDestinationHandler());
082: handlers.put("removeDestination",
083: new RemoveDestinationHandler());
084: handlers.put("statistics", new StatisticsHandler());
085:
086: }
087:
088: public void doHelp(RenderRequest renderRequest,
089: RenderResponse renderResponse) throws PortletException,
090: IOException {
091: help.include(renderRequest, renderResponse);
092: }
093:
094: public void doView(RenderRequest renderRequest,
095: RenderResponse renderResponse) throws IOException,
096: PortletException {
097:
098: if (WindowState.MINIMIZED
099: .equals(renderRequest.getWindowState())) {
100: return;
101: }
102:
103: String view = renderRequest.getParameter("processAction");
104: if (view == null) {
105: // no specific content requested - show the destinations list
106: view = "viewDestinations";
107: }
108:
109: PortletRenderer renderer = (PortletRenderer) renderers
110: .get(view);
111: if (renderer == null) {
112: throw new PortletException(
113: "Invalid view parameter specified: " + view);
114: }
115:
116: String include = renderer.render(renderRequest, renderResponse);
117: if (include != null) {
118: PortletRequestDispatcher requestDispatcher = context
119: .getRequestDispatcher(include);
120: requestDispatcher.include(renderRequest, renderResponse);
121: }
122:
123: }
124:
125: public void processAction(ActionRequest actionRequest,
126: ActionResponse actionResponse) throws PortletException,
127: IOException {
128: String processAction = actionRequest
129: .getParameter("processaction");
130:
131: PortletResponseHandler handler = (PortletResponseHandler) handlers
132: .get(processAction);
133:
134: if (handler == null) {
135: // throw new RuntimeException( "no handlers for processAction = " +
136: // processAction );
137: handler = (PortletResponseHandler) handlers
138: .get("viewDestinations");
139: }
140:
141: handler.processAction(actionRequest, actionResponse);
142: }
143:
144: public void destroy() {
145:
146: help = null;
147: edit = null;
148: super.destroy();
149: }
150:
151: }
|