home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-05-08 | 4.9 KB | 126 lines |
- /*
- * Copyright (c) 1997-1998 Borland International, Inc. All Rights Reserved.
- *
- * This SOURCE CODE FILE, which has been provided by Borland as part
- * of a Borland product for use ONLY by licensed users of the product,
- * includes CONFIDENTIAL and PROPRIETARY information of Borland.
- *
- * USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS
- * OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
- * THE PRODUCT.
- *
- * IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND, ITS RELATED
- * COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
- * OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
- * OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
- * OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
- * OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
- * CODE FILE.
- */
-
- //Title: JBuilder Tutorial
- //Version: 2.0
- //Copyright: Copyright (c) 1998
- //Author: Jens Ole Lauridsen
- //Company: Borland Int'l
- //Description: Tutorial of Distributed Computing using RMI and DataSetData.
-
- package borland.samples.tutorial.dataset.datasetdata;
-
- import borland.jbcl.dataset.*;
- import java.rmi.*;
- import java.util.*;
-
- // The ClientResolver class is an implementation of a Resolver.
- //
- class ClientResolver extends Resolver {
- ResourceBundle res = Res.getBundle("borland.samples.tutorial.dataset.datasetdata.Res");
-
- // resolveData
- // Implementation of method in borland.jbcl.dataset.Resolver
- // First, We lookup the "DataServerApp" service on the host specified by the
- // HostName property.
- // Then, we extract the changes into a DataSetData instance.
- // Next, we make the remote method call: resolveEmployeeChanges.
- // Next, if there are resolution errors, handle these accordingly.
- // Last, we call resetPendingStatus(true), which will change the
- // status bits for all our changed rows in our dataSet to be resolved.
- //
- public void resolveData(DataSet dataSet) throws DataSetException {
- try {
- String serverName = "//" + hostName + "/DataServerApp";
- EmployeeApi server = (EmployeeApi)Naming.lookup(serverName);
- ProviderHelp.startResolution(dataSet.getStorageDataSet(), true); // This blocks the dataset for invalid operations while resolving.
- DataSetData changes = DataSetData.extractDataSetChanges(dataSet);
- DataSetData errors = server.resolveEmployeeChanges(changes);
- if (errors != null)
- handleErrors(dataSet,errors);
- dataSet.resetPendingStatus(true);
- }
- catch (DataSetException ex) {
- dataSet.resetPendingStatus(false); // reset status bits to: nothing is resolved !
- throw ex;
- }
- catch (NotBoundException ex) {
- dataSet.resetPendingStatus(false); // reset status bits to: nothing is resolved !
- throw new DataSetException(res.getString("RS_NoServer"));
- }
- catch (Exception ex) {
- dataSet.resetPendingStatus(false); // reset status bits to: nothing is resolved !
- String error = ex.getMessage();
- if (error == null)
- error = res.getString("RS_NoConnect")+hostName;
- throw new DataSetException(error);
- }
- finally {
- ProviderHelp.endResolution(dataSet.getStorageDataSet()); // This unblocks the dataSet after resolving.
- }
- }
-
- // handleErrors.
- // Errors are handled in the following way in this tutorial. Note that this is
- // not the only nor the best way to handle errors, but it might give some good
- // ideas for the 'ultimate' implementation.
- //
- // We just want to show 1 error in the UI. Ignore all other possible errors.
- //
- // First we have to loop through all the errors reported, and reset the
- // status bits to not resolved for each row that caused an error.
- // Then we go to the first reported error, and let the provider fail with
- // that error.
- //
- private void handleErrors(DataSet dataSet, DataSetData errors)
- throws DataSetException
- {
- TableDataSet errorDataSet = new TableDataSet();
- errors.loadDataSet(errorDataSet);
- long internalRow;
- errorDataSet.first();
- do {
- internalRow = errorDataSet.getLong(0);
- dataSet.resetPendingStatus(internalRow,false);
- } while (errorDataSet.next());
-
- dataSet.resetPendingStatus(true);
-
- errorDataSet.first();
- internalRow = errorDataSet.getLong(0);
- dataSet.goToInternalRow(internalRow);
- DataSetException ex = (DataSetException)errorDataSet.getObject(1);
- throw ex;
- }
-
- // The HostName property is used to locate the "DataServerApp" service
- // through RMI. By default we just look at our local machine.
- //
- public String getHostName() {
- return hostName;
- }
-
- public void setHostName(String hostName) {
- this.hostName = hostName;
- }
-
- private String hostName = "localhost";
- }
-