ExportController.java revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* ident "%Z%%M% %I% %E% SMI"
*
* Copyright (c) 2001 by Sun Microsystems, Inc.
* All rights reserved.
*/
/**
* ExportController contains the logic to export the server's data to
* a file for later import on either this server or some other server.
* Users of this class must implement the Exporter interface in order
* to provide communication.
* @see Exporter
* @see ImportController
*/
public class ExportController {
// Statics used to ensure we never have null array references
/*
* The following constants are heuristics used to estimate the time
* required to complete each step of the export process; they're used to
* allow a GUI progress meter to pop up and behave relatively correctly.
* We can't afford from a performance point of view to be precise as it
* would defeat the purpose of our export architecture, so we try to
* make sure the user gets at least some idea of where we are in the
* process. The *OPS constants indicate an estimate of how expensive
* the delete operations are relative to the export operations. YMMV.
*/
private static final int OPTION_DELETE_OPS = 2;
private static final int MACRO_DELETE_OPS = 2;
private static final int NETWORK_DELETE_OPS = 2;
private static final int DEFAULT_OPTION_COUNT = 10;
private static final int DEFAULT_MACRO_COUNT = 50;
private static final int DEFAULT_CLIENTS_PER_NET = 150;
/**
* Construct an ExportController with the given Exporter and a
* server-side to use to perform the export. Don't pass in "null" for
* either argument; the implementation does not validate these inputs.
* @param exporter The exporting object
* @param server The server which will do the work for us.
*/
}
/**
* Set the name of the user performing the export. This is
* recorded in the export file for reference at import.
* @param user The name of the user
*/
}
/**
* Set the name of the file to which to export.
* @param file the full pathname of the file to export into
*/
}
/**
* Specify that all networks are to be exported
*/
public void setAllNetworks() {
allNets = true;
}
/**
* Specify the networks to be exported.
* @param networks An array of Network objects which should be exported
*/
allNets = false;
// Never allow networks to be null
} else {
}
}
/**
* Specify that all macros should be exported.
*/
public void setAllMacros() {
allMacros = true;
}
/**
* Specify the macros to be exported.
* @param macros An array of macro names
*/
allMacros = false;
// Never allow macros to be null
} else {
this.macros = emptyMacros;
}
}
/**
* Specify that all options should be exported
*/
public void setAllOptions() {
allOptions = true;
}
/**
* Specify the options to be exported.
* @param options An array of option names
*/
allOptions = false;
// Never allow options to be null
} else {
this.options = emptyOptions;
}
}
/**
* Perform the actual export.
* @param deleteData True if data should be deleted after a successful
* export.
* @param overwrite True if file should be forcibly overwritten. An
* ExistsException will be thrown if the file exists and overwrite is
* false.
* @return true if the export succeeded, false on failure.
*/
throws ExistsException {
// Value to return; default to false for failure
boolean retval = false;
// Default to deleting the file on any errors
boolean deleteFile = true;
if (allNets) {
try {
// Load network list
} catch (Exception e) {
return false;
}
}
/*
* Number of records in the export file is number of networks, plus 1
* for options, plus 1 for macros.
*/
// Calculate total number of estimated ops for progress
int optionDelOps = 0;
int macroDelOps = 0;
int netDelOps = 0;
if (totalOps == 0) {
// Nothing to export!!!
return false;
}
// If user wants to delete, add to number of ops required
if (deleteData) {
}
/*
* Open the file; catch IO errors, but if we get an ExistsException we
* just let that through to the caller, who's supposed to deal with it
* appropriately.
*/
try {
// If lock couldn't be obtained, display error and abort
return false;
}
} catch (IOException e) {
return false;
}
try {
// Initialize progress with our expected number of operations
int progress = 0;
// Now export the options
if (optionOps != 0) {
// Only update progress if we're actually doing something here
}
try {
} catch (BridgeException e) {
throw new InterruptedException();
}
if (macroOps != 0) {
// Only update progress if we're actually doing something here
}
// Now export the macros
try {
} catch (BridgeException e) {
throw new InterruptedException();
}
// Set up for progress messages
// Now export each network in turn
// Export the network
try {
} catch (BridgeException e) {
throw new InterruptedException();
}
}
// Success; don't delete the file
deleteFile = false;
// If user wants data deleted, too, then do it now
if (deleteData) {
// Delete options
if (optionDelOps != 0) {
// Only update progress if something to delete
}
if (allOptions) {
try {
} catch (BridgeException e) {
}
} else {
}
progress += optionDelOps;
// Delete macros
if (macroDelOps != 0) {
// Only update progress if something to delete
}
if (allMacros) {
try {
} catch (BridgeException e) {
}
} else {
}
progress += macroDelOps;
// Delete each network in turn
form = new MessageFormat(
try {
} catch (BridgeException e) {
}
}
// This update informs caller we're done
// Now display whatever errors happened during delete
}
}
}
}
retval = true;
} catch (InterruptedException e) {
/*
* User wanted to cancel, or some serious failure occurred; in the
* former case no need to display anything, in the latter it
* was already displayed before we got here, so just return.
*/
retval = false;
} catch (Exception e) {
// I/O error of some sort. Display it before returning.
retval = false;
} finally {
// Always close before leaving; display any resulting errors
try {
} catch (IOException e) {
}
}
return retval;
}
// Utility method to display an error message for an exception
}
}