1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.capabilities.impl; |
18 |
|
|
19 |
|
import java.util.Collection; |
20 |
|
import java.util.Hashtable; |
21 |
|
import java.util.Iterator; |
22 |
|
import java.util.Properties; |
23 |
|
import java.util.Vector; |
24 |
|
|
25 |
|
import org.apache.commons.logging.Log; |
26 |
|
import org.apache.commons.logging.LogFactory; |
27 |
|
import org.apache.jetspeed.capabilities.Capabilities; |
28 |
|
import org.apache.jetspeed.capabilities.CapabilitiesException; |
29 |
|
import org.apache.jetspeed.capabilities.Capability; |
30 |
|
import org.apache.jetspeed.capabilities.CapabilityMap; |
31 |
|
import org.apache.jetspeed.capabilities.Client; |
32 |
|
import org.apache.jetspeed.capabilities.MediaType; |
33 |
|
import org.apache.jetspeed.capabilities.MimeType; |
34 |
|
import org.apache.jetspeed.capabilities.UnableToBuildCapabilityMapException; |
35 |
|
import org.apache.jetspeed.components.dao.InitablePersistenceBrokerDaoSupport; |
36 |
|
import org.apache.ojb.broker.query.Criteria; |
37 |
|
import org.apache.ojb.broker.query.QueryByCriteria; |
38 |
|
import org.apache.ojb.broker.query.QueryFactory; |
39 |
|
import org.springframework.beans.BeansException; |
40 |
|
import org.springframework.beans.factory.BeanFactory; |
41 |
|
import org.springframework.beans.factory.BeanFactoryAware; |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
public class JetspeedCapabilities extends InitablePersistenceBrokerDaoSupport implements Capabilities ,BeanFactoryAware |
51 |
|
{ |
52 |
0 |
private static final Log log = |
53 |
0 |
LogFactory.getLog(JetspeedCapabilities.class); |
54 |
|
|
55 |
|
public static final String DEFAULT_AGENT = "Mozilla/4.0"; |
56 |
|
|
57 |
|
public static final String AGENT_XML = "agentxml/1.0"; |
58 |
|
|
59 |
|
|
60 |
0 |
Hashtable capabilityMapCache = new Hashtable(); |
61 |
|
|
62 |
0 |
private Collection clients = null; |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
private BeanFactory beanFactory; |
68 |
|
|
69 |
|
|
70 |
|
private String clientBeanName; |
71 |
|
private String capabilityBeanName; |
72 |
|
private String mimeTypeBeanName; |
73 |
|
private String mediaTypeBeanName; |
74 |
|
|
75 |
|
private Class clientClass; |
76 |
|
private Class capabilityClass; |
77 |
|
private Class mimeTypeClass; |
78 |
|
private Class mediaTypeClass; |
79 |
|
|
80 |
|
|
81 |
|
public JetspeedCapabilities(String repositoryPath, String clientBeanName, String mediaTypeBeanName, String mimeTypeBeanName, String capabilityBeanName) |
82 |
|
{ |
83 |
0 |
super(repositoryPath); |
84 |
0 |
this.clientBeanName = clientBeanName; |
85 |
0 |
this.capabilityBeanName = capabilityBeanName; |
86 |
0 |
this.mimeTypeBeanName = mimeTypeBeanName; |
87 |
0 |
this.mediaTypeBeanName = mediaTypeBeanName; |
88 |
0 |
} |
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
public JetspeedCapabilities(String repositoryPath, Properties properties) |
106 |
|
{ |
107 |
0 |
super(repositoryPath); |
108 |
0 |
} |
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
public void setBeanFactory(BeanFactory beanFactory) throws BeansException |
116 |
|
{ |
117 |
0 |
this.beanFactory = beanFactory; |
118 |
0 |
} |
119 |
|
|
120 |
|
|
121 |
|
private Class getClientClass() throws ClassNotFoundException |
122 |
|
{ |
123 |
0 |
if (clientClass == null) |
124 |
|
{ |
125 |
0 |
clientClass = createClient(null).getClass(); |
126 |
|
} |
127 |
0 |
return clientClass; |
128 |
|
} |
129 |
|
|
130 |
|
private Class getMimeTypeClass() throws ClassNotFoundException |
131 |
|
{ |
132 |
0 |
if (mimeTypeClass == null) |
133 |
|
{ |
134 |
0 |
mimeTypeClass = this.createMimeType(null).getClass(); |
135 |
|
} |
136 |
0 |
return mimeTypeClass; |
137 |
|
} |
138 |
|
private Class getCapabilityClass()throws ClassNotFoundException |
139 |
|
{ |
140 |
0 |
if (capabilityClass == null) |
141 |
|
{ |
142 |
0 |
capabilityClass = this.createCapability(null).getClass(); |
143 |
|
} |
144 |
0 |
return capabilityClass; |
145 |
|
} |
146 |
|
|
147 |
|
private Class getMediaTypeClass()throws ClassNotFoundException |
148 |
|
{ |
149 |
0 |
if (mediaTypeClass == null) |
150 |
|
{ |
151 |
0 |
mediaTypeClass = this.createMediaType(null).getClass(); |
152 |
|
} |
153 |
0 |
return mediaTypeClass; |
154 |
|
} |
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
public CapabilityMap getCapabilityMap(String userAgent) throws UnableToBuildCapabilityMapException |
163 |
|
{ |
164 |
0 |
CapabilityMap map = null; |
165 |
0 |
boolean bClientFound = false; |
166 |
0 |
String defaultAgent = null; |
167 |
|
|
168 |
0 |
if (userAgent == null) |
169 |
|
{ |
170 |
0 |
userAgent = DEFAULT_AGENT; |
171 |
|
} |
172 |
|
|
173 |
|
|
174 |
|
|
175 |
0 |
map = (CapabilityMap) capabilityMapCache.get(userAgent); |
176 |
|
|
177 |
0 |
if (map != null) |
178 |
|
{ |
179 |
|
|
180 |
0 |
return map; |
181 |
|
} |
182 |
|
|
183 |
0 |
while (!bClientFound) |
184 |
|
{ |
185 |
0 |
Client entry = findClient(userAgent); |
186 |
|
|
187 |
0 |
if (entry == null) |
188 |
|
{ |
189 |
0 |
if (userAgent.equals(DEFAULT_AGENT)) |
190 |
|
{ |
191 |
0 |
log.error( |
192 |
|
"CapabilityMap: Default agent not found in Client Registry !"); |
193 |
|
|
194 |
|
|
195 |
0 |
bClientFound = true; |
196 |
|
} else |
197 |
|
{ |
198 |
|
|
199 |
0 |
if (log.isDebugEnabled()) |
200 |
|
{ |
201 |
0 |
log.debug( |
202 |
|
"CapabilityMap: useragent " |
203 |
|
+ userAgent |
204 |
|
+ "unknown, falling back to default"); |
205 |
|
} |
206 |
|
|
207 |
|
|
208 |
0 |
defaultAgent = userAgent; |
209 |
0 |
userAgent = DEFAULT_AGENT; |
210 |
|
} |
211 |
|
} else |
212 |
|
{ |
213 |
|
|
214 |
0 |
map = new CapabilityMapImpl(); |
215 |
|
|
216 |
|
|
217 |
0 |
map.setClient(entry); |
218 |
|
|
219 |
|
|
220 |
0 |
Iterator capabilities = entry.getCapabilities().iterator(); |
221 |
0 |
while (capabilities.hasNext()) |
222 |
|
{ |
223 |
0 |
map.addCapability((Capability) capabilities.next()); |
224 |
|
} |
225 |
|
|
226 |
0 |
Collection mediatypes = |
227 |
|
getMediaTypesForMimeTypes(entry.getMimetypes().iterator()); |
228 |
|
|
229 |
|
|
230 |
0 |
Iterator mimetypes = entry.getMimetypes().iterator(); |
231 |
0 |
while (mimetypes.hasNext()) |
232 |
|
{ |
233 |
0 |
map.addMimetype((MimeType) mimetypes.next()); |
234 |
|
} |
235 |
|
|
236 |
0 |
Iterator media = mediatypes.iterator(); |
237 |
0 |
while (media.hasNext()) |
238 |
|
{ |
239 |
0 |
map.addMediaType((MediaType) media.next()); |
240 |
|
} |
241 |
|
|
242 |
|
|
243 |
0 |
MediaType mtEntry = |
244 |
|
getMediaTypeForMimeType(map.getPreferredType().getName()); |
245 |
|
|
246 |
0 |
map.setPreferredMediaType(mtEntry); |
247 |
|
|
248 |
|
|
249 |
0 |
capabilityMapCache.put(userAgent, map); |
250 |
0 |
if (defaultAgent != null) |
251 |
0 |
capabilityMapCache.put(defaultAgent, map); |
252 |
0 |
return map; |
253 |
|
} |
254 |
|
|
255 |
0 |
} |
256 |
|
|
257 |
0 |
if(map != null) |
258 |
|
{ |
259 |
0 |
return map; |
260 |
|
} |
261 |
|
else |
262 |
|
{ |
263 |
0 |
throw new UnableToBuildCapabilityMapException("We were unable to build a capability map for the agent, "+userAgent+ |
264 |
|
". This might be an indiciation that the capability database has not been correctly initialized."); |
265 |
|
} |
266 |
|
} |
267 |
|
|
268 |
|
|
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|
|
274 |
|
|
275 |
|
|
276 |
|
|
277 |
|
public Client findClient(String userAgent) |
278 |
|
{ |
279 |
0 |
Client clientEntry = null; |
280 |
0 |
Iterator clients = getClients(); |
281 |
|
|
282 |
0 |
if (log.isDebugEnabled()) |
283 |
|
{ |
284 |
0 |
log.debug( |
285 |
|
"ClientRegistry: Looking for client with useragent :" |
286 |
|
+ userAgent); |
287 |
|
} |
288 |
|
|
289 |
0 |
while (clients.hasNext()) |
290 |
|
{ |
291 |
0 |
Client client = (Client) clients.next(); |
292 |
0 |
if (client.getUserAgentPattern() != null) |
293 |
|
{ |
294 |
|
try |
295 |
|
{ |
296 |
|
|
297 |
0 |
String exp = client.getUserAgentPattern(); |
298 |
|
|
299 |
|
|
300 |
|
|
301 |
0 |
if (userAgent.matches(exp)) |
302 |
|
{ |
303 |
|
|
304 |
0 |
if (log.isDebugEnabled()) |
305 |
|
{ |
306 |
0 |
log.debug( |
307 |
|
"Client: " |
308 |
|
+ userAgent |
309 |
|
+ " matches " |
310 |
|
+ client.getUserAgentPattern()); |
311 |
|
} |
312 |
|
|
313 |
0 |
return client; |
314 |
|
} else |
315 |
|
{ |
316 |
0 |
if (log.isDebugEnabled()) |
317 |
|
{ |
318 |
0 |
log.debug( |
319 |
|
"Client: " |
320 |
|
+ userAgent |
321 |
|
+ " does not match " |
322 |
|
+ client.getUserAgentPattern()); |
323 |
|
} |
324 |
|
} |
325 |
0 |
} catch (java.util.regex.PatternSyntaxException e) |
326 |
|
{ |
327 |
0 |
String message = |
328 |
|
"CapabilityServiceImpl: UserAgentPattern not valid : " |
329 |
|
+ client.getUserAgentPattern() |
330 |
|
+ " : " |
331 |
|
+ e.getMessage(); |
332 |
0 |
log.error(message, e); |
333 |
0 |
} |
334 |
|
} |
335 |
0 |
} |
336 |
|
|
337 |
0 |
return clientEntry; |
338 |
|
} |
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
|
343 |
|
public Iterator getClients() |
344 |
|
{ |
345 |
0 |
if (null == clients) |
346 |
|
{ |
347 |
|
try |
348 |
|
{ |
349 |
0 |
QueryByCriteria query = QueryFactory.newQuery(getClientClass(), new Criteria()); |
350 |
0 |
query.addOrderByAscending("evalOrder"); |
351 |
0 |
this.clients = getPersistenceBrokerTemplate().getCollectionByQuery(query); |
352 |
|
} |
353 |
0 |
catch (Exception e) |
354 |
|
{ |
355 |
0 |
String message = |
356 |
|
"CapabilityServiceImpl: getClients query used invalid class "; |
357 |
0 |
log.error(message, e); |
358 |
0 |
return null; |
359 |
0 |
} |
360 |
|
} |
361 |
|
|
362 |
0 |
return this.clients.iterator(); |
363 |
|
} |
364 |
|
|
365 |
|
|
366 |
|
|
367 |
|
|
368 |
|
public Collection getMediaTypesForMimeTypes(Iterator mimetypes) |
369 |
|
{ |
370 |
|
|
371 |
|
|
372 |
0 |
Criteria filter = new Criteria(); |
373 |
|
|
374 |
0 |
Vector temp = new Vector(); |
375 |
|
|
376 |
0 |
while (mimetypes.hasNext()) |
377 |
|
{ |
378 |
0 |
MimeType mt = (MimeType) mimetypes.next(); |
379 |
|
|
380 |
|
|
381 |
|
|
382 |
|
|
383 |
|
|
384 |
0 |
temp.add(mt.getName()); |
385 |
0 |
} |
386 |
|
|
387 |
0 |
Collection co = null; |
388 |
0 |
if (temp.size() > 0) |
389 |
|
{ |
390 |
|
try |
391 |
|
{ |
392 |
0 |
filter.addIn("mimetypes.name", temp); |
393 |
0 |
QueryByCriteria query = QueryFactory.newQuery(getMediaTypeClass(), filter); |
394 |
0 |
co = getPersistenceBrokerTemplate().getCollectionByQuery(query); |
395 |
|
} |
396 |
0 |
catch (Exception e) |
397 |
|
{ |
398 |
0 |
String message = |
399 |
|
"CapabilityServiceImpl: getMediaTypesForMimeTypes -> getMediaTypeClass query used invalid class "; |
400 |
0 |
log.error(message, e); |
401 |
|
|
402 |
0 |
} |
403 |
|
} |
404 |
0 |
if (co == null || co.isEmpty()) |
405 |
|
{ |
406 |
0 |
MediaType mt = getMediaType("html"); |
407 |
0 |
Vector v = new Vector(); |
408 |
0 |
v.add(mt); |
409 |
0 |
return v; |
410 |
|
} |
411 |
0 |
return co; |
412 |
|
} |
413 |
|
|
414 |
|
|
415 |
|
|
416 |
|
|
417 |
|
public void deleteCapabilityMapCache() |
418 |
|
{ |
419 |
0 |
capabilityMapCache.clear(); |
420 |
0 |
clients = null; |
421 |
0 |
} |
422 |
|
|
423 |
|
|
424 |
|
|
425 |
|
|
426 |
|
public MediaType getMediaType(String mediaType) |
427 |
|
{ |
428 |
|
try |
429 |
|
{ |
430 |
0 |
Criteria filter = new Criteria(); |
431 |
0 |
filter.addEqualTo("name", mediaType); |
432 |
0 |
QueryByCriteria query = QueryFactory.newQuery(getMediaTypeClass(), filter); |
433 |
0 |
return (MediaType) getPersistenceBrokerTemplate().getObjectByQuery(query); |
434 |
|
} |
435 |
0 |
catch (Exception e) |
436 |
|
{ |
437 |
0 |
String message = |
438 |
|
"CapabilityServiceImpl: getMediaType query used invalid class "; |
439 |
0 |
log.error(message, e); |
440 |
0 |
return null; |
441 |
|
} |
442 |
|
} |
443 |
|
|
444 |
|
|
445 |
|
|
446 |
|
|
447 |
|
|
448 |
|
|
449 |
|
public MediaType getMediaTypeForMimeType(String mimeTypeName) |
450 |
|
{ |
451 |
|
|
452 |
0 |
Collection mediaTypeCollection = null; |
453 |
|
try |
454 |
|
{ |
455 |
0 |
Criteria filter = new Criteria(); |
456 |
0 |
filter.addEqualTo("mimetypes.name", mimeTypeName); |
457 |
|
|
458 |
0 |
QueryByCriteria query = QueryFactory.newQuery(getMediaTypeClass(), filter); |
459 |
0 |
mediaTypeCollection = getPersistenceBrokerTemplate().getCollectionByQuery(query); |
460 |
|
} |
461 |
0 |
catch (Exception e) |
462 |
|
{ |
463 |
0 |
String message = |
464 |
|
"CapabilityServiceImpl: getMediaTypeForMimeType query used invalid class "; |
465 |
0 |
log.error(message, e); |
466 |
0 |
return null; |
467 |
0 |
} |
468 |
|
|
469 |
0 |
Iterator mtIterator = mediaTypeCollection.iterator(); |
470 |
0 |
if (mtIterator.hasNext()) |
471 |
|
{ |
472 |
0 |
return (MediaType) mtIterator.next(); |
473 |
|
} else |
474 |
|
{ |
475 |
0 |
return null; |
476 |
|
} |
477 |
|
} |
478 |
|
|
479 |
|
|
480 |
|
|
481 |
|
|
482 |
|
|
483 |
|
public Iterator getCapabilities() |
484 |
|
{ |
485 |
0 |
QueryByCriteria query = null; |
486 |
|
try |
487 |
|
{ |
488 |
0 |
query = QueryFactory.newQuery(getCapabilityClass(), new Criteria()); |
489 |
|
} |
490 |
0 |
catch (Exception e) |
491 |
|
{ |
492 |
0 |
String message = |
493 |
|
"CapabilityServiceImpl: getCapabilities query used invalid class "; |
494 |
0 |
log.error(message, e); |
495 |
0 |
return null; |
496 |
0 |
} |
497 |
0 |
query.addOrderByAscending("name"); |
498 |
0 |
return getPersistenceBrokerTemplate().getCollectionByQuery(query).iterator(); |
499 |
|
} |
500 |
|
|
501 |
|
|
502 |
|
|
503 |
|
|
504 |
|
|
505 |
|
public Iterator getMimeTypes() |
506 |
|
{ |
507 |
|
try |
508 |
|
{ |
509 |
0 |
QueryByCriteria query = QueryFactory.newQuery(getMimeTypeClass(), new Criteria()); |
510 |
0 |
query.addOrderByAscending("name"); |
511 |
0 |
return getPersistenceBrokerTemplate().getCollectionByQuery(query).iterator(); |
512 |
|
} |
513 |
0 |
catch (Exception e) |
514 |
|
{ |
515 |
0 |
String message = |
516 |
|
"CapabilityServiceImpl: getMimeTypes query used invalid class "; |
517 |
0 |
log.error(message, e); |
518 |
0 |
return null; |
519 |
|
} |
520 |
|
} |
521 |
|
|
522 |
|
|
523 |
|
|
524 |
|
|
525 |
|
|
526 |
|
public Iterator getMediaTypes() |
527 |
|
{ |
528 |
|
try |
529 |
|
{ |
530 |
0 |
QueryByCriteria query = QueryFactory.newQuery(getMediaTypeClass(), new Criteria()); |
531 |
0 |
query.addOrderByAscending("name"); |
532 |
0 |
return getPersistenceBrokerTemplate().getCollectionByQuery(query).iterator(); |
533 |
|
} |
534 |
0 |
catch (Exception e) |
535 |
|
{ |
536 |
0 |
String message = |
537 |
|
"CapabilityServiceImpl: getMediaTypes query used invalid class "; |
538 |
0 |
log.error(message, e); |
539 |
0 |
return null; |
540 |
|
} |
541 |
|
} |
542 |
|
|
543 |
|
|
544 |
|
|
545 |
|
public String getMimeTypeBeanName() { |
546 |
0 |
return mimeTypeBeanName; |
547 |
|
} |
548 |
|
|
549 |
|
|
550 |
|
|
551 |
|
|
552 |
|
public void setMimeTypeBeanName(String mimeTypeBeanName) { |
553 |
0 |
this.mimeTypeBeanName = mimeTypeBeanName; |
554 |
0 |
} |
555 |
|
|
556 |
|
|
557 |
|
|
558 |
|
|
559 |
|
public String getClientBeanName() { |
560 |
0 |
return clientBeanName; |
561 |
|
} |
562 |
|
|
563 |
|
|
564 |
|
|
565 |
|
|
566 |
|
public void setClientBeanName(String clientBeanName) { |
567 |
0 |
this.clientBeanName = clientBeanName; |
568 |
0 |
} |
569 |
|
|
570 |
|
|
571 |
|
|
572 |
|
|
573 |
|
public String getMediaTypeBeanName() { |
574 |
0 |
return mediaTypeBeanName; |
575 |
|
} |
576 |
|
|
577 |
|
|
578 |
|
|
579 |
|
|
580 |
|
public void setMediaTypeBeanName(String mediaTypeBeanName) { |
581 |
0 |
this.mediaTypeBeanName = mediaTypeBeanName; |
582 |
0 |
} |
583 |
|
|
584 |
|
|
585 |
|
|
586 |
|
|
587 |
|
public String getCapabilityBeanName() { |
588 |
0 |
return capabilityBeanName; |
589 |
|
} |
590 |
|
|
591 |
|
|
592 |
|
|
593 |
|
|
594 |
|
public void setCapabilityBeanName(String capabilityBeanName) { |
595 |
0 |
this.capabilityBeanName = capabilityBeanName; |
596 |
0 |
} |
597 |
|
|
598 |
|
|
599 |
|
|
600 |
|
|
601 |
|
public MimeType createMimeType(String mimeType) |
602 |
|
throws ClassNotFoundException |
603 |
|
{ |
604 |
0 |
MimeType mimeTypeobj = null; |
605 |
0 |
if (mimeType != null) |
606 |
|
{ |
607 |
|
|
608 |
0 |
mimeTypeobj = this.getMimeType(mimeType); |
609 |
0 |
if (mimeTypeobj != null) |
610 |
0 |
return mimeTypeobj; |
611 |
|
} |
612 |
|
try |
613 |
|
{ |
614 |
0 |
mimeTypeobj = (MimeType) beanFactory.getBean( |
615 |
|
this.mimeTypeBeanName, MimeType.class); |
616 |
0 |
mimeTypeobj.setName(mimeType); |
617 |
0 |
return mimeTypeobj; |
618 |
0 |
} catch (Exception e) |
619 |
|
{ |
620 |
0 |
log.error("Failed to create capability instance for " + this.mimeTypeBeanName |
621 |
|
+ " error : " + e.getLocalizedMessage()); |
622 |
0 |
throw new ClassNotFoundException("Spring failed to create the " + this.mimeTypeBeanName |
623 |
|
+ " mimeType bean.", e); |
624 |
|
} |
625 |
|
} |
626 |
|
|
627 |
|
|
628 |
|
|
629 |
|
|
630 |
|
|
631 |
|
public Capability createCapability(String capabilityName) throws ClassNotFoundException |
632 |
|
{ |
633 |
0 |
Capability capability = null; |
634 |
0 |
if (capabilityName != null) |
635 |
|
{ |
636 |
|
|
637 |
0 |
capability = this.getCapability(capabilityName); |
638 |
0 |
if (capability != null) |
639 |
0 |
return capability; |
640 |
|
} |
641 |
|
try |
642 |
|
{ |
643 |
0 |
capability = (Capability) beanFactory.getBean( |
644 |
|
this.capabilityBeanName, Capability.class); |
645 |
0 |
capability.setName(capabilityName); |
646 |
0 |
return capability; |
647 |
0 |
} catch (Exception e) |
648 |
|
{ |
649 |
0 |
log.error("Failed to create capability instance for " + this.capabilityBeanName |
650 |
|
+ " error : " + e.getLocalizedMessage()); |
651 |
0 |
throw new ClassNotFoundException("Spring failed to create the " |
652 |
|
+ " capability bean.", e); |
653 |
|
} |
654 |
|
} |
655 |
|
|
656 |
|
|
657 |
|
|
658 |
|
|
659 |
|
public MediaType createMediaType(String mediaTypeName) throws ClassNotFoundException |
660 |
|
{ |
661 |
0 |
MediaType mediaType = null; |
662 |
0 |
if (mediaTypeName != null) |
663 |
|
{ |
664 |
|
|
665 |
0 |
mediaType = this.getMediaType(mediaTypeName); |
666 |
0 |
if (mediaType != null) |
667 |
0 |
return mediaType; |
668 |
|
} |
669 |
|
try |
670 |
|
{ |
671 |
0 |
mediaType = (MediaType) beanFactory.getBean( |
672 |
|
this.mediaTypeBeanName, MediaType.class); |
673 |
0 |
mediaType.setName(mediaTypeName); |
674 |
0 |
return mediaType; |
675 |
0 |
} catch (Exception e) |
676 |
|
{ |
677 |
0 |
log.error("Failed to create mediaType instance for " + this.mediaTypeBeanName |
678 |
|
+ " error : " + e.getLocalizedMessage()); |
679 |
0 |
throw new ClassNotFoundException("Spring failed to create the " |
680 |
|
+ " mediaType bean.", e); |
681 |
|
} |
682 |
|
} |
683 |
|
|
684 |
|
|
685 |
|
|
686 |
|
|
687 |
|
|
688 |
|
public Client createClient(String clientName) throws ClassNotFoundException |
689 |
|
{ |
690 |
0 |
Client client = null; |
691 |
0 |
if (clientName != null) |
692 |
|
{ |
693 |
|
|
694 |
0 |
client = this.getClient(clientName); |
695 |
0 |
if (client != null) |
696 |
0 |
return client; |
697 |
|
} |
698 |
|
try |
699 |
|
{ |
700 |
0 |
client = (Client) beanFactory.getBean( |
701 |
|
this.clientBeanName, Client.class); |
702 |
0 |
client.setName(clientName); |
703 |
0 |
return client; |
704 |
0 |
} catch (Exception e) |
705 |
|
{ |
706 |
0 |
log.error("Failed to create client instance for " + this.clientBeanName |
707 |
|
+ " error : " + e.getLocalizedMessage()); |
708 |
0 |
throw new ClassNotFoundException("Spring failed to create the " |
709 |
|
+ " client bean.", e); |
710 |
|
} |
711 |
|
} |
712 |
|
|
713 |
|
|
714 |
|
|
715 |
|
public MimeType getMimeType(String mimeType) |
716 |
|
{ |
717 |
|
try |
718 |
|
{ |
719 |
0 |
Criteria filter = new Criteria(); |
720 |
0 |
filter.addEqualTo("name", mimeType); |
721 |
0 |
QueryByCriteria query = QueryFactory.newQuery(getMimeTypeClass(), filter); |
722 |
0 |
return (MimeType) getPersistenceBrokerTemplate().getObjectByQuery(query); |
723 |
|
} |
724 |
0 |
catch (Exception e) |
725 |
|
{ |
726 |
0 |
String message = |
727 |
|
"MimeTypeserviceImpl: getCapability - query for getCapabilityClass failed "; |
728 |
0 |
log.error(message, e); |
729 |
0 |
return null; |
730 |
|
|
731 |
|
} |
732 |
|
|
733 |
|
} |
734 |
|
|
735 |
|
|
736 |
|
|
737 |
|
|
738 |
|
|
739 |
|
public Client getClient(String clientName) |
740 |
|
{ |
741 |
|
try |
742 |
|
{ |
743 |
0 |
Criteria filter = new Criteria(); |
744 |
0 |
filter.addEqualTo("name", clientName); |
745 |
0 |
QueryByCriteria query = QueryFactory.newQuery(getClientClass(), filter); |
746 |
0 |
return (Client) getPersistenceBrokerTemplate().getObjectByQuery(query); |
747 |
|
} |
748 |
0 |
catch (Exception e) |
749 |
|
{ |
750 |
0 |
String message = |
751 |
|
"MimeTypeserviceImpl: getClient - query for getClientClass failed "; |
752 |
0 |
log.error(message, e); |
753 |
0 |
return null; |
754 |
|
|
755 |
|
} |
756 |
|
} |
757 |
|
|
758 |
|
|
759 |
|
|
760 |
|
|
761 |
|
|
762 |
|
public Capability getCapability(String capability) |
763 |
|
{ |
764 |
|
try |
765 |
|
{ |
766 |
|
|
767 |
0 |
Criteria filter = new Criteria(); |
768 |
0 |
filter.addEqualTo("name", capability); |
769 |
0 |
QueryByCriteria query = QueryFactory.newQuery(getCapabilityClass(), filter); |
770 |
0 |
return (Capability) getPersistenceBrokerTemplate().getObjectByQuery(query); |
771 |
|
} |
772 |
0 |
catch (Exception e) |
773 |
|
{ |
774 |
0 |
String message = |
775 |
|
"MimeTypeserviceImpl: getCapability - query for getCapabilityClass failed "; |
776 |
0 |
log.error(message, e); |
777 |
0 |
return null; |
778 |
|
|
779 |
|
} |
780 |
|
} |
781 |
|
|
782 |
|
|
783 |
|
|
784 |
|
|
785 |
|
|
786 |
|
|
787 |
|
|
788 |
|
public void storeMediaType(MediaType mediaType) throws CapabilitiesException |
789 |
|
{ |
790 |
|
|
791 |
|
|
792 |
0 |
getPersistenceBrokerTemplate().store(mediaType); |
793 |
0 |
} |
794 |
|
|
795 |
|
|
796 |
|
|
797 |
|
|
798 |
|
|
799 |
|
|
800 |
|
public void deleteMediaType(MediaType mediaType) |
801 |
|
throws CapabilitiesException |
802 |
|
{ |
803 |
|
|
804 |
0 |
getPersistenceBrokerTemplate().delete(mediaType); |
805 |
0 |
} |
806 |
|
|
807 |
|
|
808 |
|
|
809 |
|
|
810 |
|
|
811 |
|
|
812 |
|
|
813 |
|
public void storeCapability(Capability capability) throws CapabilitiesException |
814 |
|
{ |
815 |
|
|
816 |
|
|
817 |
0 |
getPersistenceBrokerTemplate().store(capability); |
818 |
0 |
} |
819 |
|
|
820 |
|
|
821 |
|
|
822 |
|
|
823 |
|
|
824 |
|
|
825 |
|
public void deleteCapability(Capability capability) |
826 |
|
throws CapabilitiesException |
827 |
|
{ |
828 |
|
|
829 |
0 |
getPersistenceBrokerTemplate().delete(capability); |
830 |
0 |
} |
831 |
|
|
832 |
|
|
833 |
|
|
834 |
|
|
835 |
|
|
836 |
|
|
837 |
|
public void storeMimeType(MimeType mimeType) throws CapabilitiesException |
838 |
|
{ |
839 |
|
|
840 |
|
|
841 |
0 |
getPersistenceBrokerTemplate().store(mimeType); |
842 |
0 |
} |
843 |
|
|
844 |
|
|
845 |
|
|
846 |
|
|
847 |
|
|
848 |
|
|
849 |
|
public void deleteMimeType(MimeType mimeType) |
850 |
|
throws CapabilitiesException |
851 |
|
{ |
852 |
|
|
853 |
0 |
getPersistenceBrokerTemplate().delete(mimeType); |
854 |
0 |
} |
855 |
|
|
856 |
|
|
857 |
|
|
858 |
|
|
859 |
|
|
860 |
|
|
861 |
|
|
862 |
|
|
863 |
|
|
864 |
|
public void storeClient(Client client) throws CapabilitiesException |
865 |
|
{ |
866 |
|
|
867 |
|
|
868 |
0 |
getPersistenceBrokerTemplate().store(client); |
869 |
0 |
} |
870 |
|
|
871 |
|
|
872 |
|
|
873 |
|
|
874 |
|
|
875 |
|
|
876 |
|
public void deleteClient(Client client) |
877 |
|
throws CapabilitiesException |
878 |
|
{ |
879 |
|
|
880 |
0 |
getPersistenceBrokerTemplate().delete(client); |
881 |
0 |
} |
882 |
|
|
883 |
|
} |