KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > admingui > tree > MonitorTreeNode


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.tree;
25
26 import java.util.HashMap JavaDoc;
27 import java.util.HashSet JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.io.Serializable JavaDoc;
32
33 import javax.management.ObjectName JavaDoc;
34
35 import org.w3c.dom.Element JavaDoc;
36 import org.w3c.dom.Node JavaDoc;
37
38 import com.iplanet.jato.RequestContext;
39 import com.iplanet.jato.util.NonSyncStringBuffer;
40
41 import com.sun.enterprise.tools.admingui.util.Util;
42 import com.sun.enterprise.tools.admingui.util.MBeanUtil;
43 import com.sun.enterprise.tools.guiframework.exception.FrameworkException;
44
45 public class MonitorTreeNode extends IndexTreeNode implements Serializable JavaDoc {
46     
47     public MonitorTreeNode(IndexTreeNode parent, String JavaDoc type, String JavaDoc name, IndexTreeModel model) {
48     super(parent, type, name, model);
49     }
50     
51     protected void ensureChildren() {
52         if (getRefresh() == false)
53             return;
54         try {
55             updateKids();
56         } catch (Exception JavaDoc ex) {
57         if (Util.isLoggableINFO()) {
58         Util.logINFO("ERROR in IndexTreeNode.ensureChildren.", ex);
59         }
60         }
61     setRefresh(false);
62     }
63     
64     private void updateKids() {
65         String JavaDoc objectName = (String JavaDoc)getAttribute("objectName");
66         if (objectName == null || objectName.length() == 0)
67             throw new RuntimeException JavaDoc(
68                 "Object name attribute is required for tree node: "+getName());
69         
70         objectName = replaceTokens(objectName);
71         //System.out.println("objectName: "+objectName);
72
int i;
73         
74         // add all the kids to the reserve list, if they are not already on it.
75
for (i=0; i<children.size(); i++) {
76             if (reserveKids.contains(children.get(i)) == false)
77                 reserveKids.add(children.get(i));
78         }
79         // remove all the kids and then add back as necessary
80
children.clear();
81         
82         for (i=0; i<reserveKids.size(); i++) {
83             IndexTreeNode node = (IndexTreeNode)reserveKids.get(i);
84             Object JavaDoc monitorAttr = node.getAttribute("monitorAttr");
85             if (monitorAttr == null) {
86                 // no attr, just add the node.
87
children.add(node);
88             }
89             else if (monitorAttr instanceof String JavaDoc) {
90                 String JavaDoc value = (String JavaDoc)MBeanUtil.getAttribute(objectName, (String JavaDoc)monitorAttr);
91                 if (value != null && value.equalsIgnoreCase("off") == false) {
92                     children.add(node);
93                 }
94             } else if (monitorAttr instanceof ArrayList JavaDoc) {
95                 // if any of the values are turned on, then add the node.
96
Iterator JavaDoc it = ((List JavaDoc)monitorAttr).iterator();
97                 while (it.hasNext()) {
98                     String JavaDoc value = (String JavaDoc)MBeanUtil.getAttribute(objectName, (String JavaDoc)it.next());
99                     if (value != null && value.equalsIgnoreCase("off") == false) {
100                         children.add(node);
101                         break;
102                     }
103                 }
104             }
105         }
106     }
107     
108     protected List JavaDoc reserveKids = new ArrayList JavaDoc();
109 }
110
Popular Tags