ActiveX client programming, JClassProxy and JObjectProxy classes

The majority of tasks for accessing your Java™ classes and objects are handled with the JClassProxy and JObjectProxy objects.

JClassFactory is the object used to access the majority of Java Virtual Machine (JVM) features. This object handles JVM initialization, accesses classes and creates class instances (objects). Use the JClassProxy and JObjectProxy objects to access the majority of your Java classes and objects:

  • XJBInit(String astrJavaParameterArray())

    Initializes the JVM environment using an array of strings that represent the command line parameters you normally send to the java.exe file.

    If you have invalid parameters in the XJBInit() string array, the following error is displayed:
    Error: 0x6002 XJBJNI::Init() Failed to create VM when calling XJBInit()
    If you have C++ logging enabled, the activity log displays the invalid parameter.
  • JClassProxy FindClass(String strClassName)

    Uses the current thread class loader to load the specified fully qualified class name and returns a JClassProxy object representing the Java Class object.

  • JObjectProxy NewInstance()
    Creates a Class instance for the specified JClassProxy object using the parameters supplied to call the Class constructor. For more information about using the JMethodArgs method, see ActiveX to EJB bridge, calling Java methods.
    JObjectProxy NewInstance(JClassFactory obj, Variant vArg1, Variant vArg2, Variant vArg3, ...)
    JObjectProxy NewInstance(JClassFactory obj, JMethodArgs args)
  • JMethodArgs GetArgsContainer()

    Returns a JMethodArgs object (Class instance).

    You can create a JClassProxy object from the JClassFactory.FindClass() method and from any Java method call that normally return a Java Class object. You can use this object as if you had direct access to the Java Class object. All of the class static methods and fields are accessible as are the java.lang.Class methods. In case of a clash between static method names of the reflected user class and those of the java.lang.Class (for example, getName()), the reflected static methods would execute first.

    For example, the following is a static method called getName(). The java.lang.Class object also has a method called getName():
    • In Java:
      class foo{
      	foo(){};
      	public static String getName(){return abcdef;}
      	public static String getName2(){return ghijkl;}
      	public String toString2(){return xyz;}
      }
    • In Visual Basic:
      ...
      Dim clsFoo as Object
      set clsFoo = oXJB.FindClass(foo)
      clsFoo.getName() 	' Returns abcdef from the static foo class
      clsFoo.getName2()	' Returns ghijkl from the static foo class
      clsFoo.toString()	' Returns class foo from the java.lang.Class object.
      oFoo = oXJB.NewInstance(clsFoo)
      oFoo.toString()	' Returns some text from the java.lang.Object's
                        ' toString() method which foo inherits from.
      oFoo.toString2()	' Returns xyz from the foo class instance

      You can create a JObjectProxy object from the JClassFactory.NewInstance() method, and can be created from any Java method call that normally returns a Class instance object. You can use this object as if you had direct access to the Java object and can access all the static methods and fields of the object. All of object instance methods and fields are accessible (including those accessible through inheritance).

      The JMethodArgs object is created from the JClassFactory.GetArgsContainer() method. Use this object as a container for method and constructor arguments. You must use this object when overriding the object type when calling a method (for example, when sending a java.lang.String JProxyObject type to a constructor that normally takes a java.lang.Object type).

      You can use two groups of methods to add arguments to the collection: Add and Set. You can use Add to add arguments in the order that they are declared. Alternatively, you can use Set to set an argument based on its position in the argument list (where the first argument is in position 1).

      For example, if you had a Java Object Foo that took a constructor of Foo (int, String, Object), you could use a JMethodArgs object as shown in the following code extract:
      
      ...
      Dim oArgs as Object
      set oArgs = oXJB.GetArgsContainer()
      
      oArgs.AddInt(CLng(12345))
      oArgs.AddString(Apples)
      oArgs.AddObject(java.lang.Object, oSomeJObjectProxy)
      
      Dim clsFoo as Object
      Dim oFoo as Object
      set clsFoo = oXJB.FindClass(com.mypackage.foo)
      set oFoo = oXJB.NewInstance(clsFoo, oArgs)
      
      ' To reuse the oArgs object, just clear it and use the add method
      ' again, or alternatively, use the Set method to reset the parameters
      ' Here, we will use Set
      oArgs.SetInt(1, CLng(22222))
      oArgs.SetString(2, Bananas)
      oArgs.SetObject(3, java.lang.Object, oSomeOtherJObjectProxy)
      
      Dim oFoo2 as Object
      set oFoo2 = oXJB.NewInstance(clsFoo, oArgs)
  • AddObject (String strObjectTypeName, Object oArg)
    Adds an arbitrary object to the argument container in the next available position, casting the object to the class name specified in the first parameter. Arrays are specified using the traditional [] syntax; for example:
    AddObject(java.lang.Object[][], oMy2DArrayOfFooObjects)
    or
    AddObject(int[], oMyArrayOfInts)
  • AddByte (Byte byteArg)

    Adds a primitive byte value to the argument container in the next available position.

  • AddBoolean (Boolean bArg)

    Adds a primitive boolean value to the argument container in the next available position.

  • AddShort (Integer iArg)

    Adds a primitive short value to the argument container in the next available position.

  • AddInt (Long lArg)

    Adds a primitive int value to the argument container in the next available position.

  • AddLong (Currency cyArg)

    Adds a primitive long value to the argument container in the next available position.

  • AddFloat (Single fArg)

    Adds a primitive float value to the argument container in the next available position.

  • AddDouble (Double dArg)

    Adds a primitive double value to the argument container in the next available position.

  • AddChar (String strArg)

    Adds a primitive char value to the argument container in the next available position.

  • AddString (String strArg)

    Adds the argument in string form to the argument container in the next available position.

  • SetObject (Integer iArgPosition, String strObjectTypeName, Object oArg)
    Adds an arbitrary object to the argument container in the specified position casting it to the class name or primitive type name specified in the second parameter. Arrays are specified using the traditional [] syntax; for example:
    SetObject(1, java.lang.Object[][], oMy2DArrayOfFooObjects)
    or
    SetObject(2, int[], MyArrayOfInts)
  • SetByte (Integer iArgPosition, Byte byteArg)

    Sets a primitive byte value to the argument container in the position specified.

  • SetBoolean (Integer iArgPosition, Boolean bArg)

    Sets a primitive boolean value to the argument container in the position specified.

  • SetShort (Integer iArgPosition, Integer iArg)

    Sets a primitive short value to the argument container in the position specified.

  • SetInt (Integer iArgPosition, Long lArg)

    Sets a primitive int value to the argument container in the position specified.

  • SetLong (Integer iArgPosition, Currency cyArg)

    Sets a primitive long value to the argument container in the position specified.

  • SetFloat (Integer iArgPosition, Single fArg)

    Sets a primitive float value to the argument container in the position specified.

  • SetDouble (Integer iArgPosition, Double dArg)

    Sets a primitive double value to the argument container in the position specified.

  • SetChar (Integer iArgPosition, String strArg)

    Sets a primitive char value to the argument container in the position specified.

  • SetString (Integer iArgPosition, String strArg)

    Sets a java.lang.String value to the argument container in the position specified.

  • Object Item(Integer iArgPosition)

    Returns the value of an argument at a specific argument position.

  • Clear()

    Removes all arguments from the container and resets the next available position to one.

  • Long Count()

    Returns the number of arguments in the container.