import java.io.*; import java.net.*; import java.awt.*; import org.omg.CORBA.*; import com.sun.CORBA.iiop.*; import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import ClientApp.*; class ClientQueryServantImpl extends ClientApp._ClientQueryImplBase { private myDatabase database; public ResultServantImpl result = new ResultServantImpl("", "", ""); public ClientQueryServantImpl() { database = new myDatabase(); } public void search(String a) { StringBuffer asb = new StringBuffer(); StringBuffer bsb = new StringBuffer(); StringBuffer csb = new StringBuffer(); database.find(a, asb, bsb, csb); System.out.println("got back from db: " + asb.toString()); System.out.println("Name: " + asb.toString()); System.out.println("Age: " + bsb.toString()); System.out.println("Occupation: " + csb.toString()); this.result.name(asb.toString()); this.result.age(bsb.toString()); this.result.occ(csb.toString()); } public String getName() { return this.result.name(); } public String getAge() { return this.result.age(); } public String getOcc() { return this.result.occ(); } public void open() { database.open(); System.out.println("OPEN DATABASE"); } public void close() { database.close(); System.out.println("CLOSE DATABASE"); } } class ResultServantImpl extends ClientApp._ResultImplBase { public String name_; public String age_; public String occ_; public ResultServantImpl(String name, String age, String occ) { name_ = name; age_ = age; occ_ = occ; } public String toString() { StringBuffer sb = new StringBuffer(); sb.append("Name: " + this.name_ + "\nAge: " + this.age_ + "\nOccupation: " + this.occ_); return sb.toString(); } public String name() { return this.name_; } public void name(String arg) { name_ = arg; } public String age() { return this.age_; } public void age(String arg) { age_ = arg; } public String occ() { return this.occ_; } public void occ(String arg) { occ_ = arg; } } public class DBServer { public static org.omg.CORBA.ORB theOrb_; public ResultServantImpl servant1; public static void main(String[] args) { try { // create and initialize ORB theOrb_ = org.omg.CORBA.ORB.init(args, null); // create Servant and register it with ORB ClientQueryServantImpl servant = new ClientQueryServantImpl(); theOrb_.connect(servant); // get the root naming context org.omg.CORBA.Object objRef = theOrb_.resolve_initial_references("NameService"); NamingContext ncRef = NamingContextHelper.narrow(objRef); // bind the Object Reference in Naming NameComponent nc = new NameComponent("ClientApp", ""); NameComponent path1[] = {nc}; ncRef.rebind(path1, servant); // wait for invocations from clients java.lang.Object sync = new java.lang.Object(); synchronized (sync) { sync.wait(); } } catch (Exception ex) { ex.printStackTrace(); System.err.println("DB Server: Exception-> " + ex); } } }