1 16 17 package org.springframework.jmx.support; 18 19 import java.util.Hashtable ; 20 21 import javax.management.MalformedObjectNameException ; 22 import javax.management.ObjectName ; 23 24 import org.springframework.util.ClassUtils; 25 26 37 public class ObjectNameManager { 38 39 private static final boolean getInstanceAvailable = 41 ClassUtils.hasMethod(ObjectName .class, "getInstance", new Class [] {String .class}); 42 43 44 53 public static ObjectName getInstance(Object objectName) throws MalformedObjectNameException { 54 if (objectName instanceof ObjectName ) { 55 return (ObjectName ) objectName; 56 } 57 if (!(objectName instanceof String )) { 58 throw new MalformedObjectNameException ("Invalid ObjectName value type [" + 59 objectName.getClass().getName() + "]: only ObjectName and String supported."); 60 } 61 return getInstance((String ) objectName); 62 } 63 64 72 public static ObjectName getInstance(String objectName) throws MalformedObjectNameException { 73 if (getInstanceAvailable) { 74 return ObjectName.getInstance(objectName); 75 } 76 else { 77 return new ObjectName (objectName); 78 } 79 } 80 81 92 public static ObjectName getInstance(String domainName, String key, String value) 93 throws MalformedObjectNameException { 94 95 if (getInstanceAvailable) { 96 return ObjectName.getInstance(domainName, key, value); 97 } 98 else { 99 return new ObjectName (domainName, key, value); 100 } 101 } 102 103 113 public static ObjectName getInstance(String domainName, Hashtable properties) 114 throws MalformedObjectNameException { 115 116 if (getInstanceAvailable) { 117 return ObjectName.getInstance(domainName, properties); 118 } 119 else { 120 return new ObjectName (domainName, properties); 121 } 122 } 123 124 } 125 | Popular Tags |