01: /*
02: * Copyright (C) The MX4J Contributors.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the MX4J License version 1.0.
06: * See the terms of the MX4J License in the documentation provided with this software.
07: */
08:
09: package javax.management;
10:
11: /**
12: * @version $Revision: 1.6 $
13: * @serial include
14: */
15: class InQueryExp extends QueryEval implements QueryExp {
16: private static final long serialVersionUID = -5801329450358952434L;
17:
18: /**
19: * @serial The value to be tested
20: */
21: private final ValueExp val;
22: /**
23: * @serial The allowed values
24: */
25: private final ValueExp[] valueList;
26:
27: InQueryExp(ValueExp val, ValueExp[] valueList) {
28: this .val = val;
29: this .valueList = valueList;
30: }
31:
32: public void setMBeanServer(MBeanServer server) {
33: super .setMBeanServer(server);
34: if (val != null)
35: val.setMBeanServer(server);
36: if (valueList != null) {
37: for (int i = 0; i < valueList.length; ++i) {
38: ValueExp v = valueList[i];
39: if (v != null)
40: v.setMBeanServer(server);
41: }
42: }
43: }
44:
45: public boolean apply(ObjectName name)
46: throws BadStringOperationException,
47: BadBinaryOpValueExpException,
48: BadAttributeValueExpException, InvalidApplicationException {
49: if (val != null && valueList != null) {
50: ValueExp valueExp = val.apply(name);
51: if (valueExp instanceof NumericValueExp) {
52: NumericValueExp numExp = (NumericValueExp) valueExp;
53: if (numExp.isDouble()) {
54: for (int i = 0; i < valueList.length; ++i) {
55: ValueExp exp = valueList[i];
56: if (exp instanceof NumericValueExp) {
57: if (((NumericValueExp) exp).doubleValue() == numExp
58: .doubleValue())
59: return true;
60: }
61: }
62: } else {
63: for (int i = 0; i < valueList.length; ++i) {
64: ValueExp exp = valueList[i];
65: if (exp instanceof NumericValueExp) {
66: if (((NumericValueExp) exp).longValue() == numExp
67: .longValue())
68: return true;
69: }
70: }
71: }
72: } else if (valueExp instanceof StringValueExp) {
73: String s1 = ((StringValueExp) valueExp).getValue();
74: for (int i = 0; i < valueList.length; ++i) {
75: ValueExp exp = valueList[i];
76: if (exp instanceof StringValueExp) {
77: String s2 = ((StringValueExp) exp).getValue();
78: if (s1 == null && s2 == null)
79: return true;
80: if (s1 != null && s2 != null) {
81: if (s1.equals(s2))
82: return true;
83: }
84: }
85: }
86: }
87: }
88: return false;
89: }
90: }
|