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.Iterator;
24 import java.util.Map;
25 import java.util.TreeMap;
26
27 import org.apache.shale.clay.config.ClayXmlParser;
28 import org.apache.shale.clay.config.Globals;
29
30 /***
31 * <p>This ConfigBean is responsible for handling full XML views. For full XML views,
32 * the viewId will correspond to an XML file that defines meta-component declarations
33 * specific for the page. It's assumed that here will be a top-level component with a
34 * jsfid matching the viewId.</p>
35 */
36 public class TemplateComponentConfigBean extends TemplateConfigBean {
37
38 /***
39 * <p>Returns an integer value use to order the registered {@link ConfigBean} instances
40 * with the {@link ConfigBeanFactory}.
41 * </p>
42 *
43 * @return a weight of 2
44 */
45 public int getWeight() {
46 return 2;
47 }
48
49
50 /***
51 * <p>This is an overridden method called from the init method.
52 * It loads an instance of the {@link ClayXmlParser} and
53 * establishes a Map collection to hold the resource
54 * {@link org.apache.shale.clay.config.beans.ComponentConfigBean$WatchDog}'s.</p>
55 */
56 protected void loadConfigFiles() {
57
58 parser = new ClayXmlParser();
59 parser.setConfig(this);
60
61
62 String param = context.getInitParameter(Globals.CLAY_FULLXML_CONFIG_FILES);
63
64
65 parser.setConfig(this);
66
67
68 watchDogs = new TreeMap();
69
70
71 if (param != null && param.length() > 0) {
72
73 WatchDog watchDog = new WatchDog(getConfigDefinitions(param),
74 Globals.DEFAULT_COMPONENT_CONFIG_WATCHDOG);
75
76
77 watchDogs.put(watchDog.getName(), watchDog);
78
79
80 watchDog.refresh(true);
81
82 }
83
84
85 param = null;
86 }
87
88
89 /***
90 * <p>If the <code>forceReload</code> is <code>true</code>,
91 * the <code>displayElements</code> cache is invalidated.
92 * A <code>true</code> value is returned if cache has
93 * been cleared.
94 * <br/><br/>
95 * All files loaded on-demand are purged. Full view definitions
96 * loaded using the <code>Globals.CLAY_FULLXML_CONFIG_FILES</code>
97 * initialization parameter are reloaded if modified or if a
98 * <code>forceReload</code> is specified.</p>
99 *
100 * @param forceReload <code>true</code> if the group of associated resources should be reloaded
101 * @return <code>true</code> if one of the resources changed
102 */
103 public boolean refresh(boolean forceReload) {
104 boolean wasDirty = forceReload;
105
106
107 WatchDog defaultWatchDog = (WatchDog) watchDogs.get(Globals.DEFAULT_COMPONENT_CONFIG_WATCHDOG);
108
109
110 if (forceReload) {
111
112
113 if (defaultWatchDog != null) {
114 watchDogs.remove(Globals.DEFAULT_COMPONENT_CONFIG_WATCHDOG);
115 }
116
117
118 Iterator wi = watchDogs.entrySet().iterator();
119 while (wi.hasNext()) {
120 Map.Entry e = (Map.Entry) wi.next();
121 WatchDog watchDog = (WatchDog) e.getValue();
122 clear(watchDog.getName());
123 if (watchDog != null) {
124 watchDog.destroy();
125 }
126 }
127 watchDogs.clear();
128
129
130 if (defaultWatchDog != null) {
131 watchDogs.put(Globals.DEFAULT_COMPONENT_CONFIG_WATCHDOG, defaultWatchDog);
132 }
133
134 }
135
136
137 if (defaultWatchDog != null) {
138 synchronized (displayElements) {
139 wasDirty = defaultWatchDog.refresh(forceReload);
140 }
141 }
142
143 return wasDirty;
144 }
145
146
147 /***
148 * <p>Overrides the super call to change the condition of the filter. This
149 * {@link ConfigBean} can create components where the id end in the suffix
150 * defined in the web deployment descriptor as a initialization parameter with
151 * the name defined by <code>Globals.CLAY_XML_TEMPLATE_SUFFIX</code> Or, using
152 * the default defined by <code>Globals.CLAY_DEFAULT_XML_TEMPLATE_SUFFIX</code>
153 *
154 * @param id jsfid
155 * @return <code>true</code> if the jsfid can be handle
156 */
157 public boolean validMoniker(String id) {
158 return id.endsWith(suffixes[1]);
159 }
160
161
162 }