KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > admingui > handlers > ServerInstGeneralHandlers


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.tools.admingui.handlers;
25
26 import java.util.EventObject JavaDoc;
27 import java.lang.Thread JavaDoc;
28 import java.util.Properties JavaDoc;
29
30 import javax.management.MBeanException JavaDoc;
31 import javax.management.ObjectName JavaDoc;
32 import javax.management.AttributeList JavaDoc;
33 import javax.management.Attribute JavaDoc;
34 import javax.servlet.http.HttpServletRequest JavaDoc;
35
36 import com.iplanet.jato.RequestContext;
37 import com.iplanet.jato.RequestManager;
38 import com.iplanet.jato.view.View;
39 import com.iplanet.jato.view.ViewBase;
40 import com.iplanet.jato.view.ViewBean;
41 import com.iplanet.jato.util.NonSyncStringBuffer;
42 import com.iplanet.jato.model.DefaultModel;
43 import com.sun.web.ui.model.CCActionTableModelInterface;
44
45 import com.sun.enterprise.tools.guiframework.exception.FrameworkException;
46 import com.sun.enterprise.tools.guiframework.view.DescriptorContainerView;
47 import com.sun.enterprise.tools.guiframework.view.HandlerContext;
48 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor;
49 import com.sun.enterprise.tools.admingui.util.MBeanUtil;
50 import com.sun.enterprise.tools.admingui.util.Util;
51 import com.sun.enterprise.tools.admingui.AdminGUIConstants;
52
53 import com.sun.enterprise.admin.servermgmt.RuntimeStatus;
54 import com.sun.enterprise.admin.common.Status;
55
56
57 public class ServerInstGeneralHandlers {
58
59     /**
60      *
61      */

62     public String JavaDoc endPortsDisplay(RequestContext ctx, HandlerContext handlerCtx) {
63         String JavaDoc ports = "";
64         String JavaDoc objectName = (String JavaDoc)handlerCtx.getViewDescriptor().getParameter("objectName");
65         // "ias:type=http-service,config=server-config,category=config"
66
// "ias:type=iiop-service,config=server-config,category=config"
67
String JavaDoc methodName = (String JavaDoc)handlerCtx.getViewDescriptor().getParameter("methodName");
68         // "getHttpListener" or "getIiopListener"
69
try {
70             ObjectName JavaDoc[] listeners = (ObjectName JavaDoc[]) MBeanUtil.invoke(
71                 new ObjectName JavaDoc(objectName), methodName, null, null);
72
73             for (int i=0; i<listeners.length; i++) {
74                 Object JavaDoc port = MBeanUtil.getAttribute(listeners[i], "port");
75                 if (i != 0)
76                     ports += ", ";
77                 if (port != null){
78                     String JavaDoc pn = port.toString();
79                     if (pn.startsWith("$")){
80                         String JavaDoc serverName = (String JavaDoc)handlerCtx.getViewDescriptor().getParameter("serverName");
81                         port = resolveToken( (pn.substring(2, pn.length()-1) ), serverName);
82                     }
83                     ports += port.toString();
84                 }
85             }
86             
87         } catch (Exception JavaDoc ex) {
88         if (Util.isLoggableINFO()) {
89         Util.logINFO("Exception thrown in getting HTTP ports.", ex);
90         }
91         }
92
93         return ports;
94     }
95
96
97     /**
98      *
99      */

100     public String JavaDoc endConfigDirDisplay(RequestContext ctx, HandlerContext handlerCtx) {
101         String JavaDoc objectName = (String JavaDoc)handlerCtx.getViewDescriptor().getParameter("objectName");
102         String JavaDoc methodName = (String JavaDoc)handlerCtx.getViewDescriptor().getParameter("methodName");
103         String JavaDoc dir = "";
104         try {
105             Object JavaDoc configDir = MBeanUtil.invoke(
106                 new ObjectName JavaDoc(objectName), methodName, null, null);
107             dir += configDir.toString();
108         } catch (Exception JavaDoc ex) {
109         if (Util.isLoggableINFO()) {
110         Util.logINFO("Exception thrown in getting config directory.", ex);
111         }
112         }
113         return dir;
114     }
115
116
117     /**
118      *
119      */

120     public String JavaDoc endDebugDisplay(RequestContext ctx, HandlerContext handlerCtx) {
121         String JavaDoc objectName = (String JavaDoc)handlerCtx.getViewDescriptor().getParameter("objectName");
122         String JavaDoc methodName = (String JavaDoc)handlerCtx.getViewDescriptor().getParameter("methodName");
123         String JavaDoc msg = Util.getMessage("serverinst.notEnabled");
124         try {
125             Object JavaDoc debugPort = MBeanUtil.getAttribute(
126                 new ObjectName JavaDoc(objectName), methodName);
127
128             if (debugPort != null) {
129                 String JavaDoc port = debugPort.toString();
130                 if (port.equals("0") == false) {
131                     msg = Util.getMessage("serverinst.debugEnabled") +
132                         debugPort.toString();
133                 }
134             }
135         } catch (Exception JavaDoc ex) {
136         if (Util.isLoggableINFO()) {
137         Util.logINFO("Exception thrown in getting debug port.", ex);
138         }
139         }
140         return msg;
141     }
142
143
144     /**
145      *
146      */

147     public String JavaDoc endHostNameDisplay(RequestContext ctx, HandlerContext handlerCtx) {
148     View bean = handlerCtx.getView();
149         DescriptorContainerView view = (DescriptorContainerView)bean.getParent();
150         return ctx.getRequest().getServerName();
151     }
152
153
154     /**
155      * The versioning information can be retrieved using the following mbeans:
156      *
157      * j2eeType=J2EEDomain,name=com.sun.appserv,category=runtime
158      * j2eeType=J2EEServer,name=server,category=runtime
159      *
160      * in the com.sun.appserv domain. The attributes for retrieving the version
161      * using the J2EEDomain mbean is applicationServerFullVersion and
162      * applicationServerVersion. The attribute for retrieving the version using
163      * serverVersion is serverVersion. There had been a request to have the
164      * versioning accessible via the domain and server.
165      */

166     public static String JavaDoc endInstallVersionDisplay(RequestContext ctx, HandlerContext handlerCtx) {
167         String JavaDoc objectName = (String JavaDoc)handlerCtx.getViewDescriptor().getParameter("objectName");
168         String JavaDoc methodName = (String JavaDoc)handlerCtx.getViewDescriptor().getParameter("methodName");
169         String JavaDoc version = "";
170         try {
171             Object JavaDoc domainVersion = MBeanUtil.getAttribute(
172                 new ObjectName JavaDoc(objectName), methodName);
173             version += domainVersion.toString();
174         } catch (Exception JavaDoc ex) {
175         if (Util.isLoggableINFO()) {
176         Util.logINFO("Exception thrown in getting domain version.", ex);
177         }
178         }
179         return version;
180     }
181     
182     public void isServerRunning(RequestContext ctx, HandlerContext handlerCtx) {
183         boolean isRunning = false;
184     Object JavaDoc sts = (Object JavaDoc) handlerCtx.getInputValue("statusObject");
185         if (sts instanceof RuntimeStatus) {
186             Status s = ((RuntimeStatus)sts).getStatus();
187             int code = s.getStatusCode();
188             switch (code) {
189                 case Status.kInstanceRunningCode:
190                 case Status.kInstanceStartingCode:
191                     isRunning = true;
192                     break;
193                 case Status.kInstanceNotRunningCode:
194                 case Status.kInstanceStoppingCode:
195                     isRunning = false;
196                     break;
197                 case Status.kEntityEnabledCode:
198                 case Status.kEntityDisabledCode:
199                     // these code should never happen
200
return; // without setting an output value
201
}
202         }
203         handlerCtx.setOutputValue("value", (isRunning)?("true"):("false"));
204     }
205     
206     public void loadInstanceAndNodeAgent(RequestContext ctx, HandlerContext handlerCtx) {
207         try {
208             CCActionTableModelInterface model =
209             (CCActionTableModelInterface)handlerCtx.getInputValue("propertiesModel");
210             ObjectName JavaDoc[] objs = (ObjectName JavaDoc[] )handlerCtx.getInputValue("instanceList");
211             model.beforeFirst();
212             if (objs == null || objs.length < 1 )
213                 return;
214             for(int i=0; i< objs.length; i++){
215                 String JavaDoc name = (String JavaDoc) MBeanUtil.getAttribute(objs[i], "name");
216                 String JavaDoc nodeAgent = (String JavaDoc) MBeanUtil.getAttribute(objs[i], "node-agent-ref");
217                 model.appendRow();
218                 model.setValue(PropertiesHandlers.PROPERTY_NAME, name);
219                 model.setValue(PropertiesHandlers.PROPERTY_VALUE ,nodeAgent);
220                 model.setRowSelected(false);
221             }
222             
223         } catch (Exception JavaDoc ex) {
224             throw new FrameworkException("loadProperties: Loading error. ", ex);
225         }
226     }
227     
228      private String JavaDoc resolveToken(String JavaDoc pn, String JavaDoc serverName)
229     {
230         if (Util.isEmpty(serverName)){
231         throw new IllegalArgumentException JavaDoc("The parameter map did not contain serverName");
232     }
233         String JavaDoc objectName = "com.sun.appserv:type=server,category=config,name=" + serverName;
234         String JavaDoc methodName = "listSystemProperties";
235         Object JavaDoc[] params = new Object JavaDoc[]{ new Boolean JavaDoc("true")};
236         String JavaDoc[] types = new String JavaDoc[]{"boolean"};
237         try {
238             Properties JavaDoc sysProp = (Properties JavaDoc) MBeanUtil.invoke(new ObjectName JavaDoc(objectName), methodName, params, types);
239             String JavaDoc value = sysProp.getProperty(pn);
240             return value;
241         }catch (Exception JavaDoc ex){
242             throw new FrameworkException("EndPortDisplay: ", ex);
243         }
244     }
245     
246     
247 }
248
Popular Tags