1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.components.portletregistry; |
18 |
|
|
19 |
|
import java.util.ArrayList; |
20 |
|
import java.util.Collection; |
21 |
|
import java.util.HashMap; |
22 |
|
import java.util.Iterator; |
23 |
|
import java.util.List; |
24 |
|
import java.util.Locale; |
25 |
|
import java.util.Map; |
26 |
|
import java.util.prefs.BackingStoreException; |
27 |
|
import java.util.prefs.Preferences; |
28 |
|
|
29 |
|
import org.apache.jetspeed.cache.JetspeedCache; |
30 |
|
import org.apache.jetspeed.cache.JetspeedCacheEventListener; |
31 |
|
import org.apache.jetspeed.components.dao.InitablePersistenceBrokerDaoSupport; |
32 |
|
import org.apache.jetspeed.factory.PortletFactory; |
33 |
|
import org.apache.jetspeed.om.common.MutableLanguage; |
34 |
|
import org.apache.jetspeed.om.common.Support; |
35 |
|
import org.apache.jetspeed.om.common.portlet.MutablePortletApplication; |
36 |
|
import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite; |
37 |
|
import org.apache.jetspeed.om.impl.LanguageImpl; |
38 |
|
import org.apache.jetspeed.om.portlet.impl.PortletApplicationDefinitionImpl; |
39 |
|
import org.apache.jetspeed.om.portlet.impl.PortletDefinitionImpl; |
40 |
|
import org.apache.ojb.broker.query.Criteria; |
41 |
|
import org.apache.ojb.broker.query.QueryFactory; |
42 |
|
import org.apache.pluto.om.common.Language; |
43 |
|
import org.apache.pluto.om.common.ObjectID; |
44 |
|
import org.apache.pluto.om.portlet.PortletApplicationDefinition; |
45 |
|
import org.apache.pluto.om.portlet.PortletDefinition; |
46 |
|
import org.springframework.dao.DataAccessException; |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
public class PersistenceBrokerPortletRegistry |
61 |
|
extends InitablePersistenceBrokerDaoSupport |
62 |
|
implements PortletRegistry, JetspeedCacheEventListener |
63 |
|
{ |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
static final String PORTLET_UNIQUE_NAME_SEPARATOR = "::"; |
69 |
|
|
70 |
0 |
private JetspeedCache applicationOidCache = null; |
71 |
0 |
private JetspeedCache portletOidCache = null; |
72 |
0 |
private JetspeedCache applicationNameCache = null; |
73 |
0 |
private JetspeedCache portletNameCache = null; |
74 |
0 |
private Map nameCache = new HashMap(); |
75 |
0 |
private List listeners = new ArrayList(); |
76 |
|
|
77 |
|
|
78 |
|
public PersistenceBrokerPortletRegistry(String repositoryPath) |
79 |
|
{ |
80 |
0 |
this(repositoryPath, null, class="keyword">null, class="keyword">null, class="keyword">null, class="keyword">null); |
81 |
0 |
} |
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
public PersistenceBrokerPortletRegistry(String repositoryPath, PortletFactory portletFactory, |
87 |
|
JetspeedCache applicationOidCache, JetspeedCache portletOidCache, |
88 |
|
JetspeedCache applicationNameCache, JetspeedCache portletNameCache) |
89 |
|
{ |
90 |
0 |
super(repositoryPath); |
91 |
0 |
PortletDefinitionImpl.setPortletRegistry(this); |
92 |
0 |
PortletDefinitionImpl.setPortletFactory(portletFactory); |
93 |
0 |
this.applicationOidCache = applicationOidCache; |
94 |
0 |
this.portletOidCache = portletOidCache; |
95 |
0 |
this.applicationNameCache = applicationNameCache; |
96 |
0 |
this.portletNameCache = portletNameCache; |
97 |
0 |
MutablePortletApplicationProxy.setRegistry(this); |
98 |
0 |
RegistryApplicationCache.cacheInit(this, applicationOidCache, applicationNameCache, listeners); |
99 |
0 |
RegistryPortletCache.cacheInit(this, portletOidCache, portletNameCache, listeners); |
100 |
0 |
this.applicationNameCache.addEventListener(class="keyword">this, false); |
101 |
0 |
this.portletNameCache.addEventListener(class="keyword">this, false); |
102 |
0 |
} |
103 |
|
|
104 |
|
public Language createLanguage( Locale locale, String title, String shortTitle, String description, |
105 |
|
Collection keywords ) throws RegistryException |
106 |
|
{ |
107 |
|
try |
108 |
|
{ |
109 |
0 |
MutableLanguage lc = new LanguageImpl(); |
110 |
0 |
lc.setLocale(locale); |
111 |
0 |
lc.setTitle(title); |
112 |
0 |
lc.setShortTitle(shortTitle); |
113 |
0 |
lc.setKeywords(keywords); |
114 |
0 |
return lc; |
115 |
|
} |
116 |
0 |
catch (Exception e) |
117 |
|
{ |
118 |
0 |
throw new RegistryException("Unable to create language object."); |
119 |
|
} |
120 |
|
} |
121 |
|
|
122 |
|
public Collection getAllPortletDefinitions() |
123 |
|
{ |
124 |
0 |
Criteria c = new Criteria(); |
125 |
0 |
Collection list = getPersistenceBrokerTemplate().getCollectionByQuery( |
126 |
0 |
QueryFactory.newQuery(PortletDefinitionImpl.class, c)); |
127 |
0 |
postLoadColl(list); |
128 |
0 |
return list; |
129 |
|
} |
130 |
|
|
131 |
|
public MutablePortletApplication getPortletApplication( ObjectID id ) |
132 |
|
{ |
133 |
0 |
Criteria c = new Criteria(); |
134 |
0 |
c.addEqualTo("id", new Long(id.toString())); |
135 |
0 |
MutablePortletApplication app = (MutablePortletApplication) getPersistenceBrokerTemplate().getObjectByQuery( |
136 |
|
QueryFactory.newQuery(PortletApplicationDefinitionImpl.class, c)); |
137 |
0 |
postLoad(app); |
138 |
0 |
return app; |
139 |
|
} |
140 |
|
|
141 |
|
public MutablePortletApplication getPortletApplication(String name) |
142 |
|
{ |
143 |
0 |
Criteria c = new Criteria(); |
144 |
0 |
c.addEqualTo("name", name); |
145 |
0 |
MutablePortletApplication app = (MutablePortletApplication) getPersistenceBrokerTemplate().getObjectByQuery( |
146 |
|
QueryFactory.newQuery(PortletApplicationDefinitionImpl.class, c)); |
147 |
0 |
postLoad(app); |
148 |
0 |
return app; |
149 |
|
} |
150 |
|
|
151 |
|
public MutablePortletApplication getPortletApplicationByIdentifier( String identifier ) |
152 |
|
{ |
153 |
0 |
Criteria c = new Criteria(); |
154 |
0 |
c.addEqualTo("applicationIdentifier", identifier); |
155 |
0 |
MutablePortletApplication app = (MutablePortletApplication) getPersistenceBrokerTemplate().getObjectByQuery( |
156 |
|
QueryFactory.newQuery(PortletApplicationDefinitionImpl.class, c)); |
157 |
0 |
postLoad(app); |
158 |
0 |
return app; |
159 |
|
} |
160 |
|
|
161 |
|
public Collection getPortletApplications() |
162 |
|
{ |
163 |
0 |
Criteria c = new Criteria(); |
164 |
0 |
Collection list = getPersistenceBrokerTemplate().getCollectionByQuery( |
165 |
|
QueryFactory.newQuery(PortletApplicationDefinitionImpl.class, c)); |
166 |
0 |
postLoadColl(list); |
167 |
0 |
return list; |
168 |
|
} |
169 |
|
|
170 |
|
public PortletDefinitionComposite getPortletDefinitionByIdentifier( String identifier ) |
171 |
|
{ |
172 |
0 |
Criteria c = new Criteria(); |
173 |
0 |
c.addEqualTo("portletIdentifier", identifier); |
174 |
0 |
PortletDefinitionComposite def = (PortletDefinitionComposite) getPersistenceBrokerTemplate().getObjectByQuery( |
175 |
|
QueryFactory.newQuery(PortletDefinitionImpl.class, c)); |
176 |
0 |
if (def != null && def.getPortletApplicationDefinition() == class="keyword">null) |
177 |
|
{ |
178 |
0 |
final String msg = "getPortletDefinitionByIdentifier() returned a PortletDefinition that has no parent PortletApplication."; |
179 |
0 |
throw new IllegalStateException(msg); |
180 |
|
} |
181 |
|
|
182 |
0 |
postLoad(def); |
183 |
0 |
return def; |
184 |
|
} |
185 |
|
|
186 |
|
public PortletDefinitionComposite getPortletDefinitionByUniqueName( String name ) |
187 |
|
{ |
188 |
0 |
String appName = PortletRegistryHelper.parseAppName(name); |
189 |
0 |
String portletName = PortletRegistryHelper.parsePortletName(name); |
190 |
|
|
191 |
0 |
Criteria c = new Criteria(); |
192 |
0 |
c.addEqualTo("app.name", appName); |
193 |
0 |
c.addEqualTo("name", portletName); |
194 |
|
|
195 |
0 |
PortletDefinitionComposite def = (PortletDefinitionComposite) getPersistenceBrokerTemplate().getObjectByQuery( |
196 |
|
QueryFactory.newQuery(PortletDefinitionImpl.class, c)); |
197 |
0 |
if (def != null && def.getPortletApplicationDefinition() == class="keyword">null) |
198 |
|
{ |
199 |
0 |
final String msg = "getPortletDefinitionByIdentifier() returned a PortletDefinition that has no parent PortletApplication."; |
200 |
0 |
throw new IllegalStateException(msg); |
201 |
|
} |
202 |
|
|
203 |
0 |
postLoad(def); |
204 |
0 |
return def; |
205 |
|
} |
206 |
|
|
207 |
|
public boolean portletApplicationExists( String appIdentity ) |
208 |
|
{ |
209 |
0 |
return getPortletApplicationByIdentifier(appIdentity) != null; |
210 |
|
} |
211 |
|
|
212 |
|
public boolean namedPortletApplicationExists( String appName ) |
213 |
|
{ |
214 |
0 |
return getPortletApplication(appName) != null; |
215 |
|
} |
216 |
|
|
217 |
|
public boolean portletDefinitionExists( String portletName, MutablePortletApplication app ) |
218 |
|
{ |
219 |
0 |
return getPortletDefinitionByUniqueName(app.getName() + "::" + portletName) != null; |
220 |
|
} |
221 |
|
|
222 |
|
public boolean portletDefinitionExists( String portletIdentity ) |
223 |
|
{ |
224 |
0 |
return getPortletDefinitionByIdentifier(portletIdentity) != null; |
225 |
|
} |
226 |
|
|
227 |
|
public void registerPortletApplication( PortletApplicationDefinition newApp ) throws RegistryException |
228 |
|
{ |
229 |
0 |
getPersistenceBrokerTemplate().store(newApp); |
230 |
0 |
} |
231 |
|
|
232 |
|
public void removeApplication( PortletApplicationDefinition app ) throws RegistryException |
233 |
|
{ |
234 |
0 |
getPersistenceBrokerTemplate().delete(app); |
235 |
|
|
236 |
0 |
String appNodePath = MutablePortletApplication.PREFS_ROOT + "/" +((MutablePortletApplication)app).getName(); |
237 |
|
try |
238 |
|
{ |
239 |
0 |
if(Preferences.systemRoot().nodeExists(appNodePath)) |
240 |
|
{ |
241 |
0 |
Preferences node = Preferences.systemRoot().node(appNodePath); |
242 |
|
|
243 |
0 |
node.removeNode(); |
244 |
|
} |
245 |
|
} |
246 |
0 |
catch (BackingStoreException e) |
247 |
|
{ |
248 |
0 |
throw new RegistryException(e.toString(), e); |
249 |
0 |
} |
250 |
|
|
251 |
0 |
} |
252 |
|
|
253 |
|
public void updatePortletApplication( PortletApplicationDefinition app ) throws RegistryException |
254 |
|
{ |
255 |
0 |
getPersistenceBrokerTemplate().store(app); |
256 |
|
|
257 |
0 |
} |
258 |
|
|
259 |
|
private void postLoad( Object obj ) |
260 |
|
{ |
261 |
0 |
if (obj != null) |
262 |
|
{ |
263 |
|
|
264 |
0 |
if (obj instanceof Support) |
265 |
|
{ |
266 |
|
try |
267 |
|
{ |
268 |
0 |
((Support) obj).postLoad(obj); |
269 |
|
} |
270 |
0 |
catch (Exception e) |
271 |
|
{ |
272 |
0 |
} |
273 |
|
} |
274 |
|
} |
275 |
|
|
276 |
0 |
} |
277 |
|
|
278 |
|
private void postLoadColl( Collection coll ) |
279 |
|
{ |
280 |
|
|
281 |
0 |
if (coll != null && !coll.isEmpty()) |
282 |
|
{ |
283 |
0 |
Iterator itr = coll.iterator(); |
284 |
0 |
Object test = itr.next(); |
285 |
0 |
if (test instanceof Support) |
286 |
|
{ |
287 |
0 |
Support testSupport = (Support) test; |
288 |
|
try |
289 |
|
{ |
290 |
0 |
testSupport.postLoad(testSupport); |
291 |
|
} |
292 |
0 |
catch (Exception e1) |
293 |
|
{ |
294 |
|
|
295 |
0 |
} |
296 |
0 |
while (itr.hasNext()) |
297 |
|
{ |
298 |
0 |
Support support = (Support) itr.next(); |
299 |
|
try |
300 |
|
{ |
301 |
0 |
support.postLoad(support); |
302 |
|
} |
303 |
0 |
catch (Exception e) |
304 |
|
{ |
305 |
0 |
} |
306 |
0 |
} |
307 |
|
} |
308 |
|
|
309 |
|
} |
310 |
|
|
311 |
0 |
} |
312 |
|
|
313 |
|
public void savePortletDefinition( PortletDefinition portlet ) throws FailedToStorePortletDefinitionException |
314 |
|
{ |
315 |
|
try |
316 |
|
{ |
317 |
0 |
getPersistenceBrokerTemplate().store(portlet); |
318 |
|
} |
319 |
0 |
catch (DataAccessException e) |
320 |
|
{ |
321 |
|
|
322 |
0 |
throw new FailedToStorePortletDefinitionException(portlet, e); |
323 |
0 |
} |
324 |
|
|
325 |
0 |
} |
326 |
|
|
327 |
|
public PortletDefinitionComposite getPortletDefinition(ObjectID id) |
328 |
|
{ |
329 |
0 |
Criteria c = new Criteria(); |
330 |
0 |
c.addEqualTo("id", new Long(id.toString())); |
331 |
0 |
PortletDefinitionComposite portlet = (PortletDefinitionComposite) getPersistenceBrokerTemplate().getObjectByQuery( |
332 |
|
QueryFactory.newQuery(PortletDefinitionImpl.class, c)); |
333 |
|
|
334 |
0 |
postLoad(portlet); |
335 |
0 |
return portlet; |
336 |
|
} |
337 |
|
|
338 |
|
public void notifyElementAdded(JetspeedCache cache, boolean local, Object key, Object element) |
339 |
|
{ |
340 |
0 |
} |
341 |
|
|
342 |
|
public void notifyElementChanged(JetspeedCache cache, boolean local, Object key, Object element) |
343 |
|
{ |
344 |
0 |
} |
345 |
|
|
346 |
|
public void notifyElementEvicted(JetspeedCache cache, boolean local, Object key, Object element) |
347 |
|
{ |
348 |
|
|
349 |
0 |
} |
350 |
|
|
351 |
|
public void notifyElementExpired(JetspeedCache cache, boolean local, Object key, Object element) |
352 |
|
{ |
353 |
|
|
354 |
0 |
} |
355 |
|
|
356 |
|
public void notifyElementRemoved(JetspeedCache cache, boolean local, Object key, Object element) |
357 |
|
{ |
358 |
|
|
359 |
0 |
if (cache == this.portletNameCache) |
360 |
|
{ |
361 |
|
|
362 |
0 |
RegistryPortletCache.cacheRemoveQuiet((String)key, (RegistryCacheObjectWrapper)element); |
363 |
0 |
PortletDefinitionComposite pd = this.getPortletDefinitionByUniqueName((String)key); |
364 |
0 |
if (listeners != null) |
365 |
|
{ |
366 |
0 |
for (int ix=0; ix < listeners.size(); ix++) |
367 |
|
{ |
368 |
0 |
RegistryEventListener listener = (RegistryEventListener)listeners.get(ix); |
369 |
0 |
listener.portletRemoved(pd); |
370 |
|
} |
371 |
|
} |
372 |
0 |
} |
373 |
|
else |
374 |
|
{ |
375 |
|
|
376 |
0 |
RegistryApplicationCache.cacheRemoveQuiet((String) key, (RegistryCacheObjectWrapper)element); |
377 |
0 |
MutablePortletApplication pa = this.getPortletApplication((String)key); |
378 |
0 |
if (listeners != null) |
379 |
|
{ |
380 |
0 |
for (int ix=0; ix < listeners.size(); ix++) |
381 |
|
{ |
382 |
0 |
RegistryEventListener listener = (RegistryEventListener)listeners.get(ix); |
383 |
0 |
listener.applicationRemoved(pa); |
384 |
|
} |
385 |
|
} |
386 |
|
|
387 |
|
} |
388 |
0 |
} |
389 |
|
|
390 |
|
public void addRegistryListener(RegistryEventListener listener) |
391 |
|
{ |
392 |
0 |
this.listeners.add(listener); |
393 |
0 |
} |
394 |
|
|
395 |
|
public void removeRegistryEventListner(RegistryEventListener listener) |
396 |
|
{ |
397 |
0 |
this.listeners.remove(listener); |
398 |
0 |
} |
399 |
|
|
400 |
|
} |