KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > console > infomanager > ServerInfoPortlet


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
18 package org.apache.geronimo.console.infomanager;
19
20 import java.io.IOException JavaDoc;
21 import java.util.Date JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import javax.portlet.ActionRequest;
26 import javax.portlet.ActionResponse;
27 import javax.portlet.PortletConfig;
28 import javax.portlet.PortletException;
29 import javax.portlet.PortletRequestDispatcher;
30 import javax.portlet.RenderRequest;
31 import javax.portlet.RenderResponse;
32 import javax.portlet.WindowState;
33
34 import org.apache.geronimo.console.BasePortlet;
35 import org.apache.geronimo.console.util.PortletManager;
36 import org.apache.geronimo.management.geronimo.JVM;
37 import org.apache.geronimo.system.serverinfo.ServerConstants;
38
39 /**
40  * Calculates various information about the server to display in the server
41  * info portlet view (on of several JSPs depending on the portlet state).
42  *
43  * @version $Rev: 476321 $ $Date: 2006-11-17 16:18:49 -0500 (Fri, 17 Nov 2006) $
44  */

45 public class ServerInfoPortlet extends BasePortlet {
46     private static final String JavaDoc NORMALVIEW_JSP = "/WEB-INF/view/infomanager/svrInfoNormal.jsp";
47
48     private static final String JavaDoc MAXIMIZEDVIEW_JSP = "/WEB-INF/view/infomanager/svrInfoMaximized.jsp";
49
50     private static final String JavaDoc HELPVIEW_JSP = "/WEB-INF/view/infomanager/svrInfoHelp.jsp";
51
52     private PortletRequestDispatcher normalView;
53
54     private PortletRequestDispatcher maximizedView;
55
56     private PortletRequestDispatcher helpView;
57
58     public void processAction(ActionRequest actionRequest,
59                               ActionResponse actionResponse) throws PortletException, IOException JavaDoc {
60     }
61
62     protected void doView(RenderRequest renderRequest,
63                           RenderResponse renderResponse) throws IOException JavaDoc, PortletException {
64         if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) {
65             return;
66         }
67
68         Map JavaDoc svrProps = new HashMap JavaDoc();
69         Map JavaDoc jvmProps = new HashMap JavaDoc();
70
71         JVM jvm = PortletManager.getCurrentJVM(renderRequest);
72
73         Date JavaDoc bootDate = jvm.getKernelBootTime();
74         svrProps.put("Kernel Boot Time", bootDate);
75         svrProps.put("Geronimo Version", ServerConstants.getVersion());
76         renderRequest.setAttribute("svrProps", svrProps);
77
78         jvmProps.put("Java Version", jvm.getJavaVersion());
79         jvmProps.put("Java Vendor", jvm.getJavaVendor());
80         jvmProps.put("Node", jvm.getNode());
81         jvmProps.put("Available Processors", new Integer JavaDoc(jvm.getAvailableProcessors()));
82         renderRequest.setAttribute("jvmProps", jvmProps);
83
84         if (WindowState.NORMAL.equals(renderRequest.getWindowState())) {
85             normalView.include(renderRequest, renderResponse);
86         } else {
87             maximizedView.include(renderRequest, renderResponse);
88         }
89     }
90
91     protected void doHelp(RenderRequest renderRequest,
92                           RenderResponse renderResponse) throws PortletException, IOException JavaDoc {
93         helpView.include(renderRequest, renderResponse);
94     }
95
96     public void init(PortletConfig portletConfig) throws PortletException {
97         super.init(portletConfig);
98         normalView = portletConfig.getPortletContext().getRequestDispatcher(
99                 NORMALVIEW_JSP);
100         maximizedView = portletConfig.getPortletContext().getRequestDispatcher(
101                 MAXIMIZEDVIEW_JSP);
102         helpView = portletConfig.getPortletContext().getRequestDispatcher(
103                 HELPVIEW_JSP);
104     }
105
106     public void destroy() {
107         normalView = null;
108         maximizedView = null;
109         helpView = null;
110         super.destroy();
111     }
112 }
113
Popular Tags