KickJava   Java API By Example, From Geeks To Geeks.

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


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.common.XRootNode;
7
8 import com.tc.stats.DSOClassInfo;
9
10 import com.tc.admin.AdminClient;
11
12 public class ClassTreeRoot extends XRootNode implements ClassTreeNode {
13   private Integer JavaDoc instanceCount;
14
15   private static final String JavaDoc NAME =
16     AdminClient.getContext().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 JavaDoc className = classInfo[i].getClassName();
34         String JavaDoc[] 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.testGetLeaf(names[names.length-1]);
42         leaf.setInstanceCount(classInfo[i].getInstanceCount());
43       }
44     }
45   }
46
47   DSOClassInfo[] getInfo() {
48     return (DSOClassInfo[])getUserObject();
49   }
50
51   public String JavaDoc getName() {
52     return NAME;
53   }
54
55   public String JavaDoc getFullName() {
56     return getName();
57   }
58
59   public int getInstanceCount() {
60     if(instanceCount == null) {
61       ClassesHelper helper = ClassesHelper.getHelper();
62       instanceCount = new Integer JavaDoc(helper.getInstanceCount(this));
63     }
64
65     return instanceCount.intValue();
66   }
67
68   public ClassTreeBranch testGetBranch(String JavaDoc name) {
69     ClassesHelper helper = ClassesHelper.getHelper();
70     return helper.testGetBranch(this, name);
71   }
72
73   public ClassTreeLeaf testGetLeaf(String JavaDoc name) {
74     ClassesHelper helper = ClassesHelper.getHelper();
75     return helper.testGetLeaf(this, name);
76   }
77
78   public String JavaDoc toString() {
79     return getName() + " (" + getInstanceCount() + ")";
80   }
81 }
82
Popular Tags