1 /* 2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import HelloApp.*; 25 import org.omg.CosNaming.*; 26 import org.omg.CosNaming.NamingContextPackage.*; 27 import org.omg.CORBA.*; 28 29 public class HelloClient 30 { 31 static Hello helloImpl; 32 33 public static void main(String args[]) 34 { 35 try{ 36 // create and initialize the ORB 37 ORB orb = ORB.init(args, null); 38 39 // get the root naming context 40 org.omg.CORBA.Object objRef = 41 orb.resolve_initial_references("NameService"); 42 // Use NamingContextExt instead of NamingContext. This is 43 // part of the Interoperable naming Service. 44 NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); 45 46 // resolve the Object Reference in Naming 47 String name = "Hello"; 48 helloImpl = HelloHelper.narrow(ncRef.resolve_str(name)); 49 50 System.out.println("Obtained a handle on server object: " + helloImpl); 51 for (int i = 0; i < 2; i++) { 52 try { 53 System.out.println(helloImpl.sayHello()); 54 } catch (Exception e) { 55 System.out.println("Exception: " + e.getMessage()); 56 e.printStackTrace(); 57 } 58 Thread.sleep(2000); 59 } 60 61 } catch (Exception e) { 62 System.out.println("ERROR : " + e) ; 63 e.printStackTrace(System.out); 64 } 65 } 66 67 }