EqRelQueryExp.java :  » JMX » jfoxmx » org » huihoo » jfox » jmx » queries » Java Open Source

Java Open Source » JMX » jfoxmx 
jfoxmx » org » huihoo » jfox » jmx » queries » EqRelQueryExp.java
/* JFox, the OpenSource J2EE Application Server
 *
 * Copyright (C) 2002 huihoo.com
 * Distributable under GNU LGPL license
 * See the GNU Lesser General Public License for more details.
 */

package org.huihoo.jfox.jmx.queries;

import javax.management.QueryEval;
import javax.management.QueryExp;
import javax.management.ValueExp;
import javax.management.ObjectName;
import javax.management.BadStringOperationException;
import javax.management.BadBinaryOpValueExpException;
import javax.management.BadAttributeValueExpException;
import javax.management.InvalidApplicationException;
import javax.management.StringValueExp;

/**
 * 
 * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
 */

public class EqRelQueryExp extends QueryEval implements QueryExp {

  private ValueExp leftExp;
  private ValueExp rightExp;

  public EqRelQueryExp(ValueExp _leftExp, ValueExp _rightExp) {
    leftExp = _leftExp;
    rightExp = _rightExp;
  }

  public ValueExp getLeftValue() {
    return leftExp;
  }

  public ValueExp getRightValue() {
    return rightExp;
  }

  public boolean apply(ObjectName objectname) throws BadStringOperationException, BadBinaryOpValueExpException, BadAttributeValueExpException, InvalidApplicationException {
    ValueExp l_vexp = leftExp.apply(objectname);
    ValueExp r_vexp = rightExp.apply(objectname);
    boolean isNumeric = l_vexp instanceof NumericValueExp;
    boolean isBoolean = l_vexp instanceof BooleanValueExp;
    if(isNumeric) {
      if(((NumericValueExp)l_vexp).isLong()) {
        long lv = ((NumericValueExp)l_vexp).longValue();
        long rv = ((NumericValueExp)r_vexp).longValue();
        return lv == rv;
      } else {
        double lv = ((NumericValueExp)l_vexp).doubleValue();
        double rv = ((NumericValueExp)r_vexp).doubleValue();
        return lv == rv;
      }
    } else if(isBoolean) {
      boolean lv = ((BooleanValueExp)l_vexp).getValue().booleanValue();
      boolean rv = ((BooleanValueExp)r_vexp).getValue().booleanValue();
      return lv == rv;
    } else {
      String lv = ((StringValueExp)l_vexp).getValue();
      String rv = ((StringValueExp)r_vexp).getValue();
      return lv.compareTo(rv) == 0;
    }
//    return false;
  }

  public String toString() {
    return "(" + leftExp + ") == (" + rightExp + ")";
  }

}

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.