home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-tomcat-addon-1.4.9-installer.exe / jmx.jar / javax / management / BinaryRelQueryExp.class (.txt) < prev    next >
Encoding:
Java Class File  |  2002-10-28  |  2.8 KB  |  126 lines

  1. package javax.management;
  2.  
  3. class BinaryRelQueryExp extends QueryEval implements QueryExp {
  4.    private static final long serialVersionUID = -5690656271650491000L;
  5.    private int relOp;
  6.    private ValueExp exp1;
  7.    private ValueExp exp2;
  8.  
  9.    BinaryRelQueryExp(int operation, ValueExp exp1, ValueExp exp2) {
  10.       this.relOp = operation;
  11.       this.exp1 = exp1;
  12.       this.exp2 = exp2;
  13.    }
  14.  
  15.    public void setMBeanServer(MBeanServer server) {
  16.       super.setMBeanServer(server);
  17.       if (this.exp1 != null) {
  18.          this.exp1.setMBeanServer(server);
  19.       }
  20.  
  21.       if (this.exp2 != null) {
  22.          this.exp2.setMBeanServer(server);
  23.       }
  24.  
  25.    }
  26.  
  27.    public boolean apply(ObjectName name) throws BadStringOperationException, BadBinaryOpValueExpException, BadAttributeValueExpException, InvalidApplicationException {
  28.       if (this.exp1 != null || this.exp2 != null || this.relOp != 4 && this.relOp != 2 && this.relOp != 3) {
  29.          if (this.exp1 != null && this.exp2 != null) {
  30.             ValueExp val1 = this.exp1.apply(name);
  31.             ValueExp val2 = this.exp2.apply(name);
  32.             if (val1 instanceof NumericValueExp && val2 instanceof NumericValueExp) {
  33.                NumericValueExp num1 = (NumericValueExp)val1;
  34.                NumericValueExp num2 = (NumericValueExp)val2;
  35.                if (!num1.isDouble() && !num2.isDouble()) {
  36.                   return this.compare(new Long(num1.longValue()), new Long(num2.longValue()));
  37.                }
  38.  
  39.                return this.compare(new Double(num1.doubleValue()), new Double(num2.doubleValue()));
  40.             }
  41.  
  42.             if (val1 instanceof BooleanValueExp && val2 instanceof BooleanValueExp) {
  43.                boolean b1 = ((BooleanValueExp)val1).booleanValue();
  44.                boolean b2 = ((BooleanValueExp)val2).booleanValue();
  45.                return this.compare(new Long(b1 ? 1L : 0L), new Long(b2 ? 1L : 0L));
  46.             }
  47.  
  48.             if (val1 instanceof StringValueExp && val2 instanceof StringValueExp) {
  49.                String s1 = ((StringValueExp)val1).getValue();
  50.                String s2 = ((StringValueExp)val2).getValue();
  51.                return this.compare(s1, s2);
  52.             }
  53.          }
  54.  
  55.          return false;
  56.       } else {
  57.          return true;
  58.       }
  59.    }
  60.  
  61.    private boolean compare(Comparable c1, Comparable c2) {
  62.       switch (this.relOp) {
  63.          case 0:
  64.             if (c1 == null && c2 == null) {
  65.                return false;
  66.             } else if (c1 == null && c2 != null) {
  67.                return false;
  68.             } else {
  69.                if (c1 != null && c2 == null) {
  70.                   return true;
  71.                }
  72.  
  73.                return c1.compareTo(c2) > 0;
  74.             }
  75.          case 1:
  76.             if (c1 == null && c2 == null) {
  77.                return false;
  78.             } else if (c1 == null && c2 != null) {
  79.                return true;
  80.             } else {
  81.                if (c1 != null && c2 == null) {
  82.                   return false;
  83.                }
  84.  
  85.                return c1.compareTo(c2) < 0;
  86.             }
  87.          case 2:
  88.             if (c1 == null && c2 == null) {
  89.                return true;
  90.             } else if (c1 == null && c2 != null) {
  91.                return false;
  92.             } else {
  93.                if (c1 != null && c2 == null) {
  94.                   return true;
  95.                }
  96.  
  97.                return c1.compareTo(c2) >= 0;
  98.             }
  99.          case 3:
  100.             if (c1 == null && c2 == null) {
  101.                return true;
  102.             } else if (c1 == null && c2 != null) {
  103.                return true;
  104.             } else {
  105.                if (c1 != null && c2 == null) {
  106.                   return false;
  107.                }
  108.  
  109.                return c1.compareTo(c2) <= 0;
  110.             }
  111.          case 4:
  112.             if (c1 == null && c2 == null) {
  113.                return true;
  114.             } else {
  115.                if (c1 != null && c2 != null) {
  116.                   return c1.equals(c2);
  117.                }
  118.  
  119.                return false;
  120.             }
  121.          default:
  122.             return false;
  123.       }
  124.    }
  125. }
  126.