Develop Java proxy objects

After an ActiveX client program (Visual Basic, VBScript, or ASP) has initialized the XJB.JClassFactory (and thereby the JVM), it can access Java classes and initialize Java objects. To do this, the client program uses the XJB.JClassFactory FindClass() and NewInstance() methods.

In Java there are two ways to access Java classes: direct invocation through the Java compiler, and through Java's Reflection interface. Because the ActiveX to Java bridge needs no compilation and is a complete runtime interface to Java, it depends on the Reflection interface to access its classes, objects, methods, and fields. The XJB.JClassFactory FindClass() and NewInstance() methods behave very similarly to the Java Class.forName() and the the Class.newInstance() method.

XJB.JClassFactory.FindClass() takes the fully-qualified class name as its only parameter and returns a Proxy Object (JClassProxy). Use the returned Proxy object like a normal Java Class object, from it you can call static methods and access static fields. You can also create a Class Instance (or object) from it, as described below. For example, the following Visual Basic code extract returns a Proxy object for the Java class java.lang.Integer:

  ...
  Dim clsMyString as Object
  Set clsMyString = oXJB.FindClass("java.lang.Integer")

After the proxy has been created, you can access its static information directly. For example, the following code extract can be used to convert a decimal integer to its hexadecimal representation.

  ...
  Dim strHexValue as String
  strHexValue = clsMyString.toHexString(CLng(255))

The equivalent Java syntax is: static String toHexString(int i). Because ints in Java are really 32-bits (which translate to Long in VB), the CLng() function is used to convert the value from the default int to a long. Also, even though the toHexString() function returns a java.lang.String, the code extract does not return an Object Proxy. Instead, the returned java.lang.String is automatically converted to a native Visual Basic String.

To create an object from a class, you use the JClassFactory.NewInstance() method. This creates an Object Instance and takes whatever parameters your Class's constructor needs. When the object has been created, you then have access to all of it's public instance methods and fields. For example, the following Visual Basic code extract can be used to create an instance of a java.lang.Integer:

  ...
  Dim oMyInteger as Object
  set oMyInteger = oXJB.NewInstance(CLng(255))

  Dim strMyInteger as String
  strMyInteger = oMyInteger.toString