001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.admin.dso;
005:
006: import com.tc.admin.BaseHelper;
007: import com.tc.admin.AdminClient;
008: import com.tc.admin.ConnectionContext;
009: import com.tc.admin.common.XTreeNode;
010: import com.tc.stats.DSOClassInfo;
011:
012: import java.net.URL;
013:
014: import javax.management.ObjectName;
015: import javax.swing.Icon;
016: import javax.swing.ImageIcon;
017: import javax.swing.tree.TreeNode;
018:
019: public class ClassesHelper extends BaseHelper {
020: private static ClassesHelper m_helper = new ClassesHelper();
021: private Icon m_classesIcon;
022:
023: public static ClassesHelper getHelper() {
024: return m_helper;
025: }
026:
027: public Icon getClassesIcon() {
028: if (m_classesIcon == null) {
029: URL url = getClass().getResource(
030: ICONS_PATH + "class_obj.gif");
031:
032: if (url != null) {
033: m_classesIcon = new ImageIcon(url);
034: }
035: }
036:
037: return m_classesIcon;
038: }
039:
040: public DSOClassInfo[] getClassInfo(ConnectionContext cc) {
041: try {
042: ObjectName dso = DSOHelper.getHelper().getDSOMBean(cc);
043: return (DSOClassInfo[]) cc.getAttribute(dso, "ClassInfo");
044: } catch (Exception e) {
045: AdminClient.getContext().log(e);
046: return new DSOClassInfo[] { new DSOClassInfo(
047: "java.lang.Void", 0) };
048: }
049: }
050:
051: ClassTreeBranch testGetBranch(XTreeNode parent, String name) {
052: XTreeNode child;
053:
054: for (int i = 0; i < parent.getChildCount(); i++) {
055: child = (XTreeNode) parent.getChildAt(i);
056:
057: if (child instanceof ClassTreeBranch
058: && name.equals(((ClassTreeBranch) child).getName())) {
059: return (ClassTreeBranch) child;
060: }
061: }
062:
063: parent.add(child = new ClassTreeBranch(name));
064:
065: return (ClassTreeBranch) child;
066: }
067:
068: ClassTreeLeaf testGetLeaf(XTreeNode parent, String name) {
069: XTreeNode child;
070:
071: for (int i = 0; i < parent.getChildCount(); i++) {
072: child = (XTreeNode) parent.getChildAt(i);
073:
074: if (child instanceof ClassTreeLeaf
075: && name.equals(((ClassTreeLeaf) child).getName())) {
076: return (ClassTreeLeaf) child;
077: }
078: }
079:
080: parent.add(child = new ClassTreeLeaf(name));
081:
082: return (ClassTreeLeaf) child;
083: }
084:
085: int getInstanceCount(XTreeNode node) {
086: int count = 0;
087: int childCount = node.getChildCount();
088: ClassTreeNode child;
089:
090: for (int i = 0; i < childCount; i++) {
091: child = (ClassTreeNode) node.getChildAt(i);
092: count += child.getInstanceCount();
093: }
094:
095: return count;
096: }
097:
098: public String getFullName(XTreeNode node) {
099: StringBuffer sb = new StringBuffer();
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: }
|