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.QueryEval;
18:
19: /**
20: *
21: * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
22: */
23:
24: public class TimesOpValueExp extends QueryEval implements ValueExp {
25:
26: private ValueExp leftExp;
27: private ValueExp rightExp;
28:
29: public TimesOpValueExp(ValueExp _leftExp, ValueExp _rightExp) {
30: leftExp = _leftExp;
31: rightExp = _rightExp;
32: }
33:
34: public ValueExp getLeftValue() {
35: return leftExp;
36: }
37:
38: public ValueExp getRightValue() {
39: return rightExp;
40: }
41:
42: public ValueExp apply(ObjectName objectname)
43: throws BadStringOperationException,
44: BadBinaryOpValueExpException,
45: BadAttributeValueExpException, InvalidApplicationException {
46: ValueExp valueexp = leftExp.apply(objectname);
47: ValueExp valueexp1 = rightExp.apply(objectname);
48: boolean isNumeric = valueexp instanceof NumericValueExp;
49:
50: // not numeric throw exception
51: if (!isNumeric)
52: throw new BadBinaryOpValueExpException(this );
53:
54: if (((NumericValueExp) valueexp).isLong()) {
55: long lv = ((NumericValueExp) valueexp).longValue();
56: long rv = ((NumericValueExp) valueexp1).longValue();
57: return Query.value(lv * rv);
58: } else {
59: double lv = ((NumericValueExp) valueexp).doubleValue();
60: double rv = ((NumericValueExp) valueexp1).doubleValue();
61: return Query.value(lv * rv);
62: }
63:
64: }
65:
66: public String toString() {
67: return leftExp + " * " + rightExp;
68: }
69:
70: }
|