Generating EJB proxy objects

To generate EJB proxy objects, you need to create an EJB Client Proxy project. You can do this in the Project painter or with a wizard.

Using an EJB Proxy project

To create a new EJB Client Proxy project, select either of the following from the Projects page of the New dialog box:

EJB Client Proxy icon

The EJB Client Proxy icon opens the Project painter for EJB proxies so you can create a project, specify options, and build the proxy library.

To create an EJB Client Proxy project in the Project painter:

  1. Double-click the EJB Client Proxy icon on the Projects page of the New dialog box.

  2. To specify the EJB, select Edit>Select Objects and enter the fully qualified name of the component's remote interface in the text box, for example com.sybase.jaguar.sample.svu.SVULogin or portfolio.MarketMaker.

  3. Enter the path of the directory or JAR file that contains the EJB's stubs in the Classpath box and click OK.

    If the stub files are in a directory and the fully qualified name of the EJB is packagename.beanname, enter the directory that contains packagename.

  4. To specify the PBL where the proxy objects should be stored, select Edit>Properties and browse to the location of a library in the target's library list.

    You can specify an optional prefix that is added to the beginning of each generated proxy name. Adding a prefix makes it easier to identify the proxies associated with a specific EJB and can be used to avoid conflicts between class names and PowerBuilder reserved words. The prefix is not added to the name of proxies that are not specific to this EJB, such as the proxies for exceptions, stream objects, and ejbhome, ejbobject, ejbmetadata, handle, and homehandle.

  5. Close the dialog box and select File>Save to save the project.

The new project lists the EJB component for which a proxy will be generated and specifies the name of the output library that will contain the generated proxy objects.

EJB Client Proxy Wizard icon

The EJB Client Proxy Wizard helps you create the project.

To create an EJB Client Proxy project using the wizard:

  1. Double-click the EJB Client Proxy Wizard icon on the Projects page of the New dialog box and click Next on the first page of the wizard.

  2. Select a library in which to store the project object and click Next.

  3. Specify a name and optional description for the project and click Next.

  4. As shown, enter the fully qualified name of the component's remote interface in the text box, for example cocoPortfolio.Portfolio:

    The component's home interface name is entered automatically using the standard naming convention, although the wizard lets you modify this name if necessary.

  5. Browse to select the JAR file that contains the EJB's stubs or the directory that contains the stub package.

    If the stub files are in a directory and the fully qualified name of the EJB is packagename.beanname, enter the directory that contains packagename.

  6. Specify an optional prefix that is added to the beginning of each generated proxy name and click Next.

    Adding a prefix makes it easier to identify the proxies associated with a specific EJB and can be used to avoid conflicts between class names and PowerBuilder reserved words. The prefix is not added to the name of proxies that are not specific to this EJB, such as the proxies for exceptions, supporting classes, and EJBHome, EJBObject, EJBMetaData, Handle, and HomeHandle.

  7. Browse to select an existing library and click Next and Finish.

    The proxy objects are generated and stored in this library, which must be added to the target's library list.

After the wizard has created the project, you can use the Project painter to modify your project settings.

Building proxies

Whether you create the EJB Proxy project using the wizard or the painter, the final step is to build the proxy objects. To do so, click the Build icon on the painter bar or select Design>Deploy Project from the menu bar.

Proxy generation requires javap.exe

PowerBuilder uses the javap.exe utility to generate proxy objects. This executable must be in your system path. By default, EJB client development uses the Oracle JDK 1.6 installed with PowerBuilder. The path and classpath required by the Java VM are added to the path and classpath used in the current session automatically.

If you want to use a different JDK installation, select Tools>System Options, then click Set JDK Location on the Java page of the System Options dialog box. For WebSphere, the path to the IBM JDK installation can be used instead.

In addition to the proxies for the home and remote interfaces of the EJB, proxies are also generated for any Java classes referenced by the EJB, for ancestor classes, for any exceptions that can be thrown by the EJB and its supporting classes, and for the following interfaces:

Object

Description

EJBHome

Proxy for the javax.ejb.EJBHome interface, the base class for all EJB home interfaces.

EJBMetaData

