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.ConnectionContext;
008: import com.tc.admin.common.XTreeNode;
009:
010: import java.io.IOException;
011: import java.net.URL;
012: import java.util.ArrayList;
013:
014: import javax.management.AttributeNotFoundException;
015: import javax.management.InstanceNotFoundException;
016: import javax.management.MBeanException;
017: import javax.management.MalformedObjectNameException;
018: import javax.management.ObjectName;
019: import javax.management.ReflectionException;
020: import javax.swing.Icon;
021: import javax.swing.ImageIcon;
022:
023: public class RootsHelper extends BaseHelper {
024: private static RootsHelper m_helper = new RootsHelper();
025: private Icon m_rootsIcon;
026: private Icon m_rootIcon;
027: private Icon m_fieldIcon;
028: private Icon m_cycleIcon;
029:
030: public static RootsHelper getHelper() {
031: return m_helper;
032: }
033:
034: public Icon getRootsIcon() {
035: if (m_rootsIcon == null) {
036: URL url = getClass().getResource(
037: ICONS_PATH + "hierarchicalLayout.gif");
038:
039: if (url != null) {
040: m_rootsIcon = new ImageIcon(url);
041: }
042: }
043:
044: return m_rootsIcon;
045: }
046:
047: public Icon getRootIcon() {
048: if (m_rootIcon == null) {
049: URL url = getClass().getResource(
050: ICONS_PATH + "genericvariable_obj.gif");
051:
052: if (url != null) {
053: m_rootIcon = new ImageIcon(url);
054: }
055: }
056:
057: return m_rootIcon;
058: }
059:
060: public Icon getFieldIcon() {
061: if (m_fieldIcon == null) {
062: URL url = getClass().getResource(
063: ICONS_PATH + "field_protected_obj.gif");
064:
065: if (url != null) {
066: m_fieldIcon = new ImageIcon(url);
067: }
068: }
069:
070: return m_fieldIcon;
071: }
072:
073: public Icon getCycleIcon() {
074: if (m_cycleIcon == null) {
075: URL url = getClass().getResource(
076: ICONS_PATH + "obj_cycle.gif");
077:
078: if (url != null) {
079: m_cycleIcon = new ImageIcon(url);
080: }
081: }
082:
083: return m_cycleIcon;
084: }
085:
086: public DSORoot[] getRoots(ConnectionContext cc)
087: throws MBeanException, AttributeNotFoundException,
088: InstanceNotFoundException, ReflectionException,
089: IOException, MalformedObjectNameException {
090: ObjectName[] rootNames = getRootNames(cc);
091: int count = (rootNames != null) ? rootNames.length : 0;
092: DSORoot[] result = new DSORoot[count];
093:
094: for (int i = 0; i < count; i++) {
095: result[i] = new DSORoot(cc, rootNames[i]);
096: }
097:
098: return result;
099: }
100:
101: public ObjectName[] getRootNames(ConnectionContext cc)
102: throws MBeanException, AttributeNotFoundException,
103: InstanceNotFoundException, ReflectionException,
104: IOException, MalformedObjectNameException {
105: ObjectName dso = DSOHelper.getHelper().getDSOMBean(cc);
106: return (ObjectName[]) cc.getAttribute(dso, "Roots");
107: }
108:
109: public String[] trimFields(String[] fields) {
110: if (fields != null && fields.length > 0) {
111: ArrayList list = new ArrayList();
112: String field;
113:
114: for (int i = 0; i < fields.length; i++) {
115: field = fields[i];
116:
117: if (!field.startsWith("this$")) {
118: list.add(field);
119: }
120: }
121:
122: return (String[]) list.toArray(new String[0]);
123: }
124:
125: return new String[] {};
126: }
127:
128: public XTreeNode createFieldNode(ConnectionContext cc,
129: 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: }
|