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.igor.db;
25:
26: import br.com.igor.plugin.core.DynamicClassLoader;
27:
28: /**
29: * @author Igor Regis da Silva Simoes
30: */
31: public class ControllerProvider {
32: private static ControllerProvider controllerProvider = null;
33:
34: /** Cria uma nova instância de ControlerProvider */
35: private ControllerProvider() {
36: //Não fazemos nada
37: }
38:
39: /**
40: * @return ControllerProvider instancia unica
41: */
42: public static ControllerProvider getControllerProvider() {
43: if (controllerProvider == null)
44: controllerProvider = new ControllerProvider();
45:
46: return controllerProvider;
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 ControllerCreationException Caso não seja possível criar o Controller
54: */
55: public Controller getController(String controller)
56: throws ControllerCreationException {
57: try {
58: return (Controller) DynamicClassLoader.getClassLoader()
59: .loadClass(
60: "br.com.gfp.controllers." + controller
61: + "Controller").newInstance();
62: } catch (IllegalAccessException iae) {
63: throw new ControllerCreationException(iae);
64: } catch (InstantiationException ie) {
65: throw new ControllerCreationException(ie);
66: } catch (ClassNotFoundException cnfe) {
67: try {
68: return (Controller) DynamicClassLoader.getClassLoader()
69: .loadClass(
70: "br.com.gfp.controllers." + controller
71: + "Controller").newInstance();
72: } catch (Exception e) {
73: try {
74: return (Controller) DynamicClassLoader
75: .getClassLoader()
76: .loadClass(
77: "br.com.igor.controllers."
78: + controller + "Controller")
79: .newInstance();
80: } catch (Exception e2) {
81: throw new ControllerCreationException(e2);
82: }
83: }
84: }
85: }
86: }
|