More PBNI possibilities

The ability to create visual, nonvisual, and marshaler extensions, and to call PowerBuilder objects from external C++ applications, opens up numerous opportunities to combine these capabilities to develop more complex applications.

Writing an extension that loads the PBVM

Most of the examples in this book and on the PowerBuilder CodeXchange Web site show you how to create an extension in C++ and use it in PowerBuilder, or how to write a C++ application that loads the PowerBuilder VM.

You could also write an extension that loads the PowerBuilder VM and uses a custom class user object, using the techniques described in this chapter. The following figure depicts the interaction between the PBVM and an external application that uses an extension.

Figure 5-2: Interaction between PBNI, the PBVM, and external applications

Shown are three large rectangular areas. The one at left includes boxes labeled Create I P B _ Session, Create Native Object, Call Native Methods and Destroy Native Object. The Create I P B _ Session box has an arrow pointing to the top area of the middle rectangle, which is labeled I P B _ Session. The other three boxes point to the top area of the right rectangle, which is labeled Native Class. At the bottom of the right rectangle are boxes labeled Call Power Builder Function and Load P B V M, which both point to the left most rectangle, and a box labeled Create I P B _ V M, which points to the bottom area of the middle rectangle, which is labeled I P B _ V M.

Calling PowerBuilder from Java

You can combine the ability to call PowerBuilder classes from C++, as described in this chapter, with the ability to create marshaler extensions, as described in Chapter 3, “Creating Marshaler Extensions,” to call PowerBuilder from Java.

One way to do this is to create a Java proxy class that declares static native methods that can be called to load the PBVM, create PowerBuilder sessions, create PowerBuilder objects, and invoke PowerScript functions. These native methods can call into the PBVM through PBNI. Additional Java classes that represent the PBVM, PowerBuilder sessions, and PowerBuilder objects can be based on the proxy class.

The Java classes call the Java native methods through JNI, whereas the Java native methods call PowerBuilder through PBNI.

There is a sample that illustrates these techniques on the PowerBuilder CodeXchange Web site.