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 / BinaryOpValueExp.class (.txt) < prev    next >
Encoding:
Java Class File  |  2002-10-28  |  2.7 KB  |  89 lines

  1. package javax.management;
  2.  
  3. class BinaryOpValueExp extends QueryEval implements ValueExp {
  4.    private static final long serialVersionUID = 1216286847881456786L;
  5.    // $FF: renamed from: op int
  6.    private int field_0;
  7.    private ValueExp exp1;
  8.    private ValueExp exp2;
  9.  
  10.    BinaryOpValueExp(int op, ValueExp exp1, ValueExp exp2) {
  11.       this.field_0 = op;
  12.       this.exp1 = exp1;
  13.       this.exp2 = exp2;
  14.    }
  15.  
  16.    public void setMBeanServer(MBeanServer server) {
  17.       super.setMBeanServer(server);
  18.       if (this.exp1 != null) {
  19.          this.exp1.setMBeanServer(server);
  20.       }
  21.  
  22.       if (this.exp2 != null) {
  23.          this.exp2.setMBeanServer(server);
  24.       }
  25.  
  26.    }
  27.  
  28.    public ValueExp apply(ObjectName name) throws BadStringOperationException, BadBinaryOpValueExpException, BadAttributeValueExpException, InvalidApplicationException {
  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)) {
  33.             if (val1 instanceof StringValueExp) {
  34.                if (val2 instanceof StringValueExp) {
  35.                   String s1 = ((StringValueExp)val1).getValue();
  36.                   String s2 = ((StringValueExp)val2).getValue();
  37.                   switch (this.field_0) {
  38.                      case 0:
  39.                         return Query.value(s1 + s2);
  40.                      default:
  41.                         throw new BadStringOperationException("Trying to perform an operation on Strings that is not concatenation");
  42.                   }
  43.                }
  44.  
  45.                throw new BadBinaryOpValueExpException(val2);
  46.             }
  47.  
  48.             throw new BadBinaryOpValueExpException(val1);
  49.          }
  50.  
  51.          if (!(val2 instanceof NumericValueExp)) {
  52.             throw new BadBinaryOpValueExpException(val2);
  53.          }
  54.  
  55.          NumericValueExp num1 = (NumericValueExp)val1;
  56.          NumericValueExp num2 = (NumericValueExp)val2;
  57.          if (!num1.isDouble() && !num2.isDouble()) {
  58.             long l1 = num1.longValue();
  59.             long l2 = num2.longValue();
  60.             switch (this.field_0) {
  61.                case 0:
  62.                   return Query.value(l1 + l2);
  63.                case 1:
  64.                   return Query.value(l1 - l2);
  65.                case 2:
  66.                   return Query.value(l1 * l2);
  67.                case 3:
  68.                   return Query.value(l1 / l2);
  69.             }
  70.          } else {
  71.             double d1 = num1.doubleValue();
  72.             double d2 = num2.doubleValue();
  73.             switch (this.field_0) {
  74.                case 0:
  75.                   return Query.value(d1 + d2);
  76.                case 1:
  77.                   return Query.value(d1 - d2);
  78.                case 2:
  79.                   return Query.value(d1 * d2);
  80.                case 3:
  81.                   return Query.value(d1 / d2);
  82.             }
  83.          }
  84.       }
  85.  
  86.       throw new BadBinaryOpValueExpException((ValueExp)null);
  87.    }
  88. }
  89.