1 25 package org.objectweb.jonas.ws.mbean; 26 27 import java.util.Hashtable ; 28 import java.util.Iterator ; 29 30 import javax.management.MalformedObjectNameException ; 31 import javax.management.ObjectName ; 32 33 import org.objectweb.jonas.jmx.JmxService; 34 import org.objectweb.jonas.service.ServiceManager; 35 36 42 public class WebServicesObjectName { 43 44 47 public static final String WEBSERVICE_TYPE = "WebService"; 48 49 52 public static final String PORTCOMPONENT_TYPE = "WebServicePortComponent"; 53 54 57 public static final String HANDLER_TYPE = "WebServiceHandler"; 58 59 62 public static final String EJBMODULE = "EJBModule"; 63 64 67 public static final String WEBMODULE = "WebModule"; 68 69 72 public static final String J2EEAPPLICATION = "J2EEApplication"; 73 74 77 public static final String J2EESERVER = "J2EEServer"; 78 79 82 private static String domain = null; 83 84 87 private WebServicesObjectName() { 88 } 89 90 95 private static String getDomain() { 96 if (domain == null) { 97 try { 98 domain = ((JmxService) ServiceManager.getInstance() 99 .getJmxService()).getJmxServer().getDefaultDomain(); 100 } catch (Exception e) { 101 domain = null; 103 } 104 } 105 return domain; 106 } 107 108 114 private static String getInheritedPropertiesAsString(ObjectName name) { 115 Hashtable table = (Hashtable ) name.getKeyPropertyList().clone(); 116 table.remove("j2eeType"); 118 table.remove("type"); 119 table.remove("subtype"); 120 table.remove("name"); 121 StringBuffer sb = new StringBuffer (); 122 for (Iterator i = table.keySet().iterator(); i.hasNext();) { 123 String key = (String ) i.next(); 124 sb.append(key + "=" + table.get(key) + ","); 125 } 126 if (sb.length() > 1) { 127 sb.setLength(sb.length() - 1); 129 } 130 return sb.toString(); 131 } 132 133 142 public static ObjectName service(String name, ObjectName parent) 143 throws MalformedObjectNameException { 144 String parentModule = ""; 145 if (parent.getKeyProperty("j2eeType").equals(EJBMODULE)) { 146 parentModule = EJBMODULE + "=" 147 + parent.getKeyProperty("name"); 148 } else { 149 parentModule = WEBMODULE + "=" 150 + parent.getKeyProperty("name"); 151 } 152 return ObjectName.getInstance(getDomain() 153 + ":type=WebService,name=" + name + "," + parentModule + "," 154 + getInheritedPropertiesAsString(parent)); 155 } 156 157 166 public static ObjectName portComponent(String name, ObjectName parent) 167 throws MalformedObjectNameException { 168 String parentModule = ""; 169 if (parent.getKeyProperty("type").equals(WEBSERVICE_TYPE)) { 170 parentModule = WEBSERVICE_TYPE + "=" 171 + parent.getKeyProperty("name"); 172 } 173 return ObjectName.getInstance(getDomain() 174 + ":type=" + PORTCOMPONENT_TYPE + ",name=" + name + "," 175 + parentModule + "," + getInheritedPropertiesAsString(parent)); 176 } 177 178 185 public static ObjectName handler(String name, ObjectName parent) 186 throws MalformedObjectNameException { 187 String parentModule = ""; 188 if (parent.getKeyProperty("type").equals(PORTCOMPONENT_TYPE)) { 189 parentModule = PORTCOMPONENT_TYPE + "=" 190 + parent.getKeyProperty("name"); 191 } 192 return ObjectName.getInstance(getDomain() 193 + ":type=" + HANDLER_TYPE + ",name=" + name + "," 194 + parentModule + "," + getInheritedPropertiesAsString(parent)); 195 } 196 197 203 public static ObjectName getStatelessSessionBeanQuery(ObjectName parent, 204 String ejbName) { 205 try { 206 StringBuffer sb = new StringBuffer (parent.getDomain()); 207 sb.append(":j2eeType=StatelessSessionBean"); 208 sb.append(",name="); 209 sb.append(ejbName); 210 sb.append(",J2EEApplication="); 211 if (parent.getKeyProperty("J2EEApplication") != null) { 212 sb.append(parent.getKeyProperty("J2EEApplication")); 214 } else { 215 sb.append(parent.getKeyProperty("name")); 216 } 217 sb.append(",J2EEServer="); 218 sb.append(parent.getKeyProperty("J2EEServer")); 219 sb.append(",*"); 220 return new ObjectName (sb.toString()); 221 } catch (javax.management.MalformedObjectNameException e) { 222 return null; 224 } 225 } 226 227 233 public static ObjectName getServletQuery(ObjectName parent, String servletName) { 234 try { 235 StringBuffer sb = new StringBuffer (parent.getDomain()); 236 sb.append(":j2eeType=Servlet"); 237 sb.append(",name="); 238 sb.append(servletName); 239 sb.append(",J2EEApplication="); 240 if (parent.getKeyProperty("J2EEApplication") != null) { 241 sb.append(parent.getKeyProperty("J2EEApplication")); 243 } else { 244 sb.append(parent.getKeyProperty("name")); 245 } 246 sb.append(",J2EEServer="); 247 sb.append(parent.getKeyProperty("J2EEServer")); 248 sb.append(",*"); 249 return new ObjectName (sb.toString()); 250 } catch (javax.management.MalformedObjectNameException e) { 251 return null; 253 } 254 } 255 256 262 public static ObjectName getEJBModule(ObjectName ear, String key) { 263 try { 264 StringBuffer sb = new StringBuffer (ear.getDomain()); 265 sb.append(":j2eeType=EJBModule"); 266 sb.append(",name="); 267 sb.append(key); 268 sb.append(",J2EEApplication="); 269 sb.append(ear.getKeyProperty("name")); 270 sb.append(",J2EEServer="); 271 sb.append(ear.getKeyProperty("J2EEServer")); 272 sb.append(",*"); 273 return new ObjectName (sb.toString()); 274 } catch (javax.management.MalformedObjectNameException e) { 275 return null; 277 } 278 } 279 280 286 public static ObjectName getWebModule(ObjectName ear, String key) { 287 try { 288 StringBuffer sb = new StringBuffer (ear.getDomain()); 289 sb.append(":j2eeType=WebModule"); 290 sb.append(",name="); 291 sb.append(key); 292 sb.append(",J2EEApplication="); 293 sb.append(ear.getKeyProperty("name")); 294 sb.append(",J2EEServer="); 295 sb.append(ear.getKeyProperty("J2EEServer")); 296 sb.append(",*"); 297 return new ObjectName (sb.toString()); 298 } catch (javax.management.MalformedObjectNameException e) { 299 return null; 301 } 302 } 303 } 304 | Popular Tags |