View Javadoc

1   /*
2    *  UnBBayes
3    *  Copyright (C) 2002, 2008 Universidade de Brasilia - http://www.unb.br
4    *
5    *  This file is part of UnBBayes.
6    *
7    *  UnBBayes is free software: you can redistribute it and/or modify
8    *  it under the terms of the GNU General Public License as published by
9    *  the Free Software Foundation, either version 3 of the License, or
10   *  (at your option) any later version.
11   *
12   *  UnBBayes is distributed in the hope that it will be useful,
13   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   *  GNU General Public License for more details.
16   *
17   *  You should have received a copy of the GNU General Public License
18   *  along with UnBBayes.  If not, see <http://www.gnu.org/licenses/>.
19   *
20   */
21  package unbbayes.io;
22  
23  import java.io.File;
24  import java.io.IOException;
25  
26  import unbbayes.io.exception.LoadException;
27  import unbbayes.prs.Graph;
28  
29  /**
30   *  This is the most basic I/O interface for UnBBayes, which basically loads or stores a Graph from/into a file.
31   * @author Rommel N. Carvalho
32   * @author Michael S. Onishi
33   * @author Shou Matsumoto
34   * @version 2.0
35   */
36  public interface BaseIO {
37  	
38  	/**
39  	 * Loads a new network from the input file.
40  	 * 
41  	 * @param input the input file for the network
42  	 * @return The loaded network
43  	 * @throws LoadException If the file doesn't describe a network.
44  	 * @throws IOException	If an IO error occurs
45  	 */
46      public Graph load(File input) throws LoadException, IOException;
47      
48      
49      /**
50       * Saves a network to the output file.
51       * @param output	The output file to save
52       * @param net		The network to save.
53       */
54      public void save(File output, Graph net) throws IOException;
55      
56      
57      /**
58       * Returns true if the file is supported by this IO class. It may be implemented as simple extension check.
59       * False otherwise.
60       * @param file : the file to analyze extension.
61  	 * @param isLoadOnly : if set to true, it should consider file extensions for file loading (input).
62  	 * If set to false, it should consider both saving and loading. Note
63  	 * that not every I/O class can implement both loading and saving, and this parameter may separate such
64  	 * special behaviors.
65  	 * @return
66       */
67      public boolean supports(File file, boolean isLoadOnly);
68      
69      /**
70  	 * Obtains an array of file extensions supported by this network window.
71  	 * The file extensions should come without the dot
72  	 * @param isLoadOnly :  if set to true, it should consider file extensions for file loading (input).
73  	 * If set to false, it should consider both saving and loading. Note
74  	 * that not every module/plugin can implement both loading and saving, and this parameter may separate such
75  	 * special behaviors.
76  	 * @return
77  	 */
78  	public String[] getSupportedFileExtensions(boolean isLoadOnly);
79  	
80  	/**
81  	 * Gets a description of supported file extensions,
82  	 * which may be shown to the user through file chooser's file filter to explain what
83  	 * file format are supported.
84  	 * E.g. "Net (.net), XMLBIF(.xml), UnBBayes File (.ubf)"
85  	 * @param isLoadOnly :  if set to true, it should consider file extensions for file loading (input).
86  	 * If set to false, it should consider both saving and loading. Note
87  	 * that not every module/plugin can implement both loading and saving, and this parameter may separate such
88  	 * special behaviors.
89  	 */
90  	public String getSupportedFilesDescription(boolean isLoadOnly);
91  	
92  	/**
93  	 * Sets the name of this I/O component.
94  	 * This name may be displayed to a user when there is a need to choose a
95  	 * specific I/O class to use.
96  	 * @param name
97  	 */
98  	public void setName(String name);
99  	
100 	/**
101 	 * Gets the name of this I/O component.
102 	 * This name may be displayed to a user when there is a need to choose a
103 	 * specific I/O class to use.
104 	 * @return a name
105 	 */
106 	public String getName();
107 	
108    
109 }