The following example shows how the GenericFactory service is used by a client program to create an account object. The client must first create a proxy for the GenericFactory.
/usr/lpp/cicsts/<cicsts31>/lib/omgcos.jar
Where cicsts31 is
your chosen value for the USSDIR installation parameter that you defined when
you installed CICSTS. The JAR file should be downloaded in binary mode and made available on the client's CLASSPATH environment entry.
The following example, and the supplied samples, require bindings that can be imported as org.omg.CosNaming and org.omg.CosLifeCycle.
In order to create an account object, the client must first create a proxy for the GenericFactory. The following example assumes that a stringified reference to the GenericFactory exists in a file available to a client, and is returned by the getFactoryIOR() method.
import java.io.*;
import org.omg.CORBA.*;
import org.omg.CosLifeCycle.*;
import org.omg.CosNaming.*;
public class bankLineModeClient{
//The following method reads the ior from a file and returns it in the string
String factoryIOR = getFactoryIOR();
// Turn the stringified reference into the proxy
org.omg.CORBA.Object genFacRef = orb.string_to_object(factoryIOR);
// narrow to correct interface
GenericFactory fact = GenericFactoryHelper.narrow(genFacRef);
// The Generic factory needs a key, which is a sequence of namecomponents
NameComponent nc = new NameComponent("bank::BankAccount","object interface");
NameComponent key[] = {nc};
//The Generic factory also requires criteria (which it ignores)
NVP mycriteria[] = {};
//Now create the object
org.omg.CORBA.Object objRef = fact.create_object(key, mycriteria);
// and narrow to correct interface
BankAccount acctRef = BankAccountHelper.narrow(objRef);
int ac1 = 1234; // Tony's account
int ac2 = 3456; // Lou's account
String name;
String address;
int balance;
try {
name=acctRef.queryname(ac1);
System.out.println("a/c num:"+ac1+" name:"+name);
}
catch (exception e) {
System.err.println("query error");
}