KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbforms > config > DbFormsConfigRegistry


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/config/DbFormsConfigRegistry.java,v 1.6 2004/08/18 12:25:55 hkollmann Exp $
3  * $Revision: 1.6 $
4  * $Date: 2004/08/18 12:25:55 $
5  *
6  * DbForms - a Rapid Application Development Framework
7  * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */

23
24 package org.dbforms.config;
25
26 import javax.servlet.ServletContext JavaDoc;
27
28
29
30 /**
31  * Registry for DbFormsConfig classes
32  *
33  * @author Luca Fossato
34  *
35  */

36 public class DbFormsConfigRegistry {
37    /** unique instance for this class */
38    private static DbFormsConfigRegistry instance = null;
39
40    /** servlet config */
41    private ServletContext JavaDoc servletContext = null;
42
43    /**
44     * Protected constructor
45     */

46    protected DbFormsConfigRegistry() {
47    }
48
49    /**
50     * Get the instance of DatabaseEventFactory class.
51     *
52     * @return the instance of DatabaseEventFactory class
53     */

54    public static synchronized DbFormsConfigRegistry instance() {
55       if (instance == null) {
56          instance = new DbFormsConfigRegistry();
57       }
58
59       return instance;
60    }
61
62
63    /**
64     * Sets the servletContext attribute of the DbFormsConfigRegistry object
65     *
66     * @param servletContext The new servletConfig value
67     */

68    public void setServletContext(ServletContext JavaDoc servletContext) {
69       this.servletContext = servletContext;
70    }
71
72
73    /**
74     * Look up the default DbFormsConfig object stored into the registry.
75     *
76     * @return Description of the Return Value
77     *
78     * @exception Exception if the lookup operation fails
79     */

80    public DbFormsConfig lookup() throws Exception JavaDoc {
81       return lookup(DbFormsConfig.CONFIG);
82    }
83
84
85    /**
86     * Register the input DbFormsConfig object into the registry as the default
87     * config object.
88     *
89     * @param config the DbFormsConfig object
90     */

91    public void register(DbFormsConfig config) {
92       register(DbFormsConfig.CONFIG, config);
93    }
94
95
96    /**
97     * Look up a DbFormsConfig object stored into the registry.
98     *
99     * @param name the DbFormsConfig name previously used to store the config
100     * object into the registry.
101     *
102     * @return Description of the Return Value
103     *
104     * @exception Exception if the lookup operation fails
105     */

106    private DbFormsConfig lookup(String JavaDoc name) throws Exception JavaDoc {
107       DbFormsConfig config = null;
108
109       if (servletContext != null) {
110          config = (DbFormsConfig) servletContext.getAttribute(name);
111       } else {
112          throw new Exception JavaDoc("cannot lookup a config object with the name ["
113                              + name + "]");
114       }
115
116       return config;
117    }
118
119
120    /**
121     * Register a DbFormsConfig object into the registry
122     *
123     * @param name the DbFormsConfig name used as the registry key
124     * @param config the DbFormsConfig object
125     */

126    private void register(String JavaDoc name,
127                          DbFormsConfig config) {
128       if (servletContext != null) {
129          servletContext.setAttribute(name, config);
130       }
131    }
132 }
133
Popular Tags