01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.admin.dso;
05:
06: import com.tc.admin.common.XRootNode;
07:
08: import com.tc.stats.DSOClassInfo;
09:
10: import com.tc.admin.AdminClient;
11:
12: public class ClassTreeRoot extends XRootNode implements ClassTreeNode {
13: private Integer instanceCount;
14:
15: private static final String NAME = AdminClient.getContext()
16: .getMessage("dso.allClasses");
17:
18: ClassTreeRoot(DSOClassInfo[] classInfo) {
19: super ();
20:
21: if (classInfo != null) {
22: setClassInfo(classInfo);
23: }
24: }
25:
26: public void setClassInfo(DSOClassInfo[] classInfo) {
27: setUserObject(classInfo);
28:
29: tearDownChildren();
30:
31: if (classInfo != null) {
32: for (int i = 0; i < classInfo.length; i++) {
33: String className = classInfo[i].getClassName();
34: String[] names = className.split("\\.");
35: ClassTreeNode node = this ;
36:
37: for (int j = 0; j < names.length - 1; j++) {
38: node = node.testGetBranch(names[j]);
39: }
40:
41: ClassTreeLeaf leaf = node
42: .testGetLeaf(names[names.length - 1]);
43: leaf.setInstanceCount(classInfo[i].getInstanceCount());
44: }
45: }
46: }
47:
48: DSOClassInfo[] getInfo() {
49: return (DSOClassInfo[]) getUserObject();
50: }
51:
52: public String getName() {
53: return NAME;
54: }
55:
56: public String getFullName() {
57: return getName();
58: }
59:
60: public int getInstanceCount() {
61: if (instanceCount == null) {
62: ClassesHelper helper = ClassesHelper.getHelper();
63: instanceCount = new Integer(helper.getInstanceCount(this ));
64: }
65:
66: return instanceCount.intValue();
67: }
68:
69: public ClassTreeBranch testGetBranch(String name) {
70: ClassesHelper helper = ClassesHelper.getHelper();
71: return helper.testGetBranch(this , name);
72: }
73:
74: public ClassTreeLeaf testGetLeaf(String name) {
75: ClassesHelper helper = ClassesHelper.getHelper();
76: return helper.testGetLeaf(this , name);
77: }
78:
79: public String toString() {
80: return getName() + " (" + getInstanceCount() + ")";
81: }
82: }
|