01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.client.gui;
19:
20: import java.util.logging.Level;
21: import java.util.logging.Logger;
22:
23: import de.finix.contelligent.client.base.ContelligentComponent;
24: import de.finix.contelligent.client.gui.property.PropertyGUI;
25:
26: public class GUIFactory {
27:
28: private static Logger logger = Logger.getLogger(GUIFactory.class
29: .getName());
30:
31: private static GUIFactory guiFactory = null;
32:
33: // Singleton pattern
34: private GUIFactory() {
35: }
36:
37: public static GUIFactory getInstance() {
38: if (guiFactory == null) {
39: guiFactory = new GUIFactory();
40: }
41: return guiFactory;
42: }
43:
44: public GUI[] getGUI(ContelligentComponent component, View view) {
45: if (component.hasReadPermission()) {
46: GUIDescription[] guiDescriptions = view.getGUIMapping()
47: .getGUIDescriptions(component);
48: return getGUI(component, view, guiDescriptions);
49: } else {
50: GUI noReadGUI = createGUIInstance("de.finix.contelligent.client.gui.NoReadGUI");
51: noReadGUI.setComponent(component);
52: noReadGUI.setView(view);
53: noReadGUI.init();
54: return new GUI[] { noReadGUI };
55: }
56: }
57:
58: public GUI[] getGUI(ContelligentComponent component, View view,
59: GUIDescription[] guiDescriptions) {
60: GUI[] gui = new GUI[guiDescriptions.length];
61: for (int i = 0; i < guiDescriptions.length; i++) {
62: String guiImpl = guiDescriptions[i].getGuiImpl();
63: String configuration = guiDescriptions[i]
64: .getConfiguration();
65: gui[i] = createGUIInstance(guiImpl);
66: gui[i].setComponent(component);
67: gui[i].setView(view);
68: gui[i].setConfiguration(configuration);
69: gui[i].init();
70: }
71: return gui;
72: }
73:
74: public GUI createGUIInstance(String guiImpl) {
75: GUI gui = null;
76: try {
77: gui = (GUI) Class.forName(guiImpl).newInstance();
78: } catch (Exception e) {
79: logger.log(Level.SEVERE, "Could not create GUI instance: ("
80: + guiImpl + "), using property gui instead!", e);
81: gui = new PropertyGUI();
82: }
83: return gui;
84: }
85: }
|