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: import org.huihoo.jfox.jmx.queries.NumericValueExp;
21:
22: /**
23: *
24: * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
25: */
26:
27: public class BetweenQueryExp extends QueryEval implements QueryExp {
28:
29: private ValueExp exp1;
30: private ValueExp exp2;
31: private ValueExp exp3;
32:
33: public BetweenQueryExp() {
34: }
35:
36: public BetweenQueryExp(ValueExp valueexp, ValueExp valueexp1,
37: ValueExp valueexp2) {
38: exp1 = valueexp;
39: exp2 = valueexp1;
40: exp3 = valueexp2;
41: }
42:
43: public ValueExp getCheckedValue() {
44: return exp1;
45: }
46:
47: public ValueExp getLowerBound() {
48: return exp2;
49: }
50:
51: public ValueExp getUpperBound() {
52: return exp3;
53: }
54:
55: public boolean apply(ObjectName objectname)
56: throws BadStringOperationException,
57: BadBinaryOpValueExpException,
58: BadAttributeValueExpException, InvalidApplicationException {
59: ValueExp valueexp = exp1.apply(objectname);
60: ValueExp valueexp1 = exp2.apply(objectname);
61: ValueExp valueexp2 = exp3.apply(objectname);
62: boolean flag = valueexp instanceof NumericValueExp;
63: if (flag) {
64: if (((NumericValueExp) valueexp).isLong()) {
65: long l = ((NumericValueExp) valueexp).longValue();
66: long l1 = ((NumericValueExp) valueexp1).longValue();
67: long l2 = ((NumericValueExp) valueexp2).longValue();
68: return l1 <= l && l <= l2;
69: } else {
70: double d = ((NumericValueExp) valueexp).doubleValue();
71: double d1 = ((NumericValueExp) valueexp1).doubleValue();
72: double d2 = ((NumericValueExp) valueexp2).doubleValue();
73: return d1 <= d && d <= d2;
74: }
75: } else {
76: // StringValueExp
77: String s = valueexp.toString();
78: String s1 = valueexp1.toString();
79: String s2 = valueexp2.toString();
80: return s1.compareTo(s) <= 0 && s.compareTo(s2) <= 0;
81: }
82: }
83:
84: public String toString() {
85: return "(" + exp1 + ") between (" + exp2 + ") and (" + exp3
86: + ")";
87: }
88: }
|