KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > jmx > component > model > MBeanDomain


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.portlets.jmx.component.model;
6
7 import java.util.* ;
8 import javax.management.*;
9 /**
10  * Jul 29, 2004
11  * @author: Tuan Nguyen
12  * @email: tuan08@users.sourceforge.net
13  * @version: $Id: MBeanDomain.java,v 1.1 2004/07/31 14:56:21 tuan08 Exp $
14  */

15 public class MBeanDomain {
16   private String JavaDoc domainName_ ;
17   private String JavaDoc label_ ;
18   private List domains_ ;
19   private List mbeanNames_ ;
20   private boolean select_ ;
21  
22     public MBeanDomain(String JavaDoc 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 JavaDoc getDomainName() { return domainName_ ; }
32   public String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc id_ ;
89     private String JavaDoc label_ ;
90     private ObjectName oname_ ;
91     
92     public MBeanDescription (ObjectName name) {
93       oname_ = name ;
94       id_ = new String JavaDoc(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 JavaDoc getId() { return id_ ;}
105     public String JavaDoc getLabel() { return label_ ; }
106     public ObjectName getObjectName() { return oname_ ; }
107   }
108 }
Popular Tags