ImportController.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 2001-2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/**
* ImportController contains the logic to import data from a file to the
* server's data store. The file must have been written using the export
* procedure defined by ExportController. Users of this class must implement
* the Importer interface, which allows this class to communicate with the
* user.
* @see Importer
* @see ExportController
*/
public class ImportController {
/*
* The following constants are heuristics used to estimate the time
* required to complete each step of the import 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 import 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 various operations are relative to each other in a "typical"
* import, the assumption being that there are 5 macros exported to every
* option exported, and that there are around 150 clients per network.
* Obviously these can vary widely, but it gets the idea across pretty well.
*/
private static final int OPTION_OPS = 1;
private static final int MACRO_OPS = 5;
private static final int NET_OPS = 150;
/**
* Construct an ImportController with the given Importer and server
* implementation to use for the import process. Don't pass in "null"
* for either argument; the implementation does not validate these inputs.
* @param importer The importing object
* @param server The server which will perform the work
*/
}
/**
* Set the name of the file to be used for the import
* @param file The name of the file.
*/
// We can only have one file open at a time; close any currently open.
closeFile();
}
/**
* Close the file and clean up references
*/
public void closeFile() {
try {
// We *never* delete the file here
} catch (IOException e) {
e.getMessage());
}
}
}
/**
* Retrieve the header from the file.
* @return the header record from the file
*/
public ExportHeader getHeader()
throws ClassNotFoundException, IOException {
// If header not already read, then read it
// If file not yet open, then open it now
return null;
}
}
}
return header;
}
/**
* Import the data, optionally overwriting any conflicting data
* @param overwrite true if conflicting objects should be overwritten.
* @return true if the import completed successfully, false if not
*/
public boolean importData(boolean overwrite) {
// Default return is that import did not complete
boolean retval = false;
int totalOps = 0;
try {
// Ensure file is open and header has been read
// Couldn't get header; abort
return false;
}
/*
* Initialize progress display; recCount is number of networks +
* one for macros and one for options.
*/
int progress = 0;
// Update progress, and import the options
}
// Update progress and import the macros
progress += OPTION_OPS;
}
// Set up for network progress messages
/*
* Get list of networks from the header; ExportController never
* writes a null reference, always a zero-length array at worst.
*/
// For each network, update progress and import it
}
}
retval = true;
} catch (InterruptedException e) {
// User asked us to stop; nothing to do but let it fall through
} catch (ClassNotFoundException e) {
// Bad version of file
e.getMessage());
} catch (Exception e) {
// Error reading the file
e.getMessage());
} finally {
// Finish progress
try {
} catch (InterruptedException e) {
// Ignore
}
// Always close import file
closeFile();
}
return retval;
}
}
}