01: /*
02: * Created on 19/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:
24: package br.com.gfpshare.db;
25:
26: import br.com.gfpshare.plugin.core.DynamicClassLoader;
27:
28: /**
29: * @author Igor Regis da Silva Simoes
30: */
31: public class DAOProvider {
32: private static DAOProvider dAOProvider = null;
33:
34: /** Cria uma nova instância de DAOProvider */
35: private DAOProvider() {
36: //Não fazemos nada
37: }
38:
39: /**
40: * @return ControllerProvider instancia unica
41: */
42: public static DAOProvider getControllerProvider() {
43: if (dAOProvider == null)
44: dAOProvider = new DAOProvider();
45:
46: return dAOProvider;
47: }
48:
49: /**
50: * Retorna uma instancia de um Controller capaz de realizar operações sobre uma tabela de um banco de dados
51: * @param controller Tipo do controller - Geralmente o nome da tabela do banco de dados.
52: * @return Controller
53: * @throws DAOCreationException Caso não seja possível criar o Controller
54: */
55: public DAO getController(String controller)
56: throws DAOCreationException {
57: try {
58: return (DAO) DynamicClassLoader.getClassLoader().loadClass(
59: "br.com.gfp.dao." + controller + "DAO")
60: .newInstance();
61: } catch (IllegalAccessException iae) {
62: throw new DAOCreationException(iae);
63: } catch (InstantiationException ie) {
64: throw new DAOCreationException(ie);
65: } catch (ClassNotFoundException cnfe) {
66: try {
67: return (DAO) DynamicClassLoader.getClassLoader()
68: .loadClass(
69: "br.com.gfp.dao." + controller + "DAO")
70: .newInstance();
71: } catch (Exception e) {
72: try {
73: return (DAO) DynamicClassLoader.getClassLoader()
74: .loadClass(
75: "br.com.igor.dao." + controller
76: + "DAO").newInstance();
77: } catch (Exception e2) {
78: throw new DAOCreationException(e2);
79: }
80: }
81: }
82: }
83: }
|