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.ValueExp;
11: import javax.management.ObjectName;
12: import javax.management.BadStringOperationException;
13: import javax.management.BadBinaryOpValueExpException;
14: import javax.management.BadAttributeValueExpException;
15: import javax.management.InvalidApplicationException;
16: import javax.management.Query;
17: import javax.management.StringValueExp;
18: import javax.management.QueryEval;
19:
20: /**
21: *
22: * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
23: */
24:
25: public class PlusOpValueExp extends QueryEval implements ValueExp {
26:
27: private ValueExp leftExp;
28: private ValueExp rightExp;
29:
30: public PlusOpValueExp(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 ValueExp apply(ObjectName objectname)
44: throws BadStringOperationException,
45: BadBinaryOpValueExpException,
46: BadAttributeValueExpException, InvalidApplicationException {
47: ValueExp valueexp = leftExp.apply(objectname);
48: ValueExp valueexp1 = rightExp.apply(objectname);
49: boolean isNumeric = valueexp instanceof NumericValueExp;
50: if (isNumeric) {
51: if (((NumericValueExp) valueexp).isLong()) {
52: long lv = ((NumericValueExp) valueexp).longValue();
53: long rv = ((NumericValueExp) valueexp1).longValue();
54: return Query.value(lv + rv);
55: } else {
56: double lv = ((NumericValueExp) valueexp).doubleValue();
57: double rv = ((NumericValueExp) valueexp1).doubleValue();
58: return Query.value(lv + rv);
59: }
60: } else {
61: String s = ((StringValueExp) valueexp).getValue();
62: String s1 = ((StringValueExp) valueexp1).getValue();
63: return new StringValueExp(s + s1);
64: }
65: }
66:
67: public String toString() {
68: return leftExp + " + " + rightExp;
69: }
70:
71: }
|