01: /*
02: * Created on 22/05/2004
03: *
04: * Swing Components - visit http://sf.net/projects/gfd
05: *
06: * Copyright (C) 2004 Igor Regis da Silva Simões
07: *
08: * This program is free software; you can redistribute it and/or
09: * modify it under the terms of the GNU General Public License
10: * as published by the Free Software Foundation; either version 2
11: * of the License, or (at your option) any later version.
12: *
13: * This program is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: * GNU General Public License for more details.
17: *
18: * You should have received a copy of the GNU General Public License
19: * along with this program; if not, write to the Free Software
20: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21: *
22: */
23: package br.com.igor.db;
24:
25: import java.util.HashMap;
26: import java.util.Map;
27:
28: import br.com.igor.plugin.core.DynamicClassLoader;
29:
30: /**
31: * @author Igor Regis da Silva Simoes
32: */
33: public class SQLParserFactory {
34:
35: /**
36: * Instancia única
37: */
38: private static SQLParserFactory sqlParserFactory = null;
39:
40: /**
41: * Coleção de parsers já carragados.
42: */
43: private Map<String, SQLParser> parsers = new HashMap<String, SQLParser>();
44:
45: /** Cria uma nova instância de DAOFactory */
46: private SQLParserFactory() {
47: //Não fazemos nada
48: }
49:
50: /**
51: * Método estático que retorna a instancia de SQLParserFactory
52: * @return instancia de SQLParserFactory
53: */
54: public static SQLParserFactory getSQLParserFactory() {
55: if (sqlParserFactory == null)
56: sqlParserFactory = new SQLParserFactory();
57:
58: return sqlParserFactory;
59: }
60:
61: /**
62: * Método que retorna um SQLParser para um determinado banco de dados
63: * @param dataBase Nome do banco de dados para o qual deseja-se um SQLParser
64: * @return Instancia de um SQLParser
65: * @throws DataAccessException em caso de falha na criação do parser
66: */
67: public SQLParser getParser(String dataBase)
68: throws DataAccessException {
69: if (!parsers.containsKey(dataBase)) {
70: try {
71: parsers.put(dataBase, (SQLParser) DynamicClassLoader
72: .getClassLoader().loadClass(
73: "br.com.igor.db." + dataBase
74: + "SQLParser").newInstance());
75: } catch (IllegalAccessException iae) {
76: throw new DataAccessException(iae);
77: } catch (InstantiationException ie) {
78: throw new DataAccessException(ie);
79: } catch (ClassNotFoundException cnfe) {
80: throw new DataAccessException(cnfe);
81: }
82: }
83: return parsers.get(dataBase);
84: }
85: }
|