KickJava   Java API By Example, From Geeks To Geeks.

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


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 /*
25  * LogModuleHandler.java
26  *
27  */

28
29 package com.sun.enterprise.tools.admingui.handlers;
30
31 import java.util.ArrayList JavaDoc;
32 import java.util.List JavaDoc;
33
34 import com.iplanet.jato.RequestContext;
35 import com.iplanet.jato.view.DisplayField;
36 import com.iplanet.jato.view.ContainerView;
37 import com.iplanet.jato.view.View;
38 import com.iplanet.jato.view.ViewBase;
39 import com.iplanet.jato.view.html.SelectableGroup;
40 import javax.management.Attribute JavaDoc;
41
42
43
44 import com.sun.enterprise.tools.guiframework.exception.FrameworkException;
45 import com.sun.enterprise.tools.guiframework.view.HandlerContext;
46 import com.sun.enterprise.tools.guiframework.view.DescriptorContainerView;
47
48 import com.sun.enterprise.tools.admingui.util.MBeanUtil;
49 import com.sun.enterprise.tools.admingui.util.Util;
50
51 /**
52  *
53  */

54 public class LogModuleHandler {
55
56      public void showPersistenceLogLevel(RequestContext ctx, HandlerContext handlerCtx) {
57         // the child should be something like: com.sun.web.ui.view.html.CCDropDownMenu
58
SelectableGroup dropDownChild = (SelectableGroup)handlerCtx.getInputValue(DISPLAY_FIELD);
59         String JavaDoc objectName = (String JavaDoc) handlerCtx.getInputValue("objectName");
60         //show the property value set by the property "oracle.toplink.essentials"
61
String JavaDoc[] types = new String JavaDoc[]{"java.lang.String"};
62         Object JavaDoc[] params = new Object JavaDoc[]{PERSISTENCE_MODULE_PROPERTY};
63         String JavaDoc value = "INFO";
64         try {
65             value = (String JavaDoc) MBeanUtil.invoke(objectName, "getPropertyValue", params, types);
66         }catch (Exception JavaDoc ex){
67             //ignore exception if the property doesn't exist
68
}
69         dropDownChild.setValue(value);
70      }
71      
72      public void setPersistenceLogLevel(RequestContext ctx, HandlerContext handlerCtx) {
73         // the child should be something like: com.sun.web.ui.view.html.CCDropDownMenu
74
String JavaDoc objectName = (String JavaDoc) handlerCtx.getInputValue("objectName");
75         String JavaDoc value = (String JavaDoc) handlerCtx.getInputValue("value");
76         //set the property value set of "oracle.toplink.essentials"
77
Attribute JavaDoc attr = new Attribute JavaDoc(PERSISTENCE_MODULE_PROPERTY, value);
78         String JavaDoc[] types = new String JavaDoc[]{"javax.management.Attribute"};
79         Object JavaDoc[] params = new Object JavaDoc[]{attr};
80         MBeanUtil.invoke(objectName, "setProperty", params, types);
81         
82         attr = new Attribute JavaDoc("jdo", value);
83         MBeanUtil.setAttribute(objectName, attr);
84         
85         attr = new Attribute JavaDoc("cmp", value);
86         MBeanUtil.setAttribute(objectName, attr);
87         
88         attr = new Attribute JavaDoc("cmp-container", value);
89         MBeanUtil.setAttribute(objectName, attr);
90      }
91      
92      
93      public void showPersistenceLogModule(RequestContext ctx, HandlerContext handlerCtx) {
94         // the child should be something like: com.sun.web.ui.view.html.CCDropDownMenu
95
DisplayField field = (DisplayField)handlerCtx.getInputValue(DISPLAY_FIELD);
96         String JavaDoc jdo = getLoggerList("jdo", field.getName());
97         String JavaDoc cmp = getLoggerList("cmp", field.getName());
98         field.setValue( "( " + PERSISTENCE_MODULE_PROPERTY + "; " + jdo + cmp + ")" );
99      }
100      
101      public void showModuleLogger(RequestContext reqCtx, HandlerContext handlerCtx) {
102          // Get the attribute names
103
ArrayList JavaDoc attributeNames = (ArrayList JavaDoc)handlerCtx.getInputValue("attributeNames");
104     if (attributeNames == null) {
105         throw new IllegalArgumentException JavaDoc(
106         "The parameter map did not contain " + "attributeNames");
107     }
108
109     // Get the display field names
110
ArrayList JavaDoc displayNames = (ArrayList JavaDoc)handlerCtx.getInputValue("displayNames");
111     if (displayNames == null) {
112         throw new IllegalArgumentException JavaDoc(
113         "The parameter map did not contain " + "displayNames");
114     }
115
116     // Get the view which holds the display fields to set
117
ContainerView view = MBeanHandlers.getView(reqCtx, handlerCtx);
118         
119         for (int i=0; i < displayNames.size(); i++) {
120             String JavaDoc module = (String JavaDoc) attributeNames.get(i);
121             String JavaDoc label = displayNames.get(i)+"Label";
122             String JavaDoc logList = getLoggerList(module, label);
123 // view.setDisplayFieldValue(label, module + logList);
124
view.setDisplayFieldValue(label, "( " + logList + ")");
125         }
126     }
127      
128      private String JavaDoc getLoggerList(String JavaDoc module, String JavaDoc label ){
129         String JavaDoc[] params = {module};
130         String JavaDoc[] types = {"java.lang.String"};
131
132         String JavaDoc logList = "";
133         List JavaDoc loggers = (List JavaDoc) MBeanUtil.invoke(
134                 "com.sun.appserv:name=logmanager,category=runtime,server=server",
135                 "getLognames4LogModule", params, types);
136         
137         if (loggers != null){
138             for(int cnt = 0; cnt < loggers.size(); cnt++){
139                 logList += loggers.get(cnt);
140                 logList +="; ";
141             }
142         }
143         
144         return logList;
145      }
146      
147      
148      private static final String JavaDoc PERSISTENCE_MODULE_PROPERTY = "oracle.toplink.essentials";
149      private static final String JavaDoc DISPLAY_FIELD = "displayField";
150 }
151
Popular Tags