home *** CD-ROM | disk | FTP | other *** search
/ Internet News 1999 October / INEWS_10_CD.ISO / pc / jdk / jdk1.2.2 / docs / guide / idl / examples / hello / HelloServer.java < prev    next >
Encoding:
Java Source  |  1999-09-19  |  2.7 KB  |  77 lines

  1. /*
  2.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  3.  *
  4.  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
  5.  * modify and redistribute this software in source and binary code form,
  6.  * provided that i) this copyright notice and license appear on all copies of
  7.  * the software; and ii) Licensee does not utilize the software in a manner
  8.  * which is disparaging to Sun.
  9.  *
  10.  * This software is provided "AS IS," without a warranty of any kind. ALL
  11.  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
  12.  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  13.  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
  14.  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  15.  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
  16.  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
  17.  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
  18.  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
  19.  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
  20.  * POSSIBILITY OF SUCH DAMAGES.
  21.  *
  22.  * This software is not designed or intended for use in on-line control of
  23.  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
  24.  * the design, construction, operation or maintenance of any nuclear
  25.  * facility. Licensee represents and warrants that it will not use or
  26.  * redistribute the Software for such purposes.
  27.  */
  28.  
  29. import HelloApp.*;
  30.  
  31. import org.omg.CosNaming.*;
  32. import org.omg.CosNaming.NamingContextPackage.*;
  33. import org.omg.CORBA.*;
  34.  
  35. class HelloServant extends _HelloImplBase 
  36. {
  37.     public String sayHello()
  38.     {
  39.     return "\nHello world !!\n";
  40.     }
  41. }
  42.  
  43. public class HelloServer {
  44.  
  45.     public static void main(String args[])
  46.     {
  47.     try{
  48.         // create and initialize the ORB
  49.         ORB orb = ORB.init(args, null);
  50.  
  51.         // create servant and register it with the ORB
  52.         HelloServant helloRef = new HelloServant();
  53.         orb.connect(helloRef);
  54.  
  55.         // get the root naming context
  56.         org.omg.CORBA.Object objRef = 
  57.         orb.resolve_initial_references("NameService");
  58.         NamingContext ncRef = NamingContextHelper.narrow(objRef);
  59.  
  60.         // bind the Object Reference in Naming
  61.         NameComponent nc = new NameComponent("Hello", "");
  62.         NameComponent path[] = {nc};
  63.         ncRef.rebind(path, helloRef);
  64.  
  65.         // wait for invocations from clients
  66.             java.lang.Object sync = new java.lang.Object();
  67.             synchronized (sync) {
  68.                 sync.wait();
  69.             }
  70.  
  71.     } catch (Exception e) {
  72.         System.err.println("ERROR: " + e);
  73.         e.printStackTrace(System.out);
  74.     }
  75.     }
  76. }
  77.