2009/05/20 - Apache Shale has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.shale.clay.config.beans;
22
23 import java.util.Collection;
24 import java.util.Iterator;
25 import java.util.TreeSet;
26
27 /***
28 * <p>This is an abstract factory that contains a ordered collection of
29 * object pools {@link ConfigBean}. The configuration beans are registered on
30 * application startup by the {@link ClayConfigListener}.
31 * </p>
32 */
33 public final class ConfigBeanFactory {
34
35 /***
36 * <p>Hide constructor on a factory class.</p>
37 */
38 private ConfigBeanFactory() {
39 super();
40 }
41
42 /***
43 * <p>A static ordered set of {@link ConfigBean} instances.</p>
44 */
45 private static Collection configBeans = new TreeSet();
46
47 /***
48 * <p>This method is invoked to register a class instance implementing
49 * {@link ConfigBean} interface.
50 * </p>
51 *
52 * @param config {@link ConfigBean} collection of faces component metadata
53 */
54 public static void register(ConfigBean config) {
55 configBeans.add(config);
56 }
57
58 /***
59 * <p>This method will return a {@link ConfigBean} that can be used
60 * to return component metadata. The suffix of the parameter is used to
61 * find a <code>ConfigBean</code> that has the metadata.
62 * </p>
63 *
64 * @param id jsfid
65 * @return config bean
66 */
67 public static ConfigBean findConfig(String id) {
68 Iterator ci = configBeans.iterator();
69 ConfigBean config = null;
70 while (ci.hasNext()) {
71 config = (ConfigBean) ci.next();
72 if (config.validMoniker(id)) {
73 break;
74 }
75 }
76
77 return config;
78 }
79
80 /***
81 * <p>Invoked by the context listener {@link org.apache.shale.clay.config.ClayConfigureListener} on
82 * application shutdown to clean up cached resources.
83 * </p>
84 */
85 public static void destroy() {
86 Iterator ci = configBeans.iterator();
87 ConfigBean config = null;
88 while (ci.hasNext()) {
89 config = (ConfigBean) ci.next();
90 config.destroy();
91
92 }
93 configBeans.clear();
94 }
95
96
97 /***
98 * <p>This method should be called from key points in the application to invoke
99 * automatic reloading of the configuration files if they have been modified since
100 * last reloaded. If the XML files have changed, all files have to be reloaded.
101 * This includes HTML template files.
102 * </p>
103 */
104 public static void refresh() {
105 Iterator ci = configBeans.iterator();
106
107
108
109 boolean wasDirty = false;
110 while (ci.hasNext()) {
111 ConfigBean config = (ConfigBean) ci.next();
112 wasDirty = config.refresh(wasDirty);
113 }
114 }
115
116 }