01: /* JFox, the OpenSource J2EE Application Server
02: *
03: * Copyright (C) 2002 huihoo.com
04: * Distributable under GNU LGPL license
05: * See the GNU Lesser General Public License for more details.
06: */
07:
08: package org.huihoo.jfox.jmx.queries;
09:
10: import javax.management.QueryEval;
11: import javax.management.QueryExp;
12: import javax.management.ValueExp;
13: import javax.management.ObjectName;
14: import javax.management.BadStringOperationException;
15: import javax.management.BadBinaryOpValueExpException;
16: import javax.management.BadAttributeValueExpException;
17: import javax.management.InvalidApplicationException;
18: import javax.management.StringValueExp;
19:
20: /**
21: *
22: * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
23: */
24:
25: public class InQueryExp extends QueryEval implements QueryExp {
26:
27: private ValueExp val;
28: private ValueExp valueList[];
29:
30: public InQueryExp() {
31: }
32:
33: public InQueryExp(ValueExp valueexp, ValueExp avalueexp[]) {
34: val = valueexp;
35: valueList = avalueexp;
36: }
37:
38: public ValueExp getCheckedValue() {
39: return val;
40: }
41:
42: public ValueExp[] getExplicitValues() {
43: return valueList;
44: }
45:
46: public boolean apply(ObjectName objectname)
47: throws BadStringOperationException,
48: BadBinaryOpValueExpException,
49: BadAttributeValueExpException, InvalidApplicationException {
50: if (valueList != null) {
51: ValueExp valueexp = val.apply(objectname);
52: boolean flag = valueexp instanceof NumericValueExp;
53: for (int i = 0; i < valueList.length; i++)
54: if (flag) {
55: if (((NumericValueExp) valueList[i]).doubleValue() == ((NumericValueExp) valueexp)
56: .doubleValue())
57: return true;
58: } else if (((StringValueExp) valueList[i]).getValue()
59: .equals(((StringValueExp) valueexp).getValue()))
60: return true;
61: }
62: return false;
63: }
64:
65: public String toString() {
66: return val + " in (" + generateValueList() + ")";
67: }
68:
69: private String generateValueList() {
70: if (valueList == null || valueList.length == 0)
71: return "";
72: StringBuffer stringbuffer = new StringBuffer(valueList[0]
73: .toString());
74: for (int i = 1; i < valueList.length; i++) {
75: stringbuffer.append(", ");
76: stringbuffer.append(valueList[i]);
77: }
78:
79: return stringbuffer.toString();
80: }
81: }
|