1 7 8 package javax.management; 9 10 import java.security.AccessController ; 11 import java.security.PrivilegedAction ; 12 13 import com.sun.jmx.mbeanserver.GetPropertyAction; 14 15 23 class ClassAttributeValueExp extends AttributeValueExp { 24 25 private static final long oldSerialVersionUID = -2212731951078526753L; 33 private static final long newSerialVersionUID = -1081892073854801359L; 36 37 private static final long serialVersionUID; 38 static { 39 boolean compat = false; 40 try { 41 PrivilegedAction act = new GetPropertyAction("jmx.serial.form"); 42 String form = (String ) AccessController.doPrivileged(act); 43 compat = (form != null && form.equals("1.0")); 44 } catch (Exception e) { 45 } 47 if (compat) 48 serialVersionUID = oldSerialVersionUID; 49 else 50 serialVersionUID = newSerialVersionUID; 51 } 52 53 56 private String attr; 57 58 61 public ClassAttributeValueExp() { 62 attr = "Class"; 63 } 64 65 66 77 public ValueExp apply(ObjectName name) throws BadStringOperationException , BadBinaryOpValueExpException , 78 BadAttributeValueExpException , InvalidApplicationException { 79 getAttribute(name); 80 Object result = getValue(name); 81 if (result instanceof String ) { 82 return new StringValueExp ((String )result); 83 } else { 84 throw new BadAttributeValueExpException (result); 85 } 86 } 87 88 91 public String toString() { 92 return attr; 93 } 94 95 96 protected Object getValue(ObjectName name) { 97 try { 98 MBeanServer server = QueryEval.getMBeanServer(); 100 return server.getObjectInstance(name).getClassName(); 101 } catch (Exception re) { 102 return null; 103 113 } 114 } 115 116 } 117 | Popular Tags |