home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / TRIAL / JBUILDER / JVISBRKR.Z / AccountFinder.java < prev    next >
Encoding:
Java Source  |  1998-05-08  |  2.6 KB  |  75 lines

  1. /*
  2.  * Copyright (c) 1997-1998 Borland International, Inc. All Rights Reserved.
  3.  * 
  4.  * This SOURCE CODE FILE, which has been provided by Borland as part
  5.  * of a Borland product for use ONLY by licensed users of the product,
  6.  * includes CONFIDENTIAL and PROPRIETARY information of Borland.  
  7.  *
  8.  * USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 
  9.  * OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
  10.  * THE PRODUCT.
  11.  *
  12.  * IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND, ITS RELATED
  13.  * COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
  14.  * OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
  15.  * OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
  16.  * OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
  17.  * OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
  18.  * CODE FILE.
  19.  */
  20. package visibroker.samples.locate;
  21.  
  22. public class AccountFinder {
  23.  
  24.   private static void UsageHelper()
  25.   {
  26.     System.out.println("Unable to locate LocationService\n" +
  27.        "   -Make sure the locserv process is running\n" +
  28.        "   -Make sure you set the client's System Property\n" +
  29.        "    ORBservices=\"com.visigenic.vbroker.ObjLocation\"");
  30.   }
  31.  
  32.   public static void main(String[] args)
  33.   {
  34.     try {
  35.       // Initialize the ORB.
  36.       org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,null);
  37.       // Initialize the BOA.
  38.       org.omg.CORBA.BOA boa = orb.BOA_init();
  39.       com.visigenic.vbroker.ObjLocation.Agent the_agent = null;
  40.  
  41.       try {
  42.     org.omg.CORBA.Object obj = 
  43.       orb.resolve_initial_references("LocationService");
  44.     if ((obj == null) ||
  45.         ((the_agent=com.visigenic.vbroker.ObjLocation.AgentHelper.narrow(obj)) == null)) {
  46.       UsageHelper();
  47.       System.exit(1);
  48.     }
  49.       } catch (org.omg.CORBA.ORBPackage.InvalidName e) {
  50.     System.out.println("Not able to resolve references " +
  51.                "for LocationService");
  52.     UsageHelper();
  53.     System.exit(1);
  54.       } catch (Exception e) {
  55.     System.out.println("Caught exception: " + e);
  56.     UsageHelper();
  57.     System.exit(1);
  58.       }
  59.       
  60.       org.omg.CORBA.Object[] accountRefs =
  61.     the_agent.all_instances("IDL:Bank/AccountManager:1.0");
  62.       System.out.println("Agent returned " + accountRefs.length +
  63.              " object references");
  64.       for (int i=0; i < accountRefs.length; i++) {
  65.     System.out.println("Stringified IOR for account #" + (i+1) + ":");
  66.     System.out.println(orb.object_to_string(accountRefs[i]));
  67.     System.out.println();
  68.       }
  69.     } catch (Exception e) {
  70.       System.out.println("Caught exception: " + e);
  71.       System.exit(1);
  72.     }
  73.   }
  74. }
  75.