home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 August / PCO0897.ISO / filesbbs / os2 / fp1os2.arj / OS2 / DATA / 49 / C / 0 / F_26836 / JSbxValue.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-05-15  |  9.4 KB  |  566 lines

  1. import java.io.FileNotFoundException;
  2. import java.io.PrintStream;
  3. import stardiv.classfile.ClassFormatException;
  4. import stardiv.security.JScript2JavaInterface;
  5.  
  6. public class JSbxValue extends JSbxBase implements Cloneable {
  7.    public static final short JSBX_TYPE_EMPTY = 1;
  8.    public static final short JSBX_TYPE_OBJECT = 2;
  9.    public static final short JSBX_TYPE_STRING = 4;
  10.    public static final short JSBX_TYPE_BOOL = 8;
  11.    public static final short JSBX_TYPE_DOUBLE = 16;
  12.    public static final short JSBX_TYPE_FUNCTION = 32;
  13.    private short nJSbxType;
  14.    private JSbxBase aJSbxObject;
  15.    private String aJSbxString;
  16.    private boolean bJSbxBool;
  17.    private double dJSbxDouble;
  18.  
  19.    public JSbxValue() {
  20.       this.SetType((short)1);
  21.    }
  22.  
  23.    public JSbxValue(JSbxBase var1) {
  24.       this.SetType((short)2);
  25.       this.ImpSetObject(var1);
  26.    }
  27.  
  28.    public JSbxValue(String var1) {
  29.       this.SetType((short)4);
  30.       this.ImpSetString(var1);
  31.    }
  32.  
  33.    public JSbxValue(boolean var1) {
  34.       this.SetType((short)8);
  35.       this.ImpSetBool(var1);
  36.    }
  37.  
  38.    public JSbxValue(double var1) {
  39.       this.SetType((short)16);
  40.       this.ImpSetDouble(var1);
  41.    }
  42.  
  43.    public JSbxValue(JSbxValue var1) {
  44.       this.CopyData(var1);
  45.    }
  46.  
  47.    public JSbxValue(short var1) {
  48.       this.SetType(var1);
  49.    }
  50.  
  51.    private final JSbxBase ImpGetObject() {
  52.       return this.aJSbxObject;
  53.    }
  54.  
  55.    private final String ImpGetString() {
  56.       return this.aJSbxString;
  57.    }
  58.  
  59.    private final boolean ImpGetBool() {
  60.       return this.bJSbxBool;
  61.    }
  62.  
  63.    private final double ImpGetDouble() {
  64.       return this.dJSbxDouble;
  65.    }
  66.  
  67.    private final void ImpSetObject(JSbxBase var1) {
  68.       this.aJSbxObject = var1;
  69.    }
  70.  
  71.    private final void ImpSetString(String var1) {
  72.       this.aJSbxString = var1;
  73.    }
  74.  
  75.    private final void ImpSetBool(boolean var1) {
  76.       this.bJSbxBool = var1;
  77.    }
  78.  
  79.    private final void ImpSetDouble(double var1) {
  80.       this.dJSbxDouble = var1;
  81.    }
  82.  
  83.    public final void CopyData(JSbxValue var1) {
  84.       this.SetType(var1.GetType());
  85.       this.ImpSetObject(var1.ImpGetObject());
  86.       this.ImpSetString(var1.ImpGetString());
  87.       this.ImpSetBool(var1.ImpGetBool());
  88.       this.ImpSetDouble(var1.ImpGetDouble());
  89.    }
  90.  
  91.    public Object clone() {
  92.       return new JSbxValue(this);
  93.    }
  94.  
  95.    public final void Clear() {
  96.       this.ImpSetObject((JSbxBase)null);
  97.       this.ImpSetString("");
  98.       this.ImpSetBool(false);
  99.       this.ImpSetDouble((double)0.0F);
  100.    }
  101.  
  102.    private final void SetType(short var1) {
  103.       this.nJSbxType = var1;
  104.    }
  105.  
  106.    public final short GetType() {
  107.       return this.nJSbxType;
  108.    }
  109.  
  110.    public final JSbxBase GetObject() throws JSbxException {
  111.       JSbxValue var1 = this;
  112.       if (this.GetType() != 2) {
  113.          this.Get(var1 = new JSbxValue((short)2));
  114.       }
  115.  
  116.       return var1.ImpGetObject();
  117.    }
  118.  
  119.    public final String GetString() throws JSbxException {
  120.       JSbxValue var1 = this;
  121.       if (this.GetType() != 4) {
  122.          this.Get(var1 = new JSbxValue((short)4));
  123.       }
  124.  
  125.       return var1.ImpGetString();
  126.    }
  127.  
  128.    public final boolean GetBool() throws JSbxException {
  129.       JSbxValue var1 = this;
  130.       if (this.GetType() != 8) {
  131.          this.Get(var1 = new JSbxValue((short)8));
  132.       }
  133.  
  134.       return var1.ImpGetBool();
  135.    }
  136.  
  137.    public final double GetDouble() throws JSbxException {
  138.       JSbxValue var1 = this;
  139.       if (this.GetType() != 16) {
  140.          this.Get(var1 = new JSbxValue((short)16));
  141.       }
  142.  
  143.       return var1.ImpGetDouble();
  144.    }
  145.  
  146.    public final void Get(JSbxValue var1) throws JSbxException {
  147.       ImpConvert(this, var1);
  148.    }
  149.  
  150.    public final void Put(JSbxValue var1) throws JSbxException {
  151.       this.CopyData(var1);
  152.    }
  153.  
  154.    static final void ImpConvert(JSbxValue var0, JSbxValue var1) throws JSbxException {
  155.       short var2 = var0.GetType();
  156.       short var3 = var1.GetType();
  157.       if (var2 != var3 && var3 != 1) {
  158.          switch (var3) {
  159.             case 2:
  160.                switch (var2) {
  161.                   case 1:
  162.                      var1.ImpSetObject((JSbxBase)null);
  163.                   case 4:
  164.                      var1.ImpSetObject(JScriptManager.CreateClassObject("String"));
  165.                      return;
  166.                   case 8:
  167.                      var1.ImpSetObject(JScriptManager.CreateClassObject("Boolean"));
  168.                      return;
  169.                   case 16:
  170.                      var1.ImpSetObject(JScriptManager.CreateClassObject("Number"));
  171.                      return;
  172.                   default:
  173.                      return;
  174.                }
  175.             case 4:
  176.                switch (var2) {
  177.                   case 1:
  178.                      var1.ImpSetString("undefined");
  179.                      return;
  180.                   case 2:
  181.                      JSbxBase var11 = var0.GetObject();
  182.                      JSbxObject var14 = null;
  183.                      if (var11 instanceof JSbxObject) {
  184.                         var14 = (JSbxObject)var11;
  185.                      }
  186.  
  187.                      if (var14 == null) {
  188.                         var1.ImpSetString("null");
  189.                         return;
  190.                      }
  191.  
  192.                      var1.ImpSetString(var14.JS_toString());
  193.                      return;
  194.                   case 8:
  195.                      if (var0.ImpGetBool()) {
  196.                         var1.ImpSetString("true");
  197.                         return;
  198.                      }
  199.  
  200.                      var1.ImpSetString("false");
  201.                      return;
  202.                   case 16:
  203.                      double var15 = var0.ImpGetDouble();
  204.                      if (Double.isInfinite(var15)) {
  205.                         var1.ImpSetString((var15 == Double.NEGATIVE_INFINITY ? "-" : "+") + "Infinity");
  206.                         return;
  207.                      }
  208.  
  209.                      if (Double.isNaN(var15)) {
  210.                         var1.ImpSetString("NaN");
  211.                         return;
  212.                      }
  213.  
  214.                      var1.ImpSetString(ConvertNumber(var15));
  215.                      return;
  216.                   default:
  217.                      return;
  218.                }
  219.             case 8:
  220.                switch (var2) {
  221.                   case 1:
  222.                      var1.ImpSetBool(false);
  223.                      return;
  224.                   case 2:
  225.                      JSbxBase var13 = var0.GetObject();
  226.                      JSbxObject var6 = null;
  227.                      if (var13 instanceof JSbxObject) {
  228.                         var6 = (JSbxObject)var13;
  229.                      }
  230.  
  231.                      if (var6 == null) {
  232.                         var1.ImpSetBool(false);
  233.                         return;
  234.                      }
  235.  
  236.                      JSbxValue var7 = var6.JS_valueOf();
  237.                      if (var7 != null) {
  238.                         var1.ImpSetBool(var7.GetBool());
  239.                         return;
  240.                      }
  241.  
  242.                      var1.ImpSetBool(true);
  243.                      return;
  244.                   case 4:
  245.                      boolean var10 = var0.ImpGetString().length() > 0;
  246.                      var1.ImpSetBool(var10);
  247.                      return;
  248.                   case 16:
  249.                      double var12 = var0.ImpGetDouble();
  250.                      if (var12 == Double.NaN) {
  251.                         var1.ImpSetBool(false);
  252.                      }
  253.  
  254.                      var1.ImpSetBool(var0.ImpGetDouble() != (double)0.0F);
  255.                      return;
  256.                   default:
  257.                      return;
  258.                }
  259.             case 16:
  260.                switch (var2) {
  261.                   case 1:
  262.                      throw new JSbxException(4712, "Conversion: can't convert empty to number");
  263.                   case 2:
  264.                      JSbxBase var9 = var0.GetObject();
  265.                      if (var9 == null) {
  266.                         var1.ImpSetDouble((double)0.0F);
  267.                         return;
  268.                      }
  269.  
  270.                      if (var9 instanceof JSbxObject) {
  271.                         JSbxValue var5 = ((JSbxObject)var9).JS_valueOf();
  272.                         if (var5.GetType() == 16) {
  273.                            var1.ImpSetDouble(var5.GetDouble());
  274.                            return;
  275.                         }
  276.  
  277.                         throw new JSbxException(4715, var0.ImpGetObject() + " is not a number");
  278.                      }
  279.  
  280.                      throw new JSbxException(4715, var0.ImpGetObject() + " is not a number");
  281.                   case 4:
  282.                      try {
  283.                         Double var4 = new Double(var0.ImpGetString());
  284.                         var1.ImpSetDouble(var4);
  285.                         return;
  286.                      } catch (NumberFormatException var8) {
  287.                         throw new JSbxException(4714, var0.ImpGetString() + " is not a number");
  288.                      }
  289.                   case 8:
  290.                      var1.ImpSetDouble(var0.ImpGetBool() ? (double)1.0F : (double)0.0F);
  291.                      return;
  292.                }
  293.          }
  294.  
  295.       } else {
  296.          var1.CopyData(var0);
  297.       }
  298.    }
  299.  
  300.    public final JSbxValue CallFunction(JScriptCallParam var1) throws JSbxExceptionBase {
  301.       if (this.GetType() == 2) {
  302.          JSbxBase var2 = this.ImpGetObject();
  303.          if (var2 instanceof JSbxMethod) {
  304.             return ((JSbxMethod)var2).CallFunction(var1);
  305.          }
  306.       }
  307.  
  308.       throw new JSbxException(888, this.GetErrorValueInfo() + " cannot be converted to a function.");
  309.    }
  310.  
  311.    public String GetJScript_typeofString() {
  312.       return this.GetTypeString();
  313.    }
  314.  
  315.    public static Object convertJScript2Java(JSbxValue var0) {
  316.       Object var1 = null;
  317.       if (var0 != null) {
  318.          switch (var0.GetType()) {
  319.             case 2:
  320.                var1 = var0.ImpGetObject();
  321.                ((JSbxObject)var1).setLifeConnectManager(JScriptManager.GetMyJScriptManager());
  322.                break;
  323.             case 4:
  324.                var1 = var0.ImpGetString();
  325.                break;
  326.             case 8:
  327.                var1 = new Boolean(var0.ImpGetBool());
  328.                break;
  329.             case 16:
  330.                var1 = new Double(var0.ImpGetDouble());
  331.          }
  332.       }
  333.  
  334.       return var1;
  335.    }
  336.  
  337.    public static JSbxValue convertJava2JScript(Object var0, boolean var1, JScript2JavaInterface var2) throws FileNotFoundException, ClassFormatException, ClassNotFoundException {
  338.       JSbxValue var3 = null;
  339.       if (var0 == null) {
  340.          if (!var1) {
  341.             var3 = new JSbxValue((JSbxBase)null);
  342.          }
  343.       } else if (var1 && var0 instanceof Number) {
  344.          var3 = new JSbxValue(((Number)var0).doubleValue());
  345.       } else if (var1 && var0 instanceof Boolean) {
  346.          var3 = new JSbxValue((Boolean)var0);
  347.       } else if (var0 instanceof JSbxObject) {
  348.          var3 = new JSbxValue((JSbxObject)var0);
  349.       } else {
  350.          JScriptJavaObject var4 = new JScriptJavaObject(var0, var2);
  351.          var3 = new JSbxValue(var4);
  352.       }
  353.  
  354.       if (var3 == null) {
  355.          var3 = new JSbxValue();
  356.       }
  357.  
  358.       return var3;
  359.    }
  360.  
  361.    public static Object convertJScript2JSObject(JSbxValue var0) {
  362.       Object var1 = convertJScript2Java(var0);
  363.       if (var1 instanceof JScriptJavaObject) {
  364.          var1 = ((JScriptJavaObject)var1).getJavaObject();
  365.       }
  366.  
  367.       return var1;
  368.    }
  369.  
  370.    public static JSbxValue convertJSObject2JScript(Object var0) throws FileNotFoundException, ClassFormatException, ClassNotFoundException {
  371.       return convertJSObject2JScript(var0, (JScriptManager)null);
  372.    }
  373.  
  374.    public static JSbxValue convertJSObject2JScript(Object var0, JScriptManager var1) throws FileNotFoundException, ClassFormatException, ClassNotFoundException {
  375.       JSbxValue var2 = null;
  376.       if (var0 == null) {
  377.          var2 = new JSbxValue((JSbxBase)null);
  378.       } else if (var0 instanceof JSbxObject) {
  379.          var2 = new JSbxValue((JSbxObject)var0);
  380.       } else if (var0 instanceof Object[]) {
  381.          JScript2JavaInterface var3 = getSecureJScriptCalling(var1);
  382.          if (var3 != null) {
  383.             JScriptJavaObject var4 = new JScriptJavaObject(var0, var3, true);
  384.             var2 = new JSbxValue(var4);
  385.          }
  386.       } else if (var0 instanceof Boolean) {
  387.          var2 = new JSbxValue((Boolean)var0);
  388.       }
  389.  
  390.       if (var0 instanceof Number) {
  391.          var2 = new JSbxValue(((Number)var0).doubleValue());
  392.       } else {
  393.          JScript2JavaInterface var5 = getSecureJScriptCalling(var1);
  394.          if (var5 != null) {
  395.             JScriptJavaObject var6 = new JScriptJavaObject(var0, var5);
  396.             var2 = new JSbxValue(var6);
  397.          }
  398.       }
  399.  
  400.       if (var2 == null) {
  401.          var2 = new JSbxValue();
  402.       }
  403.  
  404.       return var2;
  405.    }
  406.  
  407.    private static JScript2JavaInterface getSecureJScriptCalling(JScriptManager var0) {
  408.       if (var0 == null) {
  409.          var0 = JScriptManager.GetMyJScriptManager();
  410.       }
  411.  
  412.       JScript2JavaInterface var1 = null;
  413.       if (var0 != null) {
  414.          var1 = var0.getSecureJScriptCalling();
  415.       }
  416.  
  417.       return var1;
  418.    }
  419.  
  420.    private final String GetObjectValueString() {
  421.       String var1 = "unknown";
  422.       JSbxBase var2 = this.ImpGetObject();
  423.       if (var2 == null) {
  424.          var1 = "null";
  425.       } else if (var2 instanceof JScriptMethod) {
  426.          JScriptMethod var3 = (JScriptMethod)var2;
  427.          var1 = "Function \"" + var3.GetName() + "\"";
  428.       } else if (var2 instanceof JSbxMethod) {
  429.          var1 = "JSbxMethod";
  430.       } else if (var2 instanceof JSbxObject) {
  431.          var1 = ((JSbxObject)var2).JS_toString();
  432.       } else {
  433.          var1 = "Valid";
  434.       }
  435.  
  436.       return var1;
  437.    }
  438.  
  439.    private final String GetTypeString() {
  440.       String var1 = "unknown";
  441.       switch (this.GetType()) {
  442.          case 1:
  443.             var1 = "undefined";
  444.             break;
  445.          case 2:
  446.             var1 = "object";
  447.  
  448.             try {
  449.                JSbxBase var2 = this.GetObject();
  450.                if (var2 instanceof JSbxObject) {
  451.                   JSbxObject var3 = (JSbxObject)var2;
  452.                   if (var3 != null) {
  453.                      var1 = var3.GetJScript_typeofString();
  454.                   } else {
  455.                      var1 = "object";
  456.                   }
  457.                } else {
  458.                   System.out.println("WARNING: bad object-type " + var2);
  459.                }
  460.             } catch (JSbxException var4) {
  461.             }
  462.             break;
  463.          case 4:
  464.             var1 = "string";
  465.             break;
  466.          case 8:
  467.             var1 = "boolean";
  468.             break;
  469.          case 16:
  470.             var1 = "number";
  471.       }
  472.  
  473.       return var1;
  474.    }
  475.  
  476.    private final String GetValueString() {
  477.       String var1 = "unknown";
  478.  
  479.       try {
  480.          switch (this.GetType()) {
  481.             case 1:
  482.                var1 = "empty";
  483.                break;
  484.             case 2:
  485.                var1 = this.GetObjectValueString();
  486.                break;
  487.             case 4:
  488.                var1 = "\"" + this.GetString() + "\"";
  489.                break;
  490.             case 8:
  491.                var1 = String.valueOf(this.GetBool());
  492.                break;
  493.             case 16:
  494.                var1 = String.valueOf(this.GetDouble());
  495.          }
  496.       } catch (JSbxException var2) {
  497.       }
  498.  
  499.       return var1;
  500.    }
  501.  
  502.    public void Dump(PrintStream var1, int var2, int var3) throws JSbxException {
  503.       JSbxValue var4 = new JSbxValue("");
  504.       String var5 = this.GetTypeString();
  505.       var1.print(var5);
  506.       if (this.GetType() == 2) {
  507.          JSbxBase var6 = this.ImpGetObject();
  508.          var1.println(": " + this.GetObjectValueString());
  509.          if (var6 != null) {
  510.             if (var2 < var3 || var3 == -1) {
  511.                this.ImpGetObject().Dump(var1, var2, var3);
  512.             }
  513.  
  514.             return;
  515.          }
  516.       } else {
  517.          if (this.GetType() != 1) {
  518.             this.Get(var4);
  519.             var1.print(": ");
  520.             if (this.GetType() == 4) {
  521.                var1.println("\"" + var4.ImpGetString() + "\"");
  522.                return;
  523.             }
  524.  
  525.             var1.println(var4.ImpGetString());
  526.             return;
  527.          }
  528.  
  529.          var1.println();
  530.       }
  531.  
  532.    }
  533.  
  534.    public final String GetBrowserTypeInfo() {
  535.       return this.GetTypeString();
  536.    }
  537.  
  538.    public final String GetBrowserValueInfo() {
  539.       return this.GetValueString();
  540.    }
  541.  
  542.    public final String GetBrowserInfo() {
  543.       return new String(this.GetBrowserTypeInfo() + " " + this.GetBrowserValueInfo());
  544.    }
  545.  
  546.    public final String GetErrorValueInfo() {
  547.       return this.GetValueString();
  548.    }
  549.  
  550.    public static final String ConvertNumber(double var0) {
  551.       long var2 = Double.doubleToLongBits(var0);
  552.       int var4 = (int)(var2 >> 52 & 2047L);
  553.       long var5 = var4 == 0 ? (var2 & 4503599627370495L) << 1 : var2 & 4503599627370495L | 4503599627370496L;
  554.       int var7 = var4 - 1075;
  555.       long var8 = 0L;
  556.       if (var7 > 0) {
  557.          var8 = var5 << var7;
  558.       } else {
  559.          var8 = var5 >> -var7;
  560.       }
  561.  
  562.       boolean var10 = Math.abs(var0) != (double)var8;
  563.       return var10 ? String.valueOf(var0) : String.valueOf((long)var0);
  564.    }
  565. }
  566.