Description
The following PowerBuilder® 9 sample demonstrates a PBNI marshaler extension that allows you to call Java from PowerScript.
This extension declares a native class, JavaVM, which has two functions, createJavaVM and createJavaObject.
The CJavaVM class implements the JavaVM native class.
The CreateJavaVm function of CJavaVM gets the classpath and properties from the PBCallInfo structure, and loads the JVM by calling the loadJavaVM function of the JavaVMWrapper class. The JavaVMWrapper class is a singleton class, encapsulating the JavaVM interface provided by JNI.
The CreateJavaObject function creates an instance of a Java class based on the given class name, creates a PowerBuilder proxy object for the Java object, creates a JavaMarshaler object, and associates the marshaler object with the proxy object.
The JavaMarshaler class implements the IPBX_Marshaler interface, which is responsible for translating a PowerBuilder function call into a Java function call and returning the result from Java to PowerBuilder.
A JMethod object represents a Java method, which is responsible for translating PowerBuilder data types into Java data types, and invoking the Java function specified by method name and method signature.
A JValue object represents a parameter or a return value passed to or from a Java function.
Features
· PBNI – marshaler extension
Setting up Your Environment
· PowerBuilder 9 GA
· Visual C++ 6.0 (only if the extension workspace needs to be opened)
Detailed Steps
· Unzip into a folder, for example c:\pb2java.
· Open the workspace calljava.pbw in the \test directory with PowerBuilder 9 and add the marshaler extension pbjava.pbd to the library path.
· Run the application using the running man.
· Click on the button labeled "call Java Converter." You will see a message box showing the result of the function call.
· Tips: If you encounter error messages such as: “Error calling method of PBNI object” please check your PATH and CLASSPATH environment variables. PATH should include jdk\jre\bin\classic (where the jvm.dll is located) and jdk\jre\bin. The CLASSPATH environment variable should include jdk\jre\lib.
For example when using JDK 122 in c:\program files\Sybase\shared\sun\jdk122:
Optional:
· Open the Visual C++ 6.0 workspace pb2java.dsw, and look at the different .cpp files included in the workspace to see how the extension is implemented.
For more information
The best source for information is the PowerBuilder Native Interface Programmer’s Guide and Reference. Chapter 3, “Creating Marshaler Extensions,” has some more information about this sample.
Also look for another sample called java2pb that enables you to call PowerScript from Java.