Invoking another server component’s methods
EAServer allows the methods of one server component to call
methods of another server component. The other server component
does not need to be another PowerBuilder component; it can be implemented
in any language supported by EAServer.
Accessing a component in the current server
To access methods of another EAServer component in the current
server, you can use the Connection object to communicate with the
component, just as you would from a PowerBuilder client. Alternatively,
you can use the transaction service context object that PowerBuilder
provides called TransactionServer. The TransactionServer
interface provides a method called CreateInstance that allows you
to access other components that are available locally. CreateInstance
uses the same user and password information that applies to the component
from which it is called.
Before you can use the transaction context service, declare
a variable of type TransactionServer and call the GetContextService
function to create an instance of the service.
Example In the Activate event for a component, you can call GetContextService
to instantiate the TransactionServer service:
1 |
// Instance variable:<br /> // TransactionServer ts<br /> <br /> Integer rc<br /> rc = this.GetContextService("TransactionServer", &<br /> ts)<br /> IF rc <> 1 THEN<br /> // handle the error<br /> END IF |
In one of the component methods, you can then call CreateInstance
to instantiate the second component and call one of its methods:
1 |
// Instance variable for the second component:<br /> // nvo_comp2 mycomp2 <br /> Integer rc<br /> rc = ts.CreateInstance(mycomp2, "mypackage/nvo_comp2")<br /> IF rc <> 0 THEN<br /> // handle the error<br /> ELSE<br /> mycomp2.method1()<br /> END IF |
Accessing a component in a different server
The procedure for accessing a server component on a different
server is essentially the same as the procedure for accessing a
server component from a PowerBuilder client. To access an EAServer
component on a different server, create a Connection object, set
properties for the Connection object, and call ConnectToServer.
Accessing an EJB component
A PowerBuilder component can access an EJB component using
the Lookup method of either the Connection or TransactionServer
objects. The Lookup method on the TransactionServer object has an
optional third argument you can use to specify the name of the home
interface. You use this argument only if the home interface name
does not follow typical naming conventions.
Example This script instantiates the Cart component and invokes several component
methods. In this example, the second argument to the Lookup method
specifies the component name as well as the EAServer package name:
1 |
//Instance variable:<br /> //Connection myconnect<br /> <br /> CartHome MyCartHome // EJB's home interface<br /> Cart MyShoppingCart // EJB's remote interface<br /> TransactionServer ts<br /> long ll_result<br /> <br /> This.GetContextService("TransactionServer", ts)<br /> <br /> //Get the home interface<br /> ll_result = &<br /> ts.Lookup(MyCartHome, "Shopping/Cart")<br /> <br /> //Get a reference to Cart component's business logic<br /> MyShoppingCart = MyCartHome.Create()<br /> <br /> //Use the shopping cart<br /> MyShoppingCart.AddItem(66)<br /> MyShoppingCart.Purchase() |
For information about accessing EJB components from PowerBuilder
clients, see “Invoking an EJB component
method”.
Component-demarcated transactions
EAServer components marked as OTS style can create, control,
and obtain information about EAServer transactions using functions
of the CORBACurrent context service object. The CORBACurrent object
provides most of the methods defined for the CORBA Current interface.
For more information, see “Client- and component-demarcated
transactions”.