Invoking another server component’s methods
Jaguar 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 Jaguar.
Accessing a component in the current server
To access methods of another Jaguar 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, you need
to 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 could call GetContextService
to instantiate the TransactionServer service:
1 |
// Instance variable: |
1 |
// TransactionServer ts |
1 |
1 |
Integer rc |
1 |
rc = this.GetContextService("TransactionServer", & |
1 |
ts) |
1 |
IF rc <> 1 THEN |
1 |
// handle the error |
1 |
END IF |
In one of the component methods, you could then call CreateInstance
to instantiate the second component and call one of its methods:
1 |
// Instance variable for the second component: |
1 |
// nvo_comp2 mycomp2 |
1 |
Integer rc |
1 |
rc = ts.CreateInstance(mycomp2, "mypackage/nvo_comp2") |
1 |
IF rc <> 0 THEN |
1 |
// handle the error |
1 |
ELSE |
1 |
mycomp2.method1() |
1 |
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 a Jaguar
component on a different server, you need to create a Connection
object, set properties for the Connection object, and call ConnectToServer.