KickJava   Java API By Example, From Geeks To Geeks.

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


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.ConnectionContext;
8 import com.tc.admin.common.XTreeNode;
9
10 import java.io.IOException JavaDoc;
11 import java.net.URL JavaDoc;
12 import java.util.ArrayList JavaDoc;
13
14 import javax.management.AttributeNotFoundException JavaDoc;
15 import javax.management.InstanceNotFoundException JavaDoc;
16 import javax.management.MBeanException JavaDoc;
17 import javax.management.ObjectName JavaDoc;
18 import javax.management.ReflectionException JavaDoc;
19 import javax.swing.Icon JavaDoc;
20 import javax.swing.ImageIcon JavaDoc;
21
22 public class RootsHelper extends BaseHelper {
23   private static RootsHelper m_helper = new RootsHelper();
24   private Icon JavaDoc m_rootsIcon;
25   private Icon JavaDoc m_rootIcon;
26   private Icon JavaDoc m_fieldIcon;
27   private Icon JavaDoc m_cycleIcon;
28   
29   public static RootsHelper getHelper() {
30     return m_helper;
31   }
32
33   public Icon JavaDoc getRootsIcon() {
34     if(m_rootsIcon == null) {
35       URL JavaDoc url = getClass().getResource(ICONS_PATH+"hierarchicalLayout.gif");
36       
37       if(url != null) {
38         m_rootsIcon = new ImageIcon JavaDoc(url);
39       }
40     }
41
42     return m_rootsIcon;
43   }
44
45   public Icon JavaDoc getRootIcon() {
46     if(m_rootIcon == null) {
47       URL JavaDoc url = getClass().getResource(ICONS_PATH+"genericvariable_obj.gif");
48       
49       if(url != null) {
50         m_rootIcon = new ImageIcon JavaDoc(url);
51       }
52     }
53
54     return m_rootIcon;
55   }
56
57   public Icon JavaDoc getFieldIcon() {
58     if(m_fieldIcon == null) {
59       URL JavaDoc url = getClass().getResource(ICONS_PATH+"field_protected_obj.gif");
60       
61       if(url != null) {
62         m_fieldIcon = new ImageIcon JavaDoc(url);
63       }
64     }
65
66     return m_fieldIcon;
67   }
68
69   public Icon JavaDoc getCycleIcon() {
70     if(m_cycleIcon == null) {
71       URL JavaDoc url = getClass().getResource(ICONS_PATH+"obj_cycle.gif");
72       
73       if(url != null) {
74         m_cycleIcon = new ImageIcon JavaDoc(url);
75       }
76     }
77
78     return m_cycleIcon;
79   }
80
81   public DSORoot[] getRoots(ConnectionContext cc)
82     throws MBeanException JavaDoc,
83            AttributeNotFoundException JavaDoc,
84            InstanceNotFoundException JavaDoc,
85            ReflectionException JavaDoc,
86            IOException JavaDoc
87   {
88     ObjectName JavaDoc[] rootNames = getRootNames(cc);
89     int count = (rootNames != null) ? rootNames.length : 0;
90     DSORoot[] result = new DSORoot[count];
91
92     for(int i = 0; i < count; i++) {
93       result[i] = new DSORoot(cc, rootNames[i]);
94     }
95
96     return result;
97   }
98
99   public ObjectName JavaDoc[] getRootNames(ConnectionContext cc)
100     throws MBeanException JavaDoc,
101            AttributeNotFoundException JavaDoc,
102            InstanceNotFoundException JavaDoc,
103            ReflectionException JavaDoc,
104            IOException JavaDoc
105   {
106     ObjectName JavaDoc dso = DSOHelper.getHelper().getDSOMBean(cc);
107     return (ObjectName JavaDoc[])cc.getAttribute(dso, "Roots");
108   }
109
110   public String JavaDoc[] trimFields(String JavaDoc[] fields) {
111     if(fields != null && fields.length > 0) {
112       ArrayList JavaDoc list = new ArrayList JavaDoc();
113       String JavaDoc field;
114
115       for(int i = 0; i < fields.length; i++) {
116         field = fields[i];
117
118         if(!field.startsWith("this$")) {
119           list.add(field);
120         }
121       }
122
123       return (String JavaDoc[])list.toArray(new String JavaDoc[0]);
124     }
125
126     return new String JavaDoc[]{};
127   }
128
129   public XTreeNode createFieldNode(ConnectionContext cc, DSOObject field) {
130     if(field instanceof DSOMapEntryField) {
131       return new MapEntryNode(cc, (DSOMapEntryField)field);
132     }
133
134     if(field instanceof DSOField) {
135       return new FieldTreeNode(cc, (DSOField)field);
136     }
137
138     return new XTreeNode("NoSuchObject");
139   }
140 }
141
Popular Tags