Client example

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.

Java bindings for part of the CORBA CosLifeCycle and CosNaming modules are required. If they are not provided by the client ORB, you can build them using the client ORB's IDL-to-Java compiler, from the CORBA services IDL available from the OMG website (www.omg.org). Alternatively, you can use the precompiled Java version of the IDL provided in
/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);
 
 
Now that the client has a generic factory, it can use it to create an account object.
// 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);
 
 
Now the client has an object, it can use it:
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");
}
Note: NVP (Name Value Pair) is a datatype defined in the CORBA IDL for the Generic Factory interface.