KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > management > ClassAttributeValueExp


1 /*
2  * @(#)ClassAttributeValueExp.java 4.21 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.management;
9
10 import java.security.AccessController JavaDoc;
11 import java.security.PrivilegedAction JavaDoc;
12
13 import com.sun.jmx.mbeanserver.GetPropertyAction;
14
15 /**
16  * This class represents the name of the Java implementation class of
17  * the MBean. It is used for performing queries based on the class of
18  * the MBean.
19  * @serial include
20  *
21  * @since 1.5
22  */

23 class ClassAttributeValueExp extends AttributeValueExp JavaDoc {
24
25     // Serialization compatibility stuff:
26
// Two serial forms are supported in this class. The selected form depends
27
// on system property "jmx.serial.form":
28
// - "1.0" for JMX 1.0
29
// - any other value for JMX 1.1 and higher
30
//
31
// Serial version for old serial form
32
private static final long oldSerialVersionUID = -2212731951078526753L;
33     //
34
// Serial version for new serial form
35
private static final long newSerialVersionUID = -1081892073854801359L;
36
37     private static final long serialVersionUID;
38     static {
39     boolean compat = false;
40     try {
41         PrivilegedAction JavaDoc act = new GetPropertyAction("jmx.serial.form");
42         String JavaDoc form = (String JavaDoc) AccessController.doPrivileged(act);
43         compat = (form != null && form.equals("1.0"));
44     } catch (Exception JavaDoc e) {
45         // OK: exception means no compat with 1.0, too bad
46
}
47     if (compat)
48         serialVersionUID = oldSerialVersionUID;
49     else
50         serialVersionUID = newSerialVersionUID;
51     }
52
53     /**
54      * @serial The name of the attribute
55      */

56     private String JavaDoc attr;
57
58     /**
59      * Basic Constructor.
60      */

61     public ClassAttributeValueExp() {
62     attr = "Class";
63     }
64
65
66     /**
67      * Applies the ClassAttributeValueExp on an MBean. Returns the name of
68      * the Java implementation class of the MBean.
69      *
70      * @param name The name of the MBean on which the ClassAttributeValueExp will be applied.
71      *
72      * @return The ValueExp.
73      *
74      * @exception BadAttributeValueExpException
75      * @exception InvalidApplicationException
76      */

77     public ValueExp JavaDoc apply(ObjectName JavaDoc name) throws BadStringOperationException JavaDoc, BadBinaryOpValueExpException JavaDoc,
78     BadAttributeValueExpException JavaDoc, InvalidApplicationException JavaDoc {
79     getAttribute(name);
80     Object JavaDoc result = getValue(name);
81     if (result instanceof String JavaDoc) {
82         return new StringValueExp JavaDoc((String JavaDoc)result);
83     } else {
84         throw new BadAttributeValueExpException JavaDoc(result);
85     }
86     }
87     
88     /**
89      * Returns the string "Class" representing its value
90      */

91     public String JavaDoc toString() {
92     return attr;
93     }
94     
95
96     protected Object JavaDoc getValue(ObjectName JavaDoc name) {
97     try {
98         // Get the class of the object
99
MBeanServer JavaDoc server = QueryEval.getMBeanServer();
100         return server.getObjectInstance(name).getClassName();
101     } catch (Exception JavaDoc re) {
102         return null;
103         /* In principle the MBean does exist because otherwise we
104            wouldn't be evaluating the query on it. But it could
105            potentially have disappeared in between the time we
106            discovered it and the time the query is evaluated.
107
108            Also, the exception could be a SecurityException.
109         
110            Returning null from here will cause
111            BadAttributeValueExpException, which will in turn cause
112            this MBean to be omitted from the query result. */

113     }
114     }
115
116  }
117
Popular Tags