1 22 package org.jboss.management.j2ee; 23 24 import javax.management.MBeanServer ; 25 import javax.management.MalformedObjectNameException ; 26 import javax.management.ObjectName ; 27 import java.util.ArrayList ; 28 import java.util.List ; 29 import java.util.Set ; 30 31 39 public class J2EEDomain extends J2EEManagedObject 40 implements J2EEDomainMBean 41 { 42 43 47 private static String domainName = null; 48 49 52 private List serverNames = new ArrayList (); 53 54 60 public static String getDomainName() 61 { 62 return domainName; 63 } 64 65 71 public static ObjectName getDomainServerName(MBeanServer mbeanServer) 72 { 73 ObjectName domainServer = null; 74 try 75 { 76 ObjectName serverQuery = new ObjectName (domainName + ":" + 78 J2EEManagedObject.TYPE + "=" + J2EETypeConstants.J2EEServer + "," + "*"); 79 80 Set servers = mbeanServer.queryNames(serverQuery, null); 81 if (servers.isEmpty() == false) 82 { 83 domainServer = (ObjectName ) servers.iterator().next(); 84 } 85 } 86 catch (Exception ignore) 87 { 88 } 89 return domainServer; 90 } 91 92 94 public J2EEDomain(String domainName) 95 throws MalformedObjectNameException , 96 InvalidParentException 97 { 98 super(domainName, J2EETypeConstants.J2EEDomain, domainName); 99 J2EEDomain.domainName = domainName; 100 } 101 102 104 109 public String [] getservers() 110 { 111 String [] servers = new String [serverNames.size()]; 112 serverNames.toArray(servers); 113 return servers; 114 } 115 116 119 public String getserver(int pIndex) 120 { 121 if (pIndex >= 0 && pIndex < serverNames.size()) 122 { 123 return (String ) serverNames.get(pIndex); 124 } 125 return null; 126 } 127 128 130 public void addChild(ObjectName pChild) 131 { 132 String lType = J2EEManagedObject.getType(pChild); 133 if (J2EETypeConstants.J2EEServer.equals(lType)) 134 { 135 serverNames.add(pChild.getCanonicalName()); 136 } 137 } 138 139 public void removeChild(ObjectName pChild) 140 { 141 String lType = J2EEManagedObject.getType(pChild); 142 if (J2EETypeConstants.J2EEServer.equals(lType)) 143 { 144 serverNames.remove(pChild.getCanonicalName()); 145 } 146 } 147 149 public String toString() 150 { 151 return "J2EEDomain { " + super.toString() + " } [ " + 152 ", servers: " + serverNames + 153 " ]"; 154 } 155 156 158 160 162 } 164 | Popular Tags |