/* File: ClientApp.java * Author: E. W. Grundke * * Comments: Client application for the 2-dimensional vector demo. * * To run this on borg under java 1.3: * /opt/java/j2sdk1_3_1_02/bin/idlj -fclient VecRotn.idl * /opt/java/j2sdk1_3_1_02/bin/javac *.java * /opt/java/j2sdk1_3_1_02/bin/java ClientApp * On locutus, replace /opt/java/j2sdk1_3_1_02/bin by /usr/j2se/bin. */ import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*; import java.util.Properties; public class ClientApp { public static void main(String args[]) { try { // create and initialize an ORB for port number 50505 on borg: Properties props = new Properties(); props.put("org.omg.CORBA.ORBInitialHost", "borg.cs.dal.ca"); props.put("org.omg.CORBA.ORBInitialPort", "50505"); ORB orb = ORB.init((String[])null, props); try { // get the root naming context org.omg.CORBA.Object obj = orb.resolve_initial_references("NameService"); // narrow() doestypecasting for CORBA objects NamingContext naming = NamingContextHelper.narrow(obj); System.out.println("naming = "+naming); // resolve the Object Reference; "kind" field is empty NameComponent nc = new NameComponent("Rotator", ""); System.out.println("nc = "+nc); NameComponent[] path = {nc}; // 1-element array (naming is tree-like) try { // find the CORBA object corresponding to name "Rotator" org.omg.CORBA.Object obj2 = naming.resolve(path); Vctr2Rotn rotn = Vctr2RotnHelper.narrow(obj2); /////////////// Now we're finished with CORBA. Use rotn like any java object! // constructor provided by IDL! Vctr2 v = new Vctr2(1.0, 1.0); // 90 deg counter-clockwise should give (+1, -1). v = rotn.rotate(v, 90.0); display(v); // should be // back 45 deg clockwise should give (0, +sqrt(2.0)). v = rotn.rotate(v, -45.0); display(v); System.out.println(rotn.count()); } catch (Exception e) { System.out.println("E1: "+e.getMessage()); } } catch (org.omg.CORBA.ORBPackage.InvalidName e) { System.out.println("E2: "+e); } } catch (org.omg.CORBA.SystemException e) { System.out.println("ERROR : " + e) ; e.printStackTrace(System.out); } } public static void display(Vctr2 v) { System.out.println("x: "+v.x+" y:"+v.y); } }