1 4 package com.tc.admin.dso; 5 6 import java.beans.PropertyChangeEvent ; 7 8 import javax.management.ObjectName ; 9 10 import com.tc.admin.AdminClient; 11 import com.tc.admin.ConnectionContext; 12 import com.tc.objectserver.mgmt.ManagedObjectFacade; 13 14 public class DSORoot extends DSOObject { 15 private ObjectName m_bean; 16 private String m_name; 17 private ManagedObjectFacade m_facade; 18 private DSOObject[] m_fields; 19 private String m_label; 20 21 public DSORoot(ConnectionContext cc, ObjectName bean) { 22 super(cc); 23 24 m_bean = bean; 25 m_facade = safeLookupFacade(); 26 27 updateLabel(); 28 } 29 30 public Object getFacade() { 31 return m_facade; 32 } 33 34 protected void updateLabel() { 35 m_label = getName() + " (" + getClassName() + ")"; 36 37 if(isCollection()) { 38 m_label += " [" + getFacadeSize() + "/" + getTrueObjectSize() + "]"; 39 } 40 } 41 42 protected ManagedObjectFacade safeLookupFacade() { 43 try { 44 return lookupFacade(); 45 } catch(Exception e) { 46 AdminClient.getContext().log(e); 47 } 48 49 return null; 50 } 51 52 protected ManagedObjectFacade lookupFacade() 53 throws Exception 54 { 55 String op = "lookupFacade"; 56 String [] types = new String []{"int"}; 57 Object [] args = new Object []{new Integer (m_batchSize)}; 58 59 return (ManagedObjectFacade)m_cc.invoke(m_bean, op, args, types); 60 } 61 62 public String getName() { 63 if(m_name == null) { 64 try { 65 m_name = m_cc.getStringAttribute(m_bean, "RootName"); 66 } 67 catch(Exception e) { 68 AdminClient.getContext().log(e); 69 } 70 } 71 72 return m_name; 73 } 74 75 public String getClassName() { 76 return m_facade != null ? m_facade.getClassName() : null; 77 } 78 79 public boolean isCollection() { 80 return isMap() || isList() || isSet(); 81 } 82 83 public boolean isArray() { 84 return m_facade != null ? m_facade.isArray() : false; 85 } 86 87 public boolean isMap() { 88 return m_facade != null ? m_facade.isMap() : false; 89 } 90 91 public boolean isList() { 92 return m_facade != null ? m_facade.isList() : false; 93 } 94 95 public boolean isSet() { 96 return m_facade != null ? m_facade.isSet() : false; 97 } 98 99 public int getFieldCount() { 100 String [] names = getFieldNames(); 101 return names != null ? names.length : 0; 102 } 103 104 public int getFacadeSize() { 105 return m_facade != null ? m_facade.getFacadeSize() : 0; 106 } 107 108 public int getTrueObjectSize() { 109 return m_facade != null ? m_facade.getTrueObjectSize() : 0; 110 } 111 112 public String [] getFieldNames() { 113 return m_facade != null ? m_facade.getFields() : null; 114 } 115 116 public String getFieldName(int index) { 117 String [] names = getFieldNames(); 118 return names != null ? names[index] : null; 119 } 120 121 public int getFieldIndex(String fieldName) { 122 String [] names = getFieldNames(); 123 124 if(names != null) { 125 for(int i = 0; i < names.length; i++) { 126 if(fieldName.equals(names[i])) { 127 return i; 128 } 129 } 130 } 131 132 return -1; 133 } 134 135 public DSOObject getField(int index) { 136 if(m_fields == null) { 137 m_fields = new DSOObject[getFieldCount()]; 138 } 139 140 if(m_fields[index] == null) { 141 m_fields[index] = newField(getFieldName(index)); 142 } 143 144 return m_fields[index]; 145 } 146 147 public boolean isFieldPrimitive(String fieldName) { 148 return m_facade != null ? m_facade.isPrimitive(fieldName) : true; 149 } 150 151 public String getFieldType(String fieldName) { 152 return m_facade != null ? m_facade.getFieldType(fieldName) : null; 153 } 154 155 public Object getFieldValue(String fieldName) { 156 return m_facade != null ? m_facade.getFieldValue(fieldName) : null; 157 } 158 159 private DSOObject newField(String field) { 160 try { 161 return createField(field, getFieldValue(field)); 162 } 163 catch(Exception e) { 164 AdminClient.getContext().log(e); 165 } 166 167 return null; 168 } 169 170 public DSOObject getField(String fieldName) { 171 return getField(getFieldIndex(fieldName)); 172 } 173 174 public void refresh() { 175 try { 176 m_facade = lookupFacade(); 177 m_fields = null; 178 updateLabel(); 179 180 m_changeHelper.firePropertyChange( 181 new PropertyChangeEvent (this, null, null, null)); 182 } 183 catch(Exception e) { 184 AdminClient.getContext().log(e); 185 } 186 } 187 188 public ObjectName getObjectName() { 189 return m_bean; 190 } 191 192 public String toString() { 193 return m_label; 194 } 195 196 public void accept(DSOObjectVisitor visitor) { 197 visitor.visitDSORoot(this); 198 } 199 } 200 | Popular Tags |