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 LtRelQueryExp extends QueryEval implements QueryExp {
26:
27: private ValueExp leftExp;
28: private ValueExp rightExp;
29:
30: public LtRelQueryExp(ValueExp _leftExp, ValueExp _rightExp) {
31: leftExp = _leftExp;
32: rightExp = _rightExp;
33: }
34:
35: public ValueExp getLeftValue() {
36: return leftExp;
37: }
38:
39: public ValueExp getRightValue() {
40: return rightExp;
41: }
42:
43: public boolean apply(ObjectName objectname)
44: throws BadStringOperationException,
45: BadBinaryOpValueExpException,
46: BadAttributeValueExpException, InvalidApplicationException {
47: ValueExp l_vexp = leftExp.apply(objectname);
48: ValueExp r_vexp = rightExp.apply(objectname);
49: boolean isNumeric = l_vexp instanceof NumericValueExp;
50: boolean isBoolean = l_vexp instanceof BooleanValueExp;
51: if (isNumeric) {
52: if (((NumericValueExp) l_vexp).isLong()) {
53: long lv = ((NumericValueExp) l_vexp).longValue();
54: long rv = ((NumericValueExp) r_vexp).longValue();
55: return lv < rv;
56: } else {
57: double lv = ((NumericValueExp) l_vexp).doubleValue();
58: double rv = ((NumericValueExp) r_vexp).doubleValue();
59: return lv < rv;
60: }
61: } else if (isBoolean) {
62: boolean lv = ((BooleanValueExp) l_vexp).getValue()
63: .booleanValue();
64: boolean rv = ((BooleanValueExp) r_vexp).getValue()
65: .booleanValue();
66: return !lv && rv;
67: } else {
68: String lv = ((StringValueExp) l_vexp).getValue();
69: String rv = ((StringValueExp) r_vexp).getValue();
70: return lv.compareTo(rv) < 0;
71: }
72: // return false;
73: }
74:
75: public String toString() {
76: return "(" + leftExp + ") < (" + rightExp + ")";
77: }
78:
79: }
|