1 5 package org.exoplatform.portlets.jmx.component.model; 6 7 import java.util.* ; 8 import javax.management.*; 9 15 public class MBeanDomain { 16 private String domainName_ ; 17 private String label_ ; 18 private List domains_ ; 19 private List mbeanNames_ ; 20 private boolean select_ ; 21 22 public MBeanDomain(String name) { 23 domains_ = new ArrayList() ; 24 mbeanNames_ = new ArrayList() ; 25 domainName_ = name ; 26 label_ = name ; 27 int idx = name.lastIndexOf('.') ; 28 if(idx > 0) label_ = name.substring(idx + 1 , name.length()) ; 29 } 30 31 public String getDomainName() { return domainName_ ; } 32 public String getLabel() { return label_ ; } 33 34 public List getMBeanNames() { return mbeanNames_ ;} 35 36 public List getDomains() { return domains_ ; } 37 38 public boolean isSelect() { return select_ ; } 39 public void setSelect(boolean b) { select_ = b ; } 40 41 public void addObjectName(ObjectName oname) { 42 String canonicalName = oname.getCanonicalName() ; 43 for(int i = 0 ; i < domains_.size(); i++) { 44 MBeanDomain mdomain = (MBeanDomain) domains_.get(i) ; 45 if(canonicalName.startsWith(mdomain.getDomainName())) { 46 mdomain.addObjectName(oname) ; 47 return ; 48 } 49 } 50 if(oname.getDomain().equals(domainName_)) { 51 mbeanNames_.add(new MBeanDescription(oname)) ; 52 } else { 53 String domain = oname.getDomain() ; 54 int idx = domain.indexOf(".", domainName_.length() + 1) ; 55 if(idx > 0) { 56 domain = domain.substring(0, idx) ; 57 } 58 MBeanDomain mdomain = new MBeanDomain(domain) ; 59 mdomain.addObjectName(oname) ; 60 domains_.add(mdomain) ; 61 } 62 } 63 64 public MBeanDomain findMBeanDomain(String domain) { 65 if(domainName_.equals(domain)) return this ; 66 for(int i = 0; i < domains_.size(); i++) { 67 MBeanDomain mdomain = (MBeanDomain) domains_.get(i) ; 68 MBeanDomain temp = mdomain.findMBeanDomain(domain) ; 69 if(temp != null) return temp ; 70 } 71 return null ; 72 } 73 74 public ObjectName findMBeanObjectname(String id) { 75 for(int i = 0; i < mbeanNames_.size(); i++) { 76 MBeanDescription desc = (MBeanDescription) mbeanNames_.get(i) ; 77 if(id.equals(desc.getId())) return desc.getObjectName() ; 78 } 79 for(int i = 0; i < domains_.size(); i++) { 80 MBeanDomain mdomain = (MBeanDomain) domains_.get(i) ; 81 ObjectName name = mdomain.findMBeanObjectname(id) ; 82 if(name != null) return name ; 83 } 84 return null ; 85 } 86 87 static public class MBeanDescription { 88 private String id_ ; 89 private String label_ ; 90 private ObjectName oname_ ; 91 92 public MBeanDescription (ObjectName name) { 93 oname_ = name ; 94 id_ = new String (Integer.toString(name.hashCode())) ; 95 label_ = name.getKeyProperty("type") ; 96 if(label_ == null) { 97 label_ = "mbean" ; 98 } else { 99 int idx = label_.lastIndexOf('.') ; 100 if(idx > 0) label_ = label_.substring(idx + 1 , label_.length()) ; 101 } 102 } 103 104 public String getId() { return id_ ;} 105 public String getLabel() { return label_ ; } 106 public ObjectName getObjectName() { return oname_ ; } 107 } 108 } | Popular Tags |