1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dbforms.config;
25
26 import javax.servlet.ServletContext;
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
39 private static DbFormsConfigRegistry instance = null;
40
41 /*** servlet config */
42 private ServletContext servletContext = null;
43
44 /***
45 * Protected constructor
46 */
47 protected DbFormsConfigRegistry() {
48 }
49
50 /***
51 * Get the instance of DatabaseEventFactory class.
52 *
53 * @return the instance of DatabaseEventFactory class
54 */
55 public static synchronized DbFormsConfigRegistry instance() {
56 if (instance == null) {
57 instance = new DbFormsConfigRegistry();
58 }
59
60 return instance;
61 }
62
63
64 /***
65 * Sets the servletContext attribute of the DbFormsConfigRegistry object
66 *
67 * @param servletContext The new servletConfig value
68 */
69 public void setServletContext(ServletContext servletContext) {
70 this.servletContext = servletContext;
71 }
72
73
74 /***
75 * Look up the default DbFormsConfig object stored into the registry.
76 *
77 * @return Description of the Return Value
78 *
79 * @exception Exception if the lookup operation fails
80 */
81 public DbFormsConfig lookup() throws Exception {
82 return lookup(DbFormsConfig.CONFIG);
83 }
84
85
86 /***
87 * Register the input DbFormsConfig object into the registry as the default
88 * config object.
89 *
90 * @param config the DbFormsConfig object
91 */
92 public void register(DbFormsConfig config) {
93 register(DbFormsConfig.CONFIG, config);
94 }
95
96
97 /***
98 * Look up a DbFormsConfig object stored into the registry.
99 *
100 * @param name the DbFormsConfig name previously used to store the config
101 * object into the registry.
102 *
103 * @return Description of the Return Value
104 *
105 * @exception Exception if the lookup operation fails
106 */
107 private DbFormsConfig lookup(String name) throws Exception {
108 DbFormsConfig config = null;
109
110 if (servletContext != null) {
111 config = (DbFormsConfig) servletContext.getAttribute(name);
112 } else {
113 throw new Exception("cannot lookup a config object with the name ["
114 + name + "]");
115 }
116
117 return config;
118 }
119
120
121 /***
122 * Register a DbFormsConfig object into the registry
123 *
124 * @param name the DbFormsConfig name used as the registry key
125 * @param config the DbFormsConfig object
126 */
127 private void register(String name,
128 DbFormsConfig config) {
129 if (servletContext != null) {
130 servletContext.setAttribute(name, config);
131 }
132 }
133 }