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