01: /* JFox, the OpenSource J2EE Application Server
02: *
03: * Copyright (C) 2002 huihoo.org
04: * Distributable under GNU LGPL license
05: * See the GNU Lesser General Public License for more details.
06: */
07:
08: package javax.management;
09:
10: import org.huihoo.jfox.jmx.queries.BooleanValueExp;
11: import org.huihoo.jfox.jmx.queries.NumericValueExp;
12:
13: /**
14: * Note: change from jmx-ri, extends QueryEval
15: *
16: * @author <a href="mailto:young_yy@hotmail.org">Young Yang</a>
17: */
18:
19: public class AttributeValueExp extends QueryEval implements ValueExp {
20:
21: private String attr;
22:
23: public AttributeValueExp() {
24: }
25:
26: /**
27: * Creates a new <CODE>AttributeValueExp</CODE> representing the specified object attribute,
28: * named attr.
29: */
30: public AttributeValueExp(String attr) {
31: this .attr = attr;
32: }
33:
34: /**
35: * Returns a string representation of the name of the attribute.
36: */
37: public String getAttributeName() {
38: return attr;
39: }
40:
41: /**
42: * Applies the <CODE>AttributeValueExp</CODE> on an MBean.
43: *
44: * @param name The name of the MBean on which the <CODE>AttributeValueExp</CODE> will be applied.
45: *
46: * @return The <CODE>ValueExp</CODE>.
47: *
48: * @exception BadAttributeValueExpException
49: * @exception InvalidApplicationException
50: * @exception BadStringOperationException
51: * @exception BadBinaryOpValueExpException
52: *
53: */
54: public ValueExp apply(ObjectName name)
55: throws BadStringOperationException,
56: BadBinaryOpValueExpException,
57: BadAttributeValueExpException, InvalidApplicationException {
58: Object result = getAttribute(name);
59:
60: if (result instanceof Number) {
61: return new NumericValueExp((Number) result);
62: } else if (result instanceof String) {
63: return new StringValueExp((String) result);
64: } else if (result instanceof Boolean) {
65: return new BooleanValueExp(((Boolean) result)
66: .booleanValue());
67: } else {
68: throw new BadAttributeValueExpException(result);
69: }
70: }
71:
72: /**
73: * Returns the string representing its value.
74: */
75: public String toString() {
76: return attr;
77: }
78:
79: /**
80: * Sets the MBean server on which the query is to be performed.
81: *
82: * @param s The MBean server on which the query is to be performed.
83: */
84: public void setMBeanServer(MBeanServer s) {
85: server = s;
86: }
87:
88: protected Object getAttribute(ObjectName objectname) {
89: Object obj = null;
90: try {
91: obj = this .server.getAttribute(objectname, attr);
92: } catch (Exception exception) {
93: }
94: return obj;
95: }
96: }
|