Source Code Cross Referenced for JetspeedCapabilities.java in  » Portal » jetspeed-2.1.3 » org » apache » jetspeed » capabilities » impl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » jetspeed 2.1.3 » org.apache.jetspeed.capabilities.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.jetspeed.capabilities.impl;
018:
019:        import java.util.Collection;
020:        import java.util.Hashtable;
021:        import java.util.Iterator;
022:        import java.util.Properties;
023:        import java.util.Vector;
024:
025:        import org.apache.commons.logging.Log;
026:        import org.apache.commons.logging.LogFactory;
027:        import org.apache.jetspeed.capabilities.Capabilities;
028:        import org.apache.jetspeed.capabilities.CapabilitiesException;
029:        import org.apache.jetspeed.capabilities.Capability;
030:        import org.apache.jetspeed.capabilities.CapabilityMap;
031:        import org.apache.jetspeed.capabilities.Client;
032:        import org.apache.jetspeed.capabilities.MediaType;
033:        import org.apache.jetspeed.capabilities.MimeType;
034:        import org.apache.jetspeed.capabilities.UnableToBuildCapabilityMapException;
035:        import org.apache.jetspeed.components.dao.InitablePersistenceBrokerDaoSupport;
036:        import org.apache.ojb.broker.query.Criteria;
037:        import org.apache.ojb.broker.query.QueryByCriteria;
038:        import org.apache.ojb.broker.query.QueryFactory;
039:        import org.springframework.beans.BeansException;
040:        import org.springframework.beans.factory.BeanFactory;
041:        import org.springframework.beans.factory.BeanFactoryAware;
042:
043:        /**
044:         * Jetspeed Capabilities
045:         *
046:         * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
047:         * @author <a href="mailto:roger.ruttimann@earthlink.net">Roger Ruttimann</a>
048:         * @version $Id: JetspeedCapabilities.java 517124 2007-03-12 08:10:25Z ate $
049:         */
050:        public class JetspeedCapabilities extends
051:                InitablePersistenceBrokerDaoSupport implements  Capabilities,
052:                BeanFactoryAware {
053:            private static final Log log = LogFactory
054:                    .getLog(JetspeedCapabilities.class);
055:
056:            public static final String DEFAULT_AGENT = "Mozilla/4.0";
057:
058:            public static final String AGENT_XML = "agentxml/1.0";
059:
060:            // Cache for the capability maps
061:            Hashtable capabilityMapCache = new Hashtable();
062:
063:            private Collection clients = null;
064:
065:            /**
066:             * added support for bean factory to create profile rules
067:             */
068:            private BeanFactory beanFactory;
069:
070:            /** named bean references */
071:            private String clientBeanName;
072:            private String capabilityBeanName;
073:            private String mimeTypeBeanName;
074:            private String mediaTypeBeanName;
075:
076:            private Class clientClass;
077:            private Class capabilityClass;
078:            private Class mimeTypeClass;
079:            private Class mediaTypeClass;
080:
081:            public JetspeedCapabilities(String repositoryPath,
082:                    String clientBeanName, String mediaTypeBeanName,
083:                    String mimeTypeBeanName, String capabilityBeanName) {
084:                super (repositoryPath);
085:                this .clientBeanName = clientBeanName;
086:                this .capabilityBeanName = capabilityBeanName;
087:                this .mimeTypeBeanName = mimeTypeBeanName;
088:                this .mediaTypeBeanName = mediaTypeBeanName;
089:            }
090:
091:            /**
092:             * Create a JetspeedProfiler with properties. Expected properties are:
093:             * 
094:             * 	   defaultRule   = the default profiling rule
095:             *     anonymousUser = the name of the anonymous user
096:             *     persistenceStoreName = The name of the persistence persistenceStore component to connect to  
097:             *     services.profiler.locator.impl = the pluggable Profile Locator impl
098:             *     services.profiler.principalRule.impl = the pluggable Principal Rule impl
099:             *     services.profiler.profilingRule.impl = the pluggable Profiling Rule impl
100:             *      
101:             * @param persistenceStore  The persistence persistenceStore 
102:             * @param properties  Properties for this component described above
103:             * @deprecated As of release 2.1, property-based class references replaced
104:             *             by container managed bean factory
105:             */
106:            public JetspeedCapabilities(String repositoryPath,
107:                    Properties properties) {
108:                super (repositoryPath);
109:            }
110:
111:            /*
112:             * Method called automatically by Spring container upon initialization
113:             * 
114:             * @param beanFactory automatically provided by framework @throws
115:             * BeansException
116:             */
117:            public void setBeanFactory(BeanFactory beanFactory)
118:                    throws BeansException {
119:                this .beanFactory = beanFactory;
120:            }
121:
122:            private Class getClientClass() throws ClassNotFoundException {
123:                if (clientClass == null) {
124:                    clientClass = createClient(null).getClass();
125:                }
126:                return clientClass;
127:            }
128:
129:            private Class getMimeTypeClass() throws ClassNotFoundException {
130:                if (mimeTypeClass == null) {
131:                    mimeTypeClass = this .createMimeType(null).getClass();
132:                }
133:                return mimeTypeClass;
134:            }
135:
136:            private Class getCapabilityClass() throws ClassNotFoundException {
137:                if (capabilityClass == null) {
138:                    capabilityClass = this .createCapability(null).getClass();
139:                }
140:                return capabilityClass;
141:            }
142:
143:            private Class getMediaTypeClass() throws ClassNotFoundException {
144:                if (mediaTypeClass == null) {
145:                    mediaTypeClass = this .createMediaType(null).getClass();
146:                }
147:                return mediaTypeClass;
148:            }
149:
150:            /**
151:             * @param userAgent Agent from the request
152:             * @throws UnableToBuildCapabilityMapException
153:             * @see org.apache.jetspeed.services.capability.CapabilityService#getCapabilityMap(java.lang.String)
154:             */
155:            public CapabilityMap getCapabilityMap(String userAgent)
156:                    throws UnableToBuildCapabilityMapException {
157:                CapabilityMap map = null;
158:                boolean bClientFound = false;
159:                String defaultAgent = null;
160:
161:                if (userAgent == null) {
162:                    userAgent = DEFAULT_AGENT;
163:                }
164:
165:                // Check the cache if we have already a capability map for
166:                // the given Agent
167:                map = (CapabilityMap) capabilityMapCache.get(userAgent);
168:
169:                if (map != null) {
170:                    // Entry found
171:                    return map;
172:                }
173:
174:                while (!bClientFound) {
175:                    Client entry = findClient(userAgent);
176:
177:                    if (entry == null) {
178:                        if (userAgent.equals(DEFAULT_AGENT)) {
179:                            log
180:                                    .error("CapabilityMap: Default agent not found in Client Registry !");
181:
182:                            // Stop searching -- event the default userAgent can't be found
183:                            bClientFound = true;
184:                        } else {
185:                            // Retry with the default Agent
186:                            if (log.isDebugEnabled()) {
187:                                log.debug("CapabilityMap: useragent "
188:                                        + userAgent
189:                                        + "unknown, falling back to default");
190:                            }
191:
192:                            // Use default Client
193:                            defaultAgent = userAgent;
194:                            userAgent = DEFAULT_AGENT;
195:                        }
196:                    } else {
197:                        // Found Client entry start populating the capability map.
198:                        map = new CapabilityMapImpl();
199:
200:                        // Add client to CapabilityMap
201:                        map.setClient(entry);
202:
203:                        // Add capabilities
204:                        Iterator capabilities = entry.getCapabilities()
205:                                .iterator();
206:                        while (capabilities.hasNext()) {
207:                            map.addCapability((Capability) capabilities.next());
208:                        }
209:
210:                        Collection mediatypes = getMediaTypesForMimeTypes(entry
211:                                .getMimetypes().iterator());
212:
213:                        // Add Mimetypes to map
214:                        Iterator mimetypes = entry.getMimetypes().iterator();
215:                        while (mimetypes.hasNext()) {
216:                            map.addMimetype((MimeType) mimetypes.next());
217:                        }
218:
219:                        Iterator media = mediatypes.iterator();
220:                        while (media.hasNext()) {
221:                            map.addMediaType((MediaType) media.next());
222:                        }
223:
224:                        //Set preferred Mimetype
225:                        MediaType mtEntry = getMediaTypeForMimeType(map
226:                                .getPreferredType().getName());
227:
228:                        map.setPreferredMediaType(mtEntry);
229:
230:                        // Add map to cache
231:                        capabilityMapCache.put(userAgent, map);
232:                        if (defaultAgent != null)
233:                            capabilityMapCache.put(defaultAgent, map);
234:                        return map;
235:                    }
236:
237:                }
238:
239:                if (map != null) {
240:                    return map;
241:                } else {
242:                    throw new UnableToBuildCapabilityMapException(
243:                            "We were unable to build a capability map for the agent, "
244:                                    + userAgent
245:                                    + ".  This might be an indiciation that the capability database has not been correctly initialized.");
246:                }
247:            }
248:
249:            /**
250:             * Returns the client which matches the given useragent string.
251:             *
252:             * @param useragent     the useragent to match
253:             * @return the found client or null if the user-agent does not match any
254:             *  defined client
255:             * @see org.apache.jetspeed.capabilities.CapabilityService#findClient(java.lang.String)
256:             */
257:
258:            public Client findClient(String userAgent) {
259:                Client clientEntry = null;
260:                Iterator clients = getClients();
261:
262:                if (log.isDebugEnabled()) {
263:                    log
264:                            .debug("ClientRegistry: Looking for client with useragent :"
265:                                    + userAgent);
266:                }
267:
268:                while (clients.hasNext()) {
269:                    Client client = (Client) clients.next();
270:                    if (client.getUserAgentPattern() != null) {
271:                        try {
272:                            // Java 1.4 has regular expressions build in
273:                            String exp = client.getUserAgentPattern();
274:                            //RE r = new RE(client.getUserAgentPattern());
275:                            //r.setMatchFlags(RE.MATCH_CASEINDEPENDENT);
276:                            //if (r.match(userAgent))
277:                            if (userAgent.matches(exp)) {
278:
279:                                if (log.isDebugEnabled()) {
280:                                    log.debug("Client: " + userAgent
281:                                            + " matches "
282:                                            + client.getUserAgentPattern());
283:                                }
284:
285:                                return client;
286:                            } else {
287:                                if (log.isDebugEnabled()) {
288:                                    log.debug("Client: " + userAgent
289:                                            + " does not match "
290:                                            + client.getUserAgentPattern());
291:                                }
292:                            }
293:                        } catch (java.util.regex.PatternSyntaxException e) {
294:                            String message = "CapabilityServiceImpl: UserAgentPattern not valid : "
295:                                    + client.getUserAgentPattern()
296:                                    + " : "
297:                                    + e.getMessage();
298:                            log.error(message, e);
299:                        }
300:                    }
301:                }
302:
303:                return clientEntry;
304:            }
305:
306:            /* 
307:             * @see org.apache.jetspeed.capabilities.CapabilityService#getClients()
308:             */
309:            public Iterator getClients() {
310:                if (null == clients) {
311:                    try {
312:                        QueryByCriteria query = QueryFactory.newQuery(
313:                                getClientClass(), new Criteria());
314:                        query.addOrderByAscending("evalOrder");
315:                        this .clients = getPersistenceBrokerTemplate()
316:                                .getCollectionByQuery(query);
317:                    } catch (Exception e) {
318:                        String message = "CapabilityServiceImpl: getClients query used invalid class ";
319:                        log.error(message, e);
320:                        return null;
321:                    }
322:                }
323:
324:                return this .clients.iterator();
325:            }
326:
327:            /* 
328:             * @see org.apache.jetspeed.capabilities.CapabilityService#getMediaTypesForMimeTypes(java.util.Iterator)
329:             */
330:            public Collection getMediaTypesForMimeTypes(Iterator mimetypes) {
331:                //Find the MediaType by matching the Mimetype
332:
333:                Criteria filter = new Criteria();
334:
335:                Vector temp = new Vector();
336:                // Add Mimetypes to map and create query
337:                while (mimetypes.hasNext()) {
338:                    MimeType mt = (MimeType) mimetypes.next();
339:
340:                    // Add mimetype to query
341:                    // Note: mimetypes is a member of MediaTypeImpl
342:                    // criteria.addEqualTo("mimetypes.name", mt.getName());
343:                    //stuff.add(new Integer(mt.getMimetypeId()));
344:                    temp.add(mt.getName());
345:                }
346:
347:                Collection co = null;
348:                if (temp.size() > 0) {
349:                    try {
350:                        filter.addIn("mimetypes.name", temp);
351:                        QueryByCriteria query = QueryFactory.newQuery(
352:                                getMediaTypeClass(), filter);
353:                        co = getPersistenceBrokerTemplate()
354:                                .getCollectionByQuery(query);
355:                    } catch (Exception e) {
356:                        String message = "CapabilityServiceImpl: getMediaTypesForMimeTypes -> getMediaTypeClass query used invalid class ";
357:                        log.error(message, e);
358:
359:                    }
360:                }
361:                if (co == null || co.isEmpty()) {
362:                    MediaType mt = getMediaType("html");
363:                    Vector v = new Vector();
364:                    v.add(mt);
365:                    return v;
366:                }
367:                return co;
368:            }
369:
370:            /* 
371:             * @see org.apache.jetspeed.capabilities.CapabilityService#deleteCapabilityMapCache()
372:             */
373:            public void deleteCapabilityMapCache() {
374:                capabilityMapCache.clear();
375:                clients = null;
376:            }
377:
378:            /* (non-Javadoc)
379:             * @see org.apache.jetspeed.capabilities.CapabilityService#getMediaType(java.lang.String)
380:             */
381:            public MediaType getMediaType(String mediaType) {
382:                try {
383:                    Criteria filter = new Criteria();
384:                    filter.addEqualTo("name", mediaType);
385:                    QueryByCriteria query = QueryFactory.newQuery(
386:                            getMediaTypeClass(), filter);
387:                    return (MediaType) getPersistenceBrokerTemplate()
388:                            .getObjectByQuery(query);
389:                } catch (Exception e) {
390:                    String message = "CapabilityServiceImpl: getMediaType query used invalid class ";
391:                    log.error(message, e);
392:                    return null;
393:                }
394:            }
395:
396:            /**
397:             * getMediaTypeForMimeType
398:             * @param mimeType to use for lookup
399:             * @return MediaTypeEntry that matches the lookup in the MEDIATYPE_TO_MIMETYPE table
400:             */
401:            public MediaType getMediaTypeForMimeType(String mimeTypeName) {
402:                //Find the MediaType by matching the Mimetype
403:                Collection mediaTypeCollection = null;
404:                try {
405:                    Criteria filter = new Criteria();
406:                    filter.addEqualTo("mimetypes.name", mimeTypeName);
407:
408:                    QueryByCriteria query = QueryFactory.newQuery(
409:                            getMediaTypeClass(), filter);
410:                    mediaTypeCollection = getPersistenceBrokerTemplate()
411:                            .getCollectionByQuery(query);
412:                } catch (Exception e) {
413:                    String message = "CapabilityServiceImpl: getMediaTypeForMimeType query used invalid class ";
414:                    log.error(message, e);
415:                    return null;
416:                }
417:
418:                Iterator mtIterator = mediaTypeCollection.iterator();
419:                if (mtIterator.hasNext()) {
420:                    return (MediaType) mtIterator.next();
421:                } else {
422:                    return null;
423:                }
424:            }
425:
426:            /**
427:             * Obtain an iterator of all existing capabilities.
428:             * @return Returns an iterator for all existing Capabilities of type <code>Capability</code>
429:             */
430:            public Iterator getCapabilities() {
431:                QueryByCriteria query = null;
432:                try {
433:                    query = QueryFactory.newQuery(getCapabilityClass(),
434:                            new Criteria());
435:                } catch (Exception e) {
436:                    String message = "CapabilityServiceImpl: getCapabilities query used invalid class ";
437:                    log.error(message, e);
438:                    return null;
439:                }
440:                query.addOrderByAscending("name");
441:                return getPersistenceBrokerTemplate().getCollectionByQuery(
442:                        query).iterator();
443:            }
444:
445:            /**
446:             * Obtain an iterator of all existing mime types.
447:             * @return Returns an iterator for all existing Mime Types of type <code>MimeType</code>
448:             */
449:            public Iterator getMimeTypes() {
450:                try {
451:                    QueryByCriteria query = QueryFactory.newQuery(
452:                            getMimeTypeClass(), new Criteria());
453:                    query.addOrderByAscending("name");
454:                    return getPersistenceBrokerTemplate().getCollectionByQuery(
455:                            query).iterator();
456:                } catch (Exception e) {
457:                    String message = "CapabilityServiceImpl: getMimeTypes query used invalid class ";
458:                    log.error(message, e);
459:                    return null;
460:                }
461:            }
462:
463:            /**
464:             * Obtain an iterator of all existing media types.
465:             * @return Returns an iterator for all existing media types of type <code>MediaType</code>
466:             */
467:            public Iterator getMediaTypes() {
468:                try {
469:                    QueryByCriteria query = QueryFactory.newQuery(
470:                            getMediaTypeClass(), new Criteria());
471:                    query.addOrderByAscending("name");
472:                    return getPersistenceBrokerTemplate().getCollectionByQuery(
473:                            query).iterator();
474:                } catch (Exception e) {
475:                    String message = "CapabilityServiceImpl: getMediaTypes query used invalid class ";
476:                    log.error(message, e);
477:                    return null;
478:                }
479:            }
480:
481:            /* 
482:             * @see org.apache.jetspeed.capabilities.Capabilities#getMimeTypeBeanName()
483:             */
484:            public String getMimeTypeBeanName() {
485:                return mimeTypeBeanName;
486:            }
487:
488:            /* 
489:             * @see org.apache.jetspeed.capabilities.Capabilities#setMimeTypeBeanName(String)
490:             */
491:            public void setMimeTypeBeanName(String mimeTypeBeanName) {
492:                this .mimeTypeBeanName = mimeTypeBeanName;
493:            }
494:
495:            /* 
496:             * @see org.apache.jetspeed.capabilities.Capabilities#getClientBeanName()
497:             */
498:            public String getClientBeanName() {
499:                return clientBeanName;
500:            }
501:
502:            /* 
503:             * @see org.apache.jetspeed.capabilities.Capabilities#setClientBeanName(String)
504:             */
505:            public void setClientBeanName(String clientBeanName) {
506:                this .clientBeanName = clientBeanName;
507:            }
508:
509:            /* 
510:             * @see org.apache.jetspeed.capabilities.Capabilities#getMediaTypeBeanName()
511:             */
512:            public String getMediaTypeBeanName() {
513:                return mediaTypeBeanName;
514:            }
515:
516:            /* 
517:             * @see org.apache.jetspeed.capabilities.Capabilities#setMediaTypeBeanName(String)
518:             */
519:            public void setMediaTypeBeanName(String mediaTypeBeanName) {
520:                this .mediaTypeBeanName = mediaTypeBeanName;
521:            }
522:
523:            /* 
524:             * @see org.apache.jetspeed.capabilities.Capabilities#getCapabilityBeanName()
525:             */
526:            public String getCapabilityBeanName() {
527:                return capabilityBeanName;
528:            }
529:
530:            /* 
531:             * @see org.apache.jetspeed.capabilities.Capabilities#setCapabilityBeanName(String)
532:             */
533:            public void setCapabilityBeanName(String capabilityBeanName) {
534:                this .capabilityBeanName = capabilityBeanName;
535:            }
536:
537:            /* 
538:             * @see org.apache.jetspeed.capabilities.Capabilities#createMimeType(String)
539:             */
540:            public MimeType createMimeType(String mimeType)
541:                    throws ClassNotFoundException {
542:                MimeType mimeTypeobj = null;
543:                if (mimeType != null) {
544:                    //try to find it in space
545:                    mimeTypeobj = this .getMimeType(mimeType);
546:                    if (mimeTypeobj != null)
547:                        return mimeTypeobj;
548:                }
549:                try {
550:                    mimeTypeobj = (MimeType) beanFactory.getBean(
551:                            this .mimeTypeBeanName, MimeType.class);
552:                    mimeTypeobj.setName(mimeType);
553:                    return mimeTypeobj;
554:                } catch (Exception e) {
555:                    log.error("Failed to create capability instance for "
556:                            + this .mimeTypeBeanName + " error : "
557:                            + e.getLocalizedMessage());
558:                    throw new ClassNotFoundException(
559:                            "Spring failed to create the "
560:                                    + this .mimeTypeBeanName + " mimeType bean.",
561:                            e);
562:                }
563:            }
564:
565:            /* 
566:             * @see org.apache.jetspeed.capabilities.Capabilities#createCapability(String)
567:             */
568:            public Capability createCapability(String capabilityName)
569:                    throws ClassNotFoundException {
570:                Capability capability = null;
571:                if (capabilityName != null) {
572:                    //try to find it in space
573:                    capability = this .getCapability(capabilityName);
574:                    if (capability != null)
575:                        return capability;
576:                }
577:                try {
578:                    capability = (Capability) beanFactory.getBean(
579:                            this .capabilityBeanName, Capability.class);
580:                    capability.setName(capabilityName);
581:                    return capability;
582:                } catch (Exception e) {
583:                    log.error("Failed to create capability instance for "
584:                            + this .capabilityBeanName + " error : "
585:                            + e.getLocalizedMessage());
586:                    throw new ClassNotFoundException(
587:                            "Spring failed to create the "
588:                                    + " capability bean.", e);
589:                }
590:            }
591:
592:            /* 
593:             * @see org.apache.jetspeed.capabilities.Capabilities#createMediaType(String)
594:             */
595:            public MediaType createMediaType(String mediaTypeName)
596:                    throws ClassNotFoundException {
597:                MediaType mediaType = null;
598:                if (mediaTypeName != null) {
599:                    //try to find it in space
600:                    mediaType = this .getMediaType(mediaTypeName);
601:                    if (mediaType != null)
602:                        return mediaType;
603:                }
604:                try {
605:                    mediaType = (MediaType) beanFactory.getBean(
606:                            this .mediaTypeBeanName, MediaType.class);
607:                    mediaType.setName(mediaTypeName);
608:                    return mediaType;
609:                } catch (Exception e) {
610:                    log.error("Failed to create mediaType instance for "
611:                            + this .mediaTypeBeanName + " error : "
612:                            + e.getLocalizedMessage());
613:                    throw new ClassNotFoundException(
614:                            "Spring failed to create the " + " mediaType bean.",
615:                            e);
616:                }
617:            }
618:
619:            /* 
620:             * @see org.apache.jetspeed.capabilities.Capabilities#createClient(String)
621:             */
622:            public Client createClient(String clientName)
623:                    throws ClassNotFoundException {
624:                Client client = null;
625:                if (clientName != null) {
626:                    //try to find it in space
627:                    client = this .getClient(clientName);
628:                    if (client != null)
629:                        return client;
630:                }
631:                try {
632:                    client = (Client) beanFactory.getBean(this .clientBeanName,
633:                            Client.class);
634:                    client.setName(clientName);
635:                    return client;
636:                } catch (Exception e) {
637:                    log.error("Failed to create client instance for "
638:                            + this .clientBeanName + " error : "
639:                            + e.getLocalizedMessage());
640:                    throw new ClassNotFoundException(
641:                            "Spring failed to create the " + " client bean.", e);
642:                }
643:            }
644:
645:            /* (non-Javadoc)
646:             * @see org.apache.jetspeed.capabilities.MimeTypeservice#getCapability(java.lang.String)
647:             */
648:            public MimeType getMimeType(String mimeType) {
649:                try {
650:                    Criteria filter = new Criteria();
651:                    filter.addEqualTo("name", mimeType);
652:                    QueryByCriteria query = QueryFactory.newQuery(
653:                            getMimeTypeClass(), filter);
654:                    return (MimeType) getPersistenceBrokerTemplate()
655:                            .getObjectByQuery(query);
656:                } catch (Exception e) {
657:                    String message = "MimeTypeserviceImpl: getCapability - query for getCapabilityClass failed ";
658:                    log.error(message, e);
659:                    return null;
660:
661:                }
662:
663:            }
664:
665:            /* (non-Javadoc)
666:             * @see org.apache.jetspeed.capabilities.MimeTypeservice#getClientjava.lang.String)
667:             */
668:            public Client getClient(String clientName) {
669:                try {
670:                    Criteria filter = new Criteria();
671:                    filter.addEqualTo("name", clientName);
672:                    QueryByCriteria query = QueryFactory.newQuery(
673:                            getClientClass(), filter);
674:                    return (Client) getPersistenceBrokerTemplate()
675:                            .getObjectByQuery(query);
676:                } catch (Exception e) {
677:                    String message = "MimeTypeserviceImpl: getClient - query for getClientClass failed ";
678:                    log.error(message, e);
679:                    return null;
680:
681:                }
682:            }
683:
684:            /* (non-Javadoc)
685:             * @see org.apache.jetspeed.capabilities.MimeTypeservice#getCapability(java.lang.String)
686:             */
687:            public Capability getCapability(String capability) {
688:                try {
689:
690:                    Criteria filter = new Criteria();
691:                    filter.addEqualTo("name", capability);
692:                    QueryByCriteria query = QueryFactory.newQuery(
693:                            getCapabilityClass(), filter);
694:                    return (Capability) getPersistenceBrokerTemplate()
695:                            .getObjectByQuery(query);
696:                } catch (Exception e) {
697:                    String message = "MimeTypeserviceImpl: getCapability - query for getCapabilityClass failed ";
698:                    log.error(message, e);
699:                    return null;
700:
701:                }
702:            }
703:
704:            /* 
705:             * (non-Javadoc)
706:             * 
707:             * @see org.apache.jetspeed.capabilities.Capabilities#storeMediaType(MediaType)
708:             */
709:            public void storeMediaType(MediaType mediaType)
710:                    throws CapabilitiesException {
711:
712:                //TODO: change exception to better indicate cause
713:                getPersistenceBrokerTemplate().store(mediaType);
714:            }
715:
716:            /*
717:             * (non-Javadoc)
718:             * 
719:             * @see org.apache.jetspeed.capabilities.Capabilities#deleteMediaType(MediaType)
720:             */
721:            public void deleteMediaType(MediaType mediaType)
722:                    throws CapabilitiesException {
723:                //TODO: change exception to better indicate cause
724:                getPersistenceBrokerTemplate().delete(mediaType);
725:            }
726:
727:            /* 
728:             * (non-Javadoc)
729:             * 
730:             * @see org.apache.jetspeed.capabilities.Capabilities#storeCapability(MediaType)
731:             */
732:            public void storeCapability(Capability capability)
733:                    throws CapabilitiesException {
734:
735:                //TODO: change exception to better indicate cause
736:                getPersistenceBrokerTemplate().store(capability);
737:            }
738:
739:            /*
740:             * (non-Javadoc)
741:             * 
742:             * @see org.apache.jetspeed.capabilities.Capabilities#deleteCapability(Capability)
743:             */
744:            public void deleteCapability(Capability capability)
745:                    throws CapabilitiesException {
746:                //TODO: change exception to better indicate cause
747:                getPersistenceBrokerTemplate().delete(capability);
748:            }
749:
750:            /* 
751:             * (non-Javadoc)
752:             * 
753:             * @see org.apache.jetspeed.capabilities.Capabilities#storeMimeType(MimeType)
754:             */
755:            public void storeMimeType(MimeType mimeType)
756:                    throws CapabilitiesException {
757:
758:                //TODO: change exception to better indicate cause
759:                getPersistenceBrokerTemplate().store(mimeType);
760:            }
761:
762:            /*
763:             * (non-Javadoc)
764:             * 
765:             * @see org.apache.jetspeed.capabilities.Capabilities#deleteMimeType(MimeType)
766:             */
767:            public void deleteMimeType(MimeType mimeType)
768:                    throws CapabilitiesException {
769:                //TODO: change exception to better indicate cause
770:                getPersistenceBrokerTemplate().delete(mimeType);
771:            }
772:
773:            /* 
774:             * (non-Javadoc)
775:             * 
776:             * @see org.apache.jetspeed.capabilities.Capabilities#storeClient(MediaType)
777:             */
778:            public void storeClient(Client client) throws CapabilitiesException {
779:
780:                //TODO: change exception to better indicate cause
781:                getPersistenceBrokerTemplate().store(client);
782:            }
783:
784:            /*
785:             * (non-Javadoc)
786:             * 
787:             * @see org.apache.jetspeed.capabilities.Capabilities#deleteClient(Client)
788:             */
789:            public void deleteClient(Client client)
790:                    throws CapabilitiesException {
791:                //TODO: change exception to better indicate cause
792:                getPersistenceBrokerTemplate().delete(client);
793:            }
794:
795:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.