| Home >> All >> cvebrowser >> dictionary >> data >> [ parser Javadoc ] |
Source code: cvebrowser/dictionary/data/parser/CSVMitreFileFactory.java
1 package cvebrowser.dictionary.data.parser; 2 3 import cvebrowser.dictionary.data.parser.CSVFile; 4 import cvebrowser.util.parser.Types; 5 import cvebrowser.util.parser.FileType; 6 import cvebrowser.util.parser.ParserException; 7 8 import java.util.ResourceBundle; 9 import java.util.Locale; 10 11 import java.io.InputStream; 12 import java.io.FileNotFoundException; 13 import java.io.ObjectOutputStream; 14 import java.io.ObjectInputStream; 15 16 /** 17 * This class returns to the caller the apropiate FileType. 18 * @author Jose Vicente Nunez Zuleta 19 * @version 0.1 - 06/29/2003 20 */ 21 public final class CSVMitreFileFactory { 22 23 private static ResourceBundle _bundle = ResourceBundle.getBundle(CSVMitreFileFactory.class.getName(), Locale.getDefault()); 24 25 // Hide the constructor 26 private CSVMitreFileFactory() { 27 // Empty on purpose 28 } 29 30 /** 31 * Returns the appropiate CSVFileType for a given file. In the file type is unknown then an exception is throw. 32 * @param fileName_ The filename to use to construct the parser type. 33 * @return CSVFile instance of the appropiate CSVFile file 34 * @throws DataParserException 35 */ 36 public static CSVFile getCSVFile(String fileName_) throws IllegalArgumentException, DataParserException { 37 CSVFile instance = null; 38 try { 39 instance = new CSVFile(fileName_); 40 if ( ! ( (instance != null) && (instance.getType() != Types.DATA_TYPE_UNKNOWN) ) ) { 41 throw new IllegalArgumentException(_bundle.getString("cvebrowser.dictionary.data.parser.CSVMitreFileFactory.getCSVFile")); 42 } 43 } catch (Throwable throbl) { 44 throw new DataParserException(_bundle.getString("cvebrowser.dictionary.data.parser.CSVMitreFileFactory.factoryError"), throbl); 45 } 46 return instance; 47 } 48 49 /** 50 * Returns the appropiate CSVFileType for a given input stream. In the stream type is unknown then an exception is throw. 51 * @param inputStream_ The input stream to use to construct the parser type. 52 * @return CSVFile instance of the appropiate CSVFile file 53 * @throws DataParserException 54 */ 55 public static CSVFile getCSVFile(InputStream inputStream_) throws IllegalArgumentException, DataParserException { 56 CSVFile instance = null; 57 try { 58 instance = new CSVFile(inputStream_); 59 if ( instance.getType() == Types.DATA_TYPE_UNKNOWN ) { 60 throw new IllegalArgumentException(_bundle.getString("cvebrowser.dictionary.data.parser.CSVMitreFileFactory.getCSVFile")); 61 } 62 } catch (Throwable throbl) { 63 throw new DataParserException(_bundle.getString("cvebrowser.dictionary.data.parser.CSVMitreFileFactory.factoryError"), throbl); 64 } 65 return instance; 66 } 67 68 /** 69 * Make this class uncloneable. Anyone who wants to use this class must use the constructor. 70 * @throws CloneNotSupportedException 71 */ 72 public final Object clone() throws java.lang.CloneNotSupportedException { 73 throw new java.lang.CloneNotSupportedException(); 74 } 75 76 /** 77 * Make this class unserializable. Any attempt to serialize will throw an exception. 78 * @param out_ 79 * @throws IOException 80 */ 81 private final void writeObject(ObjectOutputStream out_) throws java.io.IOException { 82 throw new java.io.IOException(); 83 } 84 85 /** 86 * Make this class undeserializeable. Throw an exception if this method is ever called. 87 * @param in_ 88 * @throws IOException 89 */ 90 private final void readObject(ObjectInputStream in_) throws java.io.IOException { 91 throw new java.io.IOException(); 92 } 93 }