1 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 ; 11 import java.net.URL ; 12 import java.util.ArrayList ; 13 14 import javax.management.AttributeNotFoundException ; 15 import javax.management.InstanceNotFoundException ; 16 import javax.management.MBeanException ; 17 import javax.management.ObjectName ; 18 import javax.management.ReflectionException ; 19 import javax.swing.Icon ; 20 import javax.swing.ImageIcon ; 21 22 public class RootsHelper extends BaseHelper { 23 private static RootsHelper m_helper = new RootsHelper(); 24 private Icon m_rootsIcon; 25 private Icon m_rootIcon; 26 private Icon m_fieldIcon; 27 private Icon m_cycleIcon; 28 29 public static RootsHelper getHelper() { 30 return m_helper; 31 } 32 33 public Icon getRootsIcon() { 34 if(m_rootsIcon == null) { 35 URL url = getClass().getResource(ICONS_PATH+"hierarchicalLayout.gif"); 36 37 if(url != null) { 38 m_rootsIcon = new ImageIcon (url); 39 } 40 } 41 42 return m_rootsIcon; 43 } 44 45 public Icon getRootIcon() { 46 if(m_rootIcon == null) { 47 URL url = getClass().getResource(ICONS_PATH+"genericvariable_obj.gif"); 48 49 if(url != null) { 50 m_rootIcon = new ImageIcon (url); 51 } 52 } 53 54 return m_rootIcon; 55 } 56 57 public Icon getFieldIcon() { 58 if(m_fieldIcon == null) { 59 URL url = getClass().getResource(ICONS_PATH+"field_protected_obj.gif"); 60 61 if(url != null) { 62 m_fieldIcon = new ImageIcon (url); 63 } 64 } 65 66 return m_fieldIcon; 67 } 68 69 public Icon getCycleIcon() { 70 if(m_cycleIcon == null) { 71 URL url = getClass().getResource(ICONS_PATH+"obj_cycle.gif"); 72 73 if(url != null) { 74 m_cycleIcon = new ImageIcon (url); 75 } 76 } 77 78 return m_cycleIcon; 79 } 80 81 public DSORoot[] getRoots(ConnectionContext cc) 82 throws MBeanException , 83 AttributeNotFoundException , 84 InstanceNotFoundException , 85 ReflectionException , 86 IOException 87 { 88 ObjectName [] 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 [] getRootNames(ConnectionContext cc) 100 throws MBeanException , 101 AttributeNotFoundException , 102 InstanceNotFoundException , 103 ReflectionException , 104 IOException 105 { 106 ObjectName dso = DSOHelper.getHelper().getDSOMBean(cc); 107 return (ObjectName [])cc.getAttribute(dso, "Roots"); 108 } 109 110 public String [] trimFields(String [] fields) { 111 if(fields != null && fields.length > 0) { 112 ArrayList list = new ArrayList (); 113 String 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 [])list.toArray(new String [0]); 124 } 125 126 return new String []{}; 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 |