Network Deployment (Distributed operating systems), v8.0 > Reference > Developer examples
Example: Using an ActiveX client application to access a Java class or object
This reference topic provides an example of using Java proxy objects with the ActiveX to EJB bridge.
To use Java proxy objects with the ActiveX to EJB bridge:
- After an ActiveX client program (Visual Basic, VBScript, or Active Server Pages (ASP)) has initialized the XJB.JClassFactory object and thereby, the Java virtual machine (JVM), the client program can access Java classes and initialize Java objects.
To complete this action, the client program uses the XJB.JClassFactory FindClass() and NewInstance() methods.
- In Java programming, two ways exists to access Java classes: direct invocation through the Java compiler and through the Java Reflection interface. Because the ActiveX to Java bridge needs no compilation and is a complete run-time interface to the Java code, the bridge depends on the latter 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 Method.invoke() and Field.invoke() methods.
- XJB.JClassFactory.FindClass() takes the fully qualified class name as its only parameter and returns a Proxy Object (JClassProxy). We can use the returned Proxy object like a normal Java Class object and call static methods and access static fields. We can also create a Class Instance (or object), as described below. For example, the following Visual Basic code extract returns a Proxy object for the java.lang.Integer Java class:
... Dim clsMyString as Object Set clsMyString = oXJB.FindClass("java.lang.Integer")
- After the proxy is created, you can access its static information directly. For example, you can use the following code extract 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 units in Java programming are really 32-bit (which translates to Long in Visual Basic), the CLng() function converts 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 method creates an Object instance and takes whatever parameters your class constructor needs. Once the object is created, we have access to all of its public instance methods and fields. For example, you can use the following Visual Basic code extract to create an instance of the java.lang.Integer string:
... Dim oMyInteger as Object set oMyInteger = oXJB.NewInstance(CLng(255)) Dim strMyInteger as String strMyInteger = oMyInteger.toString
ActiveX to EJB Bridge
Develop ActiveX client application code
Related
Example: ActiveX client application calling Java methods