home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / TRIAL / JBUILDER / JSAMPLES.Z / ClientProvider.java < prev    next >
Encoding:
Java Source  |  1998-05-08  |  2.8 KB  |  80 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.  
  21. //Title:        JBuilder Tutorial
  22. //Version:      2.0
  23. //Copyright:    Copyright (c) 1998
  24. //Author:       Jens Ole Lauridsen
  25. //Company:      Borland Int'l
  26. //Description:  Tutorial of Distributed Computing using RMI and DataSetData.
  27.  
  28. package borland.samples.tutorial.dataset.datasetdata;
  29.  
  30. import borland.jbcl.dataset.*;
  31. import java.rmi.*;
  32. import java.util.*;
  33.  
  34. // The ClientProvider class is an implementation of a Provider.
  35. //
  36. class ClientProvider extends Provider {
  37.   ResourceBundle res = Res.getBundle("borland.samples.tutorial.dataset.datasetdata.Res");
  38.   
  39.   // provideData
  40.   // Implementation of method in borland.jbcl.dataset.Provider
  41.   // We lookup the "DataServerApp" service on the host specified by the 
  42.   // HostName property. Then make the remote method call: provideEmployeeData
  43.   // and load our dataSet with the contents.
  44.   //
  45.   public void provideData(StorageDataSet dataSet, boolean toOpen) throws DataSetException {
  46.     try {
  47.       String      serverName = "//" + hostName + "/DataServerApp";
  48.       EmployeeApi server = (EmployeeApi)Naming.lookup(serverName);
  49.       DataSetData data = server.provideEmployeeData();
  50.       dataSet.empty();
  51.       data.loadDataSet(dataSet);
  52.     }
  53.     catch (NotBoundException ex) {
  54.       throw new DataSetException(res.getString("RS_NoServer"));
  55.     }
  56.     catch (DataSetException ex) {
  57.       throw ex;
  58.     }     
  59.     catch (Exception ex) {
  60.       String error = ex.getMessage();
  61.       if (error == null)
  62.         error = res.getString("RS_NoConnect")+hostName;
  63.       throw new DataSetException(error);
  64.     }
  65.   }
  66.  
  67.   // The HostName property is used to locate the "DataServerApp" service
  68.   // through RMI. By default we just look at our local machine.
  69.   //
  70.   public String getHostName() {
  71.     return hostName;
  72.   }
  73.  
  74.   public void setHostName(String hostName) {
  75.     this.hostName = hostName;
  76.   }
  77.   
  78.   private String hostName = "localhost";
  79.