home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / TRIAL / JBUILDER / JVISBRKR.Z / AccountManagerImpl.java < prev    next >
Encoding:
Java Source  |  1998-05-08  |  2.0 KB  |  51 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.bank;
  21.  
  22. import java.util.*;
  23.  
  24. public class AccountManagerImpl extends Bank._AccountManagerImplBase {
  25.   public AccountManagerImpl(String name) {
  26.     super(name);
  27.   }
  28.   public synchronized Bank.Account open(String name) {
  29.     // Lookup the account in the account dictionary.
  30.     Bank.Account account = (Bank.Account) _accounts.get(name);
  31.     // If there was no account in the dictionary, create one.
  32.     if(account == null) {
  33.       // Make up the account's balance, between 0 and 1000 dollars.
  34.       float balance = Math.abs(_random.nextInt()) % 100000 / 100f;
  35.       // Create the account implementation, given the balance.
  36.       account = new AccountImpl(balance);
  37.       // Make the object available to the ORB.
  38.       _boa().obj_is_ready(account);
  39.       // Print out the new account.
  40.       System.out.println("Created " + name + "'s account: " + account);
  41.       // Save the account in the account dictionary.
  42.       _accounts.put(name, account);
  43.     }
  44.     // Return the account.
  45.     return account;
  46.   }
  47.   private Dictionary _accounts = new Hashtable();
  48.   private Random _random = new Random();
  49. }
  50.  
  51.