org.bs.mdi
Class FileIOManager

java.lang.Object
  extended byorg.bs.mdi.FileIOManager

public class FileIOManager
extends Object

Manages File I/O modules


Field Summary
static int EXPORT
           
static int OPEN
           
static int SAVE
           
 
Constructor Summary
FileIOManager()
          Creates a new file I/O manager.
 
Method Summary
 boolean canExport()
          Determines if the file manager is able to export a file.
 boolean canLoad()
          Determines if the file manager is able to load a file.
 boolean canSave()
          Determines if the file manager is able to save a file.
 int countAllModules()
          Counts all registered modules.
 int countExporters()
          Counts all registered FileExporter modules.
 int countLoaders()
          Counts all registered FileLoader modules.
 int countSavers()
          Counts all registered FileSaver modules.
 void export(RootData data, FileExporter exporter)
          Exports the data using the specified exporter module.
 boolean fileExists(String filename)
          Returns true if the given file exists.
 FileExporter[] getFileExporters()
          Returns a list of all registered file exporter modules.
 FileLoader[] getFileLoaders()
          Returns a list of all registered file loader modules.
 FileSaver[] getFileSavers()
          Returns a list of all registered file saver modules.
 FileIOModule getIOModule(FileFormat format, int mode)
          Looks up a file I/O module for the specified format.
 FileFormat[] getSupportedFormats(int mode)
          Returns a list of all supported formats for loading, saving or exporting data.
 boolean isReady()
          Returns true if this file I/O manager is "ready".
 RootData load(String filename)
          Tries to load data from disk.
 RootData load(String filename, FileLoader loader)
          Tries to load data from disk using the specified loader module.
 void registerAllModules(FileIOModule[] modules)
          Registers all given file I/O modules in the given array.
 void registerModule(FileIOModule module)
          Registers a file I/O module.
 void save(RootData data, String filename)
          Tries to save a document to disk.
 void save(RootData data, String filename, FileSaver saver)
          Tries to save a document to disk using the specified saver module.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPEN

public static final int OPEN
See Also:
Constant Field Values

SAVE

public static final int SAVE
See Also:
Constant Field Values

EXPORT

public static final int EXPORT
See Also:
Constant Field Values
Constructor Detail

FileIOManager

public FileIOManager()
Creates a new file I/O manager.

Method Detail

load

public RootData load(String filename,
                     FileLoader loader)
              throws FileIOException
Tries to load data from disk using the specified loader module.

Parameters:
filename - the filename to be opened
loader - the loader module
Returns:
the document data
Throws:
FileIOException

load

public RootData load(String filename)
              throws FileIOException
Tries to load data from disk. This is done by finding an apropriate file I/O module for the given filename, and delegating the actual loading process to the module.

Parameters:
filename - the filename to be opened
Returns:
the document data
Throws:
FileIOException

save

public void save(RootData data,
                 String filename,
                 FileSaver saver)
          throws FileIOException
Tries to save a document to disk using the specified saver module.

Parameters:
data - the document data to be saved
filename - the filename to be written to
saver - the saver I/O module
Throws:
FileIOException

save

public void save(RootData data,
                 String filename)
          throws FileIOException
Tries to save a document to disk. This is done by finding an apropriate file I/O module for the given filename, and delegating the actual saving process to the module.

Parameters:
data - the document data to be saved
filename - the filename to be written to
Throws:
FileIOException

export

public void export(RootData data,
                   FileExporter exporter)
            throws FileIOException
Exports the data using the specified exporter module.

Parameters:
data - the document data to be exported
exporter - the exporter module to be used
Throws:
FileIOException

getFileLoaders

public FileLoader[] getFileLoaders()
Returns a list of all registered file loader modules.

Returns:
all registered file loaders

getFileSavers

public FileSaver[] getFileSavers()
Returns a list of all registered file saver modules.

Returns:
all registered file savers

getFileExporters

public FileExporter[] getFileExporters()
Returns a list of all registered file exporter modules.

Returns:
all registered file exporters

getSupportedFormats

public FileFormat[] getSupportedFormats(int mode)
Returns a list of all supported formats for loading, saving or exporting data.

Parameters:
mode - OPEN, SAVE or EXPORT
Returns:
an array of all supported file formats

getIOModule

public FileIOModule getIOModule(FileFormat format,
                                int mode)
Looks up a file I/O module for the specified format.

Parameters:
format - the file format
mode - OPEN, SAVE or EXPORT
Returns:
the appropriate file I/O module, or null on error

registerModule

public void registerModule(FileIOModule module)
Registers a file I/O module. The type of the module (loader, saver, exporter) is determined automatically. All available modules should be registered at application startup.

Parameters:
module - the module to be registered

registerAllModules

public void registerAllModules(FileIOModule[] modules)
Registers all given file I/O modules in the given array.

Parameters:
modules - the file I/O modules to be registered

isReady

public boolean isReady()
Returns true if this file I/O manager is "ready". A file I/O manager is considered ready, if at least one file saving module and at least one file loading module have been registered.

Returns:
true is this I/O manager is ready

canLoad

public boolean canLoad()
Determines if the file manager is able to load a file.

Returns:
true if at least one FileLoader has been registered, false otherwise

canSave

public boolean canSave()
Determines if the file manager is able to save a file.

Returns:
true if at least one FileSaver has been registered, false otherwise

canExport

public boolean canExport()
Determines if the file manager is able to export a file.

Returns:
true if at least one FileExporter has been registered, false otherwise

fileExists

public boolean fileExists(String filename)
Returns true if the given file exists.

Parameters:
filename - the filename
Returns:
true if the file exists, false otherwise

countLoaders

public int countLoaders()
Counts all registered FileLoader modules.

Returns:
the number of registered loader modules

countSavers

public int countSavers()
Counts all registered FileSaver modules.

Returns:
the number of registered saver modules.

countExporters

public int countExporters()
Counts all registered FileExporter modules.

Returns:
the number of registered exporter modules.

countAllModules

public int countAllModules()
Counts all registered modules. Note that a module can be counted multiple times if it provides more than one I/O service, e.g. if it supports loading as well as saving.

Returns:
the number of all registered modules.