KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > management > QualifiedAttributeValueExp


1 /*
2  * @(#)QualifiedAttributeValueExp.java 4.18 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
11 /**
12  * This class represents indexed attributes used as arguments to relational
13  * constraints. An QualifiedAttributeValueExp may be used anywhere a
14  * ValueExp is required.
15  * @serial include
16  *
17  * @since 1.5
18  */

19 class QualifiedAttributeValueExp extends AttributeValueExp JavaDoc {
20
21
22     /* Serial version */
23     private static final long serialVersionUID = 8832517277410933254L;
24
25     /**
26      * @serial The attribute class name
27      */

28     private String JavaDoc className;
29         
30
31     /**
32      * Basic Constructor.
33      */

34     public QualifiedAttributeValueExp() {
35     }
36
37     /**
38      * Creates a new QualifiedAttributeValueExp representing the specified object
39      * attribute, named attr with class name className.
40      */

41     public QualifiedAttributeValueExp(String JavaDoc className, String JavaDoc attr) {
42     super(attr);
43     this.className = className;
44     }
45
46
47     /**
48      * Returns a string representation of the class name of the attribute.
49      */

50     public String JavaDoc getAttrClassName() {
51     return className;
52     }
53
54     /**
55      * Applies the QualifiedAttributeValueExp to an MBean.
56      *
57      * @param name The name of the MBean on which the QualifiedAttributeValueExp will be applied.
58      *
59      * @return The ValueExp.
60      *
61      * @exception BadStringOperationException
62      * @exception BadBinaryOpValueExpException
63      * @exception BadAttributeValueExpException
64      * @exception InvalidApplicationException
65      */

66     public ValueExp JavaDoc apply(ObjectName JavaDoc name) throws BadStringOperationException JavaDoc, BadBinaryOpValueExpException JavaDoc,
67     BadAttributeValueExpException JavaDoc, InvalidApplicationException JavaDoc {
68     try {
69         MBeanServer JavaDoc server = QueryEval.getMBeanServer();
70         String JavaDoc v = server.getObjectInstance(name).getClassName();
71         
72         if (v.equals(className)) {
73         return super.apply(name);
74         }
75         throw new InvalidApplicationException JavaDoc("Class name is " + v +
76                           ", should be " + className);
77         
78     } catch (Exception JavaDoc e) {
79         throw new InvalidApplicationException JavaDoc("Qualified attribute: " + e);
80         /* Can happen if MBean disappears between the time we
81            construct the list of MBeans to query and the time we
82            evaluate the query on this MBean, or if
83            getObjectInstance throws SecurityException. */

84     }
85     }
86     
87     /**
88      * Returns the string representing its value
89      */

90     public String JavaDoc toString() {
91     if (className != null) {
92         return className + "." + super.toString();
93     } else {
94         return super.toString();
95     }
96     }
97     
98 }
99
Popular Tags