View Javadoc
1 /* 2 * PROJECT : DAR Runtime and Tools 3 * COPYRIGHT : Copyright (C) 1999-2004 tim.stephenson@enableit.org 4 * LICENSE : GNU LESSER GENERAL PUBLIC LICENSE 5 * Version 2.1, February 1999 6 * 7 * This program 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 2 of the License, or 10 * (at your option) any later version. 11 * 12 * This program 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 this program; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 */ 21 package org.enableit.db.darrt; 22 23 import java.io.File; 24 25 26 /*** 27 * @author tim.stephenson 28 */ 29 public class DataParserFactory { 30 /*** 31 * Returns a procesor based on the file to process. 32 * <p><b>Implementation Note:</b> The processor required is determined by the 33 * file's extension. </p> 34 * @param file File to process. 35 * @return An instance of FileProcessor capable of processing the specified file. 36 * @exception IllegalArgumentException If file is null or no processor is known to 37 * handle this file type. 38 */ 39 public static DataParser getInstance(File file) { 40 DataParser parser = null; 41 42 if (file == null) { 43 throw new IllegalArgumentException("Supplied file must not be null"); 44 } else { 45 parser = getInstance(file.getName()); 46 } 47 48 return parser; 49 } 50 51 public static DataParser getInstance(String fileName) 52 throws IllegalArgumentException { 53 DataParser parser = null; 54 55 /* TODO: First look for parser matching the exact file name. 56 * e.g. 'MonthlyBankStatement.html' 57 */ 58 59 // Here are somewhat generic parsers based on file extension 60 String ext = fileName.substring(fileName.lastIndexOf(".") + 1); 61 62 if ("XML".equalsIgnoreCase(ext)) { 63 parser = new XmlDataParser(); 64 } else if ("CSV".equalsIgnoreCase(ext)) { 65 parser = new CsvDataParser(); 66 } else { 67 throw new IllegalArgumentException("Unknown file extension: " + ext); 68 } 69 70 return parser; 71 } 72 }

This page was automatically generated by Maven