1. Alexander Strelkov
  2. PowerBuilder
  3. Friday, 1 September 2017 11:56 AM UTC

Hi,

Not long ago I've written a PBNI (PBX) library that enables closely integration of Java and PB languages. The library allows to make communication of this languages in both directions: PB can create Java objects and call its methods and Java in turn can do the exact same things with PB objects in the same shared session. Unlike from PB EJB approach to call Java methods, this library may not use PB Proxy objects at all (although it may) - sufficient to indicate required signature for Java method when calling it from PB. On Java side the same approach has being applied but only with PB method signatures. For further simplicity such calls was wrapped into methods with names that matches to the counterpart on PB side.

Stop talking and consider some simple example. Suppose we have some PB window:

We have created and initialized PB global variable with name jvm tentatively and connection to DemoEAS DB was established via SQLCA object. To DataWindow control's  (dw_main) property with name DataObject was assigned a reference to dw-object "d_customers" (grid-style). Next, in the open event of our window object we will create and initialize inv_jobject instance variable of java_object class that will present some Java Controller class. Then I receive a reference to java_method object by its Java signature, set it argument/s (if any) and at last call/invoke it.

dw_main.SetTransObject(SQLCA)
dw_main.SetFocus()

any params[]
java_method jm

//try
inv_jobject = jvm.CreateJavaObject("Controller")
jm = inv_jobject.getMethod("open", "(Lcom/powerbuilder/runtime/classes/PBDatawindow;)V")
params[1] = dw_main
jm.Invoke( params )
//catch (RunTimeError err)
//	MessageBox("Error", err.GetMessage(), Exclamation!)
//end try

The source of Controller.java file is follow:

import java.util.Date;
import com.powerbuilder.runtime.*;
import com.powerbuilder.runtime.enums.*;
import com.powerbuilder.runtime.classes.*;
import com.powerbuilder.utils.*;

public class Controller
{
    protected PBDatawindow dwo;
    
    public void open(PBDatawindow dw)
    {
        dwo = dw;
        int rows = dwo.retrieve();
    }

    public String getProperties(String expr)
    {
        return dwo.describe(expr);
    }

    public void enumFirst(int rows)
    {
        int i;
        String txt = "";
        int nCount = dwo.rowCount();
        for (i = 1; i <= Math.min(rows, nCount); i++) {
            txt +=  (int)dwo.getItemNumber(i, 1)+ ".\t" +
                dwo.getItemString(i, "fname") + "\t" +
                                   dwo.getItemString(i, "lname") + "\n";
        }

        Dialog.info("First "+rows+" records are:", txt);
    }

    public int setFilter(String filter)
    {
        dwo.setFilter(filter);
        return dwo.filter();
    }

    public void close()
    {
        Dialog.messageBox("Close", "ByBy", Icon.Exclamation);
    }
}

As we can see on Java side we'll work with the same instance of PB DataWindow object  But its type (class) in Java is PBDatawindow - mirrored class for work with any dw-objects.

Other event sources of PB Window are follows:

close event:
any params[]
inv_jobject.getMethod("close", "()V").Invoke(params)

NY'ers button clicked event:
inv_jobject &
    .getmethod("setFilter", "(Ljava/lang/String;)I") &
    .invoke({"state='NY'"})
dw_main.POST SetFocus()

Top 20 button clicked event
inv_jobject &
    .getmethod("enumFirst", "(I)V") &
    .invoke({20})

As a result First 20 records are message box was displayed

This library is in beta testing mode yet. So if anybody has some practical interest to this functionality I can give a reference to download pbx/pbd files and source of Java package with a purpose of collaborative testing this library and obtaining its fully workable version. Naturally you will have all rights to use it freely in any projects in future.

 

 

Alexander Strelkov Accepted Answer Pending Moderation
  1. Tuesday, 14 August 2018 05:41 AM UTC
  2. PowerBuilder
  3. # 1
0
Votes
Undo

PbJava v.0.9.2 has been released.

Constructive criticism and wishes are welcome.

 

Comment
There are no comments made yet.
Alexander Strelkov Accepted Answer Pending Moderation
  1. Monday, 16 July 2018 07:04 AM UTC
  2. PowerBuilder
  3. # 2
0
Votes
Undo

Hi Cecilia,

Thanks for your interest to pbjava library. I'll publish a new reference to download the latest version of this library in this topic in the next fiew days. The library has evolved and now can be installed in x32 and x64 versions (jre 9+). Also, a special procedure for automatically generation of pair java classes was created.

 

 

 

 

Comment
Hi Alexander,

I´m trying to create JavaVM with your object java_vm but I can´t. ALways return -1. I create JavaVM with the PB object JavaVM without errors. Could you tell me where could be the problem? thank you very much.
  1. Cecilia Jiménez Bedoya
  2. Friday, 23 November 2018 10:12 AM UTC
Hi Cecilia,

Result codes are identical with PB's CreateJavaVM function:

-1 Failure. The Java VM was not loaded, possibly because jvm.dll was not found in the classpath.



Check your os PATH variable. It should contain the full path to jvm.dll file that you need. As far as I know PB IDE uses its own instance of java runtime library and its path is included in java classpath already.

Think it helps.



  1. Alexander Strelkov
  2. Sunday, 25 November 2018 11:50 AM UTC
There are no comments made yet.
Cecilia Jiménez Bedoya Accepted Answer Pending Moderation
  1. Tuesday, 3 July 2018 11:25 AM UTC
  2. PowerBuilder
  3. # 3
0
Votes
Undo

Hi Alexander,

I know some time ago about this question but I was looking for information about java and powerbuilder and I found it. I think it's great that you made this library. It is not possible to download the files of the link you have placed. It would be possible for you to send me a copy to cecilia @ jerez. es. Thank you very much.

Comment
There are no comments made yet.
Alexander Strelkov Accepted Answer Pending Moderation
  1. Tuesday, 5 September 2017 06:03 AM UTC
  2. PowerBuilder
  3. # 4
0
Votes
Undo

For all who is interested with this library I prepare temporary reference to download zip file. Read README.doc file the first, please. Write me if you will have any question.

Thanks and

     best regards

 

Comment
Thanks for the files!

  1. Rodolfo Reyes
  2. Wednesday, 6 September 2017 15:17 PM UTC
Hi Alexander,



I can not download your test files.



Did you remove them?



Thanks



Enrique

  1. Enrique Perez
  2. Monday, 25 September 2017 13:45 PM UTC
Hi Alexander

Can't download your zip file.

Could you, please send it to eperezch @ hotmail.com?

thanks

enrique

  1. Enrique Perez
  2. Monday, 25 September 2017 18:20 PM UTC
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Monday, 4 September 2017 06:23 AM UTC
  2. PowerBuilder
  3. # 5
0
Votes
Undo

I'm also interested: rene [dot] ullrich [at] aufbaubank [dot] de

Comment
There are no comments made yet.
Enrique Perez Accepted Answer Pending Moderation
  1. Sunday, 3 September 2017 00:39 AM UTC
  2. PowerBuilder
  3. # 6
0
Votes
Undo

Hi Alexander,

Fantastic job.

I would like to get a copy.

Thanks

Enrique

Comment
There are no comments made yet.
Alexander Strelkov Accepted Answer Pending Moderation
  1. Saturday, 2 September 2017 02:55 AM UTC
  2. PowerBuilder
  3. # 7
0
Votes
Undo

A little more additional technical info about pbava library:

  • PBX/DLL has been compiled with MS Visual Studio 2008 (Express Edition) C++ compiler with support of unicode encoding
  • Minimum required JDK version is 6 and above.
  • I work/use PB/PBNI version of 11.5.1

I think, but not testing it that minimum PB version is 10.5 (UNICODE).

 

 

 

Comment
There are no comments made yet.
Rodolfo Reyes Accepted Answer Pending Moderation
  1. Friday, 1 September 2017 20:00 PM UTC
  2. PowerBuilder
  3. # 8
0
Votes
Undo

In my work we use a lot of the other method (EJB with Proxys). And we are facing the problem, that PowerBuilder only supports JAVA 6.

I am very interested in doing tests, to explore other alternatives.

For what version of Power Builder did you design this solution?

Which versions of Java have you tried?

Email: rodareyes@gmail.com

============

Rodolfo Reyes

============

 

 

Comment
There are no comments made yet.
Alexander Strelkov Accepted Answer Pending Moderation
  1. Friday, 1 September 2017 18:50 PM UTC
  2. PowerBuilder
  3. # 9
0
Votes
Undo

Many thanks for interest to this work, colleagues

I need some time to prepare a distribution pack reference link to which I'll send to your e-mail addresses. 

Some more info about this library:

1. PB to Java invocation capabilities

  • create Java objects
  • invoking Java object methods
  • Invoking Java static methods
  • invoking Java static class methods
  • read/write Java object instance variables
  • read/write Java static variables
  • assign PB variables of any types (including objects) as Java method's argument
  • get Java object as method's return value
  • get PB object as method's return value

2. Java to PB invocation capabilities:

  • invoking PB object's method
  • dispatch PB object's event (trigger event)
  • invoking PB Global/System functions
  • read/write global variables
  • read/write object's instance variable
  • read/write variables/method parameters of enumeration type

The main goal of this pbjava library is ensuring minimum, fast and reliable interface/foundation between this two languages, no more. Concerning Java - all tying/extension code is strongly recommended to write in pure Java language. In other words, consider pbjava library as only a transmitting tool that do nothing besides communication task via PBNI/JNI interactions..

.

Comment
There are no comments made yet.
Olan Knight Accepted Answer Pending Moderation
  1. Friday, 1 September 2017 17:23 PM UTC
  2. PowerBuilder
  3. # 10
0
Votes
Undo

That looks marvelous!
I would also love a copy, if you please!
email:  olan.knight -at- csgi -dot- com

 

Thank You,

Olan

Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Friday, 1 September 2017 13:32 PM UTC
  2. PowerBuilder
  3. # 11
0
Votes
Undo

Very interesting work!

You didn't mention the PowerBuilder version. Generating a PBD from the PBX is only needed for PB 9 and PB 10. In newer versions you can right click a library and choose Import Extension. The object interface is then created in the library.

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Friday, 1 September 2017 12:54 PM UTC
  2. PowerBuilder
  3. # 12
0
Votes
Undo

Hi Alexander;

   Great work ... I would love a copy!

Regards ... Chris

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.