Proxy for the javax.ejb.EJBMetaData interface. Allows a client to obtain the EJB's home interface and the class objects for its home and remote interfaces and primary key class (for entity beans), and to determine whether the bean is a session or stateless session object.

EJBObject

Proxy for the javax.ejb.EJBObject interface, the base class for all EJB remote interfaces.

Handle

Proxy for the javax.ejb.Handle interface. Used to provide a robust persistent reference to an EJB.

HomeHandle

Proxy for the javax.ejb.HomeHandle interface. Used to provide a robust persistent reference to a home object.


For more information about these interfaces, see the documentation for the javax.ejb package at https://docs.oracle.com/javaee/6/api/javax/ejb/package-summary.html.

The project also generates a structure that stores the mapping of Java classes to proxy names. This structure is used internally and should not be modified.

Using the ejb2pb190 tool

You can also use the ejb2pb190 command-line tool to generate proxies. The tool generates:

  • Proxies (.srx files) for the home and remote interfaces of the EJB you specify and for the classes on which the EJB depends.

  • A PowerBuilder structure object named ejbname_ejb_pb_mapping.srs, where ejbname is the name of the EJB. This structure hosts the mapping table between the Java class name and the PowerBuilder proxy name.

  • A text file called ejbproxies.txt or, if errors occur, ejbproxies.err.

These files are generated in the directory in which you invoke the command. The syntax is:

ejb2pb190 [ -classpath pathlist ] EJBName [EJBHomeName][ prefix ]

If the pathlist argument contains spaces, for example D:\Program Files, the pathlist must be enclosed in quotes. EJBName is the fully qualified remote interface class name. If you use the standard naming convention for the home interface, then including an argument for the fully qualified home interface name, EJBHomeName, is optional. If you specify the optional prefix, it is added to the beginning of the generated proxy name.

For example, the following statements generate proxies for the mytest.Calc class in the package Calc on WebLogic. The proxies for the home and remote interfaces of the Calc class have the prefix pf_, and the generated files are written to the directory D:\work\proxies:

cd D:\work\proxies
ejb2pb190 -classpath "D:\Program Files\weblogic\Calc.jar" mytest.Calc pf_

The home and remote classes for the EJB and any dependent classes must be in the class path that you specify.

After generating the proxies, you import them into your target by selecting the library that contains the client, selecting Import from its pop-up menu, and selecting the .srx files from the dialog box that displays. The order in which you import .srx files is significant -- you cannot import proxies that depend on other classes until you have imported the proxies for the dependent classes.

Viewing the generated proxies

The generated proxies display in the System Tree. You can expand the proxy nodes to display the signatures of the methods on the home and remote interfaces for the EJB component, as well as on all the other objects for which proxies were generated.

 

Conflicts with reserved words

If the name of a component method conflicts with a PowerBuilder reserved word, the string _j is appended to the method name in the proxy so that the methods can be imported into PowerBuilder. For example, the Java Iterator class has a Next method, which conflicts with the PowerBuilder reserved word NEXT. In the proxy, the method is named next_j.

Datatype mappings

The EJB Proxy generator maps datatypes between Java and PowerBuilder as shown in the following table:

Java type

PowerBuilder type

short 

Integer 

int

Long

long

LongLong

float

Real

double

Double

byte

Int

char (16-bit unsigned)

Char

java.lang.String

String

boolean

Boolean

java.util.Date

Datetime

Array of primitive type

Parameters: Array of primitive type

Return values: Any

Array of java.lang.String or java.util.Date objects

Parameters: Array of String or DateTime

Return values: Any

Array of arrays

Any

Java class arguments or return values

PowerBuilder proxies of Java classes

Other

Any


Different precision for double

A PowerBuilder double has 15 digits of precision (1.79769313486231E+308) and a Java double has 17 digits (1.7976931348623157e+308). For EJB client applications, the precision of a double is limited to the PowerBuilder range (2.2250738585073E-308 to 1.79769313486231E+308).

Arrays of arrays

Unlike Java, PowerBuilder does not support unbounded multidimensional arrays. If a Java method takes an array of arrays as a parameter, the corresponding PowerBuilder proxy method takes a parameter of type Any. To call the method in PowerBuilder, declare a PowerBuilder array with the same dimensions as the Java array, and pass the array as the parameter.