unbbayes.io
Class FileExtensionIODelegator

java.lang.Object
  extended by unbbayes.io.FileExtensionIODelegator
All Implemented Interfaces:
BaseIO
Direct Known Subclasses:
OwnerAwareFileExtensionIODelegator, PluginAwareFileExtensionIODelegator

public class FileExtensionIODelegator
extends Object
implements BaseIO

This class delegates to a specified IO class by comparing the file extensions, using BaseIO#supportsExtension(String).

Author:
Shou Matsumoto

Nested Class Summary
 class FileExtensionIODelegator.MoreThanOneCompatibleIOException
          This is an exception thrown when more than one IO class can be used to delegate.
 
Constructor Summary
protected FileExtensionIODelegator()
          Deprecated.  
 
Method Summary
static BaseIO findIOByName(List<BaseIO> ios, String name)
          Obtains the first I/O class having its BaseIO.getName() equals to the given parameter.
 List<BaseIO> getCompatibleIOs(File file, boolean isLoadOnly)
          Since this class is a delegator to another IO class, there can be more than one compatible IO for a given file.
 List<BaseIO> getDelegators()
           
 String getName()
          Gets the name of this I/O component.
static String[] getNamesFromIOs(List<BaseIO> ios)
          Obtains an array of names from a given list of I/O classes.
 String[] getSupportedFileExtensions(boolean isLoadOnly)
          Obtains an array of file extensions supported by this network window.
 String getSupportedFilesDescription(boolean isLoadOnly)
          Gets a description of supported file extensions, which may be shown to the user through file chooser's file filter to explain what file format are supported.
 Graph load(File input)
          Loads a new network from the input file.
static FileExtensionIODelegator newInstance()
          Constructor method.
 void save(File output, Graph net)
          Saves a network to the output file.
 void setDelegators(List<BaseIO> delegators)
           
 void setName(String name)
          Sets the name of this I/O component.
 boolean supports(File file, boolean isLoadOnly)
          Returns true if the file is supported by this IO class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileExtensionIODelegator

protected FileExtensionIODelegator()
Deprecated. 

Default constructor is not public. Use newInstance() instead.

Method Detail

newInstance

public static FileExtensionIODelegator newInstance()
Constructor method.

Returns:
PluginAwareFileExtensionIODelegator.

getCompatibleIOs

public List<BaseIO> getCompatibleIOs(File file,
                                     boolean isLoadOnly)
Since this class is a delegator to another IO class, there can be more than one compatible IO for a given file. This method returns all compatible IO classes for a given file.

Parameters:
file -
use - true if it must return the IO classes for loading a file. Use "false" if it is for saving a file.
Returns:

load

public Graph load(File input)
           throws LoadException,
                  IOException
Description copied from interface: BaseIO
Loads a new network from the input file.

Specified by:
load in interface BaseIO
Parameters:
input - the input file for the network
Returns:
The loaded network
Throws:
LoadException - If the file doesn't describe a network.
IOException - If an IO error occurs

save

public void save(File output,
                 Graph net)
          throws IOException
Description copied from interface: BaseIO
Saves a network to the output file.

Specified by:
save in interface BaseIO
Parameters:
output - The output file to save
net - The network to save.
Throws:
IOException

supports

public boolean supports(File file,
                        boolean isLoadOnly)
Description copied from interface: BaseIO
Returns true if the file is supported by this IO class. It may be implemented as simple extension check. False otherwise.

Specified by:
supports in interface BaseIO
Parameters:
file - : the file to analyze extension.
isLoadOnly - : if set to true, it should consider file extensions for file loading (input). If set to false, it should consider both saving and loading. Note that not every I/O class can implement both loading and saving, and this parameter may separate such special behaviors.
Returns:

getDelegators

public List<BaseIO> getDelegators()
Returns:
the delegators

setDelegators

public void setDelegators(List<BaseIO> delegators)
Parameters:
delegators - the delegators to set

getSupportedFileExtensions

public String[] getSupportedFileExtensions(boolean isLoadOnly)
Description copied from interface: BaseIO
Obtains an array of file extensions supported by this network window. The file extensions should come without the dot

Specified by:
getSupportedFileExtensions in interface BaseIO
Parameters:
isLoadOnly - : if set to true, it should consider file extensions for file loading (input). If set to false, it should consider both saving and loading. Note that not every module/plugin can implement both loading and saving, and this parameter may separate such special behaviors.
Returns:

getSupportedFilesDescription

public String getSupportedFilesDescription(boolean isLoadOnly)
Description copied from interface: BaseIO
Gets a description of supported file extensions, which may be shown to the user through file chooser's file filter to explain what file format are supported. E.g. "Net (.net), XMLBIF(.xml), UnBBayes File (.ubf)"

Specified by:
getSupportedFilesDescription in interface BaseIO
Parameters:
isLoadOnly - : if set to true, it should consider file extensions for file loading (input). If set to false, it should consider both saving and loading. Note that not every module/plugin can implement both loading and saving, and this parameter may separate such special behaviors.

getNamesFromIOs

public static String[] getNamesFromIOs(List<BaseIO> ios)
Obtains an array of names from a given list of I/O classes. The order of the returned array must be equal to the given list of I/O classes. This method is used by #openFile(File) in order to fill a list of I/O component's names, in order to ask users what I/O they prefer to use, when multiple options are available.

Parameters:
ios -
Returns:
array of names.
See Also:
BaseIO.getName(), #findIOByName(List)

findIOByName

public static BaseIO findIOByName(List<BaseIO> ios,
                                  String name)
Obtains the first I/O class having its BaseIO.getName() equals to the given parameter.

Parameters:
ios -
name -
Returns:
null if not found. Returns an instance of BaseIO if found.
See Also:
BaseIO.getName(), getNamesFromIOs(List)

getName

public String getName()
Description copied from interface: BaseIO
Gets the name of this I/O component. This name may be displayed to a user when there is a need to choose a specific I/O class to use.

Specified by:
getName in interface BaseIO
Returns:
the name

setName

public void setName(String name)
Description copied from interface: BaseIO
Sets the name of this I/O component. This name may be displayed to a user when there is a need to choose a specific I/O class to use.

Specified by:
setName in interface BaseIO
Parameters:
name - the name to set


Copyright © 2001-2010 University of Brasilia - UnB. All Rights Reserved.