KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > admin > dso > ClassesHelper


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.admin.dso;
5
6 import com.tc.admin.BaseHelper;
7 import com.tc.admin.AdminClient;
8 import com.tc.admin.ConnectionContext;
9 import com.tc.admin.common.XTreeNode;
10 import com.tc.stats.DSOClassInfo;
11
12 import java.net.URL JavaDoc;
13
14 import javax.management.ObjectName JavaDoc;
15 import javax.swing.Icon JavaDoc;
16 import javax.swing.ImageIcon JavaDoc;
17 import javax.swing.tree.TreeNode JavaDoc;
18
19 public class ClassesHelper extends BaseHelper {
20   private static ClassesHelper m_helper = new ClassesHelper();
21   private Icon JavaDoc m_classesIcon;
22
23   public static ClassesHelper getHelper() {
24     return m_helper;
25   }
26
27   public Icon JavaDoc getClassesIcon() {
28     if(m_classesIcon == null) {
29       URL JavaDoc url = getClass().getResource(ICONS_PATH+"class_obj.gif");
30       
31       if(url != null) {
32         m_classesIcon = new ImageIcon JavaDoc(url);
33       }
34     }
35
36     return m_classesIcon;
37   }
38
39   public DSOClassInfo[] getClassInfo(ConnectionContext cc) {
40     try {
41       ObjectName JavaDoc dso = DSOHelper.getHelper().getDSOMBean(cc);
42       return (DSOClassInfo[])cc.getAttribute(dso, "ClassInfo");
43     } catch(Exception JavaDoc e) {
44       AdminClient.getContext().log(e);
45       return new DSOClassInfo[]{ new DSOClassInfo("java.lang.Void", 0) };
46     }
47   }
48
49   ClassTreeBranch testGetBranch(XTreeNode parent, String JavaDoc name) {
50     XTreeNode child;
51
52     for(int i = 0; i < parent.getChildCount(); i++) {
53       child = (XTreeNode)parent.getChildAt(i);
54
55       if(child instanceof ClassTreeBranch &&
56          name.equals(((ClassTreeBranch)child).getName()))
57       {
58         return (ClassTreeBranch)child;
59       }
60     }
61
62     parent.add(child = new ClassTreeBranch(name));
63
64     return (ClassTreeBranch)child;
65   }
66
67   ClassTreeLeaf testGetLeaf(XTreeNode parent, String JavaDoc name) {
68     XTreeNode child;
69
70     for(int i = 0; i < parent.getChildCount(); i++) {
71       child = (XTreeNode)parent.getChildAt(i);
72
73       if(child instanceof ClassTreeLeaf &&
74          name.equals(((ClassTreeLeaf)child).getName()))
75       {
76         return (ClassTreeLeaf)child;
77       }
78     }
79
80     parent.add(child = new ClassTreeLeaf(name));
81
82     return (ClassTreeLeaf)child;
83   }
84
85   int getInstanceCount(XTreeNode node) {
86     int count = 0;
87     int childCount = node.getChildCount();
88     ClassTreeNode child;
89
90     for(int i = 0; i < childCount; i++) {
91       child = (ClassTreeNode)node.getChildAt(i);
92       count += child.getInstanceCount();
93     }
94
95     return count;
96   }
97
98   public String JavaDoc getFullName(XTreeNode node) {
99     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
100     TreeNode[] path = node.getPath();
101     ClassTreeNode child;
102
103     for(int i = 1; i < path.length; i++) {
104       child = (ClassTreeNode)path[i];
105
106       sb.append(child.getName());
107
108       if(i < path.length-1) {
109         sb.append(".");
110       }
111     }
112
113     return sb.toString();
114   }
115 }
116
Popular Tags