Problem
- Product Name: VisiBroker for Java
- Product Component: DSI
- Platform/OS Version: All
How to write an example using DSI and OUT parameters?
Resolution
Using the <VBROKERDIR>/examples/vbe/basic/bank_dynamic example, the IDL is modified to be:
//Bank.idl
module Bank {
interface Account {
float balance();
};
interface AccountManager {
Account open(in string name1, out string name2);
};
};
The AccountManagerImpl.java is modified to be:
...
(in invoke() method)
public void invoke(org.omg.CORBA.ServerRequest request) {
// Ensure that the operation name is correct
if (!request.operation().equals("open")) {
throw new org.omg.CORBA.BAD_OPERATION();
}
// Fetch the input parameter
String name1 = null;
org.omg.CORBA.StringHolder name2 = new org.omg.CORBA.StringHolder("RETURNed VALUE");
try {
org.omg.CORBA.NVList params = _orb.create_list(2);
org.omg.CORBA.Any any1 = _orb.create_any();
org.omg.CORBA.Any any2 = _orb.create_any();
any1.insert_string(new String(""));
any2.type(name2._type());
params.add_value("name", any1, org.omg.CORBA.ARG_IN.value);
params.add_value("name", any2, org.omg.CORBA.ARG_OUT.value);
request.arguments(params);
name1 = params.item(0).value().extract_string();
params.item(1).value().insert_Streamable((org.omg.CORBA.portable.Streamable) name2);
}
catch (Exception e) {
throw new org.omg.CORBA.BAD_PARAM();
}
// Invoke the actual implementation and fill out the result
org.omg.CORBA.Object account = open(name1);
org.omg.CORBA.Any result = _orb.create_any();
result.insert_Object(account);
request.set_result(result);
}
...
The key here is that request"s arguments() method takes an INOUT parameter. So one can directly modify this INOUT parameter to change the value of OUT parameter in the AccountManager"s open() method.
Also note that all the Holder types directly inherit from org.omg.CORBA.portable.Streamable. So the new value for the OUT parameter can be easily inserted using the Any.insert_Streamable(...) API.
#Security
#out
#INOUT
#DSI
#VisiBroker