1 7 package net.sf.panoptes.component.jmx.model; 8 9 import java.io.IOException ; 10 import java.util.ArrayList ; 11 import java.util.Collections ; 12 import java.util.Iterator ; 13 import java.util.List ; 14 import java.util.Map ; 15 16 import javax.management.InstanceNotFoundException ; 17 import javax.management.IntrospectionException ; 18 import javax.management.MBeanAttributeInfo ; 19 import javax.management.MBeanInfo ; 20 import javax.management.MBeanNotificationInfo ; 21 import javax.management.MBeanOperationInfo ; 22 import javax.management.ObjectName ; 23 import javax.management.ReflectionException ; 24 import javax.management.relation.Relation ; 25 26 import net.sf.panoptes.model.node.BrokenLinkNode; 27 import net.sf.panoptes.model.node.GroupNode; 28 import net.sf.panoptes.model.node.Leaf; 29 import net.sf.panoptes.model.node.Node; 30 import net.sf.panoptes.model.node.NodeDescriptor; 31 import net.sf.panoptes.model.node.NodeSupport; 32 33 44 public class MBeanLinkNode extends GroupNode { 45 46 private ObjectName objectName; 47 private GroupNode attributesGroup = null; 48 private GroupNode operationsGroup = null; 49 private GroupNode notificationsGroup = null; 50 private GroupNode relationsGroup = null; 51 private MBeanWrapper mbean = null; 52 53 62 public MBeanLinkNode(Node parent, ObjectName objectName) { 63 super(parent); 64 setObjectName(objectName); 65 getConfigDescriptor().setIconName(Node.ICON_MBEAN); 66 String name = getObjectName().getCanonicalName(); 67 name = name.substring(name.indexOf(':') + 1); 68 getConfigDescriptor().setName(name); 69 getConfigDescriptor().setDescription("MBean " + getObjectName().toString()); 70 } 71 72 public void setObjectName(ObjectName objectName) { 73 this.objectName = objectName; 74 super.getConfigDescriptor().setName(objectName.toString()); 75 super.getConfigDescriptor().setDescription("Symlink to " + objectName.toString()); 76 77 } 78 79 public MBeanServerNode getServer() { 80 return getWrapper().getServer(); 81 } 82 83 public List getChildren() { 84 return Collections.EMPTY_LIST; 85 } 86 87 90 public ObjectName getObjectName() { 91 return objectName; 92 } 93 94 98 public MBeanWrapper getWrapper() { 99 MBeanWrapper target; 100 MBeanServerNode serverContext = 101 (MBeanServerNode) getContext().get(MBeanServerNode.MBEANSERVERNODE_KEY); 102 try { 103 if (serverContext == null) { 104 105 target = 106 (MBeanWrapper) ServerRegistry 107 .getInstance() 108 .queryMBeans(objectName, null) 109 .iterator() 110 .next(); 111 } else { 112 target = serverContext.getMBean(objectName); 113 } 114 return target; 115 } catch (Exception e) { 116 return null; 117 } 118 } 119 120 public Object getBean() { 121 MBeanWrapper target; 122 try { 123 target = getWrapper(); 124 if (target instanceof MBeanWrapper) { 125 return ((MBeanWrapper) target).getProxy(); 126 } 127 } catch (Exception e) { 128 log.error("Unable to get bean.", e); 129 } 130 return null; 131 } 132 133 138 public void refresh() { 139 attributesGroup = null; 140 operationsGroup = null; 141 notificationsGroup = null; 142 relationsGroup = null; 143 144 } 145 146 public String toString() { 147 return "Link to " + objectName.toString(); 148 } 149 150 } 151 | Popular Tags